include/tools/wldcrd.hxx     |    2 +-
 tools/source/fsys/wldcrd.cxx |   38 +++++++++++++++++++++-----------------
 2 files changed, 22 insertions(+), 18 deletions(-)

New commits:
commit a378ac93e1b4e3c0dacdd3f0a3500813714537c7
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Mar 11 19:18:25 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Mar 12 08:41:25 2022 +0100

    tdf#147921 Filesave DOC: wrong layout and then all missing from 7.3
    
    regression from
        commit 990b2cb056788f7f412656a303456d90c003cf83
        Author: Noel Grandin <n...@peralex.com>
        Date:   Mon Jun 21 13:00:07 2021 +0200
        simplify and improve Wildcard
    
    Cannot pass a string_view into something expecting a char* because
    then it gets the length wrong.
    
    Change-Id: I638660a1e9a8a0d17e4d2f77500b3f01365a43d3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131396
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/tools/wldcrd.hxx b/include/tools/wldcrd.hxx
index fdbefcc4d2ea..5c18ad20fc68 100644
--- a/include/tools/wldcrd.hxx
+++ b/include/tools/wldcrd.hxx
@@ -32,7 +32,7 @@ private:
     OUString aWildString;
     char cSepSymbol;
 
-    static bool ImpMatch( const sal_Unicode *pWild, const sal_Unicode *pStr );
+    static bool ImpMatch( std::u16string_view aWild, std::u16string_view aStr 
);
 
 public:
     WildCard()
diff --git a/tools/source/fsys/wldcrd.cxx b/tools/source/fsys/wldcrd.cxx
index 6e0259696aca..a9867c00ba51 100644
--- a/tools/source/fsys/wldcrd.cxx
+++ b/tools/source/fsys/wldcrd.cxx
@@ -25,22 +25,26 @@
  * '?' in pWild mean match exactly one character.
  *
  */
-bool WildCard::ImpMatch( const sal_Unicode *pWild, const sal_Unicode *pStr )
+bool WildCard::ImpMatch( std::u16string_view aWild, std::u16string_view aStr )
 {
     int    pos=0;
     int    flag=0;
+    const sal_Unicode* pWild = aWild.data();
+    const sal_Unicode* pWildEnd = aWild.data() + aWild.size();
+    const sal_Unicode* pStr = aStr.data();
+    const sal_Unicode* pStrEnd = aStr.data() + aStr.size();
 
-    while ( *pWild || flag )
+    while ( pWild != pWildEnd || flag )
     {
         switch (*pWild)
         {
             case '?':
-                if ( *pStr == '\0' )
+                if ( pStr == pStrEnd )
                     return false;
                 break;
 
             default:
-                if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == 
'*')) )
+                if ( (*pWild == '\\') && (pWild + 1 != pWildEnd) && 
((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
                     pWild++;
                 if ( *pWild != *pStr )
                     if ( !pos )
@@ -53,37 +57,37 @@ bool WildCard::ImpMatch( const sal_Unicode *pWild, const 
sal_Unicode *pStr )
                 // circumstances!
                 [[fallthrough]];
             case '*':
-                while ( *pWild == '*' )
+                while ( pWild != pWildEnd && *pWild == '*' )
                     pWild++;
-                if ( *pWild == '\0' )
+                if ( pWild == pWildEnd )
                     return true;
                 flag = 1;
                 pos  = 0;
-                if ( *pStr == '\0' )
-                    return ( *pWild == '\0' );
-                while ( *pStr && *pStr != *pWild )
+                if ( pStr == pStrEnd )
+                    return false;
+                while ( pStr != pStrEnd && *pStr != *pWild )
                 {
                     if ( *pWild == '?' ) {
                         pWild++;
-                        while ( *pWild == '*' )
+                        while ( pWild != pWildEnd && *pWild == '*' )
                             pWild++;
                     }
                     pStr++;
-                    if ( *pStr == '\0' )
-                        return ( *pWild == '\0' );
+                    if ( pStr == pStrEnd )
+                        return pWild == pWildEnd;
                 }
                 break;
         }
-        if ( *pWild != '\0' )
+        if ( pWild != pWildEnd )
             pWild++;
-        if ( *pStr != '\0' )
+        if ( pStr != pStrEnd )
             pStr++;
         else
             flag = 0;
         if ( flag )
             pos--;
     }
-    return ( *pStr == '\0' ) && ( *pWild == '\0' );
+    return ( pStr == pStrEnd ) && ( pWild == pWildEnd );
 }
 
 bool WildCard::Matches( std::u16string_view rString ) const
@@ -97,13 +101,13 @@ bool WildCard::Matches( std::u16string_view rString ) const
         while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
         {
             // Check all split wildcards
-            if ( ImpMatch( aTmpWild.subView( 0, nSepPos ).data(), 
rString.data() ) )
+            if ( ImpMatch( aTmpWild.subView( 0, nSepPos ), rString ) )
                 return true;
             aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
         }
     }
 
-    return ImpMatch( aTmpWild.getStr(), rString.data() );
+    return ImpMatch( aTmpWild, rString );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to