summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-03-20 13:04:28 +0100
committerStephan Bergmann <sbergman@redhat.com>2013-03-20 13:05:35 +0100
commit77c87c18697e19cb4606717af0e4b0e5ab2139bc (patch)
treedc6345e65a30c924e7c84487a7da7dfbf10a06eb
parent2d9ce9191da681e4fd9f1d08933ca5117c56601b (diff)
Deprecate confusing rtl::OUString::compareToAscii(asciiStr, maxLength)
Change-Id: I3a41036ec03cdaefea94b19dbedf59e5a5e37dc8
-rw-r--r--sal/inc/rtl/ustring.hxx7
-rw-r--r--sal/qa/rtl/strings/test_oustring_compare.cxx13
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:
732 127. The ASCII string must be NULL-terminated. 732 127. The ASCII string must be NULL-terminated.
733 This function can't be used for language specific sorting. 733 This function can't be used for language specific sorting.
734 734
735 @deprecated This is a confusing overload with unexpectedly different
736 semantics from the one-parameter form, so it is marked as deprecated.
737 Practically all uses compare the return value against zero and can thus
738 be replaced with uses of startsWith.
739
735 @param asciiStr the 8-Bit ASCII character string to be compared. 740 @param asciiStr the 8-Bit ASCII character string to be compared.
736 @param maxLength the maximum count of characters to be compared. 741 @param maxLength the maximum count of characters to be compared.
737 @return 0 - if both strings are equal 742 @return 0 - if both strings are equal
738 < 0 - if this string is less than the string argument 743 < 0 - if this string is less than the string argument
739 > 0 - if this string is greater than the string argument 744 > 0 - if this string is greater than the string argument
740 */ 745 */
746 SAL_DEPRECATED(
747 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
741 sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(()) 748 sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
742 { 749 {
743 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length, 750 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
30private: 30private:
31 void equalsIgnoreAsciiCaseAscii(); 31 void equalsIgnoreAsciiCaseAscii();
32 32
33 void compareToAscii();
34
35 void compareToIgnoreAsciiCase(); 33 void compareToIgnoreAsciiCase();
36 34
37CPPUNIT_TEST_SUITE(Compare); 35CPPUNIT_TEST_SUITE(Compare);
38CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii); 36CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii);
39CPPUNIT_TEST(compareToAscii);
40CPPUNIT_TEST(compareToIgnoreAsciiCase); 37CPPUNIT_TEST(compareToIgnoreAsciiCase);
41CPPUNIT_TEST_SUITE_END(); 38CPPUNIT_TEST_SUITE_END();
42}; 39};
@@ -63,16 +60,6 @@ void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
63 equalsIgnoreAsciiCaseAscii("abcd")); 60 equalsIgnoreAsciiCaseAscii("abcd"));
64} 61}
65 62
66void test::oustring::Compare::compareToAscii()
67{
68 // The different overloads of compareToAscii exhibit potentially confusing
69 // behavior:
70 rtl::OUString abc("abc");
71 CPPUNIT_ASSERT(abc.compareToAscii("a") > 0);
72 CPPUNIT_ASSERT_EQUAL(
73 sal_Int32(0), abc.compareToAscii(RTL_CONSTASCII_STRINGPARAM("a")));
74}
75
76void test::oustring::Compare::compareToIgnoreAsciiCase() 63void test::oustring::Compare::compareToIgnoreAsciiCase()
77{ 64{
78 CPPUNIT_ASSERT_EQUAL( 65 CPPUNIT_ASSERT_EQUAL(