Debian Codegraph @

Frameworks/OpenVanilla/Headers/OVWildcard.h

raw symbols SCIP
1 //cxx . . $ `<file>/Frameworks/OpenVanilla/Headers/OVWildcard.h`/
2 // OVWildcard.h
3 //
4 // Copyright (c) 2004-2008 The OpenVanilla Project (http://openvanilla.org)
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // 1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // 3. Neither the name of OpenVanilla nor the names of its contributors
17 // may be used to endorse or promote products derived from this software
18 // without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 // POSSIBILITY OF SUCH DAMAGE.
31
32 #ifndef OVWildcard_h
33 #define OVWildcard_hcxx . . $ `Frameworks/OpenVanilla/Headers/OVWildcard.h:33:9`!
34
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 #include <cctype>
39
40 namespace OpenVanillacxx . . $ OpenVanilla/ {
41 using namespace std;
42
43 class OVWildcardcxx . . $ OpenVanilla/OVWildcard# {
44 public:
45 OVWildcardcxx . . $ OpenVanilla/OVWildcard#OVWildcard(6e6b56654adc35c2).(const stringcxx . . $ std/string#& expression, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false)
46 : m_caseSensitivecxx . . $ OpenVanilla/OVWildcard#m_caseSensitive.(caseSensitive)
47 , m_expressioncxx . . $ OpenVanilla/OVWildcard#m_expression.(expression)
48 , m_matchEndOfLinecxx . . $ OpenVanilla/OVWildcard#m_matchEndOfLine.(matchEndOfLine)
49 , m_matchOneCharcxx . . $ OpenVanilla/OVWildcard#m_matchOneChar.(matchOneChar)
50 , m_matchZeroOrMoreCharcxx . . $ OpenVanilla/OVWildcard#m_matchZeroOrMoreChar.(matchZeroOrMoreChar)
51 {
52 size_t index;
53 for (index = 0; index < expression.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); index++) {
54 if (expression[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).index] == matchOneChar || expression[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).index] == matchZeroOrMoreChar) break;
55 }
56
57 m_longestHeadMatchStringcxx . . $ OpenVanilla/OVWildcard#m_longestHeadMatchString. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). expression.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, index);
58
59 for (stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# i = 0; i < expression.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); i++) {
60 char c = expression[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).i];
61 if (c == matchOneChar) {
62 m_statescxx . . $ OpenVanilla/OVWildcard#m_states..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(Statecxx . . $ std/pair#pair(14d64bafa7379ebc).(AnyOnecxx . . $ OpenVanilla/OVWildcard#AnyOne., 0));
63 }
64 else if (c == matchZeroOrMoreChar) {
65 char nextChar = 0;
66 stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# j;
67 for (j = i + 1; j < expression.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); j++) {
68 char k = expression[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).j];
69 if (k != matchZeroOrMoreChar) {
70 if (k == matchOneChar) k = -1;
71
72 nextChar = k;
73 break;
74 }
75 }
76
77 i = j;
78 m_statescxx . . $ OpenVanilla/OVWildcard#m_states..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(Statecxx . . $ std/pair#pair(14d64bafa7379ebc).(AnyUntilcxx . . $ OpenVanilla/OVWildcard#AnyUntil., nextChar));
79 }
80 else {
81 m_statescxx . . $ OpenVanilla/OVWildcard#m_states..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(Statecxx . . $ std/pair#pair(14d64bafa7379ebc).(Exactcxx . . $ OpenVanilla/OVWildcard#Exact., c));
82 }
83 }
84 }
85
86 bool matchcxx . . $ OpenVanilla/OVWildcard#match(34d8d7cfe06753ad).(const stringcxx . . $ std/string#& target, size_t fromState = 0) const
87 {
88 stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# i = 0, slength = target.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).();
89 vectorcxx . . $ std/vector#<State>::size_typecxx . . $ std/vector#size_type# j, vlength = m_statescxx . . $ OpenVanilla/OVWildcard#m_states..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).();
90
91 for (j = fromState; j < vlength; j++) {
92 Statecxx . . $ OpenVanilla/OVWildcard#State# state = m_statescxx . . $ std/pair#pair(31533a781ed7dba3).[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j];
93 Directivecxx . . $ OpenVanilla/OVWildcard#Directive# d = state.firstcxx . . $ std/pair#first.;
94 int k = state.secondcxx . . $ std/pair#second.;
95
96 if (i >= slength) {
97 if (d == AnyUntilcxx . . $ OpenVanilla/OVWildcard#AnyUntil. && !k) return true;
98 return false;
99 }
100
101 switch (d) {
102 case Exactcxx . . $ OpenVanilla/OVWildcard#Exact.:
103 if (!equalCharscxx . . $ OpenVanilla/OVWildcard#equalChars(c625e3b2c1b7e3c6).(target[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).i], k)) return false;
104 i++;
105 break;
106
107 case AnyOnecxx . . $ OpenVanilla/OVWildcard#AnyOne.:
108 i++;
109 break;
110
111 case AnyUntilcxx . . $ OpenVanilla/OVWildcard#AnyUntil.:
112 if (k == -1) {
113 // means *?, equals ?, so just advance one character
114 i++;
115 }
116 else if (k == 0) {
117 // until end, always true
118 return true;
119 }
120 else {
121 bool found = false;
122 stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# backIndex;
123
124 for (backIndex = slength - 1; backIndex >= i; backIndex--) {
125 if (equalCharscxx . . $ OpenVanilla/OVWildcard#equalChars(c625e3b2c1b7e3c6).(target[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).backIndex], k)) {
126 stringcxx . . $ std/string# substring = target.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(backIndex + 1, slength - (backIndex + 1));
127
128 if (matchcxx . . $ OpenVanilla/OVWildcard#match(34d8d7cfe06753ad).(substring, j + 1)) {
129 found = true;
130 i = backIndex + 1;
131 break;
132 }
133 }
134
135 if (!backIndex)
136 break;
137 }
138
139 if (!found)
140 return false;
141 }
142
143 break;
144 }
145 }
146
147 if (m_matchEndOfLinecxx . . $ OpenVanilla/OVWildcard#m_matchEndOfLine. && i != slength)
148 return false;
149
150 return true;
151 }
152
153 const stringcxx . . $ std/string# longestHeadMatchStringcxx . . $ OpenVanilla/OVWildcard#longestHeadMatchString(fcf7e9886c190261).() const
154 {
155 return m_longestHeadMatchStringcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
156 }
157
158 const stringcxx . . $ std/string# expressioncxx . . $ OpenVanilla/OVWildcard#expression(fcf7e9886c190261).() const
159 {
160 return m_expressioncxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
161 }
162
163 bool isCaseSensitivecxx . . $ OpenVanilla/OVWildcard#isCaseSensitive(50ce9a9e25b4a850).() const
164 {
165 return m_caseSensitivecxx . . $ OpenVanilla/OVWildcard#m_caseSensitive.;
166 }
167
168 char matchOneCharcxx . . $ OpenVanilla/OVWildcard#matchOneChar(1b8b762cbef9c2c9).() const
169 {
170 return m_matchOneCharcxx . . $ OpenVanilla/OVWildcard#m_matchOneChar.;
171 }
172
173 char matchZeroOrMoreCharcxx . . $ OpenVanilla/OVWildcard#matchZeroOrMoreChar(1b8b762cbef9c2c9).() const
174 {
175 return m_matchZeroOrMoreCharcxx . . $ OpenVanilla/OVWildcard#m_matchZeroOrMoreChar.;
176 }
177
178 friend ostreamcxx . . $ std/ostream#& operatorcxx . . $ OpenVanilla/`operator<<`(26e0c351ed09e930).<<(ostreamcxx . . $ std/ostream#& stream, const OVWildcardcxx . . $ OpenVanilla/OVWildcard#& wildcard);
179
180 protected:
181 enum Directivecxx . . $ OpenVanilla/OVWildcard#Directive# {
182 Exactcxx . . $ OpenVanilla/OVWildcard#Exact.,
183 AnyOnecxx . . $ OpenVanilla/OVWildcard#AnyOne.,
184 AnyUntilcxx . . $ OpenVanilla/OVWildcard#AnyUntil.
185 };
186
187 typedef paircxx . . $ std/pair#<Directivecxx . . $ OpenVanilla/OVWildcard#Directive#, int> Statecxx . . $ OpenVanilla/OVWildcard#State#;
188
189 bool equalCharscxx . . $ OpenVanilla/OVWildcard#equalChars(c625e3b2c1b7e3c6).(char a, char b) const
190 {
191 if (m_caseSensitivecxx . . $ OpenVanilla/OVWildcard#m_caseSensitive.)
192 return a == b;
193 else
194 return tolower(a) == tolower(b);
195 }
196
197 bool m_caseSensitivecxx . . $ OpenVanilla/OVWildcard#m_caseSensitive.;
198 bool m_matchEndOfLinecxx . . $ OpenVanilla/OVWildcard#m_matchEndOfLine.;
199 char m_matchOneCharcxx . . $ OpenVanilla/OVWildcard#m_matchOneChar.;
200 char m_matchZeroOrMoreCharcxx . . $ OpenVanilla/OVWildcard#m_matchZeroOrMoreChar.;
201 vectorcxx . . $ std/vector#<Statecxx . . $ OpenVanilla/OVWildcard#State#> m_statescxx . . $ OpenVanilla/OVWildcard#m_states.;
202
203 stringcxx . . $ std/string# m_expressioncxx . . $ OpenVanilla/OVWildcard#m_expression.;
204 stringcxx . . $ std/string# m_longestHeadMatchStringcxx . . $ OpenVanilla/OVWildcard#m_longestHeadMatchString.;
205
206 public:
207 static const bool Matchcxx . . $ OpenVanilla/OVWildcard#Match(ef843920058a9bd5).(const stringcxx . . $ std/string#& text, const stringcxx . . $ std/string#& expression, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false)
208 {
209 OVWildcardcxx . . $ OpenVanilla/OVWildcard# expcxx . . $ OpenVanilla/OVWildcard#OVWildcard(6e6b56654adc35c2).(expression, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive);
210 return exp.matchcxx . . $ OpenVanilla/OVWildcard#match(34d8d7cfe06753ad).(text);
211 }
212
213 static const vectorcxx . . $ std/vector#<OVWildcardcxx . . $ OpenVanilla/OVWildcard#> WildcardsFromStringscxx . . $ OpenVanilla/OVWildcard#WildcardsFromStrings(905d9dc09460ae88).(const vectorcxx . . $ std/vector#<stringcxx . . $ std/string#>& expressions, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false)
214 {
215 vectorcxx . . $ std/vector#<OVWildcardcxx . . $ OpenVanilla/OVWildcard#> resultcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
216 vectorcxx . . $ std/vector#<string>::const_iteratorcxx . . $ std/vector#const_iterator# iter = expressions.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).();
217 for ( ; iter !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). expressions.endcxx . . $ std/vector#end(d1e1699016b9d7e6).(); iter++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
218 result.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(OVWildcardcxx . . $ OpenVanilla/OVWildcard#OVWildcard(6e6b56654adc35c2).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).iter, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive));
219
220 return resultcxx . . $ std/vector#vector(6f559d22b039ccdb).;
221 }
222
223 static bool MultiWildcardMatchAnycxx . . $ OpenVanilla/OVWildcard#MultiWildcardMatchAny(6f234c1d9e79dad4).(const stringcxx . . $ std/string#& target, const vectorcxx . . $ std/vector#<stringcxx . . $ std/string#>& expressions, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false)
224 {
225 return MultiWildcardMatchAnycxx . . $ OpenVanilla/OVWildcard#MultiWildcardMatchAny(d133848e1098df9b).(target, WildcardsFromStringscxx . . $ OpenVanilla/OVWildcard#WildcardsFromStrings(905d9dc09460ae88).(expressions, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive));
226 }
227
228 static bool MultiWildcardMatchAnycxx . . $ OpenVanilla/OVWildcard#MultiWildcardMatchAny(d133848e1098df9b).(const stringcxx . . $ std/string#& target, const vectorcxx . . $ std/vector#<OVWildcardcxx . . $ OpenVanilla/OVWildcard#>& expressions)
229 {
230 vectorcxx . . $ std/vector#<OVWildcard>::const_iteratorcxx . . $ std/vector#const_iterator# iter = expressions.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).();
231 for ( ; iter !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). expressions.endcxx . . $ std/vector#end(d1e1699016b9d7e6).(); iter++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).) {
232 if ((*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).iter).matchcxx . . $ OpenVanilla/OVWildcard#match(34d8d7cfe06753ad).(target))
233 return true;
234 }
235
236 return false;
237 }
238 };
239
240 inline ostreamcxx . . $ std/ostream#& operatorcxx . . $ OpenVanilla/`operator<<`(26e0c351ed09e930).<<(ostreamcxx . . $ std/ostream#& stream, const OVWildcardcxx . . $ OpenVanilla/OVWildcard#& wildcard)
241 {
242 vectorcxx . . $ std/vector#<OVWildcard::State>::size_typecxx . . $ std/vector#size_type# i, size = wildcard.m_statescxx . . $ OpenVanilla/OVWildcard#m_states..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).();
243 for (i = 0; i < size; i++) {
244 const OVWildcardcxx . . $ OpenVanilla/OVWildcard#::Statecxx . . $ OpenVanilla/OVWildcard#State#& state = wildcard.m_statescxx . . $ OpenVanilla/OVWildcard#m_states.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i];
245 stream <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "State " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). i <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). state.firstcxx . . $ std/pair#first. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). state.secondcxx . . $ std/pair#second. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
246 }
247
248 return stream;
249 }
250 };
251
252 #endif