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 | |
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>
-rw-r--r-- | include/rtl/ustrbuf.hxx | 52 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 334 | ||||
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 97 |
3 files changed, 477 insertions, 6 deletions
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 07188a73921e..7a9448d02d5d 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -162,6 +162,13 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), libreoffice_internal::ConstCharArrayDetector<T>::length); } + + /** @overload @since LibreOffice 5.4 */ + OUStringBuffer(OUStringLiteral const & literal): + pData(nullptr), nCapacity(literal.size + 16) //TODO: check for overflow + { + rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 16); + } #endif #ifdef RTL_STRING_UNITTEST @@ -282,6 +289,21 @@ public: pData->length = n; return *this; } + + /** @overload @since LibreOffice 5.4 */ + OUStringBuffer & operator =(OUStringLiteral const & literal) { + sal_Int32 const n = literal.size; + if (n >= nCapacity) { + ensureCapacity(n + 16); //TODO: check for overflow + } + char const * from = literal.data; + sal_Unicode * to = pData->buffer; + for (sal_Int32 i = 0; i <= n; ++i) { + to[i] = from[i]; + } + pData->length = n; + return *this; + } #endif #if defined LIBO_INTERNAL_ONLY @@ -590,6 +612,13 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length); return *this; } + + /** @overload @since LibreOffice 5.4 */ + OUStringBuffer & append(OUStringLiteral const & literal) { + rtl_uStringbuffer_insert_ascii( + &pData, &nCapacity, getLength(), literal.data, literal.size); + return *this; + } #endif #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" @@ -956,6 +985,13 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length); return *this; } + + /** @overload @since LibreOffice 5.4 */ + OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & literal) { + rtl_uStringbuffer_insert_ascii( + &pData, &nCapacity, offset, literal.data, literal.size); + return *this; + } #endif /** @@ -1360,6 +1396,16 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length); return n < 0 ? n : n + fromIndex; } + + /** @overload @since LibreOffice 5.4 */ + sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0) + const + { + sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, literal.data, + literal.size); + return n < 0 ? n : n + fromIndex; + } #endif /** @@ -1438,6 +1484,12 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), libreoffice_internal::ConstCharArrayDetector<T>::length); } + + /** @overload @since LibreOffice 5.4 */ + sal_Int32 lastIndexOf(OUStringLiteral const & literal) const { + return rtl_ustr_lastIndexOfAscii_WithLength( + pData->buffer, pData->length, literal.data, literal.size); + } #endif /** diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 337e8509a53d..c6c312442dec 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -59,18 +59,28 @@ namespace rtl /// @cond INTERNAL /** -A simple wrapper around string literal. It is usually not necessary to use, can -be mostly used to force OUString operator+ working with operands that otherwise would -not trigger it. +A simple wrapper around string literal. This class is not part of public API and is meant to be used only in LibreOffice code. @since LibreOffice 4.0 */ struct SAL_WARN_UNUSED OUStringLiteral { - template< int N > - explicit SAL_CONSTEXPR OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) - { /* only C++14 constexpr: assert( strlen( str ) == N - 1 ); */ } + template<typename T> SAL_CONSTEXPR OUStringLiteral( + T & literal, + typename libreoffice_internal::ConstCharArrayDetector< + T, libreoffice_internal::Dummy>::Type + = libreoffice_internal::Dummy()): + size(libreoffice_internal::ConstCharArrayDetector<T>::length), + data( + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal)) + { +#if HAVE_CXX14_CONSTEXPR + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); +#endif + } + int size; const char* data; }; @@ -489,6 +499,16 @@ public: } return *this; } + + /** @overload @since LibreOffice 5.4 */ + OUString & operator =(OUStringLiteral const & literal) { + if (literal.size == 0) { + rtl_uString_new(&pData); + } else { + rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0); + } + return *this; + } #endif /** @@ -557,6 +577,19 @@ public: libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16 operator +=(T &) && = delete; #endif + + /** @overload @since LibreOffice 5.4 */ + OUString & operator +=(OUStringLiteral const & literal) +#if HAVE_CXX11_REF_QUALIFIER + & +#endif + { + rtl_uString_newConcatAsciiL(&pData, pData, literal.data, literal.size); + return *this; + } +#if HAVE_CXX11_REF_QUALIFIER + void operator +=(OUStringLiteral const &) && = delete; +#endif #endif #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" @@ -726,6 +759,12 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), libreoffice_internal::ConstCharArrayDetector<T>::length); } + + /** @overload @since LibreOffice 5.4 */ + sal_Int32 reverseCompareTo(OUStringLiteral const & literal) const { + return rtl_ustr_asciil_reverseCompare_WithLength( + pData->buffer, pData->length, literal.data, literal.size); + } #endif /** @@ -828,6 +867,14 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length) == 0; } + + /** @overload @since LibreOffice 5.4 */ + bool equalsIgnoreAsciiCase(OUStringLiteral const & literal) const { + return pData->length == literal.size + && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( + pData->buffer, pData->length, literal.data) + == 0); + } #endif /** @@ -885,6 +932,15 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length) == 0; } + + /** @overload @since LibreOffice 5.4 */ + bool match(OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const { + return + rtl_ustr_ascii_shortenedCompare_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, + literal.data, literal.size) + == 0; + } #endif /** @@ -946,6 +1002,17 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length) == 0; } + + /** @overload @since LibreOffice 5.4 */ + bool matchIgnoreAsciiCase( + OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const + { + return + rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( + pData->buffer+fromIndex, pData->length-fromIndex, literal.data, + literal.size) + == 0; + } #endif /** @@ -1288,6 +1355,19 @@ public: } return b; } + + /** @overload @since LibreOffice 5.4 */ + bool startsWith(OUStringLiteral const & literal, OUString * rest = nullptr) + const + { + bool b = literal.size <= pData->length + && rtl_ustr_asciil_reverseEquals_WithLength( + pData->buffer, literal.data, literal.size); + if (b && rest != nullptr) { + *rest = copy(literal.size); + } + return b; + } #endif /** @@ -1367,6 +1447,20 @@ public: } return b; } + + /** @overload @since LibreOffice 5.4 */ + bool startsWithIgnoreAsciiCase( + OUStringLiteral const & literal, OUString * rest = nullptr) const + { + bool b + = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + pData->buffer, literal.size, literal.data, literal.size) + == 0); + if (b && rest != nullptr) { + *rest = copy(literal.size); + } + return b; + } #endif /** @@ -1445,6 +1539,20 @@ public: } return b; } + + /** @overload @since LibreOffice 5.4 */ + bool endsWith(OUStringLiteral const & literal, OUString * rest = nullptr) + const + { + bool b = literal.size <= pData->length + && rtl_ustr_asciil_reverseEquals_WithLength( + pData->buffer + pData->length - literal.size, + literal.data, literal.size); + if (b && rest != nullptr) { + *rest = copy(0, (getLength() - literal.size)); + } + return b; + } #endif /** @@ -1552,6 +1660,21 @@ public: } return b; } + + /** @overload @since LibreOffice 5.4 */ + bool endsWithIgnoreAsciiCase( + OUStringLiteral const & literal, OUString * rest = nullptr) const + { + bool b = literal.size <= pData->length + && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + pData->buffer + pData->length - literal.size, + literal.size, literal.data, literal.size) + == 0); + if (b && rest != nullptr) { + *rest = copy(0, getLength() - literal.size); + } + return b; + } #endif /** @@ -1910,6 +2033,16 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::length); return n < 0 ? n : n + fromIndex; } + + /** @overload @since LibreOffice 5.4 */ + sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0) + const + { + sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, literal.data, + literal.size); + return n < 0 ? n : n + fromIndex; + } #endif /** @@ -2022,6 +2155,12 @@ public: libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), libreoffice_internal::ConstCharArrayDetector<T>::length); } + + /** @overload @since LibreOffice 5.4 */ + sal_Int32 lastIndexOf(OUStringLiteral const & literal) const { + return rtl_ustr_lastIndexOfAscii_WithLength( + pData->buffer, pData->length, literal.data, literal.size); + } #endif /** @@ -2390,6 +2529,109 @@ public: } return OUString(s, SAL_NO_ACQUIRE); } + + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceFirst( + OUStringLiteral const & from, OUString const & to, + sal_Int32 * index = nullptr) const + { + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiL( + &s, pData, from.data, from.size, to.pData, + index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceFirst( + OUString const & from, OUStringLiteral const & to, + sal_Int32 * index = nullptr) const + { + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstToAsciiL( + &s, pData, from.pData, to.data, to.size, + index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceFirst( + OUStringLiteral const & from, OUStringLiteral const & to, + sal_Int32 * index = nullptr) const + { + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiLAsciiL( + &s, pData, from.data, from.size, to.data, to.size, + index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type + replaceFirst( + OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const + { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to)); + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiLAsciiL( + &s, pData, from.data, from.size, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to), + libreoffice_internal::ConstCharArrayDetector<T>::length, + index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type + replaceFirst( + T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const + { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from)); + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiLAsciiL( + &s, pData, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from), + libreoffice_internal::ConstCharArrayDetector<T>::length, to.data, + to.size, index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename + libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16 + replaceFirst( + OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const + { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to)); + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiLUtf16L( + &s, pData, from.data, from.size, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to), + libreoffice_internal::ConstCharArrayDetector<T>::length, + index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename + libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16 + replaceFirst( + T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const + { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from)); + rtl_uString * s = nullptr; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstUtf16LAsciiL( + &s, pData, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from), + libreoffice_internal::ConstCharArrayDetector<T>::length, to.data, + to.size, index == nullptr ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } #endif /** @@ -2594,6 +2836,86 @@ public: } return OUString(s, SAL_NO_ACQUIRE); } + + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceAll( + OUStringLiteral const & from, OUString const & to) const + { + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllAsciiL( + &s, pData, from.data, from.size, to.pData); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceAll( + OUString const & from, OUStringLiteral const & to) const + { + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllToAsciiL( + &s, pData, from.pData, to.data, to.size); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + SAL_WARN_UNUSED_RESULT OUString replaceAll( + OUStringLiteral const & from, OUStringLiteral const & to) const + { + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllAsciiLAsciiL( + &s, pData, from.data, from.size, to.data, to.size); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type + replaceAll(OUStringLiteral const & from, T & to) const { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to)); + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllAsciiLAsciiL( + &s, pData, from.data, from.size, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to), + libreoffice_internal::ConstCharArrayDetector<T>::length); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type + replaceAll(T & from, OUStringLiteral const & to) const { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from)); + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllAsciiLAsciiL( + &s, pData, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from), + libreoffice_internal::ConstCharArrayDetector<T>::length, to.data, + to.size); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename + libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16 + replaceAll(OUStringLiteral const & from, T & to) const { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to)); + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllAsciiLUtf16L( + &s, pData, from.data, from.size, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to), + libreoffice_internal::ConstCharArrayDetector<T>::length); + return OUString(s, SAL_NO_ACQUIRE); + } + /** @overload @since LibreOffice 5.4 */ + template<typename T> SAL_WARN_UNUSED_RESULT + typename + libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16 + replaceAll(T & from, OUStringLiteral const & to) const { + assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from)); + rtl_uString * s = nullptr; + rtl_uString_newReplaceAllUtf16LAsciiL( + &s, pData, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from), + libreoffice_internal::ConstCharArrayDetector<T>::length, to.data, + to.size); + return OUString(s, SAL_NO_ACQUIRE); + } #endif /** 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() |