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 | |
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')
-rw-r--r-- | include/basic/basmgr.hxx | 3 | ||||
-rw-r--r-- | include/rtl/strbuf.hxx | 13 | ||||
-rw-r--r-- | include/rtl/ustrbuf.hxx | 32 | ||||
-rw-r--r-- | include/tools/urlobj.hxx | 6 | ||||
-rw-r--r-- | include/unotools/fontcvt.hxx | 6 | ||||
-rw-r--r-- | include/unotools/fontdefs.hxx | 4 | ||||
-rw-r--r-- | include/unotools/localedatawrapper.hxx | 3 | ||||
-rw-r--r-- | include/vcl/builder.hxx | 2 | ||||
-rw-r--r-- | include/vcl/outdev.hxx | 3 | ||||
-rw-r--r-- | include/vcl/toolkit/field.hxx | 8 | ||||
-rw-r--r-- | include/vcl/uitest/logger.hxx | 2 |
11 files changed, 57 insertions, 25 deletions
diff --git a/include/basic/basmgr.hxx b/include/basic/basmgr.hxx index 32011eb70df6..e374f8f47b1c 100644 --- a/include/basic/basmgr.hxx +++ b/include/basic/basmgr.hxx @@ -24,6 +24,7 @@ #include <basic/sbstar.hxx> #include <basic/basicdllapi.h> #include <memory> +#include <string_view> #include <vector> namespace com::sun::star::script { class XLibraryContainer; } @@ -191,7 +192,7 @@ public: /// executes a given macro ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue ); /// executes a given macro - ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, OUString const& i_commaSeparatedArgs, SbxValue* i_retValue ); + ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, std::u16string_view i_commaSeparatedArgs, SbxValue* i_retValue ); private: BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib ); 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 diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx index 667bedbef388..7bb85917f952 100644 --- a/include/tools/urlobj.hxx +++ b/include/tools/urlobj.hxx @@ -297,7 +297,7 @@ public: bool ConcatData(INetProtocol eTheScheme, std::u16string_view rTheUser, std::u16string_view rThePassword, - OUString const & rTheHost, sal_uInt32 nThePort, + std::u16string_view rTheHost, sal_uInt32 nThePort, OUString const & rThePath); // Smart Parsing: @@ -445,7 +445,7 @@ public: sal_uInt32 GetPort() const; - bool SetHost(OUString const & rTheHost) + bool SetHost(std::u16string_view rTheHost) { return setHost(rTheHost, RTL_TEXTENCODING_UTF8); } bool SetPort(sal_uInt32 nThePort); @@ -1045,7 +1045,7 @@ private: bool bNetBiosName, OUStringBuffer* pCanonic); bool setHost( - OUString const & rTheHost, + std::u16string_view rTheHost, rtl_TextEncoding eCharset); // Path: diff --git a/include/unotools/fontcvt.hxx b/include/unotools/fontcvt.hxx index 7fbf2cc9c917..979183746201 100644 --- a/include/unotools/fontcvt.hxx +++ b/include/unotools/fontcvt.hxx @@ -20,6 +20,10 @@ #ifndef INCLUDED_UNOTOOLS_FONTCVT_HXX #define INCLUDED_UNOTOOLS_FONTCVT_HXX +#include <sal/config.h> + +#include <string_view> + #include <unotools/unotoolsdllapi.h> #include <rtl/ustring.hxx> @@ -31,7 +35,7 @@ enum class FontToSubsFontFlags }; typedef void* FontToSubsFontConverter; -UNOTOOLS_DLLPUBLIC FontToSubsFontConverter CreateFontToSubsFontConverter( const OUString& rFontName, FontToSubsFontFlags nFlags ); +UNOTOOLS_DLLPUBLIC FontToSubsFontConverter CreateFontToSubsFontConverter( std::u16string_view rFontName, FontToSubsFontFlags nFlags ); UNOTOOLS_DLLPUBLIC sal_Unicode ConvertFontToSubsFontChar( FontToSubsFontConverter hConverter, sal_Unicode c ); UNOTOOLS_DLLPUBLIC OUString GetFontToSubsFontName( FontToSubsFontConverter hConverter ); diff --git a/include/unotools/fontdefs.hxx b/include/unotools/fontdefs.hxx index ad1d6726f17e..671fca504d75 100644 --- a/include/unotools/fontdefs.hxx +++ b/include/unotools/fontdefs.hxx @@ -53,7 +53,7 @@ public: sal_Unicode (*mpCvtFunc)( sal_Unicode ); sal_Unicode RecodeChar( sal_Unicode c ) const; void RecodeString( OUString& rStra, sal_Int32 nIndex, sal_Int32 nLen ) const; - static const ConvertChar* GetRecodeData( const OUString& rOrgFontName, const OUString& rMapFontName ); + static const ConvertChar* GetRecodeData( std::u16string_view rOrgFontName, std::u16string_view rMapFontName ); }; @@ -85,7 +85,7 @@ enum class DefaultFontType }; UNOTOOLS_DLLPUBLIC OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ); -UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( const OUString& rName ); +UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( std::u16string_view rName ); /** Strip any "script font suffix" from the font name diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx index 7584055e1751..22cafe581c42 100644 --- a/include/unotools/localedatawrapper.hxx +++ b/include/unotools/localedatawrapper.hxx @@ -33,6 +33,7 @@ #include <unotools/unotoolsdllapi.h> #include <memory> #include <map> +#include <string_view> namespace com::sun::star::uno { class XComponentContext; } namespace com::sun::star::i18n { class XLocaleData5; } @@ -372,7 +373,7 @@ public: /** Append locale info to string, used with locale data checking. A string similar to "de_DE requested\n en_US loaded" is appended. */ - OUString appendLocaleInfo(const OUString& rDebugMsg) const; + OUString appendLocaleInfo(std::u16string_view rDebugMsg) const; /** Output a message during locale data checking. The (UTF-8) string is written to stderr and in a non-product build or if DBG_UTIL is enabled diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 504438bdab40..4aeca1459f25 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -398,7 +398,7 @@ namespace BuilderUtils VCL_DLLPUBLIC void set_properties(vcl::Window *pWindow, const VclBuilder::stringmap &rProps); //Convert _ gtk markup to ~ vcl markup - VCL_DLLPUBLIC OUString convertMnemonicMarkup(const OUString &rIn); + VCL_DLLPUBLIC OUString convertMnemonicMarkup(std::u16string_view rIn); VCL_DLLPUBLIC OUString extractCustomProperty(VclBuilder::stringmap &rMap); diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index 50ee0324af3d..6f85e0d51fef 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -63,6 +63,7 @@ #include <com/sun/star/awt/DeviceInfo.hpp> #include <memory> +#include <string_view> #include <vector> struct ImplOutDevData; @@ -1111,7 +1112,7 @@ public: FontMetric GetFontMetricFromCollection( int nDevFontIndex ) const; int GetFontFaceCollectionCount() const; - bool IsFontAvailable( const OUString& rFontName ) const; + bool IsFontAvailable( std::u16string_view rFontName ) const; bool AddTempDevFont( const OUString& rFileURL, const OUString& rFontName ); void RefreshFontData( const bool bNewFontLists ); diff --git a/include/vcl/toolkit/field.hxx b/include/vcl/toolkit/field.hxx index 9ac458f0dc00..2efab32bad2c 100644 --- a/include/vcl/toolkit/field.hxx +++ b/include/vcl/toolkit/field.hxx @@ -23,6 +23,10 @@ #error "don't use this in new code" #endif +#include <sal/config.h> + +#include <string_view> + #include <config_options.h> #include <tools/date.hxx> #include <tools/fldunit.hxx> @@ -303,14 +307,14 @@ protected: TimeFormatter(Edit* pEdit); - SAL_DLLPRIVATE void ImplTimeReformat( const OUString& rStr, OUString& rOutStr ); + SAL_DLLPRIVATE void ImplTimeReformat( std::u16string_view rStr, OUString& rOutStr ); SAL_DLLPRIVATE void ImplNewFieldValue( const tools::Time& rTime ); SAL_DLLPRIVATE void ImplSetUserTime( const tools::Time& rNewTime, Selection const * pNewSelection = nullptr ); SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; public: static OUString FormatTime(const tools::Time& rNewTime, TimeFieldFormat eFormat, TimeFormat eHourFormat, bool bDuration, const LocaleDataWrapper& rLocaleData); - static bool TextToTime(const OUString& rStr, tools::Time& rTime, TimeFieldFormat eFormat, bool bDuration, const LocaleDataWrapper& rLocaleDataWrapper, bool _bSkipInvalidCharacters = true); + static bool TextToTime(std::u16string_view rStr, tools::Time& rTime, TimeFieldFormat eFormat, bool bDuration, const LocaleDataWrapper& rLocaleDataWrapper, bool _bSkipInvalidCharacters = true); static int GetTimeArea(TimeFieldFormat eFormat, const OUString& rText, int nCursor, const LocaleDataWrapper& rLocaleDataWrapper); static tools::Time SpinTime(bool bUp, const tools::Time& rTime, TimeFieldFormat eFormat, diff --git a/include/vcl/uitest/logger.hxx b/include/vcl/uitest/logger.hxx index 2500c0d6f58e..c810b7eb7de7 100644 --- a/include/vcl/uitest/logger.hxx +++ b/include/vcl/uitest/logger.hxx @@ -43,7 +43,7 @@ private: public: UITestLogger(); - void logCommand(const OUString& rAction, + void logCommand(std::u16string_view rAction, const css::uno::Sequence<css::beans::PropertyValue>& rArgs); void logAction(VclPtr<Control> const& xUIElement, VclEventId nEvent); |