]> git.lyx.org Git - features.git/commitdiff
Make ReplaceEnvironmentPath work for both ${HOME}/foo and $HOME/foo.
authorAngus Leeming <leeming@lyx.org>
Mon, 29 Sep 2003 21:44:34 +0000 (21:44 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 29 Sep 2003 21:44:34 +0000 (21:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7838 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/ChangeLog
src/support/filetools.C

index 54e221e4feb9938a48c61788a6a115a61bf2156f..cce85cdfcdb0da2cf1aec639a1e67f317a23d3bd 100644 (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
index b2503fd6a349f97132f703b8fed12d05d3926489..9956bea164061b0af8cd1edf38d3b4c217d0593c 100644 (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;