simplify and improve Wildcard

it is faster to just process OUString data, rather than perform
expensive conversion to OString and back again.

Change-Id: Ie007b872ee507ac5c6e8b55cc0a49ef3ac1f0139
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117608
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2021-06-21 13:00:07 +02:00
committed by Noel Grandin
parent 949658028e
commit 990b2cb056
2 changed files with 9 additions and 10 deletions

View File

@@ -30,10 +30,10 @@
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC WildCard class SAL_WARN_UNUSED TOOLS_DLLPUBLIC WildCard
{ {
private: private:
OString aWildString; OUString aWildString;
char cSepSymbol; char cSepSymbol;
static bool ImpMatch( const char *pWild, const char *pStr ); static bool ImpMatch( const sal_Unicode *pWild, const sal_Unicode *pStr );
public: public:
WildCard() WildCard()
@@ -43,19 +43,19 @@ public:
} }
WildCard(std::u16string_view rWildCard, const char cSeparator = '\0') WildCard(std::u16string_view rWildCard, const char cSeparator = '\0')
: aWildString(OUStringToOString(rWildCard, osl_getThreadTextEncoding())) : aWildString(rWildCard)
, cSepSymbol(cSeparator) , cSepSymbol(cSeparator)
{ {
} }
OUString getGlob() const OUString getGlob() const
{ {
return OStringToOUString(aWildString, osl_getThreadTextEncoding()); return aWildString;
} }
void setGlob(std::u16string_view rString) void setGlob(std::u16string_view rString)
{ {
aWildString = OUStringToOString(rString, osl_getThreadTextEncoding()); aWildString = rString;
} }
bool Matches( std::u16string_view rStr ) const; bool Matches( std::u16string_view rStr ) const;

View File

@@ -25,7 +25,7 @@
* '?' in pWild mean match exactly one character. * '?' in pWild mean match exactly one character.
* *
*/ */
bool WildCard::ImpMatch( const char *pWild, const char *pStr ) bool WildCard::ImpMatch( const sal_Unicode *pWild, const sal_Unicode *pStr )
{ {
int pos=0; int pos=0;
int flag=0; int flag=0;
@@ -88,8 +88,7 @@ bool WildCard::ImpMatch( const char *pWild, const char *pStr )
bool WildCard::Matches( std::u16string_view rString ) const bool WildCard::Matches( std::u16string_view rString ) const
{ {
OString aTmpWild = aWildString; OUString aTmpWild = aWildString;
OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
sal_Int32 nSepPos; sal_Int32 nSepPos;
@@ -98,13 +97,13 @@ bool WildCard::Matches( std::u16string_view rString ) const
while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 ) while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
{ {
// Check all split wildcards // Check all split wildcards
if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) ) if ( ImpMatch( aTmpWild.subView( 0, nSepPos ).data(), rString.data() ) )
return true; return true;
aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
} }
} }
return ImpMatch( aTmpWild.getStr(), aString.getStr() ); return ImpMatch( aTmpWild.getStr(), rString.data() );
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */