From c23db901ece8b4e21121e43fc2562ac73e79fc98 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 27 Nov 2007 10:01:34 +0000 Subject: [PATCH] Getting rid of normalizePath() which is unneeded for FileName purpose (the path is always normalized internally). This commit frees up src/ from boost::filesystem. Some remaining references stays in src/client and src/tex2lyx. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21817 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/FileName.cpp | 3 ++- src/support/Package.cpp | 13 ++++++------- src/support/filetools.cpp | 21 --------------------- src/support/filetools.h | 5 ----- src/support/tests/check_filetools.cpp | 19 ++++++++++--------- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index d5507120f4..91b9a33cc4 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -76,7 +76,8 @@ struct FileName::Private FileName::FileName() : d(new Private) -{} +{ +} FileName::FileName(string const & abs_filename) : d(abs_filename.empty() ? new Private : new Private(abs_filename)) diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 0b92353860..6231a660ac 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -247,7 +247,7 @@ FileName buildSupportDir(string const & binary_dir, indirection = "../../lib"; break; } - return FileName(normalizePath(addPath(binary_dir, indirection))); + return FileName(addPath(binary_dir, indirection)); } @@ -346,8 +346,8 @@ FileName const get_locale_dir(FileName const & system_support_dir) // 2. Search for system_support_dir / // The is OS-dependent. (On Unix, it will // be "../locale/".) - FileName path(normalizePath(addPath(system_support_dir.absFilename(), - relative_locale_dir()))); + FileName path(addPath(system_support_dir.absFilename(), + relative_locale_dir())); if (path.exists() && path.isDirectory()) return path; @@ -490,8 +490,7 @@ get_system_support_dir(FileName const & abs_binary, // Try and find "chkconfig.ltx". string const binary_dir = onlyPath(binary.absFilename()); - FileName const lyxdir( - normalizePath(addPath(binary_dir, relative_lyxdir))); + FileName const lyxdir(addPath(binary_dir, relative_lyxdir)); searched_dirs.push_back(lyxdir); if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) { @@ -531,8 +530,8 @@ get_system_support_dir(FileName const & abs_binary, } // Try and find "chkconfig.ltx". - FileName const lyxdir( - normalizePath(addPath(binary_dir.absFilename(), relative_lyxdir))); + FileName const lyxdir(addPath(binary_dir.absFilename(), + relative_lyxdir)); searched_dirs.push_back(lyxdir); if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) { diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 4b80d824fe..2357f38482 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -36,7 +36,6 @@ #include "debug.h" #include -#include #include #include @@ -58,8 +57,6 @@ using std::ostringstream; using std::vector; using std::pair; -namespace fs = boost::filesystem; - namespace lyx { namespace support { @@ -524,24 +521,6 @@ string const expandPath(string const & path) } -// Normalize a path. Constracts path/../path -// Can't handle "../../" or "/../" (Asger) -// Also converts paths like /foo//bar ==> /foo/bar -string const normalizePath(string const & path) -{ - // Normalize paths like /foo//bar ==> /foo/bar - static boost::regex regex("/{2,}"); - string const tmppath = boost::regex_merge(path, regex, "/"); - - fs::path const npath = fs::path(tmppath, fs::no_check).normalize(); - - if (!npath.is_complete()) - return "./" + npath.string() + '/'; - - return npath.string() + '/'; -} - - // Search the string for ${VAR} and $VAR and replace VAR using getenv. string const replaceEnvironmentPath(string const & path) { diff --git a/src/support/filetools.h b/src/support/filetools.h index 7fb33baea0..512d78db80 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -230,11 +230,6 @@ makeRelPath(docstring const & abspath, docstring const & basepath); /// Strip filename from path name std::string const onlyPath(std::string const & fname); -/** Normalize a path. Constracts path/../path - * Also converts paths like /foo//bar ==> /foo/bar - */ -std::string const normalizePath(std::string const & path); - /// Strips path from filename std::string const onlyFilename(std::string const & fname); diff --git a/src/support/tests/check_filetools.cpp b/src/support/tests/check_filetools.cpp index 4859f8db18..ac74f3ebe6 100644 --- a/src/support/tests/check_filetools.cpp +++ b/src/support/tests/check_filetools.cpp @@ -1,4 +1,5 @@ #include "../filetools.h" +#include "../FileName.h" #include @@ -13,15 +14,15 @@ namespace lyx { 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; + cout << FileName("foo/../bar").absFilename() << endl; + cout << FileName("foo/./bar").absFilename() << endl; + cout << FileName("./foo/../bar").absFilename() << endl; + cout << FileName("./foo/./bar").absFilename() << endl; + cout << FileName("/foo/../bar").absFilename() << endl; + cout << FileName("/foo/./bar").absFilename() << endl; + cout << FileName("foo//bar").absFilename() << endl; + cout << FileName("./foo//bar").absFilename() << endl; + cout << FileName("/foo//bar").absFilename() << endl; } int main()