From 53a4b94d018820689e0b98d7fa0a92563e3971a1 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 12 Apr 2023 12:03:10 +0300 Subject: 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 --- include/rtl/ustring.hxx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include/rtl') 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 #if defined LIBO_INTERNAL_ONLY +#include #include #include #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(asciiStr.length(), std::numeric_limits::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. -- cgit