From: Angus Leeming Date: Mon, 29 Sep 2003 21:44:34 +0000 (+0000) Subject: Make ReplaceEnvironmentPath work for both ${HOME}/foo and $HOME/foo. X-Git-Tag: 1.6.10~16025 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dbd3cb42c521547780d05c7f2af7a3df6ef709a3;p=features.git 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 --- diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 54e221e4fe..cce85cdfcd 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2003-09-29 Angus Leeming + + * filetools.C (ReplaceEnvironmentPath): make it work for both + ${HOME}/foo and $HOME/foo. + 2003-09-26 Lars Gullik Bjønnes * debugstream.h: add file, updated version of the DebugStream diff --git a/src/support/filetools.C b/src/support/filetools.C index b2503fd6a3..9956bea164 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -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;