From c075b8068bff1b3c6025638aaf0acab5bbebab4d Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 17 Dec 2012 16:27:22 +0100 Subject: OUString::reverseCompareTo() string literal overload to match the AsciiL one Change-Id: Id5ca706aa3fd1831990db2310933c6b94ca376cb --- sal/inc/rtl/ustring.hxx | 13 +++++++++++++ sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 1 + 2 files changed, 14 insertions(+) (limited to 'sal') diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index 5760914fcc3f..c9fe25ec6131 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -527,6 +527,19 @@ public: str.pData->buffer, str.pData->length ); } + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 4.1 + */ + template< typename T > + typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const SAL_THROW(()) + { + assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); + return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length, + literal, internal::ConstCharArrayDetector< T, void >::size - 1 ); + } + /** Perform a comparison of two strings. diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx index a6d7145b9700..873b5366f6a5 100644 --- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -145,6 +145,7 @@ void test::oustring::StringLiterals::checkUsage() CPPUNIT_ASSERT( foobarfoo.replaceFirst( "foo", "test" ) == "testbarfoo" ); CPPUNIT_ASSERT( foobarfoo.replaceAll( "foo", test ) == "testbartest" ); CPPUNIT_ASSERT( foobarfoo.replaceAll( "foo", "test" ) == "testbartest" ); + CPPUNIT_ASSERT( foo.reverseCompareTo( "foo" ) == 0 ); // if this is not true, some of the calls above converted to OUString CPPUNIT_ASSERT( rtl_string_unittest_const_literal == false ); } -- cgit