sal/rtl/string.cxx  |   41 +++++------
 sal/rtl/strtmpl.hxx |  185 +++++++++++++++++++---------------------------------
 sal/rtl/ustring.cxx |   70 +++++++++++--------
 3 files changed, 131 insertions(+), 165 deletions(-)

New commits:
commit 3cb30369d699a4836043d434833ba4c3d3d257c3
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 2 13:11:18 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 2 22:11:23 2022 +0100

    Unify normal/shortened, null-terminated/with-length comparisons
    
    Change-Id: Ie154efd1e0d9b49601200ac896d5d5dd0422d504
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130832
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index c5d535075354..9927451c8f9e 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -325,15 +325,17 @@ 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, rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareNormal(), 
rtl::str::noShortening);
 }
 
 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_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
-                                         rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareNormal(), 
rtl::str::noShortening);
 }
 
 sal_Int32 SAL_CALL rtl_str_shortenedCompare_WithLength(const char* pStr1, 
sal_Int32 nStr1Len,
@@ -341,8 +343,9 @@ sal_Int32 SAL_CALL 
rtl_str_shortenedCompare_WithLength(const char* pStr1, sal_In
                                                        sal_Int32 
nShortenedLength)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompare_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
-                                                  nShortenedLength, 
rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareNormal(), nShortenedLength);
 }
 
 sal_Int32 SAL_CALL rtl_str_reverseCompare_WithLength(const char* pStr1, 
sal_Int32 nStr1Len,
@@ -356,23 +359,26 @@ sal_Int32 SAL_CALL 
rtl_str_reverseCompare_WithLength(const char* pStr1, sal_Int3
 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase(const char* pStr1, const 
char* pStr2)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 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::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
-                                         rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 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::shortenedCompare_WithLengths(
-        pStr1, nStr1Len, pStr2, nStr2Len, nShortenedLength, 
rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareIgnoreAsciiCase(), 
nShortenedLength);
 }
 
 sal_Int32 SAL_CALL rtl_str_hashCode(const char* pStr) SAL_THROW_EXTERN_C()
@@ -506,33 +512,28 @@ sal_Bool SAL_CALL rtl_str_toBoolean(const char* pStr) 
SAL_THROW_EXTERN_C()
 
 sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_Int32>(pStr, nRadix);
+    return rtl::str::toInt<sal_Int32>(rtl::str::null_terminated(pStr), nRadix);
 }
 
 sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_Int64>(pStr, nRadix);
+    return rtl::str::toInt<sal_Int64>(rtl::str::null_terminated(pStr), nRadix);
 }
 
 sal_Int64 SAL_CALL rtl_str_toInt64_WithLength(const char* pStr, sal_Int16 
nRadix,
                                               sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr || nStrLength == 0);
-    return rtl::str::toInt<sal_Int64>(std::basic_string_view(pStr, 
nStrLength), nRadix);
+    return rtl::str::toInt<sal_Int64>(rtl::str::with_length(pStr, nStrLength), 
nRadix);
 }
 
 sal_uInt32 SAL_CALL rtl_str_toUInt32(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_uInt32>(pStr, nRadix);
+    return rtl::str::toInt<sal_uInt32>(rtl::str::null_terminated(pStr), 
nRadix);
 }
 
 sal_uInt64 SAL_CALL rtl_str_toUInt64(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_uInt64>(pStr, nRadix);
+    return rtl::str::toInt<sal_uInt64>(rtl::str::null_terminated(pStr), 
nRadix);
 }
 
 rtl_String* rtl_string_ImplAlloc(sal_Int32 nLen) { return 
rtl::str::Alloc<rtl_String>(nLen); }
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 6988865e8f11..945aaa54a6e2 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -30,6 +30,7 @@
 
 #include "strimp.hxx"
 
+#include <o3tl/safeint.hxx>
 #include <osl/diagnose.h>
 #include <sal/log.hxx>
 #include <rtl/character.hxx>
@@ -44,6 +45,35 @@ namespace rtl::str
 {
 template <typename C> auto IMPL_RTL_USTRCODE(C c) { return 
std::make_unsigned_t<C>(c); }
 
+// Wrappers around null-terminated/known-length strings, that allow to 
generalize algorithms
+// without overhead (e.g., without need to get length of null-terminated 
strings).
+
+template <typename C> struct null_terminated
+{
+    C* p;
+    null_terminated(C* pStr)
+        : p(pStr)
+    {
+        assert(pStr);
+    }
+    auto getIter() const { return p; }
+    static auto getEndDetector() { return [](C* iter) { return *iter == 0; }; }
+};
+
+template <typename C> struct with_length
+{
+    C* p;
+    sal_Int32 len;
+    with_length(C* pStr, sal_Int32 nLength)
+        : p(pStr)
+        , len(nLength)
+    {
+        assert(len >= 0);
+    }
+    auto getIter() const { return p; }
+    auto getEndDetector() const { return [pEnd = p + len](C* iter) { return 
iter == pEnd; }; }
+};
+
 template <typename C> void Copy(C* _pDest, const C* _pSrc, sal_Int32 _nCount)
 {
     // take advantage of builtin optimisations
@@ -124,16 +154,33 @@ struct CompareIgnoreAsciiCase
 
 /* ----------------------------------------------------------------------- */
 
-template <typename C1, typename C2, class Compare>
-sal_Int32 compare(const C1* pStr1, const C2* pStr2, Compare)
+struct NoShortening
+{
+    constexpr bool operator>=(int) { return true; } // for assert
+    constexpr bool operator==(int) { return false; } // for loop break check
+    constexpr void operator--() {} // for decrement in loop
+} constexpr noShortening;
+
+template <class S1, class S2, class Compare, typename Shorten_t>
+sal_Int32 compare(S1 s1, S2 s2, Compare, Shorten_t shortenedLength)
 {
-    assert(pStr1);
-    assert(pStr2);
+    static_assert(std::is_same_v<Shorten_t, NoShortening> || 
std::is_same_v<Shorten_t, sal_Int32>);
+    assert(shortenedLength >= 0);
+    auto pStr1 = s1.getIter();
+    const auto atEnd1 = s1.getEndDetector();
+    auto pStr2 = s2.getIter();
+    const auto atEnd2 = s2.getEndDetector();
     for (;;)
     {
-        const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2);
-        if (!(nRet == 0 && *pStr2))
+        if (shortenedLength == 0)
+            return 0;
+        if (atEnd2(pStr2))
+            return atEnd1(pStr1) ? 0 : 1;
+        if (atEnd1(pStr1))
+            return -1;
+        if (const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2))
             return nRet;
+        --shortenedLength;
         ++pStr1;
         ++pStr2;
     }
@@ -141,115 +188,28 @@ sal_Int32 compare(const C1* pStr1, const C2* pStr2, 
Compare)
 
 // 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(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)
+sal_Int32 compare(null_terminated<C> s1, null_terminated<C> s2, CompareNormal, 
NoShortening)
 {
-    assert(pStr1);
-    assert(pStr2);
-    return strcmp(pStr1, pStr2);
+    return wcscmp(reinterpret_cast<wchar_t const*>(s1.p), 
reinterpret_cast<wchar_t const*>(s2.p));
 }
-
-/* ----------------------------------------------------------------------- */
-
-template <typename C1, typename C2, class Compare>
-sal_Int32 compare_WithLength(const C1* pStr1, sal_Int32 nStr1Len, const C2* 
pStr2, Compare)
+template <typename C, std::enable_if_t<sizeof(C) == sizeof(char), int> = 0>
+sal_Int32 compare(null_terminated<C> s1, null_terminated<C> s2, CompareNormal, 
NoShortening)
 {
-    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--;
-    }
+    return strcmp(reinterpret_cast<char const*>(s1.p), reinterpret_cast<char 
const*>(s2.p));
 }
-
-/* ----------------------------------------------------------------------- */
-
-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);
-    // 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))
-    {
-        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)
+sal_Int32 compare(with_length<C> s1, with_length<C> s2, CompareNormal, 
NoShortening)
 {
-    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);
+    std::basic_string_view sv1(s1.p, s1.len);
+    return sv1.compare(std::basic_string_view(s2.p, s2.len));
 }
-
-/* ----------------------------------------------------------------------- */
-
 template <typename C1, typename C2, class Compare>
-sal_Int32 shortenedCompare_WithLength(const C1* pStr1, sal_Int32 nStr1Len, 
const C2* pStr2,
-                                      sal_Int32 nShortenedLength, Compare)
+sal_Int32 compare(with_length<C1> s1, with_length<C2> s2, Compare cf, 
sal_Int32 nShortenedLength)
 {
-    assert(pStr1);
-    assert(nStr1Len >= 0);
-    assert(pStr2);
     assert(nShortenedLength >= 0);
-    const C1* pStr1End = pStr1 + nStr1Len;
-    for (;;)
-    {
-        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++;
-    }
-}
-
-/* ----------------------------------------------------------------------- */
-
-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);
+    s1.len = std::min(s1.len, nShortenedLength);
+    s2.len = std::min(s2.len, nShortenedLength);
+    return compare(s1, s2, cf, noShortening);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -786,12 +746,6 @@ template <typename T> std::pair<T, sal_Int16> 
DivMod(sal_Int16 nRadix, [[maybe_u
     return { std::numeric_limits<T>::max() / nRadix, 
std::numeric_limits<T>::max() % nRadix };
 }
 
-template <class SV> auto getIter(const SV& sv) { return sv.begin(); }
-template <typename C> auto getIter(const C* pStr) { return pStr; }
-
-template <class SV> auto good(typename SV::iterator iter, const SV& sv) { 
return iter != sv.end(); }
-template <typename C> auto good(const C* pStr, const C*) { return *pStr != 0; }
-
 template <typename T, class S> T toInt(S str, sal_Int16 nRadix)
 {
     assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
@@ -799,12 +753,13 @@ template <typename T, class S> T toInt(S str, sal_Int16 
nRadix)
     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
         nRadix = 10;
 
-    auto pStr = getIter(str);
+    auto pStr = str.getIter();
+    const auto atEnd = str.getEndDetector();
 
     /* Skip whitespaces */
-    while (good(pStr, str) && rtl_ImplIsWhitespace(IMPL_RTL_USTRCODE(*pStr)))
+    while (!atEnd(pStr) && rtl_ImplIsWhitespace(IMPL_RTL_USTRCODE(*pStr)))
         pStr++;
-    if (!good(pStr, str))
+    if (atEnd(pStr))
         return 0;
 
     const bool bNeg = HandleSignChar<T>(pStr);
@@ -812,7 +767,7 @@ template <typename T, class S> T toInt(S str, sal_Int16 
nRadix)
     assert(nDiv > 0);
 
     std::make_unsigned_t<T> n = 0;
-    while (good(pStr, str))
+    while (!atEnd(pStr))
     {
         sal_Int16 nDigit = rtl_ImplGetDigit(IMPL_RTL_USTRCODE(*pStr), nRadix);
         if ( nDigit < 0 )
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index 4451866e4588..99f4575b1240 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -164,7 +164,8 @@ 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, rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareNormal(), 
rtl::str::noShortening);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -174,7 +175,9 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compare_WithLength( const 
sal_Unicode* pStr1,
                                                       const char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, 
rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareNormal(), 
rtl::str::noShortening);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -185,8 +188,9 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_shortenedCompare_WithLength( const sal_Unicode
                                                                sal_Int32 
nShortenedLength )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nShortenedLength,
-                                                 rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareNormal(), nShortenedLength);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -230,7 +234,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase( 
const sal_Unicode* pSt
                                                           const char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -240,15 +245,18 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( const sal_U
                                                                      const 
char* pStr2 )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, 
rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 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::compare_WithLengths(first, firstLen, second, secondLen,
-                                         rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(first, firstLen),
+                             rtl::str::with_length(second, secondLen),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -259,8 +267,9 @@ sal_Int32 SAL_CALL 
rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( co
                                                                               
sal_Int32 nShortenedLength )
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, 
nShortenedLength,
-                                                 
rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareIgnoreAsciiCase(), 
nShortenedLength);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -981,23 +990,26 @@ 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, rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareNormal(), 
rtl::str::noShortening);
 }
 
 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_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
-                                         rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len), 
rtl::str::CompareNormal(),
+                             rtl::str::noShortening);
 }
 
 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_WithLengths(pStr1, nStr1Len, pStr2, 
nStr2Len,
-                                                  nShortenedLength, 
rtl::str::CompareNormal());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len), 
rtl::str::CompareNormal(),
+                             nShortenedLength);
 }
 
 sal_Int32 SAL_CALL rtl_ustr_reverseCompare_WithLength(const sal_Unicode* 
pStr1, sal_Int32 nStr1Len,
@@ -1011,7 +1023,8 @@ sal_Int32 SAL_CALL 
rtl_ustr_reverseCompare_WithLength(const sal_Unicode* pStr1,
 sal_Int32 SAL_CALL rtl_ustr_compareIgnoreAsciiCase(const sal_Unicode* pStr1,
                                                    const sal_Unicode* pStr2) 
SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare(pStr1, pStr2, rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::null_terminated(pStr1), 
rtl::str::null_terminated(pStr2),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 sal_Int32 SAL_CALL rtl_ustr_compareIgnoreAsciiCase_WithLength(const 
sal_Unicode* pStr1,
@@ -1020,16 +1033,18 @@ sal_Int32 SAL_CALL 
rtl_ustr_compareIgnoreAsciiCase_WithLength(const sal_Unicode*
                                                               sal_Int32 
nStr2Len)
     SAL_THROW_EXTERN_C()
 {
-    return rtl::str::compare_WithLengths(pStr1, nStr1Len, pStr2, nStr2Len,
-                                         rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareIgnoreAsciiCase(), 
rtl::str::noShortening);
 }
 
 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::shortenedCompare_WithLengths(
-        pStr1, nStr1Len, pStr2, nStr2Len, nShortenedLength, 
rtl::str::CompareIgnoreAsciiCase());
+    return rtl::str::compare(rtl::str::with_length(pStr1, nStr1Len),
+                             rtl::str::with_length(pStr2, nStr2Len),
+                             rtl::str::CompareIgnoreAsciiCase(), 
nShortenedLength);
 }
 
 sal_Int32 SAL_CALL rtl_ustr_hashCode(const sal_Unicode* pStr) 
SAL_THROW_EXTERN_C()
@@ -1171,35 +1186,30 @@ sal_Bool SAL_CALL rtl_ustr_toBoolean(const sal_Unicode* 
pStr) SAL_THROW_EXTERN_C
 
 sal_Int32 SAL_CALL rtl_ustr_toInt32(const sal_Unicode* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_Int32>(pStr, nRadix);
+    return rtl::str::toInt<sal_Int32>(rtl::str::null_terminated(pStr), nRadix);
 }
 
 sal_Int64 SAL_CALL rtl_ustr_toInt64(const sal_Unicode* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_Int64>(pStr, nRadix);
+    return rtl::str::toInt<sal_Int64>(rtl::str::null_terminated(pStr), nRadix);
 }
 
 sal_Int64 SAL_CALL rtl_ustr_toInt64_WithLength(const sal_Unicode* pStr, 
sal_Int16 nRadix,
                                                sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
 {
-    assert(pStr || nStrLength == 0);
-    return rtl::str::toInt<sal_Int64>(std::basic_string_view(pStr, 
nStrLength), nRadix);
+    return rtl::str::toInt<sal_Int64>(rtl::str::with_length(pStr, nStrLength), 
nRadix);
 }
 
 sal_uInt32 SAL_CALL rtl_ustr_toUInt32(const sal_Unicode* pStr, sal_Int16 
nRadix)
     SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_uInt32>(pStr, nRadix);
+    return rtl::str::toInt<sal_uInt32>(rtl::str::null_terminated(pStr), 
nRadix);
 }
 
 sal_uInt64 SAL_CALL rtl_ustr_toUInt64(const sal_Unicode* pStr, sal_Int16 
nRadix)
     SAL_THROW_EXTERN_C()
 {
-    assert(pStr);
-    return rtl::str::toInt<sal_uInt64>(pStr, nRadix);
+    return rtl::str::toInt<sal_uInt64>(rtl::str::null_terminated(pStr), 
nRadix);
 }
 
 rtl_uString* rtl_uString_ImplAlloc(sal_Int32 nLen)

Reply via email to