diff options
-rw-r--r-- | idl/inc/hash.hxx | 2 | ||||
-rw-r--r-- | idl/source/cmptools/hash.cxx | 2 | ||||
-rw-r--r-- | include/rtl/string.hxx | 91 | ||||
-rw-r--r-- | include/tools/config.hxx | 6 | ||||
-rw-r--r-- | l10ntools/source/helper.cxx | 2 | ||||
-rw-r--r-- | l10ntools/source/localize.cxx | 6 | ||||
-rw-r--r-- | sal/qa/rtl/strings/test_ostring.cxx | 4 | ||||
-rw-r--r-- | tools/source/generic/config.cxx | 6 |
8 files changed, 103 insertions, 16 deletions
diff --git a/idl/inc/hash.hxx b/idl/inc/hash.hxx index fb3ba3227b28..67b18b34badb 100644 --- a/idl/inc/hash.hxx +++ b/idl/inc/hash.hxx @@ -53,7 +53,7 @@ public: SvStringHashEntry * Insert( OString const & rElement, sal_uInt32 * pInsertPos ); bool Test( OString const & rElement, sal_uInt32 * pInsertPos ); SvStringHashEntry * Get( sal_uInt32 nInsertPos ) const; - OString GetNearString( const OString& rName ) const; + OString GetNearString( std::string_view rName ) const; }; #endif // INCLUDED_IDL_INC_HASH_HXX diff --git a/idl/source/cmptools/hash.cxx b/idl/source/cmptools/hash.cxx index ef11b489e5ae..c294a1c14755 100644 --- a/idl/source/cmptools/hash.cxx +++ b/idl/source/cmptools/hash.cxx @@ -56,7 +56,7 @@ SvStringHashEntry * SvStringHashTable::Get( sal_uInt32 nInsertPos ) const return it->second.get(); } -OString SvStringHashTable::GetNearString( const OString& rName ) const +OString SvStringHashTable::GetNearString( std::string_view rName ) const { for( auto const & rPair : maInt2EntryMap ) { diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 98298c7ce8c9..def5d2b8b141 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -122,6 +122,8 @@ public: constexpr char const * getStr() const SAL_RETURNS_NONNULL { return buffer; } + constexpr operator std::string_view() const { return {buffer, sal_uInt32(length)}; } + private: static constexpr void assertLayout() { // These static_asserts verifying the layout compatibility with rtl_String cannot be class @@ -689,6 +691,17 @@ public: @return true if the strings are equal; false, otherwise. */ +#if defined LIBO_INTERNAL_ONLY + bool equalsIgnoreAsciiCase( std::string_view str ) const + { + if ( sal_uInt32(pData->length) != str.size() ) + return false; + if ( pData->buffer == str.data() ) + return true; + return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, + str.data(), str.size() ) == 0; + } +#else bool equalsIgnoreAsciiCase( const OString & str ) const { if ( pData->length != str.pData->length ) @@ -698,6 +711,7 @@ public: return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, str.pData->buffer, str.pData->length ) == 0; } +#endif /** Perform an ASCII lowercase comparison of two strings. @@ -797,11 +811,19 @@ public: at the given position; false, otherwise. */ +#if defined LIBO_INTERNAL_ONLY + bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const + { + return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, + str.data(), str.size(), str.size() ) == 0; + } +#else bool match( const OString & str, sal_Int32 fromIndex = 0 ) const { return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; } +#endif /** @overload @@ -875,13 +897,21 @@ public: at the given position; false, otherwise. */ +#if defined LIBO_INTERNAL_ONLY + bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const + { + return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, + str.data(), str.size(), + str.size() ) == 0; + } +#else bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const { return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; } - +#endif /** @overload This function accepts an ASCII string literal as its argument. @@ -917,6 +947,15 @@ public: @since LibreOffice 4.0 */ +#if defined LIBO_INTERNAL_ONLY + bool startsWith(std::string_view str, OString * rest = NULL) const { + bool b = match(str); + if (b && rest != NULL) { + *rest = copy(str.size()); + } + return b; + } +#else bool startsWith(OString const & str, OString * rest = NULL) const { bool b = match(str); if (b && rest != NULL) { @@ -924,6 +963,7 @@ public: } return b; } +#endif /** @overload @@ -962,6 +1002,17 @@ public: @since LibreOffice 5.1 */ +#if defined LIBO_INTERNAL_ONLY + bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest = NULL) + const + { + bool b = matchIgnoreAsciiCase(str); + if (b && rest != NULL) { + *rest = copy(str.size()); + } + return b; + } +#else bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL) const { @@ -971,6 +1022,7 @@ public: } return b; } +#endif /** @overload @@ -1006,6 +1058,16 @@ public: @since LibreOffice 3.6 */ +#if defined LIBO_INTERNAL_ONLY + bool endsWith(std::string_view str, OString * rest = NULL) const { + bool b = str.size() <= sal_uInt32(getLength()) + && match(str, getLength() - str.size()); + if (b && rest != NULL) { + *rest = copy(0, getLength() - str.size()); + } + return b; + } +#else bool endsWith(OString const & str, OString * rest = NULL) const { bool b = str.getLength() <= getLength() && match(str, getLength() - str.getLength()); @@ -1014,6 +1076,7 @@ public: } return b; } +#endif /** @overload @@ -1266,13 +1329,21 @@ public: returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned. */ +#if defined LIBO_INTERNAL_ONLY + sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const + { + sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, + str.data(), str.size() ); + return (ret < 0 ? ret : ret+fromIndex); + } +#else sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const { sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length ); return (ret < 0 ? ret : ret+fromIndex); } - +#endif /** @overload This function accepts an ASCII string literal as its argument. @@ -1340,11 +1411,19 @@ public: the last such substring is returned. If it does not occur as a substring, -1 is returned. */ +#if defined LIBO_INTERNAL_ONLY + sal_Int32 lastIndexOf( std::string_view str ) const + { + return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length, + str.data(), str.size() ); + } +#else sal_Int32 lastIndexOf( const OString & str ) const { return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length, str.pData->buffer, str.pData->length ); } +#endif /** Returns the index within this string of the last occurrence of @@ -1363,11 +1442,19 @@ 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::string_view str, sal_Int32 fromIndex ) const + { + return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex, + str.data(), str.size() ); + } +#else sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const { return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex, str.pData->buffer, str.pData->length ); } +#endif /** Returns a new string that is a substring of this string. diff --git a/include/tools/config.hxx b/include/tools/config.hxx index 76e4270b5e9d..3616d087cfb9 100644 --- a/include/tools/config.hxx +++ b/include/tools/config.hxx @@ -44,15 +44,15 @@ public: void SetGroup(const OString& rGroup); const OString& GetGroup() const { return maGroupName; } - void DeleteGroup(const OString& rGroup); + void DeleteGroup(std::string_view rGroup); OString GetGroupName(sal_uInt16 nGroup) const; sal_uInt16 GetGroupCount() const; - bool HasGroup(const OString& rGroup) const; + bool HasGroup(std::string_view rGroup) const; OString ReadKey(const OString& rKey) const; OString ReadKey(const OString& rKey, const OString& rDefault) const; void WriteKey(const OString& rKey, const OString& rValue); - void DeleteKey(const OString& rKey); + void DeleteKey(std::string_view rKey); OString GetKeyName(sal_uInt16 nKey) const; OString ReadKey(sal_uInt16 nKey) const; sal_uInt16 GetKeyCount() const; diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx index 2dce070b90fc..767c04eb5152 100644 --- a/l10ntools/source/helper.cxx +++ b/l10ntools/source/helper.cxx @@ -44,7 +44,7 @@ OString unEscapeAll( { if( rText[nIndex] == '\\' && nIndex+1 < nLength ) { - sal_Int32 nEscapedOne = rEscaped.indexOf(rText.copy(nIndex,2)); + sal_Int32 nEscapedOne = rEscaped.indexOf(rText.subView(nIndex,2)); if( nEscapedOne != -1 ) { sReturn.append(rUnEscaped[nEscapedOne/2]); diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 47cc132fd8c3..38e9c21f3cac 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -118,7 +118,7 @@ void handleCommand( } void InitPoFile( - const OString& rProject, const OString& rInPath, + std::string_view rProject, const OString& rInPath, const OString& rPotDir, const OString& rOutPath ) { //Create directory for po file @@ -176,7 +176,7 @@ bool fileExists(const OString& fileName) OString gDestRoot; -bool handleFile(const OString& rProject, const OUString& rUrl, const OString& rPotDir) +bool handleFile(std::string_view rProject, const OUString& rUrl, const OString& rPotDir) { struct Command { std::u16string_view extension; @@ -281,7 +281,7 @@ bool handleFile(const OString& rProject, const OUString& rUrl, const OString& rP } void handleFilesOfDir( - std::vector<OUString>& aFiles, const OString& rProject, + std::vector<OUString>& aFiles, std::string_view rProject, const OString& rPotDir ) { ///Handle files in lexical order diff --git a/sal/qa/rtl/strings/test_ostring.cxx b/sal/qa/rtl/strings/test_ostring.cxx index 0d0d07be70ea..b4fb201cafa3 100644 --- a/sal/qa/rtl/strings/test_ostring.cxx +++ b/sal/qa/rtl/strings/test_ostring.cxx @@ -32,12 +32,12 @@ private: void Test::testStartsWithIgnoreAsciiCase() { { OString r; - CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase(OString(), &r)); + CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase(std::string_view(), &r)); CPPUNIT_ASSERT(r.isEmpty()); } { OString r; - CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase(OString(), &r)); + CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase(std::string_view(), &r)); CPPUNIT_ASSERT_EQUAL(OString("foo"), r); } { diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx index 0f2e13acea21..b2eb546c0ef7 100644 --- a/tools/source/generic/config.cxx +++ b/tools/source/generic/config.cxx @@ -647,7 +647,7 @@ void Config::SetGroup(const OString& rGroup) } } -void Config::DeleteGroup(const OString& rGroup) +void Config::DeleteGroup(std::string_view rGroup) { // Update config data if necessary if ( !mpData->mbRead ) @@ -727,7 +727,7 @@ sal_uInt16 Config::GetGroupCount() const return nGroupCount; } -bool Config::HasGroup(const OString& rGroup) const +bool Config::HasGroup(std::string_view rGroup) const { ImplGroupData* pGroup = mpData->mpFirstGroup; bool bRet = false; @@ -825,7 +825,7 @@ void Config::WriteKey(const OString& rKey, const OString& rStr) } } -void Config::DeleteKey(const OString& rKey) +void Config::DeleteKey(std::string_view rKey) { // Update config data if necessary if ( !mpData->mbRead ) |