From 5200a73627d13e2997f81b53f61e143e77e328ee Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 29 Apr 2022 11:06:33 +0200 Subject: use more string_view in various found by examining uses of OUString::copy() for likely places Change-Id: I6ff20e7b273ad6005410b82719183c1122f8c018 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133617 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../source/core/misc/conditionalexpression.cxx | 32 +++++++++++----------- .../source/filter/xml/xmlImportDocumentHandler.cxx | 6 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'reportdesign') diff --git a/reportdesign/source/core/misc/conditionalexpression.cxx b/reportdesign/source/core/misc/conditionalexpression.cxx index 97284c8b0d64..d8f37efc9578 100644 --- a/reportdesign/source/core/misc/conditionalexpression.cxx +++ b/reportdesign/source/core/misc/conditionalexpression.cxx @@ -97,8 +97,8 @@ namespace rptui // must be identical if ( _rExpression.getLength() < nLHSIndex ) return false; - const OUString sExprPart1( _rExpression.copy( 0, nLHSIndex ) ); - const OUString sMatchExprPart1( sMatchExpression.copy( 0, nLHSIndex ) ); + const std::u16string_view sExprPart1( _rExpression.subView( 0, nLHSIndex ) ); + const std::u16string_view sMatchExprPart1( sMatchExpression.subView( 0, nLHSIndex ) ); if ( sExprPart1 != sMatchExprPart1 ) // the left-most expression parts do not match return false; @@ -107,11 +107,11 @@ namespace rptui // must be identical, too bool bHaveRHS( nRHSIndex != -1 ); sal_Int32 nRightMostIndex( bHaveRHS ? nRHSIndex : nLHSIndex ); - const OUString sMatchExprPart3( sMatchExpression.copy( nRightMostIndex + 2 ) ); - if ( _rExpression.getLength() < sMatchExprPart3.getLength() ) + const std::u16string_view sMatchExprPart3( sMatchExpression.subView( nRightMostIndex + 2 ) ); + if ( _rExpression.getLength() < static_cast(sMatchExprPart3.size()) ) // the expression is not even long enough to hold the right-most part of the match expression return false; - const OUString sExprPart3( _rExpression.copy( _rExpression.getLength() - sMatchExprPart3.getLength() ) ); + const std::u16string_view sExprPart3( _rExpression.subView( _rExpression.getLength() - sMatchExprPart3.size() ) ); if ( sExprPart3 != sMatchExprPart3 ) // the right-most expression parts do not match return false; @@ -119,28 +119,28 @@ namespace rptui // if we don't have an RHS, we're done if ( !bHaveRHS ) { - _out_rLHS = _rExpression.copy( sExprPart1.getLength(), _rExpression.getLength() - sExprPart1.getLength() - sExprPart3.getLength() ); + _out_rLHS = _rExpression.copy( sExprPart1.size(), _rExpression.getLength() - sExprPart1.size() - sExprPart3.size() ); return true; } // strip the match expression by its right-most and left-most part, and by the placeholders $1 and $2 sal_Int32 nMatchExprPart2Start( nLHSIndex + sLHSPattern.getLength() ); - OUString sMatchExprPart2 = sMatchExpression.copy( + std::u16string_view sMatchExprPart2 = sMatchExpression.subView( nMatchExprPart2Start, - sMatchExpression.getLength() - nMatchExprPart2Start - sMatchExprPart3.getLength() - 2 + sMatchExpression.getLength() - nMatchExprPart2Start - sMatchExprPart3.size() - 2 ); // strip the expression by its left-most and right-most part - const OUString sExpression( _rExpression.copy( - sExprPart1.getLength(), - _rExpression.getLength() - sExprPart1.getLength() - sExprPart3.getLength() + const std::u16string_view sExpression( _rExpression.subView( + sExprPart1.size(), + _rExpression.getLength() - sExprPart1.size() - sExprPart3.size() ) ); - sal_Int32 nPart2Index = sExpression.indexOf( sMatchExprPart2 ); - if ( nPart2Index == -1 ) + size_t nPart2Index = sExpression.find( sMatchExprPart2 ); + if ( nPart2Index == std::u16string_view::npos ) // the "middle" part of the match expression does not exist in the expression at all return false; - OSL_ENSURE( sExpression.indexOf( sMatchExprPart2, nPart2Index + 1 ) == -1, + OSL_ENSURE( sExpression.find( sMatchExprPart2, nPart2Index + 1 ) == std::u16string_view::npos, "ConditionalExpression::matchExpression: ambiguous matching!" ); // if this fires, then we're lost: The middle part exists two times in the expression, // so we cannot reliably determine what's the LHS and what's the RHS. @@ -154,8 +154,8 @@ namespace rptui // Here, at the latest, you can see that we need another mechanism, anyway, which does not // rely on those strange expression building/matching - _out_rLHS = sExpression.copy( 0, nPart2Index ); - _out_rRHS = sExpression.copy( nPart2Index + sMatchExprPart2.getLength() ); + _out_rLHS = sExpression.substr( 0, nPart2Index ); + _out_rRHS = sExpression.substr( nPart2Index + sMatchExprPart2.size() ); return true; } diff --git a/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx index 4e7fd13b47c7..fa0f29037320 100644 --- a/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx +++ b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx @@ -247,14 +247,14 @@ void SAL_CALL ImportDocumentHandler::startElement(const OUString & _sName, const const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; for(sal_Int16 i = 0; i < nLength; ++i) { - OUString sLocalName; + std::u16string_view sLocalName; const OUString sAttrName = _xAttrList->getNameByIndex( i ); const sal_Int32 nColonPos = sAttrName.indexOf( ':' ); if( -1 == nColonPos ) sLocalName = sAttrName; else - sLocalName = sAttrName.copy( nColonPos + 1 ); - if ( sLocalName == "data-source-has-labels" ) + sLocalName = sAttrName.subView( nColonPos + 1 ); + if ( sLocalName == u"data-source-has-labels" ) { const OUString sValue = _xAttrList->getValueByIndex( i ); bHasCategories = sValue == "both"; -- cgit