diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-12-16 17:04:08 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-12-17 16:11:10 +0000 |
commit | 87707670c993794ab12b0fad0f048f11429269c2 (patch) | |
tree | 404dd9e971931d39b4ec8afd04f3e07378b7351f /sal | |
parent | e3077960cdc6c12eb2f5f940393e0fe3052f53a5 (diff) |
Make OUStringLiteral more useful
...by:
* making the OUStringLiteral ctor non-explicit (to be exploited in a follow-up
commit)
* adding (LIBO_INTERNAL_ONLY) overloads to OUString/OUStringBuffer functions
that can now take OUStringLiteral in addition to taking "real" string literals
(Keeping the number of overloads smaller by replacing the ConstCharArrayDetector
overloads with ones taking OUStringLiteral (for LIBO_INTERNAL_ONLY, at least)
and relying on the now-implicit conversion from "real" string literals to
OUStringLiteral unfortunately would not work: Both OUString and OUStringLiteral
argubably need implicit conversions from "real" string literals, so any function
overloaded for OUString and OUStringLiteral would be ambinguous when called with
a "real" string literal. And removing the OUString ctor taking a "real" string
literal and relying on an implicit conversion chain from "real" string literal
to OUStringLiteral to OUString doesn't work because it would involve two user-
provided conversions.)
Change-Id: I14433fc1605b048807f60b3a3e14f92221d3a226
Reviewed-on: https://gerrit.libreoffice.org/32097
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx index 0db4e2981620..3c0b996627dc 100644 --- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -216,6 +216,103 @@ void test::oustring::StringLiterals::checkOUStringLiteral() { CPPUNIT_ASSERT(bool(conditional(true) == "a")); CPPUNIT_ASSERT(bool(conditional(false) == "bb")); + + rtl::OUString s1(rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), s1); + s1 = rtlunittest::OUStringLiteral("de"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("de"), s1); + s1 += rtlunittest::OUStringLiteral("fde"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("defde"), s1); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + s1.reverseCompareTo(rtlunittest::OUStringLiteral("defde"))); + CPPUNIT_ASSERT( + s1.equalsIgnoreAsciiCase(rtlunittest::OUStringLiteral("DEFDE"))); + CPPUNIT_ASSERT(s1.match(rtlunittest::OUStringLiteral("fde"), 2)); + CPPUNIT_ASSERT( + s1.matchIgnoreAsciiCase(rtlunittest::OUStringLiteral("FDE"), 2)); + rtl::OUString s2; + CPPUNIT_ASSERT(s1.startsWith(rtlunittest::OUStringLiteral("de"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("fde"), s2); + CPPUNIT_ASSERT( + s1.startsWithIgnoreAsciiCase( + rtlunittest::OUStringLiteral("DEFD"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("e"), s2); + CPPUNIT_ASSERT(s1.endsWith(rtlunittest::OUStringLiteral("de"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("def"), s2); + CPPUNIT_ASSERT( + s1.endsWithIgnoreAsciiCase(rtlunittest::OUStringLiteral("EFDE"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("d"), s2); + CPPUNIT_ASSERT(bool(s1 == rtlunittest::OUStringLiteral("defde"))); + CPPUNIT_ASSERT(bool(rtlunittest::OUStringLiteral("defde") == s1)); + CPPUNIT_ASSERT(s1 != rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT(rtlunittest::OUStringLiteral("abc") != s1); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), s1.indexOf(rtlunittest::OUStringLiteral("de"), 1)); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), s1.lastIndexOf(rtlunittest::OUStringLiteral("de"))); + sal_Int32 i = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtlunittest::OUStringLiteral("de"), rtl::OUString("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtl::OUString("de"), rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtlunittest::OUStringLiteral("de"), + rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst(rtlunittest::OUStringLiteral("de"), "abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst("de", rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtlunittest::OUStringLiteral("de"), rtl::OUString("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtl::OUString("de"), rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtlunittest::OUStringLiteral("de"), + rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll(rtlunittest::OUStringLiteral("de"), "abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll("de", rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), + rtl::OUString( + rtl::OUString("abc") + rtlunittest::OUStringLiteral("def"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), + rtl::OUString( + rtlunittest::OUStringLiteral("abc") + rtl::OUString("def"))); + rtl::OUStringBuffer b(rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), b.toString()); + b.append(rtlunittest::OUStringLiteral("def")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abcdef"), b.toString()); + b.insert(2, rtlunittest::OUStringLiteral("gabab")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abgababcdef"), b.toString()); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), b.indexOf(rtlunittest::OUStringLiteral("ab"), 1)); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(5), b.lastIndexOf(rtlunittest::OUStringLiteral("ab"))); } void test::oustring::StringLiterals::checkOUStringLiteral1() |