From 5fb0ed491c172bb3c759d1ff5325d879221287ea Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 26 May 2009 18:27:29 +0000 Subject: [PATCH] Account for the weird case where p2 is longer than p1, such as p1 == "path" and p2 == "Path/". This would be really weird, but one never knows... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29855 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/os_cygwin.cpp | 9 +++++++-- src/support/os_unix.cpp | 9 +++++++-- src/support/os_win32.cpp | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index 1adfa5f973..8ffaef55e4 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -187,8 +187,13 @@ bool path_prefix_is(string & path, string const & pre, path_case how) if (common_len != p2_len) return false; - if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); + if (how == CASE_ADJUSTED && !prefixIs(path, pre)) { + if (p1_len < common_len) + path = to_utf8(p2.substr(0, p1_len)); + else + path = to_utf8(p2 + p1.substr(common_len, + p1_len - common_len)); + } return true; } diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index ef13ff7f9e..2e6f9ba309 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -100,8 +100,13 @@ bool path_prefix_is(string & path, string const & pre, path_case how) if (common_len != p2_len) return false; - if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); + if (how == CASE_ADJUSTED && !prefixIs(path, pre)) { + if (p1_len < common_len) + path = to_utf8(p2.substr(0, p1_len)); + else + path = to_utf8(p2 + p1.substr(common_len, + p1_len - common_len)); + } return true; #else diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index 743677833a..018b5edd6e 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -218,8 +218,13 @@ bool path_prefix_is(string & path, string const & pre, path_case how) if (common_len != p2_len) return false; - if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); + if (how == CASE_ADJUSTED && !prefixIs(path, pre)) { + if (p1_len < common_len) + path = to_utf8(p2.substr(0, p1_len)); + else + path = to_utf8(p2 + p1.substr(common_len, + p1_len - common_len)); + } return true; }