summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-04-12 12:03:10 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-04-12 19:49:15 +0200
commit53a4b94d018820689e0b98d7fa0a92563e3971a1 (patch)
tree7bf9e41d527b2ad1f1216f8a2cf19fdc5c8aee0d /include
parentd4257802159e672035fab164b0cabd9222f18515 (diff)
Use more *string_view
OUString::equalsIgnoreAsciiCaseAscii and compareToIgnoreAsciiCaseAscii taking string_view are added as overloads, rather than replacements to the variants taking const char*, because the latter have benefit when the passed C-style string's length is unknown, because these variants don't pre-calculate the length. Change-Id: I2def689d7b7784212dc6cd6b8ae9ab1d42604079 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150272 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/rtl/ustring.hxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 263cb71d74c9..c4869f43a8f0 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -35,6 +35,7 @@
#include <utility>
#if defined LIBO_INTERNAL_ONLY
+#include <algorithm>
#include <string_view>
#include <type_traits>
#endif
@@ -47,6 +48,7 @@
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
#include "config_global.h"
+#include "o3tl/safeint.hxx"
#include "rtl/stringconcat.hxx"
#endif
@@ -1307,6 +1309,15 @@ public:
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
}
+#if defined LIBO_INTERNAL_ONLY
+ bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
+ {
+ return o3tl::make_unsigned(pData->length) == asciiStr.length()
+ && rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
+ }
+#endif
+
/**
Compares two ASCII strings ignoring case
@@ -1330,6 +1341,18 @@ public:
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
}
+#if defined LIBO_INTERNAL_ONLY
+ sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
+ {
+ sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
+ sal_Int32 result = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer, pData->length, asciiStr.data(), nMax);
+ if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
+ result = -1;
+ return result;
+ }
+#endif
+
/**
Perform an ASCII lowercase comparison of two strings.