]> git.lyx.org Git - features.git/commitdiff
Account for the corner case p2.length() == 1.
authorEnrico Forestieri <forenr@lyx.org>
Mon, 25 May 2009 00:23:44 +0000 (00:23 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 25 May 2009 00:23:44 +0000 (00:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29838 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 43e56bbfd399f8963bca85d2a2de01027c1bb0f9..f33e7af4d6eaec480065162eda459063d150c444 100644 (file)
@@ -179,13 +179,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how)
 {
        docstring const p1 = from_utf8(path);
        docstring const p2 = from_utf8(pre);
-       docstring::size_type i = common_path(p1, p2);
+       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;
 
-       if (i == 0 || i + 1 != p2.length())
+       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)
                return false;
 
        if (how == CASE_ADJUSTED && !prefixIs(path, pre))
-               path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1));
+               path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len));
 
        return true;
 }
index 2463111abc7c39f2af295aa8c483515b52c597a4..b7a5b10daa2a5332214dddf924ab4bdef1eb5d71 100644 (file)
@@ -92,13 +92,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how)
 #ifdef __APPLE__
        docstring const p1 = from_utf8(path);
        docstring const p2 = from_utf8(pre);
-       docstring::size_type i = common_path(p1, p2);
+       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;
 
-       if (i == 0 || i + 1 != p2.length())
+       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)
                return false;
 
        if (how == CASE_ADJUSTED && !prefixIs(path, pre))
-               path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1));
+               path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len));
 
        return true;
 #else
index 65503f167230415080c35774d19ae0ad8fcdca8e..c51b37745d469c60b4c0ac5a50605f72c4858f5a 100644 (file)
@@ -210,13 +210,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how)
 {
        docstring const p1 = from_utf8(path);
        docstring const p2 = from_utf8(pre);
-       docstring::size_type i = common_path(p1, p2);
+       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;
 
-       if (i == 0 || i + 1 != p2.length())
+       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)
                return false;
 
        if (how == CASE_ADJUSTED && !prefixIs(path, pre))
-               path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1));
+               path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len));
 
        return true;
 }