filter/source/config/cache/filtercache.cxx |    2 -
 filter/source/config/cache/filtercache.hxx |    2 -
 include/unotools/configpaths.hxx           |    2 -
 unotools/source/config/configpaths.cxx     |   41 +++++++++++++++--------------
 4 files changed, 25 insertions(+), 22 deletions(-)

New commits:
commit 5edefc801fb48559c8064003f23d22d838710ee4
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Sep 20 11:37:12 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Sep 20 14:31:24 2022 +0200

    use more string_view in unotools
    
    Change-Id: Iaf91f9c63a0a666250e92a5ba7bebdb06dffb258
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140233
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/filter/source/config/cache/filtercache.cxx 
b/filter/source/config/cache/filtercache.cxx
index 9da457627261..5a2a59875953 100644
--- a/filter/source/config/cache/filtercache.cxx
+++ b/filter/source/config/cache/filtercache.cxx
@@ -840,7 +840,7 @@ css::uno::Reference< css::uno::XInterface > 
FilterCache::impl_openConfig(EConfig
     return *pConfig;
 }
 
-css::uno::Any FilterCache::impl_getDirectCFGValue(const OUString& sDirectKey)
+css::uno::Any FilterCache::impl_getDirectCFGValue(std::u16string_view 
sDirectKey)
 {
     OUString sRoot;
     OUString sKey ;
diff --git a/filter/source/config/cache/filtercache.hxx 
b/filter/source/config/cache/filtercache.hxx
index 2f647c33e708..635ad29a6514 100644
--- a/filter/source/config/cache/filtercache.hxx
+++ b/filter/source/config/cache/filtercache.hxx
@@ -664,7 +664,7 @@ class FilterCache : public cppu::BaseMutex
                         Can be empty if an internal error occurred or if the 
requested
                         key does not exists!
          */
-        css::uno::Any impl_getDirectCFGValue(const OUString& sDirectKey);
+        css::uno::Any impl_getDirectCFGValue(std::u16string_view sDirectKey);
 
 
         /** @short      load the underlying configuration into this cache.
diff --git a/include/unotools/configpaths.hxx b/include/unotools/configpaths.hxx
index 119733a477dc..3e8ef3c9aadc 100644
--- a/include/unotools/configpaths.hxx
+++ b/include/unotools/configpaths.hxx
@@ -51,7 +51,7 @@ namespace utl
             <FALSE/>, if the path was a one-level path or an invalid path
 
     */
-    UNOTOOLS_DLLPUBLIC bool splitLastFromConfigurationPath(OUString const& 
_sInPath,
+    UNOTOOLS_DLLPUBLIC bool splitLastFromConfigurationPath(std::u16string_view 
_sInPath,
                                             OUString& _rsOutPath,
                                             OUString& _rsLocalName);
 
diff --git a/unotools/source/config/configpaths.cxx 
b/unotools/source/config/configpaths.cxx
index 8efdf19b5519..1b3518c39f7a 100644
--- a/unotools/source/config/configpaths.cxx
+++ b/unotools/source/config/configpaths.cxx
@@ -72,72 +72,75 @@ void lcl_resolveCharEntities(OUString & aLocalString)
     aLocalString = aResult.makeStringAndClear();
 }
 
-bool splitLastFromConfigurationPath(OUString const& _sInPath,
+bool splitLastFromConfigurationPath(std::u16string_view _sInPath,
                                         OUString& _rsOutPath,
                                         OUString& _rsLocalName)
 {
-    sal_Int32 nStart,nEnd;
+    size_t nStart,nEnd;
 
-    sal_Int32 nPos = _sInPath.getLength()-1;
+    size_t nPos = _sInPath.size()-1;
 
     // strip trailing slash
-    if (nPos > 0 && _sInPath[ nPos ] == '/')
+    if (nPos != std::u16string_view::npos && _sInPath[ nPos ] == '/')
     {
         OSL_FAIL("Invalid config path: trailing '/' is not allowed");
         --nPos;
     }
 
     // check for predicate ['xxx'] or ["yyy"]
-    if (nPos  > 0 && _sInPath[ nPos ] == ']')
+    if (nPos != std::u16string_view::npos && _sInPath[ nPos ] == ']')
     {
         sal_Unicode chQuote = _sInPath[--nPos];
 
         if (chQuote == '\'' || chQuote == '\"')
         {
             nEnd = nPos;
-            nPos = _sInPath.lastIndexOf(chQuote,nEnd);
+            nPos = _sInPath.find(chQuote,nEnd);
             nStart = nPos + 1;
             --nPos; // nPos = rInPath.lastIndexOf('[',nPos);
         }
         else // allow [xxx]
         {
             nEnd = nPos + 1;
-            nPos = _sInPath.lastIndexOf('[',nEnd);
+            nPos = _sInPath.rfind('[',nEnd);
             nStart = nPos + 1;
         }
 
-        OSL_ENSURE(nPos >= 0 && _sInPath[nPos] == '[', "Invalid config path: 
unmatched quotes or brackets");
-        if (nPos >= 0 && _sInPath[nPos] == '[')
+        OSL_ENSURE(nPos != std::u16string_view::npos && _sInPath[nPos] == '[', 
"Invalid config path: unmatched quotes or brackets");
+        if (nPos != std::u16string_view::npos && _sInPath[nPos] == '[')
         {
-            nPos =  _sInPath.lastIndexOf('/',nPos);
+            nPos =  _sInPath.rfind('/',nPos);
         }
         else // defined behavior for invalid paths
         {
             nStart = 0;
-            nEnd = _sInPath.getLength();
-            nPos = -1;
+            nEnd = _sInPath.size();
+            nPos = std::u16string_view::npos;
         }
 
     }
     else
     {
         nEnd = nPos+1;
-        nPos = _sInPath.lastIndexOf('/',nEnd);
+        nPos = _sInPath.rfind('/',nEnd);
         nStart = nPos + 1;
     }
-    OSL_ASSERT( -1 <= nPos &&
+    OSL_ASSERT( nPos != std::u16string_view::npos &&
                 nPos < nStart &&
                 nStart < nEnd &&
-                nEnd <= _sInPath.getLength() );
+                nEnd <= _sInPath.size() );
 
-    OSL_ASSERT(nPos == -1 || _sInPath[nPos] == '/');
+    OSL_ASSERT(nPos == std::u16string_view::npos || _sInPath[nPos] == '/');
     OSL_ENSURE(nPos != 0 , "Invalid config child path: immediate child of 
root");
 
-    _rsLocalName = _sInPath.copy(nStart, nEnd-nStart);
-    _rsOutPath = (nPos > 0) ? _sInPath.copy(0,nPos) : OUString();
+    _rsLocalName = _sInPath.substr(nStart, nEnd-nStart);
+    if (nPos > 0 && nPos != std::u16string_view::npos)
+        _rsOutPath = _sInPath.substr(0,nPos);
+    else
+        _rsOutPath.clear();
     lcl_resolveCharEntities(_rsLocalName);
 
-    return nPos >= 0;
+    return nPos != std::u16string_view::npos;
 }
 
 OUString extractFirstFromConfigurationPath(OUString const& _sInPath, OUString* 
_sOutPath)

Reply via email to