Files
geant4/source/externals/g4tools/include/tools/path_env
T
2021-06-25 16:12:29 +02:00

57 lines
1.3 KiB
Plaintext

// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_path_env
#define tools_path_env
#include "put_env"
#include "num2s"
#include "words"
#include "sep"
#include "vmanip"
namespace tools {
inline bool env_append(const std::string& a_env,const std::string& a_sep,const std::vector<std::string>& a_vals){
std::string env_value;
if(is_env(a_env)) {
if(!get_env(a_env,env_value)) return false;
}
{std::vector<std::string>::const_iterator it;
for(it=a_vals.begin();it!=a_vals.end();++it) {
const std::string& value = *it;
if(value.empty()) continue;
if(env_value.size()) {
std::vector<std::string> ws;
words(env_value,a_sep,false,ws);
// Remove existing one, so that value be put at end.
remove(ws,value);
if(!nums2s<std::string>(ws,env_value,a_sep)) {}
}
if(env_value.size()) env_value += a_sep;
env_value += value;
}}
if(!put_env(a_env,env_value)) return false;
return true;
}
inline bool env_path_append(const std::string& a_env,const std::vector<std::string>& a_paths){
return env_append(a_env,psep(),a_paths);
}
inline bool env_append_path(const std::string& a_env,const std::string& a_path){
std::vector<std::string> v;
v.push_back(a_path);
return env_append(a_env,psep(),v);
}
}
#endif