use more string_view in xmloff

found by examining uses of OUString::copy() for likely places

Change-Id: I50adefbcdbfde8aa71134e5f162b6986a6d566a9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133623
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2022-04-29 10:41:50 +02:00
parent 7cc3d29077
commit dc3d56e5cf
9 changed files with 40 additions and 40 deletions

View File

@@ -85,7 +85,7 @@ class XMLVersionContext final : public SvXMLImportContext
{ {
private: private:
static bool ParseISODateTimeString( static bool ParseISODateTimeString(
const OUString& rString, std::u16string_view rString,
css::util::DateTime& rDateTime ); css::util::DateTime& rDateTime );
public: public:

View File

@@ -295,30 +295,30 @@ XMLTokenEnum getTokenByChartType(
// if postfix matches and leaves a non-empty type // if postfix matches and leaves a non-empty type
if( nTypeLength > 0 && rChartTypeService.match( aPostfix, nSkip + nTypeLength )) if( nTypeLength > 0 && rChartTypeService.match( aPostfix, nSkip + nTypeLength ))
{ {
OUString aServiceName( rChartTypeService.copy( nSkip, nTypeLength )); std::u16string_view aServiceName( rChartTypeService.subView( nSkip, nTypeLength ));
if ( aServiceName == "Line" ) if ( aServiceName == u"Line" )
eResult = XML_LINE; eResult = XML_LINE;
else if ( aServiceName == "Area" ) else if ( aServiceName == u"Area" )
eResult = XML_AREA; eResult = XML_AREA;
else if( aServiceName == "Bar" || else if( aServiceName == u"Bar" ||
(!bUseOldNames && aServiceName == "Column")) (!bUseOldNames && aServiceName == u"Column"))
eResult = XML_BAR; eResult = XML_BAR;
else if ( aServiceName == "Pie" ) else if ( aServiceName == u"Pie" )
eResult = XML_CIRCLE; eResult = XML_CIRCLE;
else if ( aServiceName == "Donut" ) else if ( aServiceName == u"Donut" )
eResult = XML_RING; eResult = XML_RING;
else if( (bUseOldNames && aServiceName == "XY") || else if( (bUseOldNames && aServiceName == u"XY") ||
(!bUseOldNames && aServiceName == "Scatter")) (!bUseOldNames && aServiceName == u"Scatter"))
eResult = XML_SCATTER; eResult = XML_SCATTER;
else if ( aServiceName == "Bubble" ) else if ( aServiceName == u"Bubble" )
eResult = XML_BUBBLE; eResult = XML_BUBBLE;
else if ( aServiceName == "Net" ) else if ( aServiceName == u"Net" )
eResult = XML_RADAR; eResult = XML_RADAR;
else if ( aServiceName == "FilledNet" ) else if ( aServiceName == u"FilledNet" )
eResult = XML_FILLED_RADAR; eResult = XML_FILLED_RADAR;
else if( (bUseOldNames && aServiceName == "Stock") || else if( (bUseOldNames && aServiceName == u"Stock") ||
(!bUseOldNames && aServiceName == "CandleStick")) (!bUseOldNames && aServiceName == u"CandleStick"))
eResult = XML_STOCK; eResult = XML_STOCK;
} }
} }

View File

@@ -27,6 +27,7 @@
#include <xmloff/namespacemap.hxx> #include <xmloff/namespacemap.hxx>
#include <xmloff/xmlnamespace.hxx> #include <xmloff/xmlnamespace.hxx>
#include <o3tl/string_view.hxx>
using namespace ::xmloff::token; using namespace ::xmloff::token;
@@ -517,9 +518,9 @@ bool SvXMLNamespaceMap::NormalizeOasisURN( OUString& rName )
// :urn:oasis:names:tc:[^:]:xmlns.* // :urn:oasis:names:tc:[^:]:xmlns.*
nPos = nTCIdEnd + 1; nPos = nTCIdEnd + 1;
OUString sTmp( rName.copy( nPos ) ); std::u16string_view sTmp( rName.subView( nPos ) );
const OUString& rXMLNS = GetXMLToken( XML_XMLNS ); const OUString& rXMLNS = GetXMLToken( XML_XMLNS );
if( !sTmp.startsWith( rXMLNS ) ) if( !o3tl::starts_with(sTmp, rXMLNS ) )
return false; return false;
// :urn:oasis:names:tc:[^:]:xmlns:.* // :urn:oasis:names:tc:[^:]:xmlns:.*

View File

@@ -1693,7 +1693,7 @@ void SdXMLExport::ExportContent_()
if( nIndex != -1 ) if( nIndex != -1 )
{ {
OUString aFileName( aBookmarkURL.copy( 0, nIndex ) ); OUString aFileName( aBookmarkURL.copy( 0, nIndex ) );
OUString aBookmarkName( aBookmarkURL.copy( nIndex+1 ) ); std::u16string_view aBookmarkName( aBookmarkURL.subView( nIndex+1 ) );
aBookmarkURL = GetRelativeReference( aFileName ) + "#" + aBookmarkName; aBookmarkURL = GetRelativeReference( aFileName ) + "#" + aBookmarkName;
} }

View File

@@ -190,7 +190,7 @@ SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
if( nIndex != -1 ) if( nIndex != -1 )
{ {
OUString aFileName( sHREF.copy( 0, nIndex ) ); OUString aFileName( sHREF.copy( 0, nIndex ) );
OUString aBookmarkName( sHREF.copy( nIndex+1 ) ); std::u16string_view aBookmarkName( sHREF.subView( nIndex+1 ) );
sHREF = GetImport().GetAbsoluteReference( aFileName ) + "#" sHREF = GetImport().GetAbsoluteReference( aFileName ) + "#"
+ aBookmarkName; + aBookmarkName;

View File

@@ -383,7 +383,7 @@ static bool GetNextParameter( css::drawing::EnhancedCustomShapeParameter& rParam
bValid = false; bValid = false;
if ( bValid ) if ( bValid )
{ {
OUString aNumber( rParaString.copy( nStartIndex, nIndex - nStartIndex ) ); std::u16string_view aNumber( rParaString.subView( nStartIndex, nIndex - nStartIndex ) );
if ( bE || bDot ) if ( bE || bDot )
{ {
double fAttrDouble; double fAttrDouble;

View File

@@ -49,6 +49,7 @@
#include <comphelper/extract.hxx> #include <comphelper/extract.hxx>
#include <comphelper/types.hxx> #include <comphelper/types.hxx>
#include <comphelper/sequence.hxx> #include <comphelper/sequence.hxx>
#include <o3tl/string_view.hxx>
#include <algorithm> #include <algorithm>
@@ -2002,8 +2003,6 @@ namespace xmloff
sal_Int32 nElementStart = 0; sal_Int32 nElementStart = 0;
sal_Int32 nNextSep = 0; sal_Int32 nNextSep = 0;
sal_Int32 nElementLength;
OUString sElement;
do do
{ {
// extract the current element // extract the current element
@@ -2011,15 +2010,15 @@ namespace xmloff
_rValue, nElementStart); _rValue, nElementStart);
if (-1 == nNextSep) if (-1 == nNextSep)
nNextSep = nLength; nNextSep = nLength;
sElement = _rValue.copy(nElementStart, nNextSep - nElementStart); std::u16string_view sElement = _rValue.subView(nElementStart, nNextSep - nElementStart);
nElementLength = sElement.getLength(); size_t nElementLength = sElement.size();
// when writing the sequence, we quoted the single elements with " characters // when writing the sequence, we quoted the single elements with " characters
OSL_ENSURE( sElement.startsWith("\"") && sElement.endsWith("\""), OSL_ENSURE( o3tl::starts_with(sElement, u"\"") && o3tl::ends_with(sElement, u"\""),
"OFormImport::implTranslateStringListProperty: invalid quoted element name."); "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
sElement = sElement.copy(1, nElementLength - 2); sElement = sElement.substr(1, nElementLength - 2);
aElements.push_back(sElement); aElements.push_back(OUString(sElement));
// switch to the next element // switch to the next element
nElementStart = 1 + nNextSep; nElementStart = 1 + nNextSep;

View File

@@ -202,17 +202,17 @@ XMLVersionContext::~XMLVersionContext()
{} {}
bool XMLVersionContext::ParseISODateTimeString( bool XMLVersionContext::ParseISODateTimeString(
const OUString& rString, std::u16string_view rString,
util::DateTime& rDateTime ) util::DateTime& rDateTime )
{ {
bool bSuccess = true; bool bSuccess = true;
OUString aDateStr, aTimeStr; std::u16string_view aDateStr, aTimeStr;
sal_Int32 nPos = rString.indexOf( 'T' ); size_t nPos = rString.find( 'T' );
if ( nPos >= 0 ) if ( nPos != std::u16string_view::npos )
{ {
aDateStr = rString.copy( 0, nPos ); aDateStr = rString.substr( 0, nPos );
aTimeStr = rString.copy( nPos + 1 ); aTimeStr = rString.substr( nPos + 1 );
} }
else else
aDateStr = rString; // no separator: only date part aDateStr = rString; // no separator: only date part
@@ -224,15 +224,15 @@ bool XMLVersionContext::ParseISODateTimeString(
sal_Int32 nMin = 0; sal_Int32 nMin = 0;
sal_Int32 nSec = 0; sal_Int32 nSec = 0;
const sal_Unicode* pStr = aDateStr.getStr(); auto pStr = aDateStr.begin();
sal_Int32 nDateTokens = 1; sal_Int32 nDateTokens = 1;
while ( *pStr ) while ( pStr != aDateStr.end() )
{ {
if ( *pStr == '-' ) if ( *pStr == '-' )
nDateTokens++; nDateTokens++;
pStr++; pStr++;
} }
if ( nDateTokens > 3 || aDateStr.isEmpty() ) if ( nDateTokens > 3 || aDateStr.empty() )
bSuccess = false; bSuccess = false;
else else
{ {
@@ -254,11 +254,11 @@ bool XMLVersionContext::ParseISODateTimeString(
} }
} }
if ( bSuccess && !aTimeStr.isEmpty() ) // time is optional if ( bSuccess && !aTimeStr.empty() ) // time is optional
{ {
pStr = aTimeStr.getStr(); pStr = aTimeStr.begin();
sal_Int32 nTimeTokens = 1; sal_Int32 nTimeTokens = 1;
while ( *pStr ) while ( pStr != aTimeStr.end() )
{ {
if ( *pStr == ':' ) if ( *pStr == ':' )
nTimeTokens++; nTimeTokens++;

View File

@@ -473,7 +473,7 @@ bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, cons
if( (nOpen != -1) && (nClose > nOpen) ) if( (nOpen != -1) && (nClose > nOpen) )
{ {
const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) ); const std::u16string_view aTmp( rStrImpValue.subView( nOpen+1, nClose - nOpen-1) );
sal_Int32 nIndex = 0; sal_Int32 nIndex = 0;