diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-20 14:41:14 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-20 16:37:38 +0200 |
commit | f600c5389ccad6a221732b478650a20de4355890 (patch) | |
tree | 3a965309459efcee7a030628375d09cc88b5ebb0 /svl/source | |
parent | 78afe29f3d56e589be4e0d25573eef32377548eb (diff) |
use more string_view in svl
Change-Id: Icd978cd3cb7946f96d2570a0b8c87a74eed57c98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140241
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl/source')
-rw-r--r-- | svl/source/misc/inettype.cxx | 21 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 43 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.hxx | 12 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 7 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 24 | ||||
-rw-r--r-- | svl/source/numbers/zforscan.hxx | 4 | ||||
-rw-r--r-- | svl/source/passwordcontainer/passwordcontainer.cxx | 16 | ||||
-rw-r--r-- | svl/source/passwordcontainer/passwordcontainer.hxx | 4 |
8 files changed, 67 insertions, 64 deletions
diff --git a/svl/source/misc/inettype.cxx b/svl/source/misc/inettype.cxx index b38346d702a7..ca2528c3c242 100644 --- a/svl/source/misc/inettype.cxx +++ b/svl/source/misc/inettype.cxx @@ -23,6 +23,7 @@ #include <tools/wldcrd.hxx> #include <tools/inetmime.hxx> +#include <o3tl/string_view.hxx> #include <osl/diagnose.h> #include <svl/inettype.hxx> @@ -307,22 +308,22 @@ INetContentType INetContentTypes::GetContentType4Extension(OUString const & rExt } //static -INetContentType INetContentTypes::GetContentTypeFromURL(OUString const & rURL) +INetContentType INetContentTypes::GetContentTypeFromURL(std::u16string_view rURL) { INetContentType eTypeID = CONTENT_TYPE_UNKNOWN; sal_Int32 nIdx{ 0 }; - OUString aToken( rURL.getToken(0, ':', nIdx) ); + OUString aToken( o3tl::getToken(rURL, 0, ':', nIdx) ); if (!aToken.isEmpty()) { if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_FILE)) - if (rURL[ rURL.getLength() - 1 ] == '/') // folder - if (rURL.getLength() > RTL_CONSTASCII_LENGTH("file:///")) + if (rURL[ rURL.size() - 1 ] == '/') // folder + if (rURL.size() > RTL_CONSTASCII_LENGTH("file:///")) if (WildCard(u"*/{*}/").Matches(rURL)) // special folder eTypeID = CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER; else // drive? -> "file:///?|/" - if (rURL.getLength() == 11 - && rURL[ rURL.getLength() - 2 ] == '|') + if (rURL.size() == 11 + && rURL[ rURL.size() - 2 ] == '|') { // Drives need further processing, because of // dynamic type according to underlying volume, @@ -341,13 +342,13 @@ INetContentType INetContentTypes::GetContentTypeFromURL(OUString const & rURL) eTypeID = CONTENT_TYPE_TEXT_HTML; else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_PRIVATE)) { - aToken = rURL.getToken(0, '/', nIdx); + aToken = o3tl::getToken(rURL, 0, '/', nIdx); if (aToken == "factory") { - aToken = rURL.getToken(0, '/', nIdx); + aToken = o3tl::getToken(rURL, 0, '/', nIdx); if (aToken == "swriter") { - aToken = rURL.getToken(0, '/', nIdx); + aToken = o3tl::getToken(rURL, 0, '/', nIdx); eTypeID = aToken == "web" ? CONTENT_TYPE_APP_VND_WRITER_WEB : aToken == "GlobalDocument" ? @@ -378,7 +379,7 @@ INetContentType INetContentTypes::GetContentTypeFromURL(OUString const & rURL) eTypeID = CONTENT_TYPE_APP_MACRO; else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_DATA)) { - aToken = rURL.getToken(0, ',', nIdx); + aToken = o3tl::getToken(rURL, 0, ',', nIdx); eTypeID = GetContentType(aToken); } } diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index aa6029b0f271..a30bbf600ef6 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -21,6 +21,7 @@ #include <dtoa.h> #include <float.h> #include <comphelper/string.hxx> +#include <o3tl/string_view.hxx> #include <sal/log.hxx> #include <tools/date.hxx> #include <rtl/math.hxx> @@ -484,10 +485,10 @@ bool ImpSvNumberInputScan::StringContainsWord( const OUString& rWhat, /** * Skips the supplied char */ -inline bool ImpSvNumberInputScan::SkipChar( sal_Unicode c, const OUString& rString, +inline bool ImpSvNumberInputScan::SkipChar( sal_Unicode c, std::u16string_view rString, sal_Int32& nPos ) { - if ((nPos < rString.getLength()) && (rString[nPos] == c)) + if ((nPos < static_cast<sal_Int32>(rString.size())) && (rString[nPos] == c)) { nPos++; return true; @@ -534,7 +535,7 @@ inline bool ImpSvNumberInputScan::SkipString( const OUString& rWhat, /** * Recognizes exactly ,111 in {3} and {3,2} or ,11 in {3,2} grouping */ -inline bool ImpSvNumberInputScan::GetThousandSep( const OUString& rString, +inline bool ImpSvNumberInputScan::GetThousandSep( std::u16string_view rString, sal_Int32& nPos, sal_uInt16 nStringPos ) const { @@ -542,7 +543,7 @@ inline bool ImpSvNumberInputScan::GetThousandSep( const OUString& rString, // Is it an ordinary space instead of a no-break space? bool bSpaceBreak = (rSep[0] == cNoBreakSpace || rSep[0] == cNarrowNoBreakSpace) && rString[0] == u' ' && - rSep.getLength() == 1 && rString.getLength() == 1; + rSep.getLength() == 1 && rString.size() == 1; if (!((rString == rSep || bSpaceBreak) && // nothing else nStringPos < nStringsCnt - 1 && // safety first! IsNum[ nStringPos + 1 ] )) // number follows @@ -850,18 +851,18 @@ bool ImpSvNumberInputScan::GetTimeAmPm( const OUString& rString, sal_Int32& nPos * ',' => true * else => false */ -inline bool ImpSvNumberInputScan::GetDecSep( const OUString& rString, sal_Int32& nPos ) const +inline bool ImpSvNumberInputScan::GetDecSep( std::u16string_view rString, sal_Int32& nPos ) const { - if ( rString.getLength() > nPos ) + if ( static_cast<sal_Int32>(rString.size()) > nPos ) { const OUString& rSep = pFormatter->GetNumDecimalSep(); - if ( rString.match( rSep, nPos) ) + if ( o3tl::starts_with(rString.substr(nPos), rSep) ) { nPos = nPos + rSep.getLength(); return true; } const OUString& rSepAlt = pFormatter->GetNumDecimalSepAlt(); - if ( !rSepAlt.isEmpty() && rString.match( rSepAlt, nPos) ) + if ( !rSepAlt.isEmpty() && o3tl::starts_with(rString.substr(nPos), rSepAlt) ) { nPos = nPos + rSepAlt.getLength(); return true; @@ -874,9 +875,9 @@ inline bool ImpSvNumberInputScan::GetDecSep( const OUString& rString, sal_Int32& /** * Reading a hundredth seconds separator */ -inline bool ImpSvNumberInputScan::GetTime100SecSep( const OUString& rString, sal_Int32& nPos ) const +inline bool ImpSvNumberInputScan::GetTime100SecSep( std::u16string_view rString, sal_Int32& nPos ) const { - if ( rString.getLength() > nPos ) + if ( static_cast<sal_Int32>(rString.size()) > nPos ) { if (bIso8601Tsep) { @@ -891,7 +892,7 @@ inline bool ImpSvNumberInputScan::GetTime100SecSep( const OUString& rString, sal // Even in an otherwise ISO 8601 string be lenient and accept the // locale defined separator. const OUString& rSep = pFormatter->GetLocaleData()->getTime100SecSep(); - if ( rString.match( rSep, nPos )) + if ( o3tl::starts_with(rString.substr(nPos), rSep)) { nPos = nPos + rSep.getLength(); return true; @@ -908,9 +909,9 @@ inline bool ImpSvNumberInputScan::GetTime100SecSep( const OUString& rString, sal * '(' => -1, bNegCheck = 1 * else => 0 */ -int ImpSvNumberInputScan::GetSign( const OUString& rString, sal_Int32& nPos ) +int ImpSvNumberInputScan::GetSign( std::u16string_view rString, sal_Int32& nPos ) { - if (rString.getLength() > nPos) + if (static_cast<sal_Int32>(rString.size()) > nPos) switch (rString[ nPos ]) { case '+': @@ -936,9 +937,9 @@ int ImpSvNumberInputScan::GetSign( const OUString& rString, sal_Int32& nPos ) * '-' => -1 * else => 0 */ -short ImpSvNumberInputScan::GetESign( const OUString& rString, sal_Int32& nPos ) +short ImpSvNumberInputScan::GetESign( std::u16string_view rString, sal_Int32& nPos ) { - if (rString.getLength() > nPos) + if (static_cast<sal_Int32>(rString.size()) > nPos) { switch (rString[nPos]) { @@ -1262,17 +1263,17 @@ bool ImpSvNumberInputScan::MayBeMonthDate() /** If a string is a separator plus '-' minus sign preceding a 'Y' year in a date pattern at position nPat. */ -static bool lcl_IsSignedYearSep( const OUString& rStr, const OUString& rPat, sal_Int32 nPat ) +static bool lcl_IsSignedYearSep( std::u16string_view rStr, std::u16string_view rPat, sal_Int32 nPat ) { bool bOk = false; - sal_Int32 nLen = rStr.getLength(); + sal_Int32 nLen = rStr.size(); if (nLen > 1 && rStr[nLen-1] == '-') { --nLen; - if (nPat + nLen < rPat.getLength() && rPat[nPat+nLen] == 'Y') + if (nPat + nLen < static_cast<sal_Int32>(rPat.size()) && rPat[nPat+nLen] == 'Y') { // Signed year is possible. - bOk = (rPat.indexOf( rStr.subView( 0, nLen), nPat) == nPat); + bOk = (rPat.find( rStr.substr( 0, nLen), nPat) == static_cast<size_t>(nPat)); } } return bOk; @@ -1280,11 +1281,11 @@ static bool lcl_IsSignedYearSep( const OUString& rStr, const OUString& rPat, sal /** Length of separator usually is 1 but theoretically could be anything. */ -static sal_Int32 lcl_getPatternSeparatorLength( const OUString& rPat, sal_Int32 nPat ) +static sal_Int32 lcl_getPatternSeparatorLength( std::u16string_view rPat, sal_Int32 nPat ) { sal_Int32 nSep = nPat; sal_Unicode c; - while (nSep < rPat.getLength() && (c = rPat[nSep]) != 'D' && c != 'M' && c != 'Y') + while (nSep < static_cast<sal_Int32>(rPat.size()) && (c = rPat[nSep]) != 'D' && c != 'M' && c != 'Y') ++nSep; return nSep - nPat; } diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx index ae724eb63d8b..5696b6ca21a3 100644 --- a/svl/source/numbers/zforfind.hxx +++ b/svl/source/numbers/zforfind.hxx @@ -261,7 +261,7 @@ private: // Skip a special character static inline bool SkipChar( sal_Unicode c, - const OUString& rString, + std::u16string_view rString, sal_Int32& nPos ); // Skip blank @@ -274,7 +274,7 @@ private: sal_Int32& nPos ); // Recognizes exactly ,111 as group separator - inline bool GetThousandSep( const OUString& rString, + inline bool GetThousandSep( std::u16string_view rString, sal_Int32& nPos, sal_uInt16 nStringPos ) const; // Get boolean value @@ -297,20 +297,20 @@ private: sal_Int32& nPos ); // Get decimal separator and advance string position - inline bool GetDecSep( const OUString& rString, + inline bool GetDecSep( std::u16string_view rString, sal_Int32& nPos ) const; // Get hundredth seconds separator and advance string position - inline bool GetTime100SecSep( const OUString& rString, + inline bool GetTime100SecSep( std::u16string_view rString, sal_Int32& nPos ) const; // Get sign and advance string position // Including special case '(' - int GetSign( const OUString& rString, + int GetSign( std::u16string_view rString, sal_Int32& nPos ); // Get sign of exponent and advance string position - static short GetESign( const OUString& rString, + static short GetESign( std::u16string_view rString, sal_Int32& nPos ); // Get next number as array offset diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index cc299ab37d37..59c94be3a305 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -25,6 +25,7 @@ #include <svl/currencytable.hxx> #include <comphelper/string.hxx> +#include <o3tl/string_view.hxx> #include <tools/debug.hxx> #include <unotools/charclass.hxx> #include <unotools/configmgr.hxx> @@ -3968,18 +3969,18 @@ bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString // static const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( bool & bFoundBank, std::u16string_view rSymbol, - const OUString& rExtension, + std::u16string_view rExtension, LanguageType eFormatLanguage, bool bOnlyStringLanguage ) { - sal_Int32 nExtLen = rExtension.getLength(); + sal_Int32 nExtLen = rExtension.size(); LanguageType eExtLang; if ( nExtLen ) { // rExtension should be a 16-bit hex value max FFFF which may contain a // leading "-" separator (that is not a minus sign, but toInt32 can be // used to parse it, with post-processing as necessary): - sal_Int32 nExtLang = rExtension.toInt32( 16 ); + sal_Int32 nExtLang = o3tl::toInt32(rExtension, 16); if ( !nExtLang ) { eExtLang = LANGUAGE_DONTKNOW; diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 43f26e76287c..80b314bc5208 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1574,12 +1574,12 @@ bool SvNumberformat::LocaleType::isPlainLocale() const } // static -SvNumberformat::LocaleType SvNumberformat::ImpGetLocaleType(const OUString& rString, sal_Int32& nPos ) +SvNumberformat::LocaleType SvNumberformat::ImpGetLocaleType(std::u16string_view rString, sal_Int32& nPos ) { sal_uInt32 nNum = 0; sal_Unicode cToken = 0; sal_Int32 nStart = nPos; - sal_Int32 nLen = rString.getLength(); + sal_Int32 nLen = rString.size(); while ( nPos < nLen && (nPos - nStart < 8) ) { cToken = rString[nPos]; @@ -1610,12 +1610,12 @@ SvNumberformat::LocaleType SvNumberformat::ImpGetLocaleType(const OUString& rStr return (cToken == ']' || nPos == nLen) ? LocaleType(nNum) : LocaleType(); } -static bool lcl_matchKeywordAndGetNumber( const OUString & rString, const sal_Int32 nPos, - const OUString & rKeyword, sal_Int32 & nNumber ) +static bool lcl_matchKeywordAndGetNumber( std::u16string_view rString, const sal_Int32 nPos, + std::u16string_view rKeyword, sal_Int32 & nNumber ) { - if (0 <= nPos && nPos + rKeyword.getLength() < rString.getLength() && rString.matchIgnoreAsciiCase( rKeyword, nPos)) + if (0 <= nPos && nPos + static_cast<sal_Int32>(rKeyword.size()) < static_cast<sal_Int32>(rString.size()) && o3tl::matchIgnoreAsciiCase( rString, rKeyword, nPos)) { - nNumber = o3tl::toInt32(rString.subView( nPos + rKeyword.getLength())); + nNumber = o3tl::toInt32(rString.substr( nPos + rKeyword.size())); return true; } else @@ -2141,11 +2141,11 @@ short SvNumberformat::ImpCheckCondition(double fNumber, } } -static bool lcl_appendStarFillChar( OUStringBuffer& rBuf, const OUString& rStr ) +static bool lcl_appendStarFillChar( OUStringBuffer& rBuf, std::u16string_view rStr ) { // Right during user input the star symbol is the very // last character before the user enters another one. - if (rStr.getLength() > 1) + if (rStr.size() > 1) { rBuf.append(u'\x001B'); rBuf.append(rStr[1]); @@ -2154,9 +2154,9 @@ static bool lcl_appendStarFillChar( OUStringBuffer& rBuf, const OUString& rStr ) return false; } -static bool lcl_insertStarFillChar( OUStringBuffer& rBuf, sal_Int32 nPos, const OUString& rStr ) +static bool lcl_insertStarFillChar( OUStringBuffer& rBuf, sal_Int32 nPos, std::u16string_view rStr ) { - if (rStr.getLength() > 1) + if (rStr.size() > 1) { rBuf.insert( nPos, rStr[1]); rBuf.insert( nPos, u'\x001B'); @@ -3429,11 +3429,11 @@ void SvNumberformat::SwitchToOtherCalendar( OUString& rOrgCalendar, rCal.setDateTime( fOrgDateTime ); } -void SvNumberformat::SwitchToGregorianCalendar( const OUString& rOrgCalendar, +void SvNumberformat::SwitchToGregorianCalendar( std::u16string_view rOrgCalendar, double fOrgDateTime ) const { CalendarWrapper& rCal = GetCal(); - if ( rOrgCalendar.getLength() && rCal.getUniqueID() != GREGORIAN ) + if ( rOrgCalendar.size() && rCal.getUniqueID() != GREGORIAN ) { rCal.loadCalendar( GREGORIAN, rLoc().getLanguageTag().getLocale() ); rCal.setDateTime( fOrgDateTime ); diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx index 4e6f7d1454ea..8bf67a4a4a45 100644 --- a/svl/source/numbers/zforscan.hxx +++ b/svl/source/numbers/zforscan.hxx @@ -292,8 +292,8 @@ private: // Private section /** Swap nTypeArray and sStrArray elements at positions. */ void SwapArrayElements( size_t nPos1, size_t nPos2 ); - static bool StringEqualsChar( const OUString& rStr, sal_Unicode ch ) - { return rStr.getLength() == 1 && rStr[0] == ch; } + static bool StringEqualsChar( std::u16string_view rStr, sal_Unicode ch ) + { return rStr.size() == 1 && rStr[0] == ch; } // remove "..." and \... quotes from rStr, return how many chars removed static sal_Int32 RemoveQuotes( OUString& rStr ); diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx index 0abddc2d6b13..7f9cf4944ae7 100644 --- a/svl/source/passwordcontainer/passwordcontainer.cxx +++ b/svl/source/passwordcontainer/passwordcontainer.cxx @@ -413,20 +413,20 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& ) } } -std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode ) +std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, std::u16string_view aMasterPasswd, css::task::PasswordRequestMode mode ) { - if( !aMasterPasswd.isEmpty() ) + if( !aMasterPasswd.empty() ) { rtlCipher aDecoder = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); OSL_ENSURE( aDecoder, "Can't create decoder" ); if( aDecoder ) { - OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!" ); + OSL_ENSURE( aMasterPasswd.size() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!" ); unsigned char code[RTL_DIGEST_LENGTH_MD5]; for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ ) - code[ ind ] = static_cast<char>(o3tl::toUInt32(aMasterPasswd.subView( ind*2, 2 ), 16)); + code[ ind ] = static_cast<char>(o3tl::toUInt32(aMasterPasswd.substr( ind*2, 2 ), 16)); unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0}; if (!aIV.empty()) @@ -473,9 +473,9 @@ std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view "Can't decode!", css::uno::Reference<css::uno::XInterface>(), mode); } -OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, const OUString& aMasterPasswd) +OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, std::u16string_view aMasterPasswd) { - if( !aMasterPasswd.isEmpty() ) + if( !aMasterPasswd.empty() ) { OString aSeq = OUStringToOString( createIndex( lines ), RTL_TEXTENCODING_UTF8 ); @@ -484,11 +484,11 @@ OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines if( aEncoder ) { - OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!" ); + OSL_ENSURE( aMasterPasswd.size() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!" ); unsigned char code[RTL_DIGEST_LENGTH_MD5]; for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ ) - code[ ind ] = static_cast<char>(o3tl::toUInt32(aMasterPasswd.subView( ind*2, 2 ), 16)); + code[ ind ] = static_cast<char>(o3tl::toUInt32(aMasterPasswd.substr( ind*2, 2 ), 16)); unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0}; if (!aIV.empty()) diff --git a/svl/source/passwordcontainer/passwordcontainer.hxx b/svl/source/passwordcontainer/passwordcontainer.hxx index ca4b549f3b2d..541d1a5e41bb 100644 --- a/svl/source/passwordcontainer/passwordcontainer.hxx +++ b/svl/source/passwordcontainer/passwordcontainer.hxx @@ -317,10 +317,10 @@ private: const css::uno::Reference< css::task::XInteractionHandler >& Handler ); /// @throws css::uno::RuntimeException - static ::std::vector< OUString > DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, const OUString& aMasterPassword, css::task::PasswordRequestMode mode ); + static ::std::vector< OUString > DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, std::u16string_view aMasterPassword, css::task::PasswordRequestMode mode ); /// @throws css::uno::RuntimeException - static OUString EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, const OUString& aMasterPassword ); + static OUString EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, std::u16string_view aMasterPassword ); public: PasswordContainer( const css::uno::Reference< css::uno::XComponentContext >& ); |