| |
1 |
1 |
#include "stdafx.h" |
| |
2 |
2 |
#include "TStringPattern.h" |
| |
3 |
3 |
#include <tchar.h> |
| |
4 |
|
#include "TStringException.h" |
| |
5 |
4 |
|
| |
6 |
|
namespace string |
| |
|
5 |
using namespace string; |
| |
|
6 |
|
| |
|
7 |
namespace chcore |
| |
7 |
8 |
{ |
| |
8 |
9 |
namespace |
| |
9 |
10 |
{ |
| |
10 |
11 |
bool _tcicmp(TCHAR c1, TCHAR c2) |
| |
11 |
12 |
{ |
| |
12 |
13 |
TCHAR ch1[2] = { c1, 0 }, ch2[2] = { c2, 0 }; |
| |
13 |
14 |
return (_tcsicmp(ch1, ch2) == 0); |
| |
14 |
15 |
} |
| |
15 |
16 |
} |
| |
16 |
17 |
|
| |
17 |
18 |
TStringPattern::TStringPattern(EPatternType ePatternType) : |
| |
18 |
19 |
m_ePatternType(ePatternType) |
| |
19 |
20 |
{ |
| |
20 |
21 |
} |
| |
21 |
22 |
|
| |
22 |
23 |
TStringPattern::TStringPattern(const TString& strPattern, EPatternType ePatternType) : |
| |
23 |
24 |
m_strPattern(strPattern), |
| |
24 |
25 |
m_ePatternType(ePatternType) |
| |
25 |
26 |
{ |
| |
26 |
27 |
} |
|
| |
36 |
37 |
{ |
| |
37 |
38 |
m_ePatternType = eDefaultPatternType; |
| |
38 |
39 |
if (strPattern.StartsWith(L"WC;")) |
| |
39 |
40 |
{ |
| |
40 |
41 |
m_strPattern = strPattern.Mid(3); |
| |
41 |
42 |
m_ePatternType = EPatternType::eType_Wildcard; |
| |
42 |
43 |
} |
| |
43 |
44 |
else |
| |
44 |
45 |
m_strPattern = strPattern; |
| |
45 |
46 |
} |
| |
46 |
47 |
|
| |
47 |
48 |
TString TStringPattern::ToString() const |
| |
48 |
49 |
{ |
| |
49 |
50 |
TString strPrefix; |
| |
50 |
51 |
switch (m_ePatternType) |
| |
51 |
52 |
{ |
| |
52 |
53 |
case EPatternType::eType_Wildcard: |
| |
53 |
54 |
break; |
| |
54 |
55 |
|
| |
55 |
56 |
default: |
| |
56 |
|
throw TStringException("Pattern type not supported"); |
| |
|
57 |
throw std::invalid_argument("Pattern type not supported"); |
| |
57 |
58 |
} |
| |
58 |
59 |
|
| |
59 |
60 |
return TString(strPrefix + m_strPattern); |
| |
60 |
61 |
} |
| |
61 |
62 |
|
| |
62 |
63 |
bool TStringPattern::operator!=(const TStringPattern& rSrc) const |
| |
63 |
64 |
{ |
| |
64 |
65 |
return m_ePatternType != rSrc.m_ePatternType || m_strPattern != rSrc.m_strPattern; |
| |
65 |
66 |
} |
| |
66 |
67 |
|
| |
67 |
68 |
bool TStringPattern::operator==(const TStringPattern& rSrc) const |
| |
68 |
69 |
{ |
| |
69 |
70 |
return m_ePatternType == rSrc.m_ePatternType && m_strPattern == rSrc.m_strPattern; |
| |
70 |
71 |
} |
| |
71 |
72 |
|
| |
72 |
73 |
bool TStringPattern::MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const |
| |
73 |
74 |
{ |
| |
74 |
75 |
bool bMatch = true; |
| |
75 |
76 |
|
| |
76 |
77 |
|