diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-13 21:04:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-14 11:25:07 +0200 |
commit | 250a70dc37a921b71049817d5e46aae2eb4cced6 (patch) | |
tree | 7ed4a47122280c6cb63412e786ef3b89e2ef1c3d /oox | |
parent | 41fa4bb83ad95f0b2171808b405fa755613cef81 (diff) |
use more string_view in oox
Change-Id: I25fe1cbfae43bb533e7dfc2561d0b70976aa6a40
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132985
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/core/relations.cxx | 9 | ||||
-rw-r--r-- | oox/source/crypto/AgileEngine.cxx | 43 | ||||
-rw-r--r-- | oox/source/dump/dumperbase.cxx | 12 | ||||
-rw-r--r-- | oox/source/dump/pptxdumper.cxx | 2 |
4 files changed, 36 insertions, 30 deletions
diff --git a/oox/source/core/relations.cxx b/oox/source/core/relations.cxx index 9b29f20a1124..f927c542c89e 100644 --- a/oox/source/core/relations.cxx +++ b/oox/source/core/relations.cxx @@ -28,9 +28,12 @@ namespace oox::core { namespace { -OUString lclRemoveFileName( const OUString& rPath ) +std::u16string_view lclRemoveFileName( std::u16string_view rPath ) { - return rPath.copy( 0, ::std::max< sal_Int32 >( rPath.lastIndexOf( '/' ), 0 ) ); + size_t idx = rPath.rfind( '/' ); + if (idx == std::u16string_view::npos) + return std::u16string_view(); + return rPath.substr( 0, idx ); } OUString lclAppendFileName( std::u16string_view rPath, const OUString& rFileName ) @@ -108,7 +111,7 @@ OUString Relations::getFragmentPathFromRelation( const Relation& rRelation ) con return rRelation.maTarget; // resolve relative target path according to base path - OUString aPath = lclRemoveFileName( maFragmentPath ); + OUString aPath( lclRemoveFileName( maFragmentPath ) ); sal_Int32 nStartPos = 0; while( nStartPos < rRelation.maTarget.getLength() ) { diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx index 0fd655ced63c..09748e9dfd7b 100644 --- a/oox/source/crypto/AgileEngine.cxx +++ b/oox/source/crypto/AgileEngine.cxx @@ -44,9 +44,12 @@ namespace oox::crypto { namespace { -OUString stripNamespacePrefix(OUString const & rsInputName) +std::u16string_view stripNamespacePrefix(std::u16string_view rsInputName) { - return rsInputName.copy(rsInputName.indexOf(":") + 1); + size_t idx = rsInputName.find(':'); + if (idx == std::u16string_view::npos) + return rsInputName; + return rsInputName.substr(idx + 1); } class AgileTokenHandler : public sax_fastparser::FastTokenHandlerBase @@ -85,79 +88,79 @@ public: void SAL_CALL startUnknownElement( const OUString& /*aNamespace*/, const OUString& rName, const Reference< XFastAttributeList >& aAttributeList ) override { - const OUString& rLocalName = stripNamespacePrefix(rName); + std::u16string_view rLocalName = stripNamespacePrefix(rName); const css::uno::Sequence<Attribute> aUnknownAttributes = aAttributeList->getUnknownAttributes(); for (const Attribute& rAttribute : aUnknownAttributes) { - const OUString& rAttrLocalName = stripNamespacePrefix(rAttribute.Name); + std::u16string_view rAttrLocalName = stripNamespacePrefix(rAttribute.Name); - if (rAttrLocalName == "spinCount") + if (rAttrLocalName == u"spinCount") { ::sax::Converter::convertNumber(mInfo.spinCount, rAttribute.Value); } - else if (rAttrLocalName == "saltSize") + else if (rAttrLocalName == u"saltSize") { ::sax::Converter::convertNumber(mInfo.saltSize, rAttribute.Value); } - else if (rAttrLocalName == "blockSize") + else if (rAttrLocalName == u"blockSize") { ::sax::Converter::convertNumber(mInfo.blockSize, rAttribute.Value); } - else if (rAttrLocalName == "keyBits") + else if (rAttrLocalName == u"keyBits") { ::sax::Converter::convertNumber(mInfo.keyBits, rAttribute.Value); } - else if (rAttrLocalName == "hashSize") + else if (rAttrLocalName == u"hashSize") { ::sax::Converter::convertNumber(mInfo.hashSize, rAttribute.Value); } - else if (rAttrLocalName == "cipherAlgorithm") + else if (rAttrLocalName == u"cipherAlgorithm") { mInfo.cipherAlgorithm = rAttribute.Value; } - else if (rAttrLocalName == "cipherChaining") + else if (rAttrLocalName == u"cipherChaining") { mInfo.cipherChaining = rAttribute.Value; } - else if (rAttrLocalName == "hashAlgorithm") + else if (rAttrLocalName == u"hashAlgorithm") { mInfo.hashAlgorithm = rAttribute.Value; } - else if (rAttrLocalName == "saltValue") + else if (rAttrLocalName == u"saltValue") { Sequence<sal_Int8> saltValue; comphelper::Base64::decode(saltValue, rAttribute.Value); - if (rLocalName == "encryptedKey") + if (rLocalName == u"encryptedKey") mInfo.saltValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(saltValue); - else if (rLocalName == "keyData") + else if (rLocalName == u"keyData") mInfo.keyDataSalt = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(saltValue); } - else if (rAttrLocalName == "encryptedVerifierHashInput") + else if (rAttrLocalName == u"encryptedVerifierHashInput") { Sequence<sal_Int8> encryptedVerifierHashInput; comphelper::Base64::decode(encryptedVerifierHashInput, rAttribute.Value); mInfo.encryptedVerifierHashInput = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedVerifierHashInput); } - else if (rAttrLocalName == "encryptedVerifierHashValue") + else if (rAttrLocalName == u"encryptedVerifierHashValue") { Sequence<sal_Int8> encryptedVerifierHashValue; comphelper::Base64::decode(encryptedVerifierHashValue, rAttribute.Value); mInfo.encryptedVerifierHashValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedVerifierHashValue); } - else if (rAttrLocalName == "encryptedKeyValue") + else if (rAttrLocalName == u"encryptedKeyValue") { Sequence<sal_Int8> encryptedKeyValue; comphelper::Base64::decode(encryptedKeyValue, rAttribute.Value); mInfo.encryptedKeyValue = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(encryptedKeyValue); } - if (rAttrLocalName == "encryptedHmacKey") + if (rAttrLocalName == u"encryptedHmacKey") { Sequence<sal_Int8> aValue; comphelper::Base64::decode(aValue, rAttribute.Value); mInfo.hmacEncryptedKey = comphelper::sequenceToContainer<std::vector<sal_uInt8>>(aValue); } - if (rAttrLocalName == "encryptedHmacValue") + if (rAttrLocalName == u"encryptedHmacValue") { Sequence<sal_Int8> aValue; comphelper::Base64::decode(aValue, rAttribute.Value); diff --git a/oox/source/dump/dumperbase.cxx b/oox/source/dump/dumperbase.cxx index 092ab09ff319..61d603228b42 100644 --- a/oox/source/dump/dumperbase.cxx +++ b/oox/source/dump/dumperbase.cxx @@ -78,13 +78,13 @@ sal_Int32 InputOutputHelper::getFileNamePos( std::u16string_view rFileUrl ) return (nSepPos == std::u16string_view::npos) ? 0 : (nSepPos + 1); } -OUString InputOutputHelper::getFileNameExtension( const OUString& rFileUrl ) +std::u16string_view InputOutputHelper::getFileNameExtension( std::u16string_view rFileUrl ) { sal_Int32 nNamePos = getFileNamePos( rFileUrl ); - sal_Int32 nExtPos = rFileUrl.lastIndexOf( '.' ); - if( nExtPos >= nNamePos ) - return rFileUrl.copy( nExtPos + 1 ); - return OUString(); + size_t nExtPos = rFileUrl.rfind( '.' ); + if( nExtPos != std::u16string_view::npos && static_cast<sal_Int32>(nExtPos) >= nNamePos ) + return rFileUrl.substr( nExtPos + 1 ); + return std::u16string_view(); } // input streams -------------------------------------------------------------- @@ -2374,7 +2374,7 @@ void XmlStreamObject::implDumpText( TextInputStream& rTextStrm ) matching start/end elements and the element text on the same line. */ OUStringBuffer aOldStartElem; // special handling for VML - bool bIsVml = InputOutputHelper::getFileNameExtension( maSysFileName ).equalsIgnoreAsciiCase("vml"); + bool bIsVml = o3tl::equalsIgnoreAsciiCase(InputOutputHelper::getFileNameExtension( maSysFileName ), u"vml"); while( !rTextStrm.isEof() ) { diff --git a/oox/source/dump/pptxdumper.cxx b/oox/source/dump/pptxdumper.cxx index fb1b42fb10b5..dba538593aae 100644 --- a/oox/source/dump/pptxdumper.cxx +++ b/oox/source/dump/pptxdumper.cxx @@ -42,7 +42,7 @@ RootStorageObject::RootStorageObject( const DumperBase& rParent ) void RootStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName ) { - OUString aExt = InputOutputHelper::getFileNameExtension( rStrmName ); + OUString aExt( InputOutputHelper::getFileNameExtension( rStrmName ) ); if( aExt.equalsIgnoreAsciiCase("pptx") || aExt.equalsIgnoreAsciiCase("potx") ) { |