]> git.lyx.org Git - features.git/commitdiff
Modify NormalizePath to work with boost 1.33.1, add regressions test
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 5 Mar 2006 18:11:11 +0000 (18:11 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 5 Mar 2006 18:11:11 +0000 (18:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13297 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/ChangeLog
src/support/filetools.C
src/support/tests/ChangeLog
src/support/tests/Makefile.am
src/support/tests/filetools.C [new file with mode: 0755]
src/support/tests/regfiles/filetools [new file with mode: 0644]
src/support/tests/test_filetools [new file with mode: 0755]

index 867e9fdb5e3bf2180b167e084db9b16e4c36ff75..4fa4c2faf53ada842663d6358732298bd952191e 100644 (file)
@@ -1,3 +1,8 @@
+2006-03-05  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * filetools.C (NormalizePath): Change to use boost::filesystem and
+       alter regex usage in preparation for boost 1.33.1.
+
 2006-02-12  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * package.C.in (relative_system_support_dir): fix for win32 and
index 149448c9c808685a7fca414a42873dbea4f5c2f2..4b1fc8e791f85db6d36068bb263b9d3cf374e4b7 100644 (file)
@@ -594,42 +594,16 @@ string const ExpandPath(string const & path)
 // Also converts paths like /foo//bar ==> /foo/bar
 string const NormalizePath(string const & path)
 {
-       string TempBase;
-       string RTemp;
-       string Temp;
-
-       if (os::is_absolute_path(path))
-               RTemp = path;
-       else
-               // Make implicit current directory explicit
-               RTemp = "./" + path;
-
-       // Normalise paths like /foo//bar ==> /foo/bar
-       boost::RegEx regex("/{2,}");
-       RTemp = regex.Merge(RTemp, "/");
-
-       while (!RTemp.empty()) {
-               // Split by next /
-               RTemp = split(RTemp, Temp, '/');
+       // Normalize paths like /foo//bar ==> /foo/bar
+       static boost::regex regex("/{2,}");
+       string const tmppath = boost::regex_merge(path, regex, "/");
 
-               if (Temp == ".") {
-                       TempBase = "./";
-               } else if (Temp == "..") {
-                       // Remove one level of TempBase
-                       string::difference_type i = TempBase.length() - 2;
-                       while (i > 0 && TempBase[i] != '/')
-                               --i;
-                       if (i >= 0 && TempBase[i] == '/')
-                               TempBase.erase(i + 1, string::npos);
-                       else
-                               TempBase = "../";
-               } else {
-                       TempBase += Temp + '/';
-               }
-       }
+       fs::path const npath = fs::path(tmppath, fs::no_check).normalize();
 
-       // returns absolute path
-       return TempBase;
+       if (!npath.is_complete())
+               return "./" + npath.string() + '/';
+       
+       return npath.string() + '/';
 }
 
 
index 35b3007e36b6a95c4fcd29590a906a83cc8e7063..c5f4e43ac8b4e8aa02e120a497371ca7abba7630 100644 (file)
@@ -1,3 +1,13 @@
+2006-03-05  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * Makefile.am: update for filetools test
+
+       * filetools.C: test prog
+
+       * regfiles/filetools: regression data
+
+       * test_filetools: new test driver
+
 2005-02-25  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * Makefile.am (makeregfiles): rename from regfiles
index 30ca937991be849841fb047e95e2e2cc0cfef194..4b49c145b50488fbc97c51c558f290dd688558a3 100644 (file)
@@ -1,15 +1,17 @@
 include $(top_srcdir)/config/common.am
 
-EXTRA_DIST = pch.h test_convert test_lstrings regfiles
+EXTRA_DIST = pch.h test_convert test_filetools test_lstrings regfiles
 
 BUILT_SOURCES = $(PCH_FILE)
 
 TESTS = \
        test_convert \
+       test_filetools \
        test_lstrings
 
 check_PROGRAMS = \
        convert \
+       filetools \
        lstrings
 
 AM_CPPFLAGS += $(BOOST_INCLUDES)
@@ -19,6 +21,11 @@ convert_SOURCES = \
        convert.C \
        boost.C
 
+filetools_LDADD = ../../debug.o ../libsupport.la $(BOOST_REGEX) $(BOOST_FILESYSTEM)
+filetools_SOURCES = \
+       filetools.C \
+       boost.C
+
 lstrings_LDADD = ../lstrings.o
 lstrings_SOURCES = \
        lstrings.C \
diff --git a/src/support/tests/filetools.C b/src/support/tests/filetools.C
new file mode 100755 (executable)
index 0000000..2c391c4
--- /dev/null
@@ -0,0 +1,30 @@
+#include "../filetools.h"
+
+#include <iostream>
+
+using namespace lyx::support;
+
+using namespace std;
+
+string _(string const & str)
+{
+       return str;
+}
+
+void test_NormalizePath()
+{
+       cout << NormalizePath("foo/../bar") << endl;
+       cout << NormalizePath("foo/./bar") << endl;
+       cout << NormalizePath("./foo/../bar") << endl;
+       cout << NormalizePath("./foo/./bar") << endl;
+       cout << NormalizePath("/foo/../bar") << endl;
+       cout << NormalizePath("/foo/./bar") << endl;
+       cout << NormalizePath("foo//bar") << endl;      
+       cout << NormalizePath("./foo//bar") << endl;    
+       cout << NormalizePath("/foo//bar") << endl;     
+}
+
+int main()
+{
+       test_NormalizePath();
+}
diff --git a/src/support/tests/regfiles/filetools b/src/support/tests/regfiles/filetools
new file mode 100644 (file)
index 0000000..96c5eca
--- /dev/null
@@ -0,0 +1,9 @@
+./bar/
+./foo/bar/
+./bar/
+./foo/bar/
+/bar/
+/foo/bar/
+./foo/bar/
+./foo/bar/
+/foo/bar/
diff --git a/src/support/tests/test_filetools b/src/support/tests/test_filetools
new file mode 100755 (executable)
index 0000000..e44c1b8
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+regfile=`cat ${srcdir}/regfiles/filetools`
+output=`./filetools`
+
+test "$regfile" = "$output"
+exit $?