]> git.lyx.org Git - features.git/commitdiff
Simpler things are almost always better.
authorEnrico Forestieri <forenr@lyx.org>
Mon, 25 May 2009 17:30:02 +0000 (17:30 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 25 May 2009 17:30:02 +0000 (17:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29843 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/os.h
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp

index 2528043733817be030fea59073f8a1be438088b7..115bfdbfaf2b1899b44dcd3a39380ac19705a5dc 100644 (file)
@@ -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.
index f33e7af4d6eaec480065162eda459063d150c444..79b8a16ce0f5f7214cd5a78c938e68317df2f19f 100644 (file)
@@ -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))
index b7a5b10daa2a5332214dddf924ab4bdef1eb5d71..32febd978586c21b407b062fad1cd7cb5d951f02 100644 (file)
@@ -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))
index c51b37745d469c60b4c0ac5a50605f72c4858f5a..651961de77760e6f543cb66bce354f7b71d02a76 100644 (file)
@@ -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))