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:
static bool ParseISODateTimeString(
const OUString& rString,
std::u16string_view rString,
css::util::DateTime& rDateTime );
public:

View File

@@ -295,30 +295,30 @@ XMLTokenEnum getTokenByChartType(
// if postfix matches and leaves a non-empty type
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;
else if ( aServiceName == "Area" )
else if ( aServiceName == u"Area" )
eResult = XML_AREA;
else if( aServiceName == "Bar" ||
(!bUseOldNames && aServiceName == "Column"))
else if( aServiceName == u"Bar" ||
(!bUseOldNames && aServiceName == u"Column"))
eResult = XML_BAR;
else if ( aServiceName == "Pie" )
else if ( aServiceName == u"Pie" )
eResult = XML_CIRCLE;
else if ( aServiceName == "Donut" )
else if ( aServiceName == u"Donut" )
eResult = XML_RING;
else if( (bUseOldNames && aServiceName == "XY") ||
(!bUseOldNames && aServiceName == "Scatter"))
else if( (bUseOldNames && aServiceName == u"XY") ||
(!bUseOldNames && aServiceName == u"Scatter"))
eResult = XML_SCATTER;
else if ( aServiceName == "Bubble" )
else if ( aServiceName == u"Bubble" )
eResult = XML_BUBBLE;
else if ( aServiceName == "Net" )
else if ( aServiceName == u"Net" )
eResult = XML_RADAR;
else if ( aServiceName == "FilledNet" )
else if ( aServiceName == u"FilledNet" )
eResult = XML_FILLED_RADAR;
else if( (bUseOldNames && aServiceName == "Stock") ||
(!bUseOldNames && aServiceName == "CandleStick"))
else if( (bUseOldNames && aServiceName == u"Stock") ||
(!bUseOldNames && aServiceName == u"CandleStick"))
eResult = XML_STOCK;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -49,6 +49,7 @@
#include <comphelper/extract.hxx>
#include <comphelper/types.hxx>
#include <comphelper/sequence.hxx>
#include <o3tl/string_view.hxx>
#include <algorithm>
@@ -2002,8 +2003,6 @@ namespace xmloff
sal_Int32 nElementStart = 0;
sal_Int32 nNextSep = 0;
sal_Int32 nElementLength;
OUString sElement;
do
{
// extract the current element
@@ -2011,15 +2010,15 @@ namespace xmloff
_rValue, nElementStart);
if (-1 == nNextSep)
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
OSL_ENSURE( sElement.startsWith("\"") && sElement.endsWith("\""),
OSL_ENSURE( o3tl::starts_with(sElement, u"\"") && o3tl::ends_with(sElement, u"\""),
"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
nElementStart = 1 + nNextSep;

View File

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

View File

@@ -473,7 +473,7 @@ bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, cons
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;