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:
parent
949658028e
commit
990b2cb056
@ -30,10 +30,10 @@
|
||||
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC WildCard
|
||||
{
|
||||
private:
|
||||
OString aWildString;
|
||||
OUString aWildString;
|
||||
char cSepSymbol;
|
||||
|
||||
static bool ImpMatch( const char *pWild, const char *pStr );
|
||||
static bool ImpMatch( const sal_Unicode *pWild, const sal_Unicode *pStr );
|
||||
|
||||
public:
|
||||
WildCard()
|
||||
@ -43,19 +43,19 @@ public:
|
||||
}
|
||||
|
||||
WildCard(std::u16string_view rWildCard, const char cSeparator = '\0')
|
||||
: aWildString(OUStringToOString(rWildCard, osl_getThreadTextEncoding()))
|
||||
: aWildString(rWildCard)
|
||||
, cSepSymbol(cSeparator)
|
||||
{
|
||||
}
|
||||
|
||||
OUString getGlob() const
|
||||
{
|
||||
return OStringToOUString(aWildString, osl_getThreadTextEncoding());
|
||||
return aWildString;
|
||||
}
|
||||
|
||||
void setGlob(std::u16string_view rString)
|
||||
{
|
||||
aWildString = OUStringToOString(rString, osl_getThreadTextEncoding());
|
||||
aWildString = rString;
|
||||
}
|
||||
|
||||
bool Matches( std::u16string_view rStr ) const;
|
||||
|
@ -25,7 +25,7 @@
|
||||
* '?' 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 flag=0;
|
||||
@ -88,8 +88,7 @@ bool WildCard::ImpMatch( const char *pWild, const char *pStr )
|
||||
|
||||
bool WildCard::Matches( std::u16string_view rString ) const
|
||||
{
|
||||
OString aTmpWild = aWildString;
|
||||
OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
|
||||
OUString aTmpWild = aWildString;
|
||||
|
||||
sal_Int32 nSepPos;
|
||||
|
||||
@ -98,13 +97,13 @@ bool WildCard::Matches( std::u16string_view rString ) const
|
||||
while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
|
||||
{
|
||||
// Check all split wildcards
|
||||
if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) )
|
||||
if ( ImpMatch( aTmpWild.subView( 0, nSepPos ).data(), rString.data() ) )
|
||||
return true;
|
||||
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: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user