// 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& a_vals){ std::string env_value; if(is_env(a_env)) { if(!get_env(a_env,env_value)) return false; } {std::vector::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 ws; words(env_value,a_sep,false,ws); // Remove existing one, so that value be put at end. remove(ws,value); if(!nums2s(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& 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 v; v.push_back(a_path); return env_append(a_env,psep(),v); } } #endif