stoc/source/typeconv/convert.cxx            |   39 ++++++++++++++--------------
 stoc/source/uriproc/UriReferenceFactory.cxx |   18 ++++++------
 2 files changed, 29 insertions(+), 28 deletions(-)

New commits:
commit 113d9bba057b2fd634fcfcebb83a4d92cf41d69f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Sep 30 09:06:51 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 30 13:13:31 2022 +0200

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

diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx
index 1b50c94494fb..29e8f344b4a7 100644
--- a/stoc/source/typeconv/convert.cxx
+++ b/stoc/source/typeconv/convert.cxx
@@ -21,6 +21,7 @@
 
 #include <o3tl/any.hxx>
 #include <o3tl/safeint.hxx>
+#include <o3tl/string_view.hxx>
 #include <osl/diagnose.h>
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/supportsservice.hxx>
@@ -63,26 +64,26 @@ static double round( double aVal )
 }
 
 
-static bool getNumericValue( double & rfVal, const OUString & rStr )
+static bool getNumericValue( double & rfVal, std::u16string_view rStr )
 {
-    double fRet = rStr.toDouble();
+    double fRet = o3tl::toDouble(rStr);
     if (fRet == 0.0)
     {
-        sal_Int32 nLen = rStr.getLength();
+        size_t nLen = rStr.size();
         if (!nLen || (nLen == 1 && rStr[0] == '0')) // common case
         {
             rfVal = 0.0;
             return true;
         }
 
-        OUString trim( rStr.trim() );
+        std::u16string_view trim( o3tl::trim(rStr) );
 
         // try hex
-        sal_Int32 nX = trim.indexOf( 'x' );
-        if (nX < 0)
-            nX = trim.indexOf( 'X' );
+        size_t nX = trim.find( 'x' );
+        if (nX == std::u16string_view::npos)
+            nX = trim.find( 'X' );
 
-        if (nX > 0 && trim[nX-1] == '0') // 0x
+        if (nX > 0 && nX != std::u16string_view::npos && trim[nX-1] == '0') // 
0x
         {
             bool bNeg = false;
             switch (nX)
@@ -99,7 +100,7 @@ static bool getNumericValue( double & rfVal, const OUString 
& rStr )
                 return false;
             }
 
-            OUString aHexRest( trim.copy( nX+1 ) );
+            OUString aHexRest( trim.substr( nX+1 ) );
             sal_uInt64 nRet = aHexRest.toUInt64( 16 );
 
             if (nRet == 0)
@@ -115,8 +116,8 @@ static bool getNumericValue( double & rfVal, const OUString 
& rStr )
             return true;
         }
 
-        nLen = trim.getLength();
-        sal_Int32 nPos = 0;
+        nLen = trim.size();
+        size_t nPos = 0;
 
         // skip +/-
         if (nLen && (trim[0] == '-' || trim[0] == '+'))
@@ -145,23 +146,23 @@ static bool getNumericValue( double & rfVal, const 
OUString & rStr )
 }
 
 
-static bool getHyperValue( sal_Int64 & rnVal, const OUString & rStr )
+static bool getHyperValue( sal_Int64 & rnVal, std::u16string_view rStr )
 {
-    sal_Int32 nLen = rStr.getLength();
+    size_t nLen = rStr.size();
     if (!nLen || (nLen == 1 && rStr[0] == '0')) // common case
     {
         rnVal = 0;
         return true;
     }
 
-    OUString trim( rStr.trim() );
+    std::u16string_view trim( o3tl::trim(rStr) );
 
     // try hex
-    sal_Int32 nX = trim.indexOf( 'x' );
-    if (nX < 0)
-        nX = trim.indexOf( 'X' );
+    size_t nX = trim.find( 'x' );
+    if (nX == std::u16string_view::npos)
+        nX = trim.find( 'X' );
 
-    if (nX >= 0)
+    if (nX != std::u16string_view::npos)
     {
         if (nX > 0 && trim[nX-1] == '0') // 0x
         {
@@ -180,7 +181,7 @@ static bool getHyperValue( sal_Int64 & rnVal, const 
OUString & rStr )
                 return false;
             }
 
-            OUString aHexRest( trim.copy( nX+1 ) );
+            OUString aHexRest( trim.substr( nX+1 ) );
             sal_uInt64 nRet = aHexRest.toUInt64( 16 );
 
             if (nRet == 0)
diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx 
b/stoc/source/uriproc/UriReferenceFactory.cxx
index ed739cdc32cf..aa6da45197de 100644
--- a/stoc/source/uriproc/UriReferenceFactory.cxx
+++ b/stoc/source/uriproc/UriReferenceFactory.cxx
@@ -167,10 +167,10 @@ private:
 };
 
 css::uno::Reference< css::uri::XUriReference > parseGeneric(
-    OUString const & scheme, OUString const & schemeSpecificPart)
+    OUString const & scheme, std::u16string_view schemeSpecificPart)
 {
-    sal_Int32 len = schemeSpecificPart.getLength();
-    sal_Int32 i = 0;
+    size_t len = schemeSpecificPart.size();
+    size_t i = 0;
     bool hasAuthority = false;
     OUString authority;
     if (len - i >= 2 && schemeSpecificPart[i] == '/'
@@ -183,22 +183,22 @@ css::uno::Reference< css::uri::XUriReference > 
parseGeneric(
             ++i;
         }
         hasAuthority = true;
-        authority = schemeSpecificPart.copy(n, i - n);
+        authority = schemeSpecificPart.substr(n, i - n);
     }
     sal_Int32 n = i;
-    i = schemeSpecificPart.indexOf('?', i);
-    if (i == -1) {
+    i = schemeSpecificPart.find('?', i);
+    if (i == std::u16string_view::npos) {
         i = len;
     }
-    OUString path = schemeSpecificPart.copy(n, i - n);
+    std::u16string_view path = schemeSpecificPart.substr(n, i - n);
     bool hasQuery = false;
     OUString query;
     if (i != len) {
         hasQuery = true;
-        query = schemeSpecificPart.copy(i + 1);
+        query = schemeSpecificPart.substr(i + 1);
     }
     return new UriReference(
-        scheme, hasAuthority, authority, path, hasQuery, query);
+        scheme, hasAuthority, authority, OUString(path), hasQuery, query);
 }
 
 struct Segment {

Reply via email to