From 8cdce6fa83802c83474a29443b285feee4838ab6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 11 Mar 2022 19:18:25 +0200 Subject: tdf#147921 Filesave DOC: wrong layout and then all missing from 7.3 regression from commit 990b2cb056788f7f412656a303456d90c003cf83 Author: Noel Grandin 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 (cherry picked from commit a378ac93e1b4e3c0dacdd3f0a3500813714537c7) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131595 Reviewed-by: Michael Stahl --- tools/source/fsys/wldcrd.cxx | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'tools/source') 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: */ -- cgit