From b24a4d255d31233c48152e6e1ce992a693cdaeae Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 10 Apr 2022 15:36:21 +0200 Subject: use more string_view found by tweaking the loplugin:stringview and making it whitelist getLength Change-Id: Ic15d3703d1fb07658e99e1db1c89e2fa5bc70c19 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132771 Tested-by: Jenkins Reviewed-by: Noel Grandin --- basegfx/source/inc/stringconversiontools.hxx | 2 +- basegfx/source/polygon/b2dsvgpolypolygon.cxx | 8 ++-- basegfx/source/tools/stringconversiontools.cxx | 19 ++++----- comphelper/source/misc/accessibletexthelper.cxx | 4 +- comphelper/source/misc/docpasswordhelper.cxx | 6 +-- comphelper/source/misc/mimeconfighelper.cxx | 8 ++-- comphelper/source/misc/storagehelper.cxx | 17 ++++---- filter/source/xsltdialog/xmlfilterjar.cxx | 4 +- include/basegfx/polygon/b2dpolygontools.hxx | 2 +- include/basegfx/polygon/b2dpolypolygontools.hxx | 2 +- include/comphelper/accessibletexthelper.hxx | 2 +- include/comphelper/docpasswordhelper.hxx | 3 +- include/comphelper/mimeconfighelper.hxx | 2 +- include/comphelper/storagehelper.hxx | 2 +- include/sfx2/docfile.hxx | 2 +- include/tools/Guid.hxx | 6 +-- l10ntools/inc/cfgmerge.hxx | 2 +- l10ntools/inc/helper.hxx | 8 ++-- l10ntools/inc/po.hxx | 2 +- l10ntools/source/cfgmerge.cxx | 4 +- l10ntools/source/helper.cxx | 46 +++++++++++----------- l10ntools/source/po.cxx | 26 ++++++------ reportdesign/source/core/sdr/ReportDrawPage.cxx | 2 +- sfx2/source/doc/docfile.cxx | 4 +- slideshow/source/engine/animationfactory.cxx | 2 +- stoc/source/uriproc/UriReferenceFactory.cxx | 14 +++---- .../UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx | 19 ++++----- ucb/source/ucp/package/pkguri.cxx | 4 +- unoidl/source/sourceprovider-parser.y | 9 +++-- unoidl/source/sourcetreeprovider.cxx | 8 ++-- unoidl/source/unoidlprovider.cxx | 12 +++--- 31 files changed, 128 insertions(+), 123 deletions(-) diff --git a/basegfx/source/inc/stringconversiontools.hxx b/basegfx/source/inc/stringconversiontools.hxx index fdf2f83e0f4e..797697d203ac 100644 --- a/basegfx/source/inc/stringconversiontools.hxx +++ b/basegfx/source/inc/stringconversiontools.hxx @@ -51,7 +51,7 @@ namespace basegfx::internal bool importDoubleAndSpaces(double& o_fRetval, sal_Int32& io_rPos, - const OUString& rStr, + std::u16string_view rStr, const sal_Int32 nLen ); bool importFlagAndSpaces(sal_Int32& o_nRetval, diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx index 323fff14c024..aa0fedb2ddf2 100644 --- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx +++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx @@ -74,12 +74,12 @@ namespace basegfx::utils bool importFromSvgD( B2DPolyPolygon& o_rPolyPolygon, - const OUString& rSvgDStatement, + std::u16string_view rSvgDStatement, bool bHandleRelativeNextPointCompatible, PointIndexSet* pHelpPointIndexSet) { o_rPolyPolygon.clear(); - const sal_Int32 nLen(rSvgDStatement.getLength()); + const sal_Int32 nLen(rSvgDStatement.size()); sal_Int32 nPos(0); double nLastX( 0.0 ); double nLastY( 0.0 ); @@ -664,10 +664,10 @@ namespace basegfx::utils } bool importFromSvgPoints( B2DPolygon& o_rPoly, - const OUString& rSvgPointsAttribute ) + std::u16string_view rSvgPointsAttribute ) { o_rPoly.clear(); - const sal_Int32 nLen(rSvgPointsAttribute.getLength()); + const sal_Int32 nLen(rSvgPointsAttribute.size()); sal_Int32 nPos(0); double nX, nY; diff --git a/basegfx/source/tools/stringconversiontools.cxx b/basegfx/source/tools/stringconversiontools.cxx index d9f7df14cf50..d6a702faa687 100644 --- a/basegfx/source/tools/stringconversiontools.cxx +++ b/basegfx/source/tools/stringconversiontools.cxx @@ -46,9 +46,10 @@ namespace basegfx::internal static bool getDoubleChar(double& o_fRetval, sal_Int32& io_rPos, - const OUString& rStr) + std::u16string_view rStr) { - sal_Unicode aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + const sal_Int64 nStrSize = rStr.size(); + sal_Unicode aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; OUStringBuffer sNumberString; // sign @@ -63,7 +64,7 @@ namespace basegfx::internal { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; } // point @@ -71,7 +72,7 @@ namespace basegfx::internal { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; } // numbers after point @@ -79,7 +80,7 @@ namespace basegfx::internal { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; } // 'e' @@ -87,14 +88,14 @@ namespace basegfx::internal { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; // sign for 'e' if(aChar == '+' || aChar == '-') { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; } // number for 'e' @@ -102,7 +103,7 @@ namespace basegfx::internal { sNumberString.append(rStr[io_rPos]); io_rPos++; - aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0; + aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0; } } @@ -121,7 +122,7 @@ namespace basegfx::internal bool importDoubleAndSpaces(double& o_fRetval, sal_Int32& io_rPos, - const OUString& rStr, + std::u16string_view rStr, const sal_Int32 nLen ) { if( !getDoubleChar(o_fRetval, io_rPos, rStr) ) diff --git a/comphelper/source/misc/accessibletexthelper.cxx b/comphelper/source/misc/accessibletexthelper.cxx index 35fe769c1700..0678456192d7 100644 --- a/comphelper/source/misc/accessibletexthelper.cxx +++ b/comphelper/source/misc/accessibletexthelper.cxx @@ -215,9 +215,9 @@ namespace comphelper } - sal_Unicode OCommonAccessibleText::implGetCharacter( const OUString& rText, sal_Int32 nIndex ) + sal_Unicode OCommonAccessibleText::implGetCharacter( std::u16string_view rText, sal_Int32 nIndex ) { - if ( !implIsValidIndex( nIndex, rText.getLength() ) ) + if ( !implIsValidIndex( nIndex, rText.size() ) ) throw IndexOutOfBoundsException(); return rText[nIndex]; diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index 436b599f9e1f..e32c3d8b1303 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -197,7 +197,7 @@ bool DocPasswordHelper::IsModifyPasswordCorrect( std::u16string_view aPassword, sal_uInt32 DocPasswordHelper::GetWordHashAsUINT32( - const OUString& aUString ) + std::u16string_view aUString ) { static const sal_uInt16 pInitialCode[] = { 0xE1F0, // 1 @@ -236,7 +236,7 @@ sal_uInt32 DocPasswordHelper::GetWordHashAsUINT32( }; sal_uInt32 nResult = 0; - sal_uInt32 nLen = aUString.getLength(); + size_t nLen = aUString.size(); if ( nLen ) { @@ -246,7 +246,7 @@ sal_uInt32 DocPasswordHelper::GetWordHashAsUINT32( sal_uInt16 nHighResult = pInitialCode[nLen - 1]; sal_uInt16 nLowResult = 0; - for ( sal_uInt32 nInd = 0; nInd < nLen; nInd++ ) + for ( size_t nInd = 0; nInd < nLen; nInd++ ) { // NO Encoding during conversion! // The specification says that the low byte should be used in case it is not NULL diff --git a/comphelper/source/misc/mimeconfighelper.cxx b/comphelper/source/misc/mimeconfighelper.cxx index 8ec72e271f55..0046c7f11d4f 100644 --- a/comphelper/source/misc/mimeconfighelper.cxx +++ b/comphelper/source/misc/mimeconfighelper.cxx @@ -81,18 +81,18 @@ static sal_uInt8 GetDigit_Impl( char aChar ) } -uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassIDRepresentation( const OUString& aClassID ) +uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassIDRepresentation( std::u16string_view aClassID ) { - sal_Int32 nLength = aClassID.getLength(); + size_t nLength = aClassID.size(); if ( nLength == 36 ) { OString aCharClassID = OUStringToOString( aClassID, RTL_TEXTENCODING_ASCII_US ); uno::Sequence< sal_Int8 > aResult( 16 ); auto pResult = aResult.getArray(); - sal_Int32 nStrPointer = 0; + size_t nStrPointer = 0; sal_Int32 nSeqInd = 0; - while( nSeqInd < 16 && nStrPointer + 1 < nLength ) + while( nSeqInd < 16 && nStrPointer + 1U < nLength ) { sal_uInt8 nDigit1 = GetDigit_Impl( aCharClassID[nStrPointer++] ); sal_uInt8 nDigit2 = GetDigit_Impl( aCharClassID[nStrPointer++] ); diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 13e9eb3aa288..b850d7d70197 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -56,6 +56,7 @@ #include #include #include +#include #if HAVE_FEATURE_GPGME # include @@ -561,27 +562,27 @@ bool OStorageHelper::IsValidZipEntryFileName( } -bool OStorageHelper::PathHasSegment( const OUString& aPath, const OUString& aSegment ) +bool OStorageHelper::PathHasSegment( std::u16string_view aPath, std::u16string_view aSegment ) { bool bResult = false; - const sal_Int32 nPathLen = aPath.getLength(); - const sal_Int32 nSegLen = aSegment.getLength(); + const size_t nPathLen = aPath.size(); + const size_t nSegLen = aSegment.size(); - if ( !aSegment.isEmpty() && nPathLen >= nSegLen ) + if ( !aSegment.empty() && nPathLen >= nSegLen ) { - OUString aEndSegment = "/" + aSegment; + OUString aEndSegment = OUString::Concat("/") + aSegment; OUString aInternalSegment = aEndSegment + "/"; - if ( aPath.indexOf( aInternalSegment ) >= 0 ) + if ( aPath.find( aInternalSegment ) != std::u16string_view::npos ) bResult = true; - if ( !bResult && aPath.startsWith( aSegment ) ) + if ( !bResult && o3tl::starts_with(aPath, aSegment ) ) { if ( nPathLen == nSegLen || aPath[nSegLen] == '/' ) bResult = true; } - if ( !bResult && nPathLen > nSegLen && aPath.subView( nPathLen - nSegLen - 1, nSegLen + 1 ) == aEndSegment ) + if ( !bResult && nPathLen > nSegLen && aPath.substr( nPathLen - nSegLen - 1, nSegLen + 1 ) == aEndSegment ) bResult = true; } diff --git a/filter/source/xsltdialog/xmlfilterjar.cxx b/filter/source/xsltdialog/xmlfilterjar.cxx index e3c8d6239a83..aa3e17859932 100644 --- a/filter/source/xsltdialog/xmlfilterjar.cxx +++ b/filter/source/xsltdialog/xmlfilterjar.cxx @@ -308,8 +308,8 @@ bool XMLFilterJarHelper::copyFile( const Reference< XHierarchicalNameAccess >& x { OUString szPackagePath( encodeZipUri( rURL.copy( sVndSunStarPackage.getLength() ) ) ); - if ( ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, ".." ) - || ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, "." ) ) + if ( ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, u".." ) + || ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, u"." ) ) throw lang::IllegalArgumentException(); if( xIfc->hasByHierarchicalName( szPackagePath ) ) diff --git a/include/basegfx/polygon/b2dpolygontools.hxx b/include/basegfx/polygon/b2dpolygontools.hxx index 5d5e51c3f2ea..8f3ef342f3bc 100644 --- a/include/basegfx/polygon/b2dpolygontools.hxx +++ b/include/basegfx/polygon/b2dpolygontools.hxx @@ -507,7 +507,7 @@ namespace basegfx::utils @return true, if the string was successfully parsed */ BASEGFX_DLLPUBLIC bool importFromSvgPoints( B2DPolygon& o_rPoly, - const OUString& rSvgPointsAttribute ); + std::u16string_view rSvgPointsAttribute ); /** Write poly-polygon to SVG. diff --git a/include/basegfx/polygon/b2dpolypolygontools.hxx b/include/basegfx/polygon/b2dpolypolygontools.hxx index f104ec931ab9..d253531f6ac9 100644 --- a/include/basegfx/polygon/b2dpolypolygontools.hxx +++ b/include/basegfx/polygon/b2dpolypolygontools.hxx @@ -150,7 +150,7 @@ namespace basegfx::utils */ BASEGFX_DLLPUBLIC bool importFromSvgD( B2DPolyPolygon& o_rPolyPoly, - const OUString& rSvgDAttribute, + std::u16string_view rSvgDAttribute, bool bHandleRelativeNextPointCompatible, PointIndexSet* pHelpPointIndexSet); diff --git a/include/comphelper/accessibletexthelper.hxx b/include/comphelper/accessibletexthelper.hxx index 576cc89cf4ee..2c1e464d7e2f 100644 --- a/include/comphelper/accessibletexthelper.hxx +++ b/include/comphelper/accessibletexthelper.hxx @@ -54,7 +54,7 @@ namespace comphelper static bool implIsValidBoundary( css::i18n::Boundary const & rBoundary, sal_Int32 nLength ); static bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength ); static bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength ); - static sal_Unicode implGetCharacter( const OUString& rText, sal_Int32 nIndex ); + static sal_Unicode implGetCharacter( std::u16string_view rText, sal_Int32 nIndex ); static OUString implGetTextRange( const OUString& rText, sal_Int32 nStartIndex, sal_Int32 nEndIndex ); virtual OUString implGetText() = 0; virtual css::lang::Locale implGetLocale() = 0; diff --git a/include/comphelper/docpasswordhelper.hxx b/include/comphelper/docpasswordhelper.hxx index dc78110519dd..a5b99d201831 100644 --- a/include/comphelper/docpasswordhelper.hxx +++ b/include/comphelper/docpasswordhelper.hxx @@ -145,8 +145,7 @@ public: The hash represented by sal_uInt32 */ - static sal_uInt32 GetWordHashAsUINT32( - const OUString& aString ); + static sal_uInt32 GetWordHashAsUINT32( std::u16string_view aString ); /** This helper function generates the hash code based on the algorithm diff --git a/include/comphelper/mimeconfighelper.hxx b/include/comphelper/mimeconfighelper.hxx index c06d156c649f..83f5c41cb267 100644 --- a/include/comphelper/mimeconfighelper.hxx +++ b/include/comphelper/mimeconfighelper.hxx @@ -55,7 +55,7 @@ public: static OUString GetStringClassIDRepresentation( const css::uno::Sequence< sal_Int8 >& aClassID ); - static css::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation( const OUString& aClassID ); + static css::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation( std::u16string_view aClassID ); css::uno::Reference< css::container::XNameAccess > GetObjConfiguration(); diff --git a/include/comphelper/storagehelper.hxx b/include/comphelper/storagehelper.hxx index 9e1c453b54ca..9cb09fc89597 100644 --- a/include/comphelper/storagehelper.hxx +++ b/include/comphelper/storagehelper.hxx @@ -180,7 +180,7 @@ public: static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed ); static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed ); - static bool PathHasSegment( const OUString& aPath, const OUString& aSegment ); + static bool PathHasSegment( std::u16string_view aPath, std::u16string_view aSegment ); // Methods to allow easy use of hierarchical names inside storages diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx index 6fd2ba45792a..d6c97879e2dd 100644 --- a/include/sfx2/docfile.hxx +++ b/include/sfx2/docfile.hxx @@ -294,7 +294,7 @@ public: static bool CallApproveHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler, const css::uno::Any& rRequest, bool bAllowAbort); static bool SetWritableForUserOnly( const OUString& aURL ); - static sal_uInt32 CreatePasswordToModifyHash( const OUString& aPasswd, bool bWriter ); + static sal_uInt32 CreatePasswordToModifyHash( std::u16string_view aPasswd, bool bWriter ); private: enum class ShowLockResult { NoLock, Succeeded, Try }; diff --git a/include/tools/Guid.hxx b/include/tools/Guid.hxx index 62208f5fcdfa..3922a3da9ff2 100644 --- a/include/tools/Guid.hxx +++ b/include/tools/Guid.hxx @@ -43,9 +43,9 @@ private: return (gethex(high) << 4) + gethex(low); } - void parse(OString const& rString) + void parse(std::string_view rString) { - if (rString.getLength() != 38) + if (rString.size() != 38) return; if (rString[0] != '{' || rString[37] != '}' || rString[9] != '-' || rString[14] != '-' @@ -104,7 +104,7 @@ public: Guid() { maGuidArray.fill(0); } /// parse the GUID from the string - Guid(OString const& rString) + Guid(std::string_view rString) { maGuidArray.fill(0); parse(rString); diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx index 8c7e90720081..12e5cace11f2 100644 --- a/l10ntools/inc/cfgmerge.hxx +++ b/l10ntools/inc/cfgmerge.hxx @@ -118,7 +118,7 @@ private: const OString &rIsoLang, const OString &rResTyp ); - static bool IsTokenClosed(const OString &rToken); + static bool IsTokenClosed(std::string_view rToken); public: CfgParser(); diff --git a/l10ntools/inc/helper.hxx b/l10ntools/inc/helper.hxx index fb0db0fc13f7..c1347db04c64 100644 --- a/l10ntools/inc/helper.hxx +++ b/l10ntools/inc/helper.hxx @@ -25,15 +25,15 @@ namespace helper { /// Escape all given character in the text OString escapeAll( - const OString& rText, const OString& rUnEscaped, const OString& rEscaped ); + std::string_view rText, std::string_view rUnEscaped, std::string_view rEscaped ); /// Unescape all given character in the text OString unEscapeAll( - const OString& rText, const OString& rEscaped, std::string_view rUnEscaped ); + std::string_view rText, std::string_view rEscaped, std::string_view rUnEscaped ); /// Convert special characters to XML entity references -OString QuotHTML( const OString &rString ); +OString QuotHTML( std::string_view rString ); /// Convert XML entity references to single characters -OString UnQuotHTML( const OString& rString ); +OString UnQuotHTML( std::string_view rString ); /// Check whether text is a valid XML expression bool isWellFormedXML( std::string_view text ); diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index db513cab1f8e..8267525133b7 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -47,7 +47,7 @@ public: PoEntry(); PoEntry( const OString& rSourceFile, std::string_view rResType, std::string_view rGroupId, - std::string_view rLocalId, const OString& rHelpText, const OString& rText, + std::string_view rLocalId, std::string_view rHelpText, const OString& rText, const TYPE eType ); ~PoEntry(); diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index 69fbd3777f85..aa0126b22822 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -134,9 +134,9 @@ CfgParser::~CfgParser() { } -bool CfgParser::IsTokenClosed(const OString &rToken) +bool CfgParser::IsTokenClosed(std::string_view rToken) { - return rToken[rToken.getLength() - 2] == '/'; + return rToken[rToken.size() - 2] == '/'; } void CfgParser::AddText( diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx index b8df012dc149..4726234b19dd 100644 --- a/l10ntools/source/helper.cxx +++ b/l10ntools/source/helper.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -19,16 +20,16 @@ namespace helper { OString escapeAll( - const OString& rText, const OString& rUnEscaped, const OString& rEscaped ) + std::string_view rText, std::string_view rUnEscaped, std::string_view rEscaped ) { - assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); + assert( rEscaped.size() == 2*rUnEscaped.size() ); OStringBuffer sReturn; - for ( sal_Int32 nIndex = 0; nIndex < rText.getLength(); ++nIndex ) + for ( size_t nIndex = 0; nIndex < rText.size(); ++nIndex ) { - sal_Int32 nUnEscapedOne = rUnEscaped.indexOf(rText[nIndex]); - if( nUnEscapedOne != -1 ) + size_t nUnEscapedOne = rUnEscaped.find(rText[nIndex]); + if( nUnEscapedOne != std::string_view::npos ) { - sReturn.append(rEscaped.subView(nUnEscapedOne*2,2)); + sReturn.append(rEscaped.substr(nUnEscapedOne*2,2)); } else sReturn.append(rText[nIndex]); @@ -38,17 +39,17 @@ OString escapeAll( OString unEscapeAll( - const OString& rText, const OString& rEscaped, std::string_view rUnEscaped) + std::string_view rText, std::string_view rEscaped, std::string_view rUnEscaped) { - assert( o3tl::make_unsigned(rEscaped.getLength()) == 2*rUnEscaped.length() ); + assert( rEscaped.size() == 2*rUnEscaped.length() ); OStringBuffer sReturn; - const sal_Int32 nLength = rText.getLength(); - for ( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex ) + const size_t nLength = rText.size(); + for ( size_t nIndex = 0; nIndex < nLength; ++nIndex ) { if( rText[nIndex] == '\\' && nIndex+1 < nLength ) { - sal_Int32 nEscapedOne = rEscaped.indexOf(rText.subView(nIndex,2)); - if( nEscapedOne != -1 ) + size_t nEscapedOne = rEscaped.find(rText.substr(nIndex,2)); + if( nEscapedOne != std::string_view::npos ) { sReturn.append(rUnEscaped[nEscapedOne/2]); ++nIndex; @@ -65,10 +66,10 @@ OString unEscapeAll( } -OString QuotHTML(const OString &rString) +OString QuotHTML(std::string_view rString) { OStringBuffer sReturn; - for (sal_Int32 i = 0; i < rString.getLength(); ++i) + for (size_t i = 0; i < rString.size(); ++i) { switch (rString[i]) { @@ -85,7 +86,7 @@ OString QuotHTML(const OString &rString) sReturn.append("'"); break; case '&': - if (rString.match("&", i)) + if (o3tl::starts_with(rString.substr(i), "&")) sReturn.append('&'); else sReturn.append("&"); @@ -98,23 +99,24 @@ OString QuotHTML(const OString &rString) return sReturn.makeStringAndClear(); } -OString UnQuotHTML( const OString& rString ) +OString UnQuotHTML( std::string_view rString ) { OStringBuffer sReturn; - for (sal_Int32 i = 0; i != rString.getLength();) { - if (rString.match("&", i)) { + for (size_t i = 0; i != rString.size();) { + auto tmp = rString.substr(i); + if (o3tl::starts_with(tmp, "&")) { sReturn.append('&'); i += RTL_CONSTASCII_LENGTH("&"); - } else if (rString.match("<", i)) { + } else if (o3tl::starts_with(tmp, "<")) { sReturn.append('<'); i += RTL_CONSTASCII_LENGTH("<"); - } else if (rString.match(">", i)) { + } else if (o3tl::starts_with(tmp, ">")) { sReturn.append('>'); i += RTL_CONSTASCII_LENGTH(">"); - } else if (rString.match(""", i)) { + } else if (o3tl::starts_with(tmp, """)) { sReturn.append('"'); i += RTL_CONSTASCII_LENGTH("""); - } else if (rString.match("'", i)) { + } else if (o3tl::starts_with(tmp, "'")) { sReturn.append('\''); i += RTL_CONSTASCII_LENGTH("'"); } else { diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index a29fb4fe98dd..2bf522d4b05e 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -80,9 +80,9 @@ public: namespace { // Convert a normal string to msg/po output string - OString lcl_GenMsgString(const OString& rString) + OString lcl_GenMsgString(std::string_view rString) { - if ( rString.isEmpty() ) + if ( rString.empty() ) return "\"\""; OString sResult = @@ -107,11 +107,11 @@ namespace } // Convert msg string to normal form - OString lcl_GenNormString(const OString& rString) + OString lcl_GenNormString(std::string_view rString) { return helper::unEscapeAll( - rString.copy(1,rString.getLength()-2), + rString.substr(1,rString.size()-2), "\\n""\\t""\\r""\\\\""\\\"", "\n""\t""\r""\\""\""); } @@ -150,7 +150,7 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) const << std::endl; if ( !m_sMsgStrPlural.empty() ) for(auto & line : m_sMsgStrPlural) - rOFStream << line.copy(0,10) << lcl_GenMsgString(line.copy(10)) << std::endl; + rOFStream << line.copy(0,10) << lcl_GenMsgString(line.subView(10)) << std::endl; else rOFStream << "msgstr " << lcl_GenMsgString(m_sMsgStr) << std::endl; @@ -192,29 +192,29 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) } else if (sLine.startsWith("msgctxt ")) { - m_sMsgCtxt = lcl_GenNormString(sLine.copy(8)); + m_sMsgCtxt = lcl_GenNormString(sLine.subView(8)); pLastMsg = &m_sMsgCtxt; } else if (sLine.startsWith("msgid ")) { - m_sMsgId = lcl_GenNormString(sLine.copy(6)); + m_sMsgId = lcl_GenNormString(sLine.subView(6)); pLastMsg = &m_sMsgId; } else if (sLine.startsWith("msgid_plural ")) { - m_sMsgIdPlural = lcl_GenNormString(sLine.copy(13)); + m_sMsgIdPlural = lcl_GenNormString(sLine.subView(13)); pLastMsg = &m_sMsgIdPlural; } else if (sLine.startsWith("msgstr ")) { - m_sMsgStr = lcl_GenNormString(sLine.copy(7)); + m_sMsgStr = lcl_GenNormString(sLine.subView(7)); pLastMsg = &m_sMsgStr; } else if (sLine.startsWith("msgstr[")) { // assume there are no more than 10 plural forms... // and that plural strings are never split to multi-line in po - m_sMsgStrPlural.push_back(sLine.subView(0,10) + lcl_GenNormString(sLine.copy(10))); + m_sMsgStrPlural.push_back(sLine.subView(0,10) + lcl_GenNormString(sLine.subView(10))); } else if (sLine.startsWith("\"") && pLastMsg) { @@ -241,7 +241,7 @@ PoEntry::PoEntry() PoEntry::PoEntry( const OString& rSourceFile, std::string_view rResType, std::string_view rGroupId, - std::string_view rLocalId, const OString& rHelpText, + std::string_view rLocalId, std::string_view rHelpText, const OString& rText, const TYPE eType ) : m_bIsInitialized( false ) { @@ -253,7 +253,7 @@ PoEntry::PoEntry( throw NOGROUPID; else if ( rText.isEmpty() ) throw NOSTRING; - else if ( rHelpText.getLength() == 5 ) + else if ( rHelpText.size() == 5 ) throw WRONGHELPTEXT; m_pGenPo.reset( new GenPoEntry() ); @@ -277,7 +277,7 @@ PoEntry::PoEntry( m_pGenPo->setMsgCtxt(sMsgCtxt); m_pGenPo->setMsgId(rText); m_pGenPo->setExtractCom(OStringConcatenation( - ( !rHelpText.isEmpty() ? rHelpText + "\n" : OString()) + + ( !rHelpText.empty() ? OString::Concat(rHelpText) + "\n" : OString()) + genKeyId( m_pGenPo->getReference().front() + rGroupId + rLocalId + rResType + rText ) )); m_bIsInitialized = true; } diff --git a/reportdesign/source/core/sdr/ReportDrawPage.cxx b/reportdesign/source/core/sdr/ReportDrawPage.cxx index 1f80905252ec..2689f1b437f9 100644 --- a/reportdesign/source/core/sdr/ReportDrawPage.cxx +++ b/reportdesign/source/core/sdr/ReportDrawPage.cxx @@ -104,7 +104,7 @@ uno::Reference< drawing::XShape > OReportDrawPage::CreateShape( SdrObject *pObj OUString sName; xObj = pObj->getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().CreateEmbeddedObject( ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( - "80243D39-6741-46C5-926E-069164FF87BB"), sName ); + u"80243D39-6741-46C5-926E-069164FF87BB"), sName ); OSL_ENSURE(xObj.is(),"Embedded Object could not be created!"); /************************************************** diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 3c652adb89c7..2a1cf03c0601 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3044,11 +3044,11 @@ const std::shared_ptr& SfxMedium::GetFilter() const return pImpl->m_pFilter; } -sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const OUString& aPasswd, bool bWriter ) +sal_uInt32 SfxMedium::CreatePasswordToModifyHash( std::u16string_view aPasswd, bool bWriter ) { sal_uInt32 nHash = 0; - if ( !aPasswd.isEmpty() ) + if ( !aPasswd.empty() ) { if ( bWriter ) { diff --git a/slideshow/source/engine/animationfactory.cxx b/slideshow/source/engine/animationfactory.cxx index e5a7d3b9e74c..0d160e3f5513 100644 --- a/slideshow/source/engine/animationfactory.cxx +++ b/slideshow/source/engine/animationfactory.cxx @@ -200,7 +200,7 @@ namespace slideshow::internal class PathAnimation : public NumberAnimation { public: - PathAnimation( const OUString& rSVGDPath, + PathAnimation( std::u16string_view rSVGDPath, sal_Int16 nAdditive, const ShapeManagerSharedPtr& rShapeManager, const ::basegfx::B2DVector& rSlideSize, diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx b/stoc/source/uriproc/UriReferenceFactory.cxx index bb96a55d88ed..254097c179fe 100644 --- a/stoc/source/uriproc/UriReferenceFactory.cxx +++ b/stoc/source/uriproc/UriReferenceFactory.cxx @@ -53,10 +53,10 @@ namespace { -bool equalIgnoreEscapeCase(OUString const & s1, OUString const & s2) { - if (s1.getLength() == s2.getLength()) { - for (sal_Int32 i = 0; i < s1.getLength();) { - if (s1[i] == '%' && s2[i] == '%' && s1.getLength() - i > 2 +bool equalIgnoreEscapeCase(std::u16string_view s1, std::u16string_view s2) { + if (s1.size() == s2.size()) { + for (size_t i = 0; i < s1.size();) { + if (s1[i] == '%' && s2[i] == '%' && s1.size() - i > 2 && rtl::isAsciiHexDigit(s1[i + 1]) && rtl::isAsciiHexDigit(s1[i + 2]) && rtl::isAsciiHexDigit(s2[i + 1]) @@ -77,9 +77,9 @@ bool equalIgnoreEscapeCase(OUString const & s1, OUString const & s2) { } } -sal_Int32 parseScheme(OUString const & uriReference) { - if (uriReference.getLength() >= 2 && rtl::isAsciiAlpha(uriReference[0])) { - for (sal_Int32 i = 0; i < uriReference.getLength(); ++i) { +sal_Int32 parseScheme(std::u16string_view uriReference) { + if (uriReference.size() >= 2 && rtl::isAsciiAlpha(uriReference[0])) { + for (size_t i = 0; i < uriReference.size(); ++i) { sal_Unicode c = uriReference[i]; if (c == ':') { return i; diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx index 59eadd9f2db2..ac37da853a83 100644 --- a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx +++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -49,8 +50,8 @@ int getHexWeight(sal_Unicode c) { : -1; } -int parseEscaped(OUString const & part, sal_Int32 * index) { - if (part.getLength() - *index < 3 || part[*index] != '%') { +int parseEscaped(std::u16string_view part, sal_Int32 * index) { + if (part.size() - *index < 3 || part[*index] != '%') { return -1; } int n1 = getHexWeight(part[*index + 1]); @@ -63,10 +64,10 @@ int parseEscaped(OUString const & part, sal_Int32 * index) { } OUString parsePart( - OUString const & part, bool namePart, sal_Int32 * index) + std::u16string_view part, bool namePart, sal_Int32 * index) { OUStringBuffer buf(64); - while (*index < part.getLength()) { + while (o3tl::make_unsigned(*index) < part.size()) { sal_Unicode c = part[*index]; if (namePart ? c == '?' : c == '&' || c == '=') { break; @@ -150,25 +151,25 @@ OUString encodeNameOrParamFragment(OUString const & fragment) { RTL_TEXTENCODING_UTF8); } -bool parseSchemeSpecificPart(OUString const & part) { - sal_Int32 len = part.getLength(); +bool parseSchemeSpecificPart(std::u16string_view part) { + size_t len = part.size(); sal_Int32 i = 0; if (parsePart(part, true, &i).isEmpty() || part[0] == '/') { return false; } - if (i == len) { + if (o3tl::make_unsigned(i) == len) { return true; } for (;;) { ++i; // skip '?' or '&' - if (parsePart(part, false, &i).isEmpty() || i == len + if (parsePart(part, false, &i).isEmpty() || o3tl::make_unsigned(i) == len || part[i] != '=') { return false; } ++i; parsePart(part, false, &i); - if (i == len) { + if (o3tl::make_unsigned(i) == len) { return true; } if (part[i] != '&') { diff --git a/ucb/source/ucp/package/pkguri.cxx b/ucb/source/ucp/package/pkguri.cxx index 9796ecc34c73..b1de54aa4756 100644 --- a/ucb/source/ucp/package/pkguri.cxx +++ b/ucb/source/ucp/package/pkguri.cxx @@ -185,8 +185,8 @@ void PackageUri::init() const if ( m_aPath.indexOf( "//" ) != -1 || m_aPath.indexOf( "%2F" ) != -1 || m_aPath.indexOf( "%2f" ) != -1 - || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, ".." ) - || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, "." ) ) + || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, u".." ) + || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, u"." ) ) { // error, but remember that we did an init(). m_aPath = "/"; diff --git a/unoidl/source/sourceprovider-parser.y b/unoidl/source/sourceprovider-parser.y index 0175b5379897..2c076f08ac70 100644 --- a/unoidl/source/sourceprovider-parser.y +++ b/unoidl/source/sourceprovider-parser.y @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -165,11 +166,11 @@ template rtl::Reference getCurrentPad( return pad; } -bool nameHasSameIdentifierAs(OUString const & name, OUString const & identifier) +bool nameHasSameIdentifierAs(std::u16string_view name, std::u16string_view identifier) { - sal_Int32 i = name.lastIndexOf('.') + 1; - return identifier.getLength() == name.getLength() - i - && name.match(identifier, i); + size_t i = name.rfind('.') + 1; + return identifier.size() == name.size() - i + && o3tl::starts_with(name.substr(i), identifier); } bool coerce( diff --git a/unoidl/source/sourcetreeprovider.cxx b/unoidl/source/sourcetreeprovider.cxx index 404938c376cc..fea67405cd54 100644 --- a/unoidl/source/sourcetreeprovider.cxx +++ b/unoidl/source/sourcetreeprovider.cxx @@ -126,9 +126,9 @@ private: OUString uri_; }; -bool isValidFileName(OUString const & name, bool directory) { - for (sal_Int32 i = 0;; ++i) { - if (i == name.getLength()) { +bool isValidFileName(std::u16string_view name, bool directory) { + for (size_t i = 0;; ++i) { + if (i == name.size()) { if (i == 0) { return false; } @@ -139,7 +139,7 @@ bool isValidFileName(OUString const & name, bool directory) { if (i == 0 || name[i - 1] == '_') { return false; } - return !directory && name.subView(i + 1) == u"idl"; + return !directory && name.substr(i + 1) == u"idl"; } else if (c == '_') { //TODO: Ignore case of name[0] only for case-insensitive file systems: if (i == 0 || name[i - 1] == '_') { diff --git a/unoidl/source/unoidlprovider.cxx b/unoidl/source/unoidlprovider.cxx index 217251dca053..e7816afdb2be 100644 --- a/unoidl/source/unoidlprovider.cxx +++ b/unoidl/source/unoidlprovider.cxx @@ -183,14 +183,14 @@ bool isSimpleType(std::u16string_view type) { // ::= | "a"--"z" | "0"--"9" // ::= "A"--"Z" // -bool isIdentifier(OUString const & type, bool scoped) { - if (type.isEmpty()) { +bool isIdentifier(std::u16string_view type, bool scoped) { + if (type.empty()) { return false; } - for (sal_Int32 i = 0; i != type.getLength(); ++i) { + for (size_t i = 0; i != type.size(); ++i) { sal_Unicode c = type[i]; if (c == '.') { - if (!scoped || i == 0 || i == type.getLength() - 1 + if (!scoped || i == 0 || i == type.size() - 1 || type[i - 1] == '.') { return false; @@ -247,11 +247,11 @@ void checkTypeName( } void checkEntityName( - rtl::Reference< MappedFile > const & file, OUString const & name) + rtl::Reference< MappedFile > const & file, std::u16string_view name) { if (isSimpleType(name) || !isIdentifier(name, false)) { throw FileFormatException( - file->uri, "UNOIDL format: bad entity name \"" + name + "\""); + file->uri, OUString::Concat("UNOIDL format: bad entity name \"") + name + "\""); } } -- cgit