diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-10-01 09:09:45 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-10-11 14:22:22 +0200 |
commit | 4f5b3e4bd53d6d61df1f65f496f7bc8dc525c8a1 (patch) | |
tree | e0ac44b8f22f944f3303bac8e494da41d6c7b164 /include/rtl | |
parent | 5f84c44e3d5ff19b800b6358e61228546e318d4f (diff) |
In O[U]StringBuffer, make string_view params replacements for OUString ones
...for LIBO_INTERNAL_ONLY, instead of having them as additional overloads. That
way, loplugin:bufferadd and loplugin:stringviewparam found many further
opportunities for simplification (all addressed here). Some notes:
* There is no longer an implicit conversion from O[U]String to O[U]StringBuffer
(as that goes via user-defined conversions through string_view now), which was
most noticeable in copy initializations like
OStringBuffer buf = someStr;
that had to be changed to direct initialization,
OStringBuffer buf(someStr);
But then again, it wasn't too many places that were affected and I think we can
live with that.
* I made the O[U]StringBuffer ctors taking string_view non-explicit, mainly to
get them in line with their counterparts taking O[U]String.
* I added an OUStringBuffer::lastIndexOf string_view overload that was missing
(relative to OUStringBuffer::indexOf).
* loplugin:stringconstant needed some addition to keep the
compilerplugins/clang/test/stringconstant.cxx checks related to
OStringBuffer::append and OStringBuffer::insert working.
* loplugin:stringviewparam no longer needs the special O[U]StringBuffer-related
code that had been introduced in 1250aecd71fabde4dba990bfceb61bbe8e06b8ea
"loplugin:stringviewparam extend to new.."
Change-Id: Ib1bb8c4632d99b744e742605a9fef6eae959fd72
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122904
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/strbuf.hxx | 13 | ||||
-rw-r--r-- | include/rtl/ustrbuf.hxx | 32 |
2 files changed, 33 insertions, 12 deletions
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx index a238f305fa07..52399b6da8b4 100644 --- a/include/rtl/strbuf.hxx +++ b/include/rtl/strbuf.hxx @@ -137,7 +137,7 @@ public: @param value the initial string value. */ #if defined LIBO_INTERNAL_ONLY - explicit OStringBuffer(std::string_view sv) + OStringBuffer(std::string_view sv) : pData(nullptr) , nCapacity( sv.length() + 16 ) { @@ -146,13 +146,14 @@ public: } rtl_stringbuffer_newFromStr_WithLength( &pData, sv.data(), sv.length() ); } -#endif +#else OStringBuffer(const OString& value) : pData(NULL) , nCapacity( value.getLength() + 16 ) { rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() ); } +#endif /** @overload @@ -280,7 +281,7 @@ public: pData->length = n; return *this; } -#endif +#else OStringBuffer & operator =(OString const & string) { sal_Int32 n = string.getLength(); if (n >= nCapacity) { @@ -290,6 +291,7 @@ public: pData->length = n; return *this; } +#endif /** Assign from a string literal. @@ -513,6 +515,7 @@ public: return OString(pData->buffer, pData->length); } +#if !defined LIBO_INTERNAL_ONLY /** Appends the string to this string buffer. @@ -527,6 +530,7 @@ public: { return append( str.getStr(), str.getLength() ); } +#endif /** Appends the string representation of the <code>char</code> array @@ -799,11 +803,12 @@ public: { return insert( offset, str.data(), str.length() ); } -#endif +#else OStringBuffer & insert(sal_Int32 offset, const OString & str) { return insert( offset, str.getStr(), str.getLength() ); } +#endif /** Inserts the string representation of the <code>char</code> array diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 65762d53960d..2b8288b26b1e 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -138,7 +138,7 @@ public: @param value the initial contents of the buffer. */ #if defined LIBO_INTERNAL_ONLY - explicit OUStringBuffer(std::u16string_view sv) + OUStringBuffer(std::u16string_view sv) : pData(nullptr) , nCapacity( sv.length() + 16 ) { @@ -147,13 +147,14 @@ public: } rtl_uStringbuffer_newFromStr_WithLength( &pData, sv.data(), sv.length() ); } -#endif +#else OUStringBuffer(const OUString& value) : pData(NULL) , nCapacity( value.getLength() + 16 ) { rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() ); } +#endif template< typename T > OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() ) @@ -288,7 +289,7 @@ public: pData->length = n; return *this; } -#endif +#else OUStringBuffer & operator =(OUString const & string) { sal_Int32 n = string.getLength(); if (n >= nCapacity) { @@ -300,6 +301,7 @@ public: pData->length = n; return *this; } +#endif /** Assign from a string literal. @@ -583,12 +585,12 @@ public: @param str a string. @return this string buffer. */ +#if !defined LIBO_INTERNAL_ONLY OUStringBuffer & append(const OUString &str) { return append( str.getStr(), str.getLength() ); } - -#if defined LIBO_INTERNAL_ONLY +#else OUStringBuffer & append(std::u16string_view sv) { if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) { throw std::bad_alloc(); @@ -597,6 +599,7 @@ public: } #endif +#if !defined LIBO_INTERNAL_ONLY /** Appends the content of a stringbuffer to this string buffer. @@ -617,6 +620,7 @@ public: } return *this; } +#endif /** Appends the string representation of the <code>char</code> array @@ -992,11 +996,12 @@ public: { return insert( offset, str.data(), str.length() ); } -#endif +#else OUStringBuffer & insert(sal_Int32 offset, const OUString & str) { return insert( offset, str.getStr(), str.getLength() ); } +#endif /** Inserts the string representation of the <code>char</code> array @@ -1452,7 +1457,7 @@ public: str.data(), str.length() ); return (ret < 0 ? ret : ret+fromIndex); } -#endif +#else sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const { assert( fromIndex >= 0 && fromIndex <= pData->length ); @@ -1460,6 +1465,7 @@ public: str.pData->buffer, str.pData->length ); return (ret < 0 ? ret : ret+fromIndex); } +#endif /** @overload @@ -1528,12 +1534,13 @@ public: return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length, str.data(), str.length() ); } -#endif +#else sal_Int32 lastIndexOf( const OUString & str ) const { return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length, str.pData->buffer, str.pData->length ); } +#endif /** Returns the index within this string of the last occurrence of @@ -1554,12 +1561,21 @@ public: of the first character of the last such substring is returned. Otherwise, -1 is returned. */ +#if defined LIBO_INTERNAL_ONLY + sal_Int32 lastIndexOf( std::u16string_view str, sal_Int32 fromIndex ) const + { + assert( fromIndex >= 0 && fromIndex <= pData->length ); + return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex, + str.data(), str.length() ); + } +#else sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const { assert( fromIndex >= 0 && fromIndex <= pData->length ); return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex, str.pData->buffer, str.pData->length ); } +#endif /** @overload |