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/numbers | |
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/numbers')
-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 |
5 files changed, 46 insertions, 44 deletions
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 ); |