blob: ad69f05ae75e5083ddbf8a3fd1124d59fdfd9df4 [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3257c982010-06-17 00:34:59 +00007//
8//===----------------------------------------------------------------------===//
9
10// <regex>
11
12// template <class charT> struct regex_traits;
13
14// bool isctype(charT c, char_class_type f) const;
15
16#include <regex>
Howard Hinnantf409d2f2010-06-21 21:01:43 +000017#include <cassert>
Howard Hinnant3257c982010-06-17 00:34:59 +000018
19int main()
20{
Howard Hinnantf409d2f2010-06-21 21:01:43 +000021 {
22 std::regex_traits<char> t;
23
24 std::string s("w");
25 assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
26 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
27 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
28 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
29 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
30 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
31 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
32
33 s = "alnum";
34 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
35 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
36 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
37 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
38 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
39 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
40 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
41
42 s = "alpha";
43 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
44 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
45 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
46 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
47 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
48 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
49 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
50
51 s = "blank";
52 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
53 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
54 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
55 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
56 assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
57 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
58 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
59
60 s = "cntrl";
61 assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
62 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
63 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
64 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
65 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
66 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
67 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
68 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
69
70 s = "digit";
71 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
72 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
73 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
74 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
75 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
76 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
77 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
78 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
79
80 s = "graph";
81 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
82 assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
83 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
84 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
85 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
86 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
87 assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
88 assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
89
90 s = "lower";
91 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
92 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
93 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
94 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
95 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
96 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
97 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
98 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
99
100 s = "print";
101 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
102 assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
103 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
104 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
105 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
106 assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
107 assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
108 assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
109
110 s = "punct";
111 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
112 assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
113 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
114 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
115 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
116 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
117 assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
118 assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
119
120 s = "space";
121 assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
122 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
123 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
124 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
125 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
126 assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
127 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
128 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
129
130 s = "upper";
131 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
132 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
133 assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
134 assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
135 assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
136 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
137 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
138 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
139
140 s = "xdigit";
141 assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
142 assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
143 assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
144 assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
145 assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
146 assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
147 assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
148 assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
149 }
150 {
151 std::regex_traits<wchar_t> t;
152
153 std::wstring s(L"w");
154 assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
155 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
156 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
157 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
158 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
159 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
160 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
161
162 s = L"alnum";
163 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
164 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
165 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
166 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
167 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
168 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
169 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
170
171 s = L"alpha";
172 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
173 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
174 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
175 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
176 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
177 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
178 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
179
180 s = L"blank";
181 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
182 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
183 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
184 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
185 assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
186 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
187 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
188
189 s = L"cntrl";
190 assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
191 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
192 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
193 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
194 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
195 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
196 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
197 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
198
199 s = L"digit";
200 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
201 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
202 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
203 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
204 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
205 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
206 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
207 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
208
209 s = L"graph";
210 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
211 assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
212 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
213 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
214 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
215 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
216 assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
217 assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
218
219 s = L"lower";
220 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
221 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
222 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
223 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
224 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
225 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
226 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
227 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
228
229 s = L"print";
230 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
231 assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
232 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
233 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
234 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
235 assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
236 assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
237 assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
238
239 s = L"punct";
240 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
241 assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
242 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
243 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
244 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
245 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
246 assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
247 assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
248
249 s = L"space";
250 assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
251 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
252 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
253 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
254 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
255 assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
256 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
257 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
258
259 s = L"upper";
260 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
261 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
262 assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
263 assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
264 assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
265 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
266 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
267 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
268
269 s = L"xdigit";
270 assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
271 assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
272 assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
273 assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
274 assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
275 assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
276 assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
277 assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
278 }
Howard Hinnant3257c982010-06-17 00:34:59 +0000279}