forked from CobaltFusion/DebugViewPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchType.cpp
More file actions
152 lines (135 loc) · 3.1 KB
/
Copy pathMatchType.cpp
File metadata and controls
152 lines (135 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cassert>
#include <stdexcept>
#include "DebugViewppLib/MatchType.h"
namespace fusion {
namespace debugviewpp {
bool IsSpecialRegexCharacter(char c)
{
switch (c)
{
case '^':
case '$':
case '\\':
case '.':
case '*':
case '+':
case '?':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '|': return true;
default: return false;
}
}
std::string MakeSimplePattern(const std::string& text)
{
std::string pattern;
for (auto c : text)
{
if (IsSpecialRegexCharacter(c))
{
pattern += '\\';
}
pattern += c;
}
return pattern;
}
std::string MakeWildcardPattern(const std::string& text)
{
std::string pattern;
for (auto c : text)
{
switch (c)
{
case '?': pattern += ".?"; break;
case '*': pattern += ".*"; break;
default:
if (IsSpecialRegexCharacter(c))
{
pattern += '\\';
}
pattern += c;
break;
}
}
return pattern;
}
std::string MakePattern(MatchType::type type, const std::string& text)
{
switch (type)
{
case MatchType::Simple: return MakeSimplePattern(text);
case MatchType::Wildcard: return MakeWildcardPattern(text);
case MatchType::Regex:
case MatchType::RegexGroups:
case MatchType::RegexCase: return text;
default: assert("Unexpected MatchType"); break;
}
return text;
}
int MatchTypeToInt(MatchType::type value)
{
#define MATCH_TYPE(f, id) \
case MatchType::f: return id;
switch (value)
{
MATCH_TYPES()
default: assert(!"Unexpected MatchType"); break;
}
#undef MATCH_TYPE
throw std::invalid_argument("bad MatchType!");
}
MatchType::type IntToMatchType(int value)
{
#define MATCH_TYPE(f, id) \
case id: return MatchType::f;
switch (value)
{
MATCH_TYPES()
default: assert(!"Unexpected MatchType"); break;
}
#undef MATCH_TYPE
throw std::invalid_argument("bad MatchType!");
}
std::string MatchTypeToString(MatchType::type value)
{
#define MATCH_TYPE(f, id) \
case MatchType::f: return #f;
switch (value)
{
MATCH_TYPES()
default: assert(!"Unexpected MatchType"); break;
}
#undef MATCH_TYPE
throw std::invalid_argument("bad MatchType!");
}
const wchar_t* EnumToWCharPtr(MatchType::type value)
{
#define MATCH_TYPE(f, id) \
case MatchType::f: return L## #f;
switch (value)
{
MATCH_TYPES()
default: assert(!"Unexpected MatchType"); break;
}
#undef MATCH_TYPE
throw std::invalid_argument("bad MatchType!");
}
MatchType::type StringToMatchType(const std::string& s)
{
#define MATCH_TYPE(f, id) \
if (s == #f) \
return MatchType::f;
MATCH_TYPES()
#undef MATCH_TYPE
throw std::invalid_argument("bad MatchType!");
}
} // namespace debugviewpp
} // namespace fusion