blob: 48fada0ccf8d5527ffd16ab685d3b0a65605f2c4 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2011, 2017 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.r.core.renv;
public class REnvUtils {
public static String encode(final IREnv rEnv) {
if (rEnv != null) {
final String name= rEnv.getName();
if (name != null && !IREnv.DEFAULT_WORKBENCH_ENV_ID.equals(rEnv.getId())) {
return rEnv.getId() + ';' + name;
}
else {
return rEnv.getId() + ';';
}
}
return ""; //$NON-NLS-1$
}
public static IREnv decode(final String encodedSetting, final IREnvManager manager) {
if (encodedSetting != null) {
final int idx= encodedSetting.indexOf(';');
final IREnv rEnv;
if (idx >= 0) {
rEnv= manager.get(encodedSetting.substring(0, idx), encodedSetting.substring(idx + 1));
}
else {
rEnv= manager.get(encodedSetting, null);
}
if (rEnv != null) {
return rEnv;
}
}
return null;
}
private REnvUtils() {
}
}