sal/rtl/strtmpl.hxx |   40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

New commits:
commit 04af8ac89ecdc98361f52b792ff0ce1c3ccb4517
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Mar 3 10:18:20 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Mar 3 12:49:11 2022 +0100

    Use a more conventional begin() / end() syntax
    
    Also would potentially enable use in std range algorithms
    that take different end sentinel type.
    
    Change-Id: Ia75005caa7ce44302fc8612f5717a41d11087622
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130902
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 945aaa54a6e2..7234afd39ec1 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -30,7 +30,6 @@
 
 #include "strimp.hxx"
 
-#include <o3tl/safeint.hxx>
 #include <osl/diagnose.h>
 #include <sal/log.hxx>
 #include <rtl/character.hxx>
@@ -56,8 +55,15 @@ template <typename C> struct null_terminated
     {
         assert(pStr);
     }
-    auto getIter() const { return p; }
-    static auto getEndDetector() { return [](C* iter) { return *iter == 0; }; }
+    auto begin() const { return p; }
+    struct EndDetector
+    {
+        friend bool operator==(EndDetector, C* iter) { return *iter == 0; }
+        friend bool operator==(C* iter, EndDetector) { return *iter == 0; }
+        friend bool operator!=(EndDetector, C* iter) { return *iter != 0; }
+        friend bool operator!=(C* iter, EndDetector) { return *iter != 0; }
+    };
+    static auto end() { return EndDetector{}; }
 };
 
 template <typename C> struct with_length
@@ -70,8 +76,8 @@ template <typename C> struct with_length
     {
         assert(len >= 0);
     }
-    auto getIter() const { return p; }
-    auto getEndDetector() const { return [pEnd = p + len](C* iter) { return 
iter == pEnd; }; }
+    auto begin() const { return p; }
+    auto end() const { return p + len; }
 };
 
 template <typename C> void Copy(C* _pDest, const C* _pSrc, sal_Int32 _nCount)
@@ -166,17 +172,17 @@ sal_Int32 compare(S1 s1, S2 s2, Compare, Shorten_t 
shortenedLength)
 {
     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();
+    auto pStr1 = s1.begin();
+    const auto end1 = s1.end();
+    auto pStr2 = s2.begin();
+    const auto end2 = s2.end();
     for (;;)
     {
         if (shortenedLength == 0)
             return 0;
-        if (atEnd2(pStr2))
-            return atEnd1(pStr1) ? 0 : 1;
-        if (atEnd1(pStr1))
+        if (pStr2 == end2)
+            return pStr1 == end1 ? 0 : 1;
+        if (pStr1 == end1)
             return -1;
         if (const sal_Int32 nRet = Compare::compare(*pStr1, *pStr2))
             return nRet;
@@ -753,13 +759,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 = str.getIter();
-    const auto atEnd = str.getEndDetector();
+    auto pStr = str.begin();
+    const auto end = str.end();
 
     /* Skip whitespaces */
-    while (!atEnd(pStr) && rtl_ImplIsWhitespace(IMPL_RTL_USTRCODE(*pStr)))
+    while (pStr != end && rtl_ImplIsWhitespace(IMPL_RTL_USTRCODE(*pStr)))
         pStr++;
-    if (atEnd(pStr))
+    if (pStr == end)
         return 0;
 
     const bool bNeg = HandleSignChar<T>(pStr);
@@ -767,7 +773,7 @@ template <typename T, class S> T toInt(S str, sal_Int16 
nRadix)
     assert(nDiv > 0);
 
     std::make_unsigned_t<T> n = 0;
-    while (!atEnd(pStr))
+    while (pStr != end)
     {
         sal_Int16 nDigit = rtl_ImplGetDigit(IMPL_RTL_USTRCODE(*pStr), nRadix);
         if ( nDigit < 0 )

Reply via email to