diff options
-rw-r--r-- | sal/inc/rtl/ustring.hxx | 40 | ||||
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index 37e455a75c51..017b04343909 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -944,6 +944,46 @@ public: } /** + Check whether this string ends with a given string, ignoring the case of + ASCII letters. + + Character values between 65 and 90 (ASCII A-Z) are interpreted as + values between 97 and 122 (ASCII a-z). + This function can't be used for language specific comparison. + + @param str the object (substring) to be compared. + @return true if this string ends with str, ignoring the case of ASCII + letters ("A"--"Z" and "a"--"z"); otherwise, false is returned + @since 3.6 + */ + sal_Bool endsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(()) + { + return str.getLength() <= getLength() + && matchIgnoreAsciiCase(str, getLength() - str.getLength()); + } + + /** + @overload + This function accepts an ASCII string literal as its argument. + @since 3.6 + */ + template< int N > + sal_Bool endsWithIgnoreAsciiCase( const char (&literal)[ N ] ) const SAL_THROW(()) + { + return N - 1 <= pData->length + && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + pData->buffer + pData->length - ( N - 1 ), + N - 1, literal, N - 1) + == 0); + } + + /** + * It is an error to call this overload. Strings cannot directly use non-const char[]. + * @internal + */ + template< int N > + sal_Bool endsWithIgnoreAsciiCase( char (&literal)[ N ] ) const SAL_THROW(()); + /** Check whether this string ends with a given ASCII string, ignoring the case of ASCII letters. diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx index d35596c34111..59e130071484 100644 --- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -120,6 +120,7 @@ void test::oustring::StringLiterals::checkUsage() CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( "bAr", 3 )); CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( "fOo" )); CPPUNIT_ASSERT( foobar.endsWith( "bar" )); + CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( "bar" )); CPPUNIT_ASSERT( foo == "foo" ); CPPUNIT_ASSERT( "foo" == foo ); CPPUNIT_ASSERT( foo != "bar" ); |