diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-03-08 02:26:15 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-03-12 13:35:58 +0100 |
commit | 814cb6a3d63707198e23131facb7ce9f23c389b6 (patch) | |
tree | 283ca363897bfd94cff3186b0f33b163a2e0835d /sal | |
parent | 91752ecd4ededaaf44f5ac870b3c01dd17b5d3c9 (diff) |
implement OUString::endsWithIgnoreAsciiCase()
match() has matchIgnoreAsciiCase(), so it makes sense that endsWith()
also has the IgnoreAsciiCase variant, especially given there already is
endsWithIgnoreAsciiCaseAsciiL()
Diffstat (limited to 'sal')
-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" ); |