aboutsummaryrefslogtreecommitdiff
path: root/src/SFileFindFile.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <ladislav.zezula@avg.com>2015-04-27 10:53:25 +0200
committerLadislav Zezula <ladislav.zezula@avg.com>2015-04-27 10:53:25 +0200
commita205159d004871efbedd7cbfb686b8fe82bfb532 (patch)
treeb8eb404dd2a2b86948383f16526b42662b2f8337 /src/SFileFindFile.cpp
parentc538757a38df05a60f306fe8b193c4bc38f78a7b (diff)
+ Better algorithm of checking wildcards
Diffstat (limited to 'src/SFileFindFile.cpp')
-rw-r--r--src/SFileFindFile.cpp93
1 files changed, 30 insertions, 63 deletions
diff --git a/src/SFileFindFile.cpp b/src/SFileFindFile.cpp
index 0f7bd39..fb71871 100644
--- a/src/SFileFindFile.cpp
+++ b/src/SFileFindFile.cpp
@@ -49,88 +49,55 @@ static TMPQSearch * IsValidSearchHandle(HANDLE hFind)
bool CheckWildCard(const char * szString, const char * szWildCard)
{
- const char * szSubString;
- int nSubStringLength;
- int nMatchCount = 0;
+ const char * szWildCardPtr;
- // When the mask is empty, it never matches
- if(szWildCard == NULL || *szWildCard == 0)
- return false;
-
- // If the wildcard contains just "*", then it always matches
- if(szWildCard[0] == '*' && szWildCard[1] == 0)
- return true;
-
- // Do normal test
for(;;)
{
// If there is '?' in the wildcard, we skip one char
- while(*szWildCard == '?')
+ while(szWildCard[0] == '?')
{
+ if(szString[0] == 0)
+ return false;
+
szWildCard++;
szString++;
}
- // If there is '*', means zero or more chars. We have to
- // find the sequence after '*'
- if(*szWildCard == '*')
+ // Handle '*'
+ szWildCardPtr = szWildCard;
+ if(szWildCardPtr[0] != 0)
{
- // More stars is equal to one star
- while(*szWildCard == '*' || *szWildCard == '?')
- szWildCard++;
-
- // If we found end of the wildcard, it's a match
- if(*szWildCard == 0)
- return true;
+ if(szWildCardPtr[0] == '*')
+ {
+ szWildCardPtr++;
- // Determine the length of the substring in szWildCard
- szSubString = szWildCard;
- while(*szSubString != 0 && *szSubString != '?' && *szSubString != '*')
- szSubString++;
- nSubStringLength = (int)(szSubString - szWildCard);
- nMatchCount = 0;
+ if(szWildCardPtr[0] == '*')
+ continue;
- // Now we have to find a substring in szString,
- // that matches the substring in szWildCard
- while(*szString != 0)
- {
- // Calculate match count
- while(nMatchCount < nSubStringLength)
- {
- if(AsciiToUpperTable[(BYTE)szString[nMatchCount]] != AsciiToUpperTable[(BYTE)szWildCard[nMatchCount]])
- break;
- if(szString[nMatchCount] == 0)
- break;
- nMatchCount++;
- }
+ if(szWildCardPtr[0] == 0)
+ return true;
- // If the match count has reached substring length, we found a match
- if(nMatchCount == nSubStringLength)
+ if(AsciiToUpperTable[szWildCardPtr[0]] == AsciiToUpperTable[szString[0]])
{
- szWildCard += nMatchCount;
- szString += nMatchCount;
- break;
+ if(CheckWildCard(szString, szWildCardPtr))
+ return true;
}
-
- // No match, move to the next char in szString
- nMatchCount = 0;
- szString++;
}
- }
- else
- {
- // If we came to the end of the string, compare it to the wildcard
- if(AsciiToUpperTable[(BYTE)*szString] != AsciiToUpperTable[(BYTE)*szWildCard])
- return false;
+ else
+ {
+ if(AsciiToUpperTable[szWildCardPtr[0]] != AsciiToUpperTable[szString[0]])
+ return false;
- // If we arrived to the end of the string, it's a match
- if(*szString == 0)
- return true;
+ szWildCard = szWildCardPtr + 1;
+ }
- // Otherwise, continue in comparing
- szWildCard++;
- szString++;
+ if(szString[0] == 0)
+ return false;
}
+
+ if(szString[0] == 0)
+ return true;
+ szString++;
}
}