sal/rtl/string.cxx  |   20 ++--
 sal/rtl/strtmpl.hxx |  219 ++++++++++++++++++++++++++++------------------------
 sal/rtl/ustring.cxx |  147 +++++-----------------------------
 3 files changed, 154 insertions(+), 232 deletions(-)

New commits:
commit 2126968ffbceb3c6f05db29c26ec90975e3f6331
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Feb 26 20:41:55 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Feb 27 06:07:21 2022 +0100

    Deduplicate more comparison functions
    
    Change-Id: I93aba36b7cde268e358bd96b55183533ddc70b16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130603
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 2b118a57aada..4b08b5e2c39f 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -337,14 +337,15 @@ sal_Int32 SAL_CALL rtl_str_getLength(const char* pStr) 
SAL_THROW_EXTERN_C()
 
 sal_Int32 SAL_CALL rtl_str_compare(const char* pStr1, const char* pStr2) 
SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_str_compare_WithLength(const char* pStr1, sal_Int32 
nStr1Len,
                                               const char* pStr2, sal_Int32 
nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, nStr2Len);
+    return rtl::str::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
+                                         rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_str_shortenedCompare_WithLength(const char* pStr1, 
sal_Int32 nStr1Len,
@@ -352,35 +353,38 @@ sal_Int32 SAL_CALL 
rtl_str_shortenedCompare_WithLength(const char* pStr1, sal_In
                                                        sal_Int32 
nShortenedLength)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len, nShortenedLength);
+    return rtl::str::shortenedCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
+                                                  nShortenedLength, 
rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_str_reverseCompare_WithLength(const char* pStr1, 
sal_Int32 nStr1Len,
                                                      const char* pStr2, 
sal_Int32 nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::reverseCompare_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len);
+    return rtl::str::reverseCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
+                                                rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase(const char* pStr1, const 
char* pStr2)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase_WithLength(const char* 
pStr1, sal_Int32 nStr1Len,
                                                              const char* 
pStr2, sal_Int32 nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len);
+    return rtl::str::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
+                                         rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
     const char* pStr1, sal_Int32 nStr1Len, const char* pStr2, sal_Int32 
nStr2Len,
     sal_Int32 nShortenedLength) SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompareIgnoreAsciiCase_WithLength(pStr1, 
nStr1Len, pStr2, nStr2Len,
-                                                              
nShortenedLength);
+    return rtl::str::shortenedCompare_WithLengths(
+        pStr1, nStr1Len, pStr2, nStr2Len, nShortenedLength, 
rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_str_hashCode(const char* pStr) SAL_THROW_EXTERN_C()
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 256c0cc99dd0..c5cdc23fbc84 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -98,143 +98,173 @@ template <typename C1, typename C2> void 
warnIfOneIsCharAndNotAscii(C1 c1, C2 c2
     }
 }
 
-/* ----------------------------------------------------------------------- */
-
-template <typename C1, typename C2> sal_Int32 compare(const C1* pStr1, const 
C2* pStr2)
+struct CompareNormal
 {
-    assert(pStr1);
-    assert(pStr2);
-    if constexpr (sizeof(C1) == sizeof(char) && sizeof(C2) == sizeof(char))
+    template <typename C1, typename C2> static sal_Int32 compare(C1 c1, C2 c2)
     {
-        // take advantage of builtin optimisations
-        return strcmp( pStr1, pStr2);
+        warnIfOneIsCharAndNotAscii(c1, c2);
+        return static_cast<sal_Int32>(IMPL_RTL_USTRCODE(c1))
+               - static_cast<sal_Int32>(IMPL_RTL_USTRCODE(c2));
     }
-    else if constexpr (sizeof(C1) == sizeof(wchar_t) && sizeof(C2) == 
sizeof(wchar_t))
+};
+
+struct CompareIgnoreAsciiCase
+{
+    template <typename C1, typename C2> static sal_Int32 compare(C1 c1, C2 c2)
     {
-        // take advantage of builtin optimisations
-        return wcscmp(reinterpret_cast<wchar_t const *>(pStr1), 
reinterpret_cast<wchar_t const *>(pStr2));
+        warnIfOneIsCharAndNotAscii(c1, c2);
+        return rtl::compareIgnoreAsciiCase(IMPL_RTL_USTRCODE(c1), 
IMPL_RTL_USTRCODE(c2));
     }
-    else // including C1 != C2
-    {
-        sal_Int32 nRet;
-        for (;;)
-        {
-            warnIfOneIsCharAndNotAscii(*pStr1, *pStr2);
-
-            nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE(*pStr1)) -
-                   static_cast<sal_Int32>(IMPL_RTL_USTRCODE(*pStr2));
-            if (!(nRet == 0 && *pStr2 ))
-                break;
-            pStr1++;
-            pStr2++;
-        }
+};
 
-        return nRet;
+/* ----------------------------------------------------------------------- */
+
+template <typename C1, typename C2, class Compare>
+sal_Int32 compare(const C1* pStr1, const C2* pStr2, Compare)
+{
+    assert(pStr1);
+    assert(pStr2);
+    for (;;)
+    {
+        const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2);
+        if (!(nRet == 0 && *pStr2))
+            return nRet;
+        ++pStr1;
+        ++pStr2;
     }
 }
 
-/* ----------------------------------------------------------------------- */
-
-template <typename IMPL_RTL_STRCODE>
-sal_Int32 compare_WithLength                             ( const 
IMPL_RTL_STRCODE* pStr1,
-                                                           sal_Int32 nStr1Len,
-                                                           const 
IMPL_RTL_STRCODE* pStr2,
-                                                           sal_Int32 nStr2Len )
+// take advantage of builtin optimisations
+template <typename C, std::enable_if_t<sizeof(C) == sizeof(wchar_t), int> = 0>
+sal_Int32 compare(const C* pStr1, const C* pStr2, CompareNormal)
 {
-    assert(nStr1Len >= 0);
-    assert(nStr2Len >= 0);
-    // take advantage of builtin optimisations
-    std::basic_string_view<IMPL_RTL_STRCODE> aView1(pStr1, nStr1Len);
-    std::basic_string_view<IMPL_RTL_STRCODE> aView2(pStr2, nStr2Len);
-    return aView1.compare(aView2);
+    assert(pStr1);
+    assert(pStr2);
+    return wcscmp(reinterpret_cast<wchar_t const*>(pStr1), 
reinterpret_cast<wchar_t const*>(pStr2));
+}
+inline sal_Int32 compare(const char* pStr1, const char* pStr2, CompareNormal)
+{
+    assert(pStr1);
+    assert(pStr2);
+    return strcmp(pStr1, pStr2);
 }
 
 /* ----------------------------------------------------------------------- */
 
-template <typename IMPL_RTL_STRCODE>
-sal_Int32 shortenedCompare_WithLength                             ( const 
IMPL_RTL_STRCODE* pStr1,
-                                                                    sal_Int32 
nStr1Len,
-                                                                    const 
IMPL_RTL_STRCODE* pStr2,
-                                                                    sal_Int32 
nStr2Len,
-                                                                    sal_Int32 
nShortenedLength )
+template <typename C1, typename C2, class Compare>
+sal_Int32 compare_WithLength(const C1* pStr1, sal_Int32 nStr1Len, const C2* 
pStr2, Compare)
 {
-    return compare_WithLength(pStr1, std::min(nStr1Len, nShortenedLength),
-                              pStr2, std::min(nStr2Len, nShortenedLength));
+    assert(pStr1 || nStr1Len == 0);
+    assert(nStr1Len >= 0);
+    assert(pStr2);
+    for (;;)
+    {
+        if (*pStr2 == '\0')
+            return nStr1Len;
+        if (nStr1Len == 0)
+            return -1;
+        if (const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2))
+            return nRet;
+        pStr1++;
+        pStr2++;
+        nStr1Len--;
+    }
 }
 
 /* ----------------------------------------------------------------------- */
 
-template <typename C1, typename C2>
-sal_Int32 reverseCompare_WithLength(const C1* pStr1, sal_Int32 nStr1Len,
-                                    const C2* pStr2, sal_Int32 nStr2Len)
+template <typename C1, typename C2, class Compare>
+sal_Int32 compare_WithLengths(const C1* pStr1, sal_Int32 nStr1Len,
+                              const C2* pStr2, sal_Int32 nStr2Len, Compare)
 {
+    assert(pStr1 || nStr1Len == 0);
     assert(nStr1Len >= 0);
+    assert(pStr2 || nStr2Len == 0);
     assert(nStr2Len >= 0);
-    const C1* pStr1Run = pStr1+nStr1Len;
-    const C2* pStr2Run = pStr2+nStr2Len;
-    sal_Int32               nRet;
-    while ( (pStr1 < pStr1Run) && (pStr2 < pStr2Run) )
+    // TODO: use std::lexicographical_compare_three_way when C++20 is available
+    const C1* pStr1End = pStr1 + nStr1Len;
+    const C2* pStr2End = pStr2 + nStr2Len;
+    while ((pStr1 < pStr1End) && (pStr2 < pStr2End))
     {
-        warnIfOneIsCharAndNotAscii(*pStr1, *pStr2);
-
-        pStr1Run--;
-        pStr2Run--;
-        nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr1Run ))-
-               static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr2Run ));
-        if ( nRet )
+        if (const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2))
             return nRet;
+        pStr1++;
+        pStr2++;
     }
 
     return nStr1Len - nStr2Len;
 }
 
+template <typename C>
+sal_Int32 compare_WithLengths(const C* pStr1, sal_Int32 nStr1Len,
+                              const C* pStr2, sal_Int32 nStr2Len, 
CompareNormal)
+{
+    assert(pStr1 || nStr1Len == 0);
+    assert(nStr1Len >= 0);
+    assert(pStr2 || nStr2Len == 0);
+    assert(nStr2Len >= 0);
+    // take advantage of builtin optimisations
+    std::basic_string_view<C> aView1(pStr1, nStr1Len);
+    std::basic_string_view<C> aView2(pStr2, nStr2Len);
+    return aView1.compare(aView2);
+}
+
 /* ----------------------------------------------------------------------- */
 
-template <typename C1, typename C2>
-sal_Int32 compareIgnoreAsciiCase(const C1* pStr1, const C2* pStr2)
+template <typename C1, typename C2, class Compare>
+sal_Int32 shortenedCompare_WithLength(const C1* pStr1, sal_Int32 nStr1Len, 
const C2* pStr2,
+                                      sal_Int32 nShortenedLength, Compare)
 {
     assert(pStr1);
+    assert(nStr1Len >= 0);
     assert(pStr2);
-    sal_uInt32 c1;
-    do
+    assert(nShortenedLength >= 0);
+    const C1* pStr1End = pStr1 + nStr1Len;
+    for (;;)
     {
-        warnIfOneIsCharAndNotAscii(*pStr1, *pStr2);
-
-        c1 = IMPL_RTL_USTRCODE(*pStr1);
-        sal_Int32 nRet = rtl::compareIgnoreAsciiCase(
-            c1, IMPL_RTL_USTRCODE(*pStr2));
-        if ( nRet != 0 )
+        if (nShortenedLength == 0)
+            return 0;
+        if (*pStr2 == '\0')
+            return pStr1End - pStr1;
+        if (pStr1 == pStr1End)
+            return -1; // first is a substring of the second string => less 
(negative value)
+        if (const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2))
             return nRet;
-
+        nShortenedLength--;
         pStr1++;
         pStr2++;
     }
-    while (c1);
+}
 
-    return 0;
+/* ----------------------------------------------------------------------- */
+
+template <typename C1, typename C2, class Compare>
+sal_Int32 shortenedCompare_WithLengths(const C1* pStr1, sal_Int32 nStr1Len,
+                                       const C2* pStr2, sal_Int32 nStr2Len,
+                                       sal_Int32 nShortenedLength, Compare cf)
+{
+    return compare_WithLengths(pStr1, std::min(nStr1Len, nShortenedLength),
+                               pStr2, std::min(nStr2Len, nShortenedLength), 
cf);
 }
 
 /* ----------------------------------------------------------------------- */
 
-template <typename C1, typename C2>
-sal_Int32 compareIgnoreAsciiCase_WithLength(const C1* pStr1, sal_Int32 
nStr1Len,
-                                            const C2* pStr2, sal_Int32 
nStr2Len)
+template <typename C1, typename C2, class Compare>
+sal_Int32 reverseCompare_WithLengths(const C1* pStr1, sal_Int32 nStr1Len,
+                                     const C2* pStr2, sal_Int32 nStr2Len, 
Compare)
 {
+    assert(pStr1 || nStr1Len == 0);
     assert(nStr1Len >= 0);
+    assert(pStr2 || nStr2Len == 0);
     assert(nStr2Len >= 0);
-    const C1* pStr1End = pStr1 + nStr1Len;
-    const C2* pStr2End = pStr2 + nStr2Len;
-    while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) )
+    const C1* pStr1Run = pStr1+nStr1Len;
+    const C2* pStr2Run = pStr2+nStr2Len;
+    while ((pStr1 < pStr1Run) && (pStr2 < pStr2Run))
     {
-        warnIfOneIsCharAndNotAscii(*pStr1, *pStr2);
-
-        sal_Int32 nRet = rtl::compareIgnoreAsciiCase(
-            IMPL_RTL_USTRCODE(*pStr1), IMPL_RTL_USTRCODE(*pStr2));
-        if ( nRet != 0 )
+        pStr1Run--;
+        pStr2Run--;
+        if (const sal_Int32 nRet = Compare::compare(*pStr1Run, *pStr2Run))
             return nRet;
-
-        pStr1++;
-        pStr2++;
     }
 
     return nStr1Len - nStr2Len;
@@ -242,19 +272,6 @@ sal_Int32 compareIgnoreAsciiCase_WithLength(const C1* 
pStr1, sal_Int32 nStr1Len,
 
 /* ----------------------------------------------------------------------- */
 
-template <typename IMPL_RTL_STRCODE>
-sal_Int32 shortenedCompareIgnoreAsciiCase_WithLength                           
  ( const IMPL_RTL_STRCODE* pStr1,
-                                                                               
    sal_Int32 nStr1Len,
-                                                                               
    const IMPL_RTL_STRCODE* pStr2,
-                                                                               
    sal_Int32 nStr2Len,
-                                                                               
    sal_Int32 nShortenedLength )
-{
-    return compareIgnoreAsciiCase_WithLength(pStr1, std::min(nStr1Len, 
nShortenedLength),
-                                             pStr2, std::min(nStr2Len, 
nShortenedLength));
-}
-
-/* ----------------------------------------------------------------------- */
-
 template <typename IMPL_RTL_STRCODE>
 sal_Int32 hashCode_WithLength(const IMPL_RTL_STRCODE*, sal_Int32);
 
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index b289ae2a3f21..f2503f5c2d06 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -175,7 +175,7 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compare( const 
sal_Unicode* pStr1,
                                            const char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareNormal());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -185,24 +185,7 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compare_WithLength( 
const sal_Unicode* pStr1,
                                                       const char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    assert(pStr1);
-    assert(nStr1Len >= 0);
-    assert(pStr2);
-    sal_Int32 nRet = 0;
-    for (;;)
-    {
-        nRet = (nStr1Len ? static_cast<sal_Int32>(*pStr1) : 0) -
-               static_cast<sal_Int32>(static_cast<unsigned char>(*pStr2));
-        if (!(nRet == 0 && nStr1Len && *pStr2 ))
-            break;
-        SAL_WARN_IF( !rtl::isAscii(static_cast<unsigned char>(*pStr2)), 
"rtl.string",
-                    "rtl_ustr_ascii_compare_WithLength - Found char > 127" );
-        pStr1++;
-        pStr2++;
-        nStr1Len--;
-    }
-
-    return nRet;
+    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, 
rtl::str::CompareNormal());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -213,42 +196,8 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_shortenedCompare_WithLength( const sal_Unicode
                                                                sal_Int32 
nShortenedLength )
     SAL_THROW_EXTERN_C()
 {
-    assert(nStr1Len >= 0);
-    assert(nShortenedLength >= 0);
-    const sal_Unicode*  pStr1End = pStr1 + nStr1Len;
-    sal_Int32           nRet;
-    while ( (nShortenedLength > 0) &&
-            (pStr1 < pStr1End) && *pStr2 )
-    {
-        SAL_WARN_IF( !rtl::isAscii(static_cast<unsigned char>(*pStr2)), 
"rtl.string",
-                    "rtl_ustr_ascii_shortenedCompare_WithLength - Found char > 
127" );
-
-        nRet = static_cast<sal_Int32>(*pStr1)-
-               static_cast<sal_Int32>(static_cast<unsigned char>(*pStr2));
-        if ( nRet != 0 )
-            return nRet;
-
-        nShortenedLength--;
-        pStr1++;
-        pStr2++;
-    }
-
-    if ( nShortenedLength <= 0 )
-        return 0;
-
-    if ( *pStr2 )
-    {
-        OSL_ENSURE( pStr1 == pStr1End, "pStr1 == pStr1End failed" );
-        // first is a substring of the second string => less (negative value)
-        nRet = -1;
-    }
-    else
-    {
-        // greater or equal
-        nRet = pStr1End - pStr1;
-    }
-
-    return nRet;
+    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nShortenedLength,
+                                                 rtl::str::CompareNormal());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -259,7 +208,8 @@ sal_Int32 SAL_CALL 
rtl_ustr_asciil_reverseCompare_WithLength( const sal_Unicode*
                                                               sal_Int32 
nStr2Len )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::reverseCompare_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len);
+    return rtl::str::reverseCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
+                                                rtl::str::CompareNormal());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -291,7 +241,7 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase( 
const sal_Unicode* pSt
                                                           const char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -301,35 +251,15 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( const sal_U
                                                                      const 
char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    assert(nStr1Len >= 0);
-    assert(pStr2);
-    unsigned char c2;
-    do
-    {
-        SAL_WARN_IF( !rtl::isAscii(static_cast<unsigned char>(*pStr2)), 
"rtl.string",
-                    "rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength - Found 
char > 127" );
-        if ( !nStr1Len )
-            return *pStr2 == '\0' ? 0 : -1;
-
-        c2 = static_cast<unsigned char>(*pStr2);
-        sal_Int32 nRet = rtl::compareIgnoreAsciiCase(*pStr1, c2);
-        if ( nRet != 0 )
-            return nRet;
-
-        pStr1++;
-        pStr2++;
-        nStr1Len--;
-    }
-    while( c2 );
-
-    return 0;
+    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, 
rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
     sal_Unicode const * first, sal_Int32 firstLen,
     char const * second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase_WithLength(first, firstLen, 
second, secondLen);
+    return rtl::str::compare_WithLengths(first, firstLen, second, secondLen,
+                                         rtl::str::CompareIgnoreAsciiCase());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -340,41 +270,8 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( co
                                                                               
sal_Int32 nShortenedLength )
     SAL_THROW_EXTERN_C()
 {
-    assert(nStr1Len >= 0);
-    assert(nShortenedLength >= 0);
-    const sal_Unicode*  pStr1End = pStr1 + nStr1Len;
-    sal_Int32           nRet;
-    while ( (nShortenedLength > 0) &&
-            (pStr1 < pStr1End) && *pStr2 )
-    {
-        SAL_WARN_IF( !rtl::isAscii(static_cast<unsigned char>(*pStr2)), 
"rtl.string",
-                    "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength 
- Found char > 127" );
-
-        nRet = rtl::compareIgnoreAsciiCase(*pStr1, static_cast<unsigned 
char>(*pStr2));
-        if ( nRet != 0 )
-            return nRet;
-
-        nShortenedLength--;
-        pStr1++;
-        pStr2++;
-    }
-
-    if ( nShortenedLength <= 0 )
-        return 0;
-
-    if ( *pStr2 )
-    {
-        OSL_ENSURE( pStr1 == pStr1End, "pStr1 == pStr1End failed" );
-        // first is a substring of the second string => less (negative value)
-        nRet = -1;
-    }
-    else
-    {
-        // greater or equal
-        nRet = pStr1End - pStr1;
-    }
-
-    return nRet;
+    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nShortenedLength,
+                                                 
rtl::str::CompareIgnoreAsciiCase());
 }
 
 /* ----------------------------------------------------------------------- */
@@ -1096,34 +993,37 @@ sal_Int32 SAL_CALL rtl_ustr_getLength(const sal_Unicode* 
pStr) SAL_THROW_EXTERN_
 sal_Int32 SAL_CALL rtl_ustr_compare(const sal_Unicode* pStr1, const 
sal_Unicode* pStr2)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_compare_WithLength(const sal_Unicode* pStr1, 
sal_Int32 nStr1Len,
                                                const sal_Unicode* pStr2, 
sal_Int32 nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, nStr2Len);
+    return rtl::str::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
+                                         rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_shortenedCompare_WithLength(
     const sal_Unicode* pStr1, sal_Int32 nStr1Len, const sal_Unicode* pStr2, 
sal_Int32 nStr2Len,
     sal_Int32 nShortenedLength) SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len, nShortenedLength);
+    return rtl::str::shortenedCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
+                                                  nShortenedLength, 
rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_reverseCompare_WithLength(const sal_Unicode* 
pStr1, sal_Int32 nStr1Len,
                                                       const sal_Unicode* 
pStr2, sal_Int32 nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::reverseCompare_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len);
+    return rtl::str::reverseCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
+                                                rtl::str::CompareNormal());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_compareIgnoreAsciiCase(const sal_Unicode* pStr1,
                                                    const sal_Unicode* pStr2) 
SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase(pStr1, pStr2);
+    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_compareIgnoreAsciiCase_WithLength(const 
sal_Unicode* pStr1,
@@ -1132,15 +1032,16 @@ sal_Int32 SAL_CALL 
rtl_ustr_compareIgnoreAsciiCase_WithLength(const sal_Unicode*
                                                               sal_Int32 
nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compareIgnoreAsciiCase_WithLength(pStr1, nStr1Len, pStr2, 
nStr2Len);
+    return rtl::str::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
+                                         rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
     const sal_Unicode* pStr1, sal_Int32 nStr1Len, const sal_Unicode* pStr2, 
sal_Int32 nStr2Len,
     sal_Int32 nShortenedLength) SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompareIgnoreAsciiCase_WithLength(pStr1, 
nStr1Len, pStr2, nStr2Len,
-                                                              
nShortenedLength);
+    return rtl::str::shortenedCompare_WithLengths(
+        pStr1, nStr1Len, pStr2, nStr2Len, nShortenedLength, 
rtl::str::CompareIgnoreAsciiCase());
 }
 
 sal_Int32 SAL_CALL rtl_ustr_hashCode(const sal_Unicode* pStr) 
SAL_THROW_EXTERN_C()

Reply via email to