From: Enrico Forestieri Date: Mon, 25 May 2009 17:30:02 +0000 (+0000) Subject: Simpler things are almost always better. X-Git-Tag: 2.0.0~6448 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2fb21c28b50d9b043501f02766a1aebafad3135b;p=features.git Simpler things are almost always better. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29843 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/os.h b/src/support/os.h index 2528043733..115bfdbfaf 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -60,9 +60,9 @@ std::string const python(); bool isFilesystemCaseSensitive(); /// Extract the path common to both @c p1 and @c p2. DBCS aware! -/// \p p1 and \p p2 are encoded in ucs4, \returns the index to the -/// end of the last matching path component (the index may be pointing -/// to the path separator, if it is the last char in @c p2). +/// \p p1 and \p p2 are encoded in ucs4, \returns the index to the end of +/// the last matching path component (the index may be pointing after the +/// end of @c p1 or @c p2 if their last char is not the path separator). std::size_t common_path(docstring const & p1, docstring const & p2); /// Converts a unix style path to host OS style. diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index f33e7af4d6..79b8a16ce0 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -162,9 +162,7 @@ docstring::size_type common_path(docstring const & p1, docstring const & p2) --i; // here was the last match while (i && p1[i] != '/') --i; - } else - --i; - + } return i; } @@ -181,13 +179,12 @@ bool path_prefix_is(string & path, string const & pre, path_case how) docstring const p2 = from_utf8(pre); docstring::size_type const p1_len = p1.length(); docstring::size_type const p2_len = p2.length(); - docstring::size_type const common_len = common_path(p1, p2) + 1; + docstring::size_type common_len = common_path(p1, p2); - if (common_len == 1) { - if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] - || (p1_len != 1 && p1[1] != '/')) - return false; - } else if (common_len != p2_len) + if (p2[p2_len - 1] == '/') + ++common_len; + + if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre)) diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index b7a5b10daa..32febd9785 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -70,9 +70,7 @@ docstring::size_type common_path(docstring const & p1, docstring const & p2) --i; // here was the last match while (i && p1[i] != '/') --i; - } else - --i; - + } return i; } @@ -94,13 +92,12 @@ bool path_prefix_is(string & path, string const & pre, path_case how) docstring const p2 = from_utf8(pre); docstring::size_type const p1_len = p1.length(); docstring::size_type const p2_len = p2.length(); - docstring::size_type const common_len = common_path(p1, p2) + 1; + docstring::size_type common_len = common_path(p1, p2); - if (common_len == 1) { - if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] - || (p1_len != 1 && p1[1] != '/')) - return false; - } else if (common_len != p2_len) + if (p2[p2_len - 1] == '/') + ++common_len; + + if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre)) diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index c51b37745d..651961de77 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -193,9 +193,7 @@ docstring::size_type common_path(docstring const & p1, docstring const & p2) --i; // here was the last match while (i && p1[i] != '/') --i; - } else - --i; - + } return i; } @@ -212,13 +210,12 @@ bool path_prefix_is(string & path, string const & pre, path_case how) docstring const p2 = from_utf8(pre); docstring::size_type const p1_len = p1.length(); docstring::size_type const p2_len = p2.length(); - docstring::size_type const common_len = common_path(p1, p2) + 1; + docstring::size_type common_len = common_path(p1, p2); - if (common_len == 1) { - if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] - || (p1_len != 1 && p1[1] != '/')) - return false; - } else if (common_len != p2_len) + if (p2[p2_len - 1] == '/') + ++common_len; + + if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre))