mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
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:
parent
5927128c94
commit
dbd3cb42c5
@ -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>
|
2003-09-26 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||||
|
|
||||||
* debugstream.h: add file, updated version of the DebugStream
|
* debugstream.h: add file, updated version of the DebugStream
|
||||||
|
@ -737,22 +737,29 @@ string const GetFileContents(string const & fname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Search the string for ${...} and replace the ... with the value of the
|
// Search the string for ${VAR} and $VAR and replace VAR using getenv.
|
||||||
// denoted environment variable
|
|
||||||
string const ReplaceEnvironmentPath(string const & path)
|
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]*\}
|
// $\{[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;
|
boost::smatch what;
|
||||||
|
|
||||||
string result = path;
|
string result = path;
|
||||||
while (1) {
|
while (1) {
|
||||||
regex_match(result, what, re, boost::match_partial);
|
regex_match(result, what, envvar_br_re);
|
||||||
|
if (!what[0].matched) {
|
||||||
|
regex_match(result, what, envvar_re);
|
||||||
if (!what[0].matched)
|
if (!what[0].matched)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
result = what.str(1) + GetEnv(what.str(2)) + what.str(3);
|
result = what.str(1) + GetEnv(what.str(2)) + what.str(3);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user