Make ReplaceEnvironmentPath work for both ${HOME}/foo and $HOME/foo.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7838 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-29 21:44:34 +00:00
parent 5927128c94
commit dbd3cb42c5
2 changed files with 20 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2003-09-29 Angus Leeming <leeming@lyx.org>
* filetools.C (ReplaceEnvironmentPath): make it work for both
${HOME}/foo and $HOME/foo.
2003-09-26 Lars Gullik Bjønnes <larsbj@gullik.net>
* debugstream.h: add file, updated version of the DebugStream

View File

@ -737,22 +737,29 @@ string const GetFileContents(string const & fname)
}
// Search the string for ${...} and replace the ... with the value of the
// denoted environment variable
// Search the string for ${VAR} and $VAR and replace VAR using getenv.
string const ReplaceEnvironmentPath(string const & path)
{
// A valid environment variable is defined as
// ${VAR} is defined as
// $\{[A-Za-z_][A-Za-z_0-9]*\}
string const valid_var = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
string const envvar_br = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
boost::regex re("(.*)" + valid_var + "(.*)");
// $VAR is defined as:
// $\{[A-Za-z_][A-Za-z_0-9]*\}
string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
boost::regex envvar_br_re("(.*)" + envvar_br + "(.*)");
boost::regex envvar_re("(.*)" + envvar + "(.*)");
boost::smatch what;
string result = path;
while (1) {
regex_match(result, what, re, boost::match_partial);
if (!what[0].matched)
break;
regex_match(result, what, envvar_br_re);
if (!what[0].matched) {
regex_match(result, what, envvar_re);
if (!what[0].matched)
break;
}
result = what.str(1) + GetEnv(what.str(2)) + what.str(3);
}
return result;