| |
|
1 |
|
| |
|
2 |
|
| |
|
3 |
|
| |
|
4 |
|
| |
|
5 |
|
| |
|
6 |
|
| |
|
7 |
|
| |
|
8 |
|
| |
|
9 |
|
| |
|
10 |
|
| |
|
11 |
|
| |
|
12 |
|
| |
|
13 |
|
| |
|
14 |
|
| |
|
15 |
|
| |
|
16 |
|
| |
|
17 |
|
| |
|
18 |
|
| |
1 |
19 |
#include "stdafx.h" |
| |
2 |
20 |
#include "TStringPattern.h" |
| |
3 |
21 |
#include <tchar.h> |
| |
4 |
22 |
|
| |
5 |
23 |
using namespace string; |
| |
6 |
24 |
|
| |
7 |
25 |
namespace chcore |
| |
8 |
26 |
{ |
| |
9 |
27 |
namespace |
| |
10 |
28 |
{ |
| |
11 |
29 |
bool _tcicmp(TCHAR c1, TCHAR c2) |
| |
12 |
30 |
{ |
| |
13 |
31 |
TCHAR ch1[2] = { c1, 0 }, ch2[2] = { c2, 0 }; |
| |
14 |
32 |
return (_tcsicmp(ch1, ch2) == 0); |
| |
15 |
33 |
} |
| |
16 |
34 |
} |
| |
17 |
35 |
|
| |
18 |
36 |
TStringPattern::TStringPattern(EPatternType ePatternType) : |
| |
19 |
37 |
m_ePatternType(ePatternType) |
| |
20 |
38 |
{ |
|
| |
112 |
130 |
return true; |
| |
113 |
131 |
|
| |
114 |
132 |
LPCTSTR wdsCopy = lpszMask; |
| |
115 |
133 |
LPCTSTR lpszStringCopy = lpszString; |
| |
116 |
134 |
bool bMatch = true; |
| |
117 |
135 |
do |
| |
118 |
136 |
{ |
| |
119 |
137 |
if (!MatchMask(lpszMask, lpszString)) lpszStringCopy++; |
| |
120 |
138 |
lpszMask = wdsCopy; |
| |
121 |
139 |
lpszString = lpszStringCopy; |
| |
122 |
140 |
while (!(_tcicmp(*lpszMask, *lpszString)) && (*lpszString != '\0')) lpszString++; |
| |
123 |
141 |
wdsCopy = lpszMask; |
| |
124 |
142 |
lpszStringCopy = lpszString; |
| |
125 |
143 |
} while ((*lpszString != _T('\0')) ? !MatchMask(lpszMask, lpszString) : (bMatch = false) != false); |
| |
126 |
144 |
|
| |
127 |
145 |
if (*lpszString == _T('\0') && *lpszMask == _T('\0')) return true; |
| |
128 |
146 |
|
| |
129 |
147 |
return bMatch; |
| |
130 |
148 |
} |
| |
131 |
149 |
|
| |
132 |
|
bool TStringPattern::Matches(const TString& strTextToMatch) const |
| |
|
150 |
bool TStringPattern::Matches(const TSmartPath& pathToMatch) const |
| |
133 |
151 |
{ |
| |
134 |
|
return MatchMask(m_strPattern.c_str(), strTextToMatch.c_str()); |
| |
|
152 |
switch(m_ePatternType) |
| |
|
153 |
{ |
| |
|
154 |
case EPatternType::eType_Wildcard: |
| |
|
155 |
return MatchMask(m_strPattern.c_str(), pathToMatch.GetFileName().ToString()); |
| |
|
156 |
default: |
| |
|
157 |
throw std::invalid_argument("Unsupported pattern type"); |
| |
135 |
158 |
} |
| |
|
159 |
} |
| |
136 |
160 |
|
| |
137 |
161 |
void TStringPattern::SetPattern(const TString& strPattern, EPatternType ePatternType) |
| |
138 |
162 |
{ |
| |
139 |
163 |
m_ePatternType = ePatternType; |
| |
140 |
164 |
m_strPattern = strPattern; |
| |
141 |
165 |
} |
| |
142 |
166 |
} |