fix o3tl::equalsIgnoreAsciiCase()
As the OUString equivalent shows, it needs to check == 0. Commit
33ecd0d5c4 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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -60,6 +60,7 @@ private:
|
||||
CPPUNIT_TEST(testStartsWithRest);
|
||||
CPPUNIT_TEST(testEndsWith);
|
||||
CPPUNIT_TEST(testEndsWithRest);
|
||||
CPPUNIT_TEST(testEqualsIgnoreAsciiCase);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void testStartsWith()
|
||||
@@ -585,6 +586,13 @@ private:
|
||||
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
|
||||
}
|
||||
}
|
||||
|
||||
void testEqualsIgnoreAsciiCase()
|
||||
{
|
||||
using namespace std::string_view_literals;
|
||||
CPPUNIT_ASSERT(o3tl::equalsIgnoreAsciiCase(u"test"sv, u"test"sv));
|
||||
CPPUNIT_ASSERT(!o3tl::equalsIgnoreAsciiCase(u"test"sv, u"test2"sv));
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
||||
|
||||
Reference in New Issue
Block a user