From 77c87c18697e19cb4606717af0e4b0e5ab2139bc Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 20 Mar 2013 13:04:28 +0100 Subject: Deprecate confusing rtl::OUString::compareToAscii(asciiStr, maxLength) Change-Id: I3a41036ec03cdaefea94b19dbedf59e5a5e37dc8 --- sal/inc/rtl/ustring.hxx | 7 +++++++ sal/qa/rtl/strings/test_oustring_compare.cxx | 13 ------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index ae0af9eb8be4..4d9650e535c8 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -732,12 +732,19 @@ public: 127. The ASCII string must be NULL-terminated. This function can't be used for language specific sorting. + @deprecated This is a confusing overload with unexpectedly different + semantics from the one-parameter form, so it is marked as deprecated. + Practically all uses compare the return value against zero and can thus + be replaced with uses of startsWith. + @param asciiStr the 8-Bit ASCII character string to be compared. @param maxLength the maximum count of characters to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument */ + SAL_DEPRECATED( + "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)") sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(()) { return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length, diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx index e3ad8dd9d4bf..7f56546df914 100644 --- a/sal/qa/rtl/strings/test_oustring_compare.cxx +++ b/sal/qa/rtl/strings/test_oustring_compare.cxx @@ -30,13 +30,10 @@ class Compare: public CppUnit::TestFixture private: void equalsIgnoreAsciiCaseAscii(); - void compareToAscii(); - void compareToIgnoreAsciiCase(); CPPUNIT_TEST_SUITE(Compare); CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii); -CPPUNIT_TEST(compareToAscii); CPPUNIT_TEST(compareToIgnoreAsciiCase); CPPUNIT_TEST_SUITE_END(); }; @@ -63,16 +60,6 @@ void test::oustring::Compare::equalsIgnoreAsciiCaseAscii() equalsIgnoreAsciiCaseAscii("abcd")); } -void test::oustring::Compare::compareToAscii() -{ - // The different overloads of compareToAscii exhibit potentially confusing - // behavior: - rtl::OUString abc("abc"); - CPPUNIT_ASSERT(abc.compareToAscii("a") > 0); - CPPUNIT_ASSERT_EQUAL( - sal_Int32(0), abc.compareToAscii(RTL_CONSTASCII_STRINGPARAM("a"))); -} - void test::oustring::Compare::compareToIgnoreAsciiCase() { CPPUNIT_ASSERT_EQUAL( -- cgit v1.2.3