include/xmloff/unoatrcn.hxx         |    2 +-
 xmloff/inc/txtflde.hxx              |    2 +-
 xmloff/source/chart/SchXMLTools.cxx |    8 ++++----
 xmloff/source/core/unoatrcn.cxx     |   10 +++++-----
 xmloff/source/core/xmlexp.cxx       |    8 ++++----
 xmloff/source/draw/shapeexport.cxx  |   23 ++++++++++++-----------
 xmloff/source/text/txtflde.cxx      |   10 +++++-----
 7 files changed, 32 insertions(+), 31 deletions(-)

New commits:
commit 0d55188fbf7b0399f01bae521f1a34d22ad8ba18
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Apr 13 16:14:26 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Apr 13 20:36:16 2022 +0200

    use more string_view in xmloff
    
    Change-Id: I0d860fa6e3d3261f3393e912b27930066dd93f7c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132972
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/xmloff/unoatrcn.hxx b/include/xmloff/unoatrcn.hxx
index 68baa3bd8b2e..8e5556bb18aa 100644
--- a/include/xmloff/unoatrcn.hxx
+++ b/include/xmloff/unoatrcn.hxx
@@ -45,7 +45,7 @@ class XMLOFF_DLLPUBLIC SvUnoAttributeContainer final :
 private:
     std::unique_ptr<SvXMLAttrContainerData> mpContainer;
 
-    SAL_DLLPRIVATE sal_uInt16 getIndexByName(const OUString& aName )
+    SAL_DLLPRIVATE sal_uInt16 getIndexByName(std::u16string_view aName )
         const;
 
 public:
diff --git a/xmloff/inc/txtflde.hxx b/xmloff/inc/txtflde.hxx
index 66c5eed3f67e..8670cac40cf6 100644
--- a/xmloff/inc/txtflde.hxx
+++ b/xmloff/inc/txtflde.hxx
@@ -395,7 +395,7 @@ private:
 
     /// explode a field master name into field type and field name
     static void ExplodeFieldMasterName(
-        const OUString& sMasterName, /// name as returned by SO API
+        std::u16string_view sMasterName, /// name as returned by SO API
         OUString& sFieldType,        /// out: field type
         OUString& sVarName);         /// out: variable name
 
diff --git a/xmloff/source/chart/SchXMLTools.cxx 
b/xmloff/source/chart/SchXMLTools.cxx
index 27fa23987b59..828d550e9f56 100644
--- a/xmloff/source/chart/SchXMLTools.cxx
+++ b/xmloff/source/chart/SchXMLTools.cxx
@@ -86,15 +86,15 @@ OUString lcl_getGeneratorFromModelOrItsParent( const 
uno::Reference< frame::XMod
     return aGenerator;
 }
 
-sal_Int32 lcl_getBuildIDFromGenerator( const OUString& rGenerator )
+sal_Int32 lcl_getBuildIDFromGenerator( std::u16string_view rGenerator )
 {
     //returns -1 if nothing found
     sal_Int32 nBuildId = -1;
     static const OUStringLiteral sBuildCompare(  u"$Build-"  );
-    sal_Int32 nBegin = rGenerator.indexOf( sBuildCompare );
-    if( nBegin >= 0 )
+    size_t nBegin = rGenerator.find( sBuildCompare );
+    if( nBegin != std::u16string_view::npos )
     {
-        OUString sBuildId( rGenerator.copy( nBegin + sBuildCompare.getLength() 
) );
+        OUString sBuildId( rGenerator.substr( nBegin + 
sBuildCompare.getLength() ) );
         nBuildId = sBuildId.toInt32();
     }
     return nBuildId;
diff --git a/xmloff/source/core/unoatrcn.cxx b/xmloff/source/core/unoatrcn.cxx
index 9125e6cfb93c..354cd47b49ce 100644
--- a/xmloff/source/core/unoatrcn.cxx
+++ b/xmloff/source/core/unoatrcn.cxx
@@ -56,12 +56,12 @@ sal_Bool SAL_CALL SvUnoAttributeContainer::hasElements()
     return mpContainer->GetAttrCount() != 0;
 }
 
-sal_uInt16 SvUnoAttributeContainer::getIndexByName(const OUString& aName ) 
const
+sal_uInt16 SvUnoAttributeContainer::getIndexByName(std::u16string_view aName ) 
const
 {
     const sal_uInt16 nAttrCount = mpContainer->GetAttrCount();
 
-    sal_Int32 nPos = aName.indexOf( ':' );
-    if( nPos == -1 )
+    size_t nPos = aName.find( ':' );
+    if( nPos == std::u16string_view::npos )
     {
         for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
         {
@@ -72,8 +72,8 @@ sal_uInt16 SvUnoAttributeContainer::getIndexByName(const 
OUString& aName ) const
     }
     else
     {
-        const OUString aPrefix( aName.copy( 0L, nPos ) );
-        const OUString aLName( aName.copy( nPos+1 ) );
+        const std::u16string_view aPrefix( aName.substr( 0L, nPos ) );
+        const std::u16string_view aLName( aName.substr( nPos+1 ) );
 
         for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
         {
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index e0110892a6f3..cc4eb39b3bd8 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -265,11 +265,11 @@ public:
     bool                                                
mbExportTextNumberElement;
     bool                                                mbNullDateInitialized;
 
-    void SetSchemeOf( const OUString& rOrigFileName )
+    void SetSchemeOf( std::u16string_view rOrigFileName )
     {
-        sal_Int32 nSep = rOrigFileName.indexOf(':');
-        if( nSep != -1 )
-            msPackageURIScheme = rOrigFileName.copy( 0, nSep );
+        size_t nSep = rOrigFileName.find(':');
+        if( nSep != std::u16string_view::npos )
+            msPackageURIScheme = rOrigFileName.substr( 0, nSep );
     }
 };
 
diff --git a/xmloff/source/draw/shapeexport.cxx 
b/xmloff/source/draw/shapeexport.cxx
index bc642d344e68..55de243f07aa 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -90,6 +90,7 @@
 
 #include <o3tl/any.hxx>
 #include <o3tl/typed_flags_set.hxx>
+#include <o3tl/string_view.hxx>
 
 #include <rtl/math.hxx>
 #include <rtl/ustrbuf.hxx>
@@ -2408,22 +2409,22 @@ void XMLShapeExport::ImpExportPolygonShape(
 namespace
 {
 
-OUString getNameFromStreamURL(OUString const & rURL)
+OUString getNameFromStreamURL(std::u16string_view rURL)
 {
-    static const OUStringLiteral sPackageURL(u"vnd.sun.star.Package:");
+    static constexpr std::u16string_view sPackageURL(u"vnd.sun.star.Package:");
 
     OUString sResult;
 
-    if (rURL.match(sPackageURL))
+    if (o3tl::starts_with(rURL, sPackageURL))
     {
-        OUString sRequestedName = rURL.copy(sPackageURL.getLength());
-        sal_Int32 nLastIndex = sRequestedName.lastIndexOf('/') + 1;
-        if ((nLastIndex > 0) && (nLastIndex < sRequestedName.getLength()))
-            sRequestedName = sRequestedName.copy(nLastIndex);
-        nLastIndex = sRequestedName.lastIndexOf('.');
-        if (nLastIndex >= 0)
-            sRequestedName = sRequestedName.copy(0, nLastIndex);
-        if (!sRequestedName.isEmpty())
+        std::u16string_view sRequestedName = rURL.substr(sPackageURL.size());
+        size_t nLastIndex = sRequestedName.rfind('/') + 1;
+        if ((nLastIndex > 0) && (nLastIndex < sRequestedName.size()))
+            sRequestedName = sRequestedName.substr(nLastIndex);
+        nLastIndex = sRequestedName.rfind('.');
+        if (nLastIndex != std::u16string_view::npos)
+            sRequestedName = sRequestedName.substr(0, nLastIndex);
+        if (!sRequestedName.empty())
             sResult = sRequestedName;
     }
 
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx
index 1fe5da65caf6..fb6cd419b923 100644
--- a/xmloff/source/text/txtflde.cxx
+++ b/xmloff/source/text/txtflde.cxx
@@ -2847,19 +2847,19 @@ void XMLTextFieldExport::ExportDataBaseElement(
 
 // explode a field master name into field type and field name
 void XMLTextFieldExport::ExplodeFieldMasterName(
-    const OUString& sMasterName, OUString& sFieldType, OUString& sVarName)
+    std::u16string_view sMasterName, OUString& sFieldType, OUString& sVarName)
 {
     sal_Int32 nLength = gsFieldMasterPrefix.getLength();
-    sal_Int32 nSeparator = sMasterName.indexOf('.', nLength);
+    size_t nSeparator = sMasterName.find('.', nLength);
 
     // '.' found?
-    if (nSeparator <= nLength) {
+    if (static_cast<sal_Int32>(nSeparator) == nLength || nSeparator == 
std::u16string_view::npos) {
         SAL_WARN("xmloff.text", "no field var name!");
     }
     else
     {
-        sFieldType = sMasterName.copy(nLength, nSeparator-nLength);
-        sVarName = sMasterName.copy(nSeparator+1);
+        sFieldType = sMasterName.substr(nLength, nSeparator-nLength);
+        sVarName = sMasterName.substr(nSeparator+1);
     }
 }
 

Reply via email to