From c0ce7ff6593c30da8deb278ef48e118f4214769a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 5 Mar 2006 18:11:11 +0000 Subject: [PATCH] Modify NormalizePath to work with boost 1.33.1, add regressions test git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13297 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 5 ++++ src/support/filetools.C | 42 ++++++---------------------- src/support/tests/ChangeLog | 10 +++++++ src/support/tests/Makefile.am | 9 +++++- src/support/tests/filetools.C | 30 ++++++++++++++++++++ src/support/tests/regfiles/filetools | 9 ++++++ src/support/tests/test_filetools | 7 +++++ 7 files changed, 77 insertions(+), 35 deletions(-) create mode 100755 src/support/tests/filetools.C create mode 100644 src/support/tests/regfiles/filetools create mode 100755 src/support/tests/test_filetools diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 867e9fdb5e..4fa4c2faf5 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2006-03-05 Lars Gullik Bjønnes + + * 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 * package.C.in (relative_system_support_dir): fix for win32 and diff --git a/src/support/filetools.C b/src/support/filetools.C index 149448c9c8..4b1fc8e791 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -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() + '/'; } diff --git a/src/support/tests/ChangeLog b/src/support/tests/ChangeLog index 35b3007e36..c5f4e43ac8 100644 --- a/src/support/tests/ChangeLog +++ b/src/support/tests/ChangeLog @@ -1,3 +1,13 @@ +2006-03-05 Lars Gullik Bjønnes + + * 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 * Makefile.am (makeregfiles): rename from regfiles diff --git a/src/support/tests/Makefile.am b/src/support/tests/Makefile.am index 30ca937991..4b49c145b5 100644 --- a/src/support/tests/Makefile.am +++ b/src/support/tests/Makefile.am @@ -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 index 0000000000..2c391c4fc7 --- /dev/null +++ b/src/support/tests/filetools.C @@ -0,0 +1,30 @@ +#include "../filetools.h" + +#include + +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 index 0000000000..96c5eca7b0 --- /dev/null +++ b/src/support/tests/regfiles/filetools @@ -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 index 0000000000..e44c1b8607 --- /dev/null +++ b/src/support/tests/test_filetools @@ -0,0 +1,7 @@ +#!/bin/bash + +regfile=`cat ${srcdir}/regfiles/filetools` +output=`./filetools` + +test "$regfile" = "$output" +exit $? -- 2.39.2