]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.C
small changes + patch from Dekel
[lyx.git] / src / support / lstrings.C
index f80377648452871b3c46808eafe7e3f24193012b..6be5d94b1265038b22649bc1b421b44f840f82c1 100644 (file)
@@ -34,7 +34,6 @@ using std::toupper;
 
 int compare_no_case(string const & s, string const & s2)
 {
-       // ANSI C
        string::const_iterator p = s.begin();
        string::const_iterator p2 = s2.begin();
 
@@ -46,7 +45,7 @@ int compare_no_case(string const & s, string const & s2)
                ++p;
                ++p2;
        }
-       
+
        if (s.size() == s2.size())
                return 0;
        if (s.size() < s2.size())
@@ -69,7 +68,8 @@ int compare_no_case(string const & s, string const & s2, unsigned int len)
                ++p;
                ++p2;
        }
-       if (s.size() == s2.size())
+
+       if (s.size() >= len && s2.size() >= len)
                return 0;
        if (s.size() < s2.size())
                return -1;
@@ -258,7 +258,7 @@ bool prefixIs(string const & a, string const & pre)
        string::size_type const prelen = pre.length();
        string::size_type const alen = a.length();
        
-       if (prelen < alen || a.empty())
+       if (prelen > alen || a.empty())
                return false;
        else {
 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
@@ -282,19 +282,21 @@ bool suffixIs(string const & a, char const * suf)
        Assert(suf);
        
        size_t const suflen = strlen(suf);
-       if (suflen > a.length())
+       string::size_type const alen = a.length();
+       
+       if (suflen > alen)
                return false;
        else {
 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
                // Delete this code when the compilers get a bit better.
-               string tmp(a, a.length() - suflen);
+               string tmp(a, alen - suflen);
                return ::strncmp(tmp.c_str(), suf, suflen) == 0;
 #else
                // This is the code that we really want to use
                // but until gcc ships with a basic_string that
                // implements std::string correctly we have to
                // use the code above.
-               return a.compare(a.length() - suflen, suflen, suf) == 0;
+               return a.compare(alen - suflen, suflen, suf) == 0;
 #endif
        }
 }