22 while (p < s.size()) {
24 std::string::size_type dp = s.find(
'$', p);
25 if (dp == std::string::npos)
28 if (dp + 1 < s.size() && s[dp + 1] ==
'{') {
32 std::string::size_type de = s.find(
'}', dp + 2);
33 if (de == std::string::npos) {
39 std::string var = s.substr(dp + 2, de - (dp + 2));
41 const char* v = getenv(var.c_str());
44 size_t vlen = std::strlen(v);
47 s.replace(dp, de - dp + 1, v);
51 else if (dp + 1 < s.size() &&
52 (std::isalpha(s[dp + 1]) || s[dp + 1] ==
'_')) {
55 std::string::size_type de = dp + 1;
56 while (de < s.size() &&
57 (std::isalnum(s[de]) || s[de] ==
'_'))
61 std::string var = s.substr(dp + 1, de - (dp + 1));
63 const char* v = getenv(var.c_str());
66 size_t vlen = std::strlen(v);
69 s.replace(dp, de - dp, v);
std::string & expand_environment_variables(std::string *sp)
Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment variables.