+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
// 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() + '/';
}
+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
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)
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 \
--- /dev/null
+#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();
+}
--- /dev/null
+./bar/
+./foo/bar/
+./bar/
+./foo/bar/
+/bar/
+/foo/bar/
+./foo/bar/
+./foo/bar/
+/foo/bar/
--- /dev/null
+#!/bin/bash
+
+regfile=`cat ${srcdir}/regfiles/filetools`
+output=`./filetools`
+
+test "$regfile" = "$output"
+exit $?