summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-03-01 10:44:12 +0100
committerLuboš Luňák <l.lunak@collabora.com>2022-03-01 18:00:17 +0100
commitffe7850a1449c43dd077c5cb073d8eee178f7099 (patch)
tree0b68713d8aa234e861afc8172e392b41ee126248 /include
parentee2a192923bf709d05c174848e7054cd411b205a (diff)
fix o3tl::equalsIgnoreAsciiCase()
As the OUString equivalent shows, it needs to check == 0. Commit 33ecd0d5c4fff9511a8436513936a3f7044a775a for some reason also dropped the cheap checks (even from OUString) that OString has, so add them. Change-Id: I88e68b5ae10fd76c3c08b9b36d5abed0fad17bbf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130753 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Reviewed-by: Luboš Luňák <l.lunak@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/string_view.hxx7
-rw-r--r--include/rtl/ustring.hxx4
2 files changed, 10 insertions, 1 deletions
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 0ca26a829932..74f15bf33b54 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -23,7 +23,12 @@ namespace o3tl
// Like OUString::equalsIgnoreAsciiCase, but for two std::u16string_view:
inline bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
{
- return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), s2.data(), s2.size());
+ if (s1.size() != s2.size())
+ return false;
+ if (s1.data() == s2.data())
+ return true;
+ return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), s2.data(), s2.size())
+ == 0;
};
// Similar to OString::getToken, returning the first token of a std::string_view, starting at a
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index cad257caeb58..4d983a089f72 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -977,6 +977,10 @@ public:
*/
#if defined LIBO_INTERNAL_ONLY
bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
+ if ( sal_uInt32(pData->length) != sv.size() )
+ return false;
+ if ( pData->buffer == sv.data() )
+ return true;
return
rtl_ustr_compareIgnoreAsciiCase_WithLength(
pData->buffer, pData->length, sv.data(), sv.size())