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
@@ -729,18 +729,25 @@ public:
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
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,
asciiStr, maxLength );
}
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
@@ -27,19 +27,16 @@ namespace test { namespace oustring {
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();
};
} }
@@ -60,22 +57,12 @@ void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
CPPUNIT_ASSERT(!rtl::OUString("abcd").
equalsIgnoreAsciiCaseAscii("abc"));
CPPUNIT_ASSERT(!rtl::OUString("abc").
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(
sal_Int32(0),
rtl::OUString("abc").compareToIgnoreAsciiCase(rtl::OUString("ABC")));
CPPUNIT_ASSERT(