4 #ifndef tools_file_name
5 #define tools_file_name
14 inline bool rep_env(std::string& a_string) {
15 char spec_char =
'\n';
16 std::string::size_type dollar;
17 while((dollar=a_string.find(
'$'))!=std::string::npos){
18 std::string::size_type slash = a_string.find(
'/',dollar+1);
19 std::string::size_type back_slash = a_string.find(
'\\',dollar+1);
20 std::string::size_type pos = std::string::npos;
21 if(slash!=std::string::npos) {
22 if(back_slash!=std::string::npos) {
23 pos = slash<back_slash?slash:back_slash;
28 if(back_slash!=std::string::npos) {
31 pos = std::string::npos;
35 if(pos==std::string::npos) {
36 env = a_string.substr(dollar+1,a_string.length()-(dollar+1));
40 env = a_string.substr(dollar+1,pos-(dollar+1));
42 char* val = ::getenv(env.c_str());
49 a_string[dollar] = spec_char;
51 std::string
value = a_string.substr(0,dollar);
53 if(pos!=std::string::npos)
value += a_string.substr(pos,a_string.length()-pos);
57 replace(a_string,spec_char,
'$');
61 inline bool file_name(
const std::string& a_path,std::string& a_name) {
64 if(!
rep_env(a_name)) {a_name.clear();
return false;}