blob: d2065a033d383b8161f9efde62afbb72b2e9c4d4 [file] [log] [blame]
Howard Hinnantaa78f9c2010-08-14 19:58:44 +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 Hinnantaa78f9c2010-08-14 19:58:44 +00007//
8//===----------------------------------------------------------------------===//
9
10// <regex>
11
12// template <class BidirectionalIterator, class Allocator, class charT,
13// class traits>
14// bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
15// match_results<BidirectionalIterator, Allocator>& m,
16// const basic_regex<charT, traits>& e,
17// regex_constants::match_flag_type flags
18// = regex_constants::match_default);
19
20#include <regex>
21#include <cassert>
22
Marshall Clow83e2c4d2013-01-05 03:21:01 +000023#include "test_iterators.h"
Howard Hinnantaa78f9c2010-08-14 19:58:44 +000024
25int main()
26{
Howard Hinnant8b00e6c2013-08-02 00:26:35 +000027/* {
Howard Hinnantaa78f9c2010-08-14 19:58:44 +000028 std::cmatch m;
29 const char s[] = "a";
30 assert(std::regex_match(s, m, std::regex("a", std::regex_constants::awk)));
31 assert(m.size() == 1);
32 assert(!m.empty());
33 assert(!m.prefix().matched);
34 assert(m.prefix().first == s);
35 assert(m.prefix().second == m[0].first);
36 assert(!m.suffix().matched);
37 assert(m.suffix().first == m[0].second);
38 assert(m.suffix().second == s+1);
39 assert(m.length(0) == 1);
40 assert(m.position(0) == 0);
41 assert(m.str(0) == "a");
42 }
43 {
44 std::cmatch m;
45 const char s[] = "ab";
46 assert(std::regex_match(s, m, std::regex("ab", std::regex_constants::awk)));
47 assert(m.size() == 1);
48 assert(!m.prefix().matched);
49 assert(m.prefix().first == s);
50 assert(m.prefix().second == m[0].first);
51 assert(!m.suffix().matched);
52 assert(m.suffix().first == m[0].second);
53 assert(m.suffix().second == s+2);
54 assert(m.length(0) == 2);
55 assert(m.position(0) == 0);
56 assert(m.str(0) == "ab");
57 }
58 {
59 std::cmatch m;
60 const char s[] = "ab";
61 assert(!std::regex_match(s, m, std::regex("ba", std::regex_constants::awk)));
62 assert(m.size() == 0);
63 assert(m.empty());
64 }
65 {
66 std::cmatch m;
67 const char s[] = "aab";
68 assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::awk)));
69 assert(m.size() == 0);
70 }
71 {
72 std::cmatch m;
73 const char s[] = "aab";
74 assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::awk),
75 std::regex_constants::match_continuous));
76 assert(m.size() == 0);
77 }
78 {
79 std::cmatch m;
80 const char s[] = "abcd";
81 assert(!std::regex_match(s, m, std::regex("bc", std::regex_constants::awk)));
82 assert(m.size() == 0);
83 }
84 {
85 std::cmatch m;
86 const char s[] = "abbc";
87 assert(std::regex_match(s, m, std::regex("ab*c", std::regex_constants::awk)));
88 assert(m.size() == 1);
89 assert(!m.prefix().matched);
90 assert(m.prefix().first == s);
91 assert(m.prefix().second == m[0].first);
92 assert(!m.suffix().matched);
93 assert(m.suffix().first == m[0].second);
94 assert(m.suffix().second == s+4);
95 assert(m.length(0) == 4);
96 assert(m.position(0) == 0);
97 assert(m.str(0) == s);
98 }
99 {
100 std::cmatch m;
101 const char s[] = "ababc";
102 assert(std::regex_match(s, m, std::regex("(ab)*c", std::regex_constants::awk)));
103 assert(m.size() == 2);
104 assert(!m.prefix().matched);
105 assert(m.prefix().first == s);
106 assert(m.prefix().second == m[0].first);
107 assert(!m.suffix().matched);
108 assert(m.suffix().first == m[0].second);
109 assert(m.suffix().second == s+5);
110 assert(m.length(0) == 5);
111 assert(m.position(0) == 0);
112 assert(m.str(0) == s);
113 assert(m.length(1) == 2);
114 assert(m.position(1) == 2);
115 assert(m.str(1) == "ab");
116 }
117 {
118 std::cmatch m;
119 const char s[] = "abcdefghijk";
120 assert(!std::regex_match(s, m, std::regex("cd((e)fg)hi",
121 std::regex_constants::awk)));
122 assert(m.size() == 0);
123 }
124 {
125 std::cmatch m;
126 const char s[] = "abc";
127 assert(std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
128 assert(m.size() == 1);
129 assert(!m.prefix().matched);
130 assert(m.prefix().first == s);
131 assert(m.prefix().second == m[0].first);
132 assert(!m.suffix().matched);
133 assert(m.suffix().first == m[0].second);
134 assert(m.suffix().second == s+3);
135 assert(m.length(0) == 3);
136 assert(m.position(0) == 0);
137 assert(m.str(0) == s);
138 }
139 {
140 std::cmatch m;
141 const char s[] = "abcd";
142 assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
143 assert(m.size() == 0);
144 }
145 {
146 std::cmatch m;
147 const char s[] = "aabc";
148 assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::awk)));
149 assert(m.size() == 0);
150 }
151 {
152 std::cmatch m;
153 const char s[] = "abc";
154 assert(std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
155 assert(m.size() == 1);
156 assert(!m.prefix().matched);
157 assert(m.prefix().first == s);
158 assert(m.prefix().second == m[0].first);
159 assert(!m.suffix().matched);
160 assert(m.suffix().first == m[0].second);
161 assert(m.suffix().second == s+3);
162 assert(m.length(0) == 3);
163 assert(m.position(0) == 0);
164 assert(m.str(0) == s);
165 }
166 {
167 std::cmatch m;
168 const char s[] = "efabc";
169 assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
170 assert(m.size() == 0);
171 }
172 {
173 std::cmatch m;
174 const char s[] = "efabcg";
175 assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::awk)));
176 assert(m.size() == 0);
177 }
178 {
179 std::cmatch m;
180 const char s[] = "abc";
181 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
182 assert(m.size() == 1);
183 assert(!m.prefix().matched);
184 assert(m.prefix().first == s);
185 assert(m.prefix().second == m[0].first);
186 assert(!m.suffix().matched);
187 assert(m.suffix().first == m[0].second);
188 assert(m.suffix().second == s+3);
189 assert(m.length(0) == 3);
190 assert(m.position(0) == 0);
191 assert(m.str(0) == s);
192 }
193 {
194 std::cmatch m;
195 const char s[] = "acc";
196 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
197 assert(m.size() == 1);
198 assert(!m.prefix().matched);
199 assert(m.prefix().first == s);
200 assert(m.prefix().second == m[0].first);
201 assert(!m.suffix().matched);
202 assert(m.suffix().first == m[0].second);
203 assert(m.suffix().second == s+3);
204 assert(m.length(0) == 3);
205 assert(m.position(0) == 0);
206 assert(m.str(0) == s);
207 }
208 {
209 std::cmatch m;
210 const char s[] = "acc";
211 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::awk)));
212 assert(m.size() == 1);
213 assert(!m.prefix().matched);
214 assert(m.prefix().first == s);
215 assert(m.prefix().second == m[0].first);
216 assert(!m.suffix().matched);
217 assert(m.suffix().first == m[0].second);
218 assert(m.suffix().second == s+3);
219 assert(m.length(0) == 3);
220 assert(m.position(0) == 0);
221 assert(m.str(0) == s);
222 }
223 {
224 std::cmatch m;
225 const char s[] = "abcdef";
226 assert(std::regex_match(s, m, std::regex("(.*).*", std::regex_constants::awk)));
227 assert(m.size() == 2);
228 assert(!m.prefix().matched);
229 assert(m.prefix().first == s);
230 assert(m.prefix().second == m[0].first);
231 assert(!m.suffix().matched);
232 assert(m.suffix().first == m[0].second);
233 assert(m.suffix().second == s+6);
234 assert(m.length(0) == 6);
235 assert(m.position(0) == 0);
236 assert(m.str(0) == s);
237 assert(m.length(1) == 6);
238 assert(m.position(1) == 0);
239 assert(m.str(1) == s);
240 }
241 {
242 std::cmatch m;
243 const char s[] = "bc";
244 assert(!std::regex_match(s, m, std::regex("(a*)*", std::regex_constants::awk)));
245 assert(m.size() == 0);
246 }
247 {
248 std::cmatch m;
249 const char s[] = "abbc";
250 assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
251 assert(m.size() == 0);
252 }
253 {
254 std::cmatch m;
255 const char s[] = "abbbc";
256 assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
257 assert(m.size() == 1);
258 assert(!m.prefix().matched);
259 assert(m.prefix().first == s);
260 assert(m.prefix().second == m[0].first);
261 assert(!m.suffix().matched);
262 assert(m.suffix().first == m[0].second);
263 assert(m.suffix().second == m[0].second);
264 assert(m.length(0) == std::char_traits<char>::length(s));
265 assert(m.position(0) == 0);
266 assert(m.str(0) == s);
267 }
268 {
269 std::cmatch m;
270 const char s[] = "abbbbc";
271 assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
272 assert(m.size() == 1);
273 assert(!m.prefix().matched);
274 assert(m.prefix().first == s);
275 assert(m.prefix().second == m[0].first);
276 assert(!m.suffix().matched);
277 assert(m.suffix().first == m[0].second);
278 assert(m.suffix().second == m[0].second);
279 assert(m.length(0) == std::char_traits<char>::length(s));
280 assert(m.position(0) == 0);
281 assert(m.str(0) == s);
282 }
283 {
284 std::cmatch m;
285 const char s[] = "abbbbbc";
286 assert(std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
287 assert(m.size() == 1);
288 assert(!m.prefix().matched);
289 assert(m.prefix().first == s);
290 assert(m.prefix().second == m[0].first);
291 assert(!m.suffix().matched);
292 assert(m.suffix().first == m[0].second);
293 assert(m.suffix().second == m[0].second);
294 assert(m.length(0) == std::char_traits<char>::length(s));
295 assert(m.position(0) == 0);
296 assert(m.str(0) == s);
297 }
298 {
299 std::cmatch m;
300 const char s[] = "adefc";
301 assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
302 assert(m.size() == 0);
303 }
304 {
305 std::cmatch m;
306 const char s[] = "abbbbbbc";
307 assert(!std::regex_match(s, m, std::regex("ab{3,5}c", std::regex_constants::awk)));
308 assert(m.size() == 0);
309 }
310 {
311 std::cmatch m;
312 const char s[] = "adec";
313 assert(!std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
314 assert(m.size() == 0);
315 }
316 {
317 std::cmatch m;
318 const char s[] = "adefc";
319 assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
320 assert(m.size() == 1);
321 assert(!m.prefix().matched);
322 assert(m.prefix().first == s);
323 assert(m.prefix().second == m[0].first);
324 assert(!m.suffix().matched);
325 assert(m.suffix().first == m[0].second);
326 assert(m.suffix().second == m[0].second);
327 assert(m.length(0) == std::char_traits<char>::length(s));
328 assert(m.position(0) == 0);
329 assert(m.str(0) == s);
330 }
331 {
332 std::cmatch m;
333 const char s[] = "adefgc";
334 assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
335 assert(m.size() == 1);
336 assert(!m.prefix().matched);
337 assert(m.prefix().first == s);
338 assert(m.prefix().second == m[0].first);
339 assert(!m.suffix().matched);
340 assert(m.suffix().first == m[0].second);
341 assert(m.suffix().second == m[0].second);
342 assert(m.length(0) == std::char_traits<char>::length(s));
343 assert(m.position(0) == 0);
344 assert(m.str(0) == s);
345 }
346 {
347 std::cmatch m;
348 const char s[] = "adefghc";
349 assert(std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
350 assert(m.size() == 1);
351 assert(!m.prefix().matched);
352 assert(m.prefix().first == s);
353 assert(m.prefix().second == m[0].first);
354 assert(!m.suffix().matched);
355 assert(m.suffix().first == m[0].second);
356 assert(m.suffix().second == m[0].second);
357 assert(m.length(0) == std::char_traits<char>::length(s));
358 assert(m.position(0) == 0);
359 assert(m.str(0) == s);
360 }
361 {
362 std::cmatch m;
363 const char s[] = "adefghic";
364 assert(!std::regex_match(s, m, std::regex("a.{3,5}c", std::regex_constants::awk)));
365 assert(m.size() == 0);
366 }
367 {
368 std::cmatch m;
369 const char s[] = "tournament";
370 assert(std::regex_match(s, m, std::regex("tour|to|tournament",
371 std::regex_constants::awk)));
372 assert(m.size() == 1);
373 assert(!m.prefix().matched);
374 assert(m.prefix().first == s);
375 assert(m.prefix().second == m[0].first);
376 assert(!m.suffix().matched);
377 assert(m.suffix().first == m[0].second);
378 assert(m.suffix().second == m[0].second);
379 assert(m.length(0) == std::char_traits<char>::length(s));
380 assert(m.position(0) == 0);
381 assert(m.str(0) == s);
382 }
383 {
384 std::cmatch m;
385 const char s[] = "tournamenttotour";
386 assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+",
387 std::regex_constants::awk | std::regex_constants::nosubs)));
388 assert(m.size() == 1);
389 assert(!m.prefix().matched);
390 assert(m.prefix().first == s);
391 assert(m.prefix().second == m[0].first);
392 assert(!m.suffix().matched);
393 assert(m.suffix().first == m[0].second);
394 assert(m.suffix().second == m[0].second);
395 assert(m.length(0) == std::char_traits<char>::length(s));
396 assert(m.position(0) == 0);
397 assert(m.str(0) == s);
398 }
399 {
400 std::cmatch m;
401 const char s[] = "ttotour";
402 assert(std::regex_match(s, m, std::regex("(tour|to|t)+",
403 std::regex_constants::awk)));
404 assert(m.size() == 2);
405 assert(!m.prefix().matched);
406 assert(m.prefix().first == s);
407 assert(m.prefix().second == m[0].first);
408 assert(!m.suffix().matched);
409 assert(m.suffix().first == m[0].second);
410 assert(m.suffix().second == m[0].second);
411 assert(m.length(0) == std::char_traits<char>::length(s));
412 assert(m.position(0) == 0);
413 assert(m.str(0) == s);
414 assert(m.length(1) == 4);
415 assert(m.position(1) == 3);
416 assert(m.str(1) == "tour");
417 }
418 {
419 std::cmatch m;
420 const char s[] = "-ab,ab-";
421 assert(!std::regex_match(s, m, std::regex("-(.*),\1-", std::regex_constants::awk)));
422 assert(m.size() == 0);
423 }
424 {
425 std::cmatch m;
426 const char s[] = "-ab,ab-";
427 assert(std::regex_match(s, m, std::regex("-.*,.*-", std::regex_constants::awk)));
428 assert(m.size() == 1);
429 assert(!m.prefix().matched);
430 assert(m.prefix().first == s);
431 assert(m.prefix().second == m[0].first);
432 assert(!m.suffix().matched);
433 assert(m.suffix().first == m[0].second);
434 assert(m.suffix().second == m[0].second);
435 assert(m.length(0) == std::char_traits<char>::length(s));
436 assert(m.position(0) == 0);
437 assert(m.str(0) == s);
438 }
439 {
440 std::cmatch m;
441 const char s[] = "a";
442 assert(std::regex_match(s, m, std::regex("^[a]$",
443 std::regex_constants::awk)));
444 assert(m.size() == 1);
445 assert(!m.prefix().matched);
446 assert(m.prefix().first == s);
447 assert(m.prefix().second == m[0].first);
448 assert(!m.suffix().matched);
449 assert(m.suffix().first == m[0].second);
450 assert(m.suffix().second == m[0].second);
451 assert(m.length(0) == 1);
452 assert(m.position(0) == 0);
453 assert(m.str(0) == "a");
454 }
455 {
456 std::cmatch m;
457 const char s[] = "a";
458 assert(std::regex_match(s, m, std::regex("^[ab]$",
459 std::regex_constants::awk)));
460 assert(m.size() == 1);
461 assert(!m.prefix().matched);
462 assert(m.prefix().first == s);
463 assert(m.prefix().second == m[0].first);
464 assert(!m.suffix().matched);
465 assert(m.suffix().first == m[0].second);
466 assert(m.suffix().second == m[0].second);
467 assert(m.length(0) == 1);
468 assert(m.position(0) == 0);
469 assert(m.str(0) == "a");
470 }
471 {
472 std::cmatch m;
473 const char s[] = "c";
474 assert(std::regex_match(s, m, std::regex("^[a-f]$",
475 std::regex_constants::awk)));
476 assert(m.size() == 1);
477 assert(!m.prefix().matched);
478 assert(m.prefix().first == s);
479 assert(m.prefix().second == m[0].first);
480 assert(!m.suffix().matched);
481 assert(m.suffix().first == m[0].second);
482 assert(m.suffix().second == m[0].second);
483 assert(m.length(0) == 1);
484 assert(m.position(0) == 0);
485 assert(m.str(0) == s);
486 }
487 {
488 std::cmatch m;
489 const char s[] = "g";
490 assert(!std::regex_match(s, m, std::regex("^[a-f]$",
491 std::regex_constants::awk)));
492 assert(m.size() == 0);
493 }
494 {
495 std::cmatch m;
496 const char s[] = "Iraqi";
497 assert(!std::regex_match(s, m, std::regex("q[^u]",
498 std::regex_constants::awk)));
499 assert(m.size() == 0);
500 }
501 {
502 std::cmatch m;
503 const char s[] = "Iraq";
504 assert(!std::regex_match(s, m, std::regex("q[^u]",
505 std::regex_constants::awk)));
506 assert(m.size() == 0);
507 }
508 {
509 std::cmatch m;
510 const char s[] = "AmB";
511 assert(std::regex_match(s, m, std::regex("A[[:lower:]]B",
512 std::regex_constants::awk)));
513 assert(m.size() == 1);
514 assert(!m.prefix().matched);
515 assert(m.prefix().first == s);
516 assert(m.prefix().second == m[0].first);
517 assert(!m.suffix().matched);
518 assert(m.suffix().first == m[0].second);
519 assert(m.suffix().second == m[0].second);
520 assert(m.length(0) == std::char_traits<char>::length(s));
521 assert(m.position(0) == 0);
522 assert(m.str(0) == s);
523 }
524 {
525 std::cmatch m;
526 const char s[] = "AMB";
527 assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B",
528 std::regex_constants::awk)));
529 assert(m.size() == 0);
530 }
531 {
532 std::cmatch m;
533 const char s[] = "AMB";
534 assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B",
535 std::regex_constants::awk)));
536 assert(m.size() == 1);
537 assert(!m.prefix().matched);
538 assert(m.prefix().first == s);
539 assert(m.prefix().second == m[0].first);
540 assert(!m.suffix().matched);
541 assert(m.suffix().first == m[0].second);
542 assert(m.suffix().second == m[0].second);
543 assert(m.length(0) == std::char_traits<char>::length(s));
544 assert(m.position(0) == 0);
545 assert(m.str(0) == s);
546 }
547 {
548 std::cmatch m;
549 const char s[] = "AmB";
550 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B",
551 std::regex_constants::awk)));
552 assert(m.size() == 0);
553 }
554 {
555 std::cmatch m;
556 const char s[] = "A5B";
557 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B",
558 std::regex_constants::awk)));
559 assert(m.size() == 0);
560 }
561 {
562 std::cmatch m;
563 const char s[] = "A?B";
564 assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B",
565 std::regex_constants::awk)));
566 assert(m.size() == 1);
567 assert(!m.prefix().matched);
568 assert(m.prefix().first == s);
569 assert(m.prefix().second == m[0].first);
570 assert(!m.suffix().matched);
571 assert(m.suffix().first == m[0].second);
572 assert(m.suffix().second == m[0].second);
573 assert(m.length(0) == std::char_traits<char>::length(s));
574 assert(m.position(0) == 0);
575 assert(m.str(0) == s);
576 }
577 {
578 std::cmatch m;
579 const char s[] = "-";
580 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
581 std::regex_constants::awk)));
582 assert(m.size() == 1);
583 assert(!m.prefix().matched);
584 assert(m.prefix().first == s);
585 assert(m.prefix().second == m[0].first);
586 assert(!m.suffix().matched);
587 assert(m.suffix().first == m[0].second);
588 assert(m.suffix().second == m[0].second);
589 assert(m.length(0) == std::char_traits<char>::length(s));
590 assert(m.position(0) == 0);
591 assert(m.str(0) == s);
592 }
593 {
594 std::cmatch m;
595 const char s[] = "z";
596 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
597 std::regex_constants::awk)));
598 assert(m.size() == 1);
599 assert(!m.prefix().matched);
600 assert(m.prefix().first == s);
601 assert(m.prefix().second == m[0].first);
602 assert(!m.suffix().matched);
603 assert(m.suffix().first == m[0].second);
604 assert(m.suffix().second == m[0].second);
605 assert(m.length(0) == std::char_traits<char>::length(s));
606 assert(m.position(0) == 0);
607 assert(m.str(0) == s);
608 }
609 {
610 std::cmatch m;
611 const char s[] = "m";
612 assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
613 std::regex_constants::awk)));
614 assert(m.size() == 0);
615 }
616 std::locale::global(std::locale("cs_CZ.ISO8859-2"));
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000617*/ {
Howard Hinnantaa78f9c2010-08-14 19:58:44 +0000618 std::cmatch m;
619 const char s[] = "m";
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000620 /* assert(std::regex_match(s, m,*/ std::regex("[a[=M=]z]"/*,
621 std::regex_constants::awk*/);//));
622/* assert(m.size() == 1);
Howard Hinnantaa78f9c2010-08-14 19:58:44 +0000623 assert(!m.prefix().matched);
624 assert(m.prefix().first == s);
625 assert(m.prefix().second == m[0].first);
626 assert(!m.suffix().matched);
627 assert(m.suffix().first == m[0].second);
628 assert(m.suffix().second == m[0].second);
629 assert(m.length(0) == std::char_traits<char>::length(s));
630 assert(m.position(0) == 0);
631 assert(m.str(0) == s);
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000632*/ }
633/* {
Howard Hinnantaa78f9c2010-08-14 19:58:44 +0000634 std::cmatch m;
635 const char s[] = "Ch";
636 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
637 std::regex_constants::awk | std::regex_constants::icase)));
638 assert(m.size() == 1);
639 assert(!m.prefix().matched);
640 assert(m.prefix().first == s);
641 assert(m.prefix().second == m[0].first);
642 assert(!m.suffix().matched);
643 assert(m.suffix().first == m[0].second);
644 assert(m.suffix().second == m[0].second);
645 assert(m.length(0) == std::char_traits<char>::length(s));
646 assert(m.position(0) == 0);
647 assert(m.str(0) == s);
648 }
649 std::locale::global(std::locale("C"));
650 {
651 std::cmatch m;
652 const char s[] = "m";
653 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]",
654 std::regex_constants::awk)));
655 assert(m.size() == 0);
656 }
657 {
658 std::cmatch m;
659 const char s[] = "01a45cef9";
660 assert(!std::regex_match(s, m, std::regex("[ace1-9]*",
661 std::regex_constants::awk)));
662 assert(m.size() == 0);
663 }
664 {
665 std::cmatch m;
666 const char s[] = "01a45cef9";
667 assert(!std::regex_match(s, m, std::regex("[ace1-9]+",
668 std::regex_constants::awk)));
669 assert(m.size() == 0);
670 }
671 {
672 const char r[] = "^[-+]?[0-9]+[CF]$";
673 std::ptrdiff_t sr = std::char_traits<char>::length(r);
674 typedef forward_iterator<const char*> FI;
675 typedef bidirectional_iterator<const char*> BI;
676 std::regex regex(FI(r), FI(r+sr), std::regex_constants::awk);
677 std::match_results<BI> m;
678 const char s[] = "-40C";
679 std::ptrdiff_t ss = std::char_traits<char>::length(s);
680 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
681 assert(m.size() == 1);
682 assert(!m.prefix().matched);
683 assert(m.prefix().first == BI(s));
684 assert(m.prefix().second == m[0].first);
685 assert(!m.suffix().matched);
686 assert(m.suffix().first == m[0].second);
687 assert(m.suffix().second == m[0].second);
688 assert(m.length(0) == 4);
689 assert(m.position(0) == 0);
690 assert(m.str(0) == s);
691 }
692 {
693 std::cmatch m;
694 const char s[] = "\n\n\n";
695 assert(std::regex_match(s, m, std::regex("[\\n]+",
696 std::regex_constants::awk)));
697 assert(m.size() == 1);
698 assert(!m.prefix().matched);
699 assert(m.prefix().first == s);
700 assert(m.prefix().second == m[0].first);
701 assert(!m.suffix().matched);
702 assert(m.suffix().first == m[0].second);
703 assert(m.suffix().second == s + std::char_traits<char>::length(s));
704 assert(m.length(0) == std::char_traits<char>::length(s));
705 assert(m.position(0) == 0);
706 assert(m.str(0) == s);
707 }
708 {
709 std::wcmatch m;
710 const wchar_t s[] = L"a";
711 assert(std::regex_match(s, m, std::wregex(L"a", std::regex_constants::awk)));
712 assert(m.size() == 1);
713 assert(!m.empty());
714 assert(!m.prefix().matched);
715 assert(m.prefix().first == s);
716 assert(m.prefix().second == m[0].first);
717 assert(!m.suffix().matched);
718 assert(m.suffix().first == m[0].second);
719 assert(m.suffix().second == s+1);
720 assert(m.length(0) == 1);
721 assert(m.position(0) == 0);
722 assert(m.str(0) == L"a");
723 }
724 {
725 std::wcmatch m;
726 const wchar_t s[] = L"ab";
727 assert(std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::awk)));
728 assert(m.size() == 1);
729 assert(!m.prefix().matched);
730 assert(m.prefix().first == s);
731 assert(m.prefix().second == m[0].first);
732 assert(!m.suffix().matched);
733 assert(m.suffix().first == m[0].second);
734 assert(m.suffix().second == s+2);
735 assert(m.length(0) == 2);
736 assert(m.position(0) == 0);
737 assert(m.str(0) == L"ab");
738 }
739 {
740 std::wcmatch m;
741 const wchar_t s[] = L"ab";
742 assert(!std::regex_match(s, m, std::wregex(L"ba", std::regex_constants::awk)));
743 assert(m.size() == 0);
744 assert(m.empty());
745 }
746 {
747 std::wcmatch m;
748 const wchar_t s[] = L"aab";
749 assert(!std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::awk)));
750 assert(m.size() == 0);
751 }
752 {
753 std::wcmatch m;
754 const wchar_t s[] = L"aab";
755 assert(!std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::awk),
756 std::regex_constants::match_continuous));
757 assert(m.size() == 0);
758 }
759 {
760 std::wcmatch m;
761 const wchar_t s[] = L"abcd";
762 assert(!std::regex_match(s, m, std::wregex(L"bc", std::regex_constants::awk)));
763 assert(m.size() == 0);
764 }
765 {
766 std::wcmatch m;
767 const wchar_t s[] = L"abbc";
768 assert(std::regex_match(s, m, std::wregex(L"ab*c", std::regex_constants::awk)));
769 assert(m.size() == 1);
770 assert(!m.prefix().matched);
771 assert(m.prefix().first == s);
772 assert(m.prefix().second == m[0].first);
773 assert(!m.suffix().matched);
774 assert(m.suffix().first == m[0].second);
775 assert(m.suffix().second == s+4);
776 assert(m.length(0) == 4);
777 assert(m.position(0) == 0);
778 assert(m.str(0) == s);
779 }
780 {
781 std::wcmatch m;
782 const wchar_t s[] = L"ababc";
783 assert(std::regex_match(s, m, std::wregex(L"(ab)*c", std::regex_constants::awk)));
784 assert(m.size() == 2);
785 assert(!m.prefix().matched);
786 assert(m.prefix().first == s);
787 assert(m.prefix().second == m[0].first);
788 assert(!m.suffix().matched);
789 assert(m.suffix().first == m[0].second);
790 assert(m.suffix().second == s+5);
791 assert(m.length(0) == 5);
792 assert(m.position(0) == 0);
793 assert(m.str(0) == s);
794 assert(m.length(1) == 2);
795 assert(m.position(1) == 2);
796 assert(m.str(1) == L"ab");
797 }
798 {
799 std::wcmatch m;
800 const wchar_t s[] = L"abcdefghijk";
801 assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi",
802 std::regex_constants::awk)));
803 assert(m.size() == 0);
804 }
805 {
806 std::wcmatch m;
807 const wchar_t s[] = L"abc";
808 assert(std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
809 assert(m.size() == 1);
810 assert(!m.prefix().matched);
811 assert(m.prefix().first == s);
812 assert(m.prefix().second == m[0].first);
813 assert(!m.suffix().matched);
814 assert(m.suffix().first == m[0].second);
815 assert(m.suffix().second == s+3);
816 assert(m.length(0) == 3);
817 assert(m.position(0) == 0);
818 assert(m.str(0) == s);
819 }
820 {
821 std::wcmatch m;
822 const wchar_t s[] = L"abcd";
823 assert(!std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
824 assert(m.size() == 0);
825 }
826 {
827 std::wcmatch m;
828 const wchar_t s[] = L"aabc";
829 assert(!std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
830 assert(m.size() == 0);
831 }
832 {
833 std::wcmatch m;
834 const wchar_t s[] = L"abc";
835 assert(std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
836 assert(m.size() == 1);
837 assert(!m.prefix().matched);
838 assert(m.prefix().first == s);
839 assert(m.prefix().second == m[0].first);
840 assert(!m.suffix().matched);
841 assert(m.suffix().first == m[0].second);
842 assert(m.suffix().second == s+3);
843 assert(m.length(0) == 3);
844 assert(m.position(0) == 0);
845 assert(m.str(0) == s);
846 }
847 {
848 std::wcmatch m;
849 const wchar_t s[] = L"efabc";
850 assert(!std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
851 assert(m.size() == 0);
852 }
853 {
854 std::wcmatch m;
855 const wchar_t s[] = L"efabcg";
856 assert(!std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
857 assert(m.size() == 0);
858 }
859 {
860 std::wcmatch m;
861 const wchar_t s[] = L"abc";
862 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
863 assert(m.size() == 1);
864 assert(!m.prefix().matched);
865 assert(m.prefix().first == s);
866 assert(m.prefix().second == m[0].first);
867 assert(!m.suffix().matched);
868 assert(m.suffix().first == m[0].second);
869 assert(m.suffix().second == s+3);
870 assert(m.length(0) == 3);
871 assert(m.position(0) == 0);
872 assert(m.str(0) == s);
873 }
874 {
875 std::wcmatch m;
876 const wchar_t s[] = L"acc";
877 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
878 assert(m.size() == 1);
879 assert(!m.prefix().matched);
880 assert(m.prefix().first == s);
881 assert(m.prefix().second == m[0].first);
882 assert(!m.suffix().matched);
883 assert(m.suffix().first == m[0].second);
884 assert(m.suffix().second == s+3);
885 assert(m.length(0) == 3);
886 assert(m.position(0) == 0);
887 assert(m.str(0) == s);
888 }
889 {
890 std::wcmatch m;
891 const wchar_t s[] = L"acc";
892 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
893 assert(m.size() == 1);
894 assert(!m.prefix().matched);
895 assert(m.prefix().first == s);
896 assert(m.prefix().second == m[0].first);
897 assert(!m.suffix().matched);
898 assert(m.suffix().first == m[0].second);
899 assert(m.suffix().second == s+3);
900 assert(m.length(0) == 3);
901 assert(m.position(0) == 0);
902 assert(m.str(0) == s);
903 }
904 {
905 std::wcmatch m;
906 const wchar_t s[] = L"abcdef";
907 assert(std::regex_match(s, m, std::wregex(L"(.*).*", std::regex_constants::awk)));
908 assert(m.size() == 2);
909 assert(!m.prefix().matched);
910 assert(m.prefix().first == s);
911 assert(m.prefix().second == m[0].first);
912 assert(!m.suffix().matched);
913 assert(m.suffix().first == m[0].second);
914 assert(m.suffix().second == s+6);
915 assert(m.length(0) == 6);
916 assert(m.position(0) == 0);
917 assert(m.str(0) == s);
918 assert(m.length(1) == 6);
919 assert(m.position(1) == 0);
920 assert(m.str(1) == s);
921 }
922 {
923 std::wcmatch m;
924 const wchar_t s[] = L"bc";
925 assert(!std::regex_match(s, m, std::wregex(L"(a*)*", std::regex_constants::awk)));
926 assert(m.size() == 0);
927 }
928 {
929 std::wcmatch m;
930 const wchar_t s[] = L"abbc";
931 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
932 assert(m.size() == 0);
933 }
934 {
935 std::wcmatch m;
936 const wchar_t s[] = L"abbbc";
937 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
938 assert(m.size() == 1);
939 assert(!m.prefix().matched);
940 assert(m.prefix().first == s);
941 assert(m.prefix().second == m[0].first);
942 assert(!m.suffix().matched);
943 assert(m.suffix().first == m[0].second);
944 assert(m.suffix().second == m[0].second);
945 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
946 assert(m.position(0) == 0);
947 assert(m.str(0) == s);
948 }
949 {
950 std::wcmatch m;
951 const wchar_t s[] = L"abbbbc";
952 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
953 assert(m.size() == 1);
954 assert(!m.prefix().matched);
955 assert(m.prefix().first == s);
956 assert(m.prefix().second == m[0].first);
957 assert(!m.suffix().matched);
958 assert(m.suffix().first == m[0].second);
959 assert(m.suffix().second == m[0].second);
960 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
961 assert(m.position(0) == 0);
962 assert(m.str(0) == s);
963 }
964 {
965 std::wcmatch m;
966 const wchar_t s[] = L"abbbbbc";
967 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
968 assert(m.size() == 1);
969 assert(!m.prefix().matched);
970 assert(m.prefix().first == s);
971 assert(m.prefix().second == m[0].first);
972 assert(!m.suffix().matched);
973 assert(m.suffix().first == m[0].second);
974 assert(m.suffix().second == m[0].second);
975 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
976 assert(m.position(0) == 0);
977 assert(m.str(0) == s);
978 }
979 {
980 std::wcmatch m;
981 const wchar_t s[] = L"adefc";
982 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
983 assert(m.size() == 0);
984 }
985 {
986 std::wcmatch m;
987 const wchar_t s[] = L"abbbbbbc";
988 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
989 assert(m.size() == 0);
990 }
991 {
992 std::wcmatch m;
993 const wchar_t s[] = L"adec";
994 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
995 assert(m.size() == 0);
996 }
997 {
998 std::wcmatch m;
999 const wchar_t s[] = L"adefc";
1000 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1001 assert(m.size() == 1);
1002 assert(!m.prefix().matched);
1003 assert(m.prefix().first == s);
1004 assert(m.prefix().second == m[0].first);
1005 assert(!m.suffix().matched);
1006 assert(m.suffix().first == m[0].second);
1007 assert(m.suffix().second == m[0].second);
1008 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1009 assert(m.position(0) == 0);
1010 assert(m.str(0) == s);
1011 }
1012 {
1013 std::wcmatch m;
1014 const wchar_t s[] = L"adefgc";
1015 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1016 assert(m.size() == 1);
1017 assert(!m.prefix().matched);
1018 assert(m.prefix().first == s);
1019 assert(m.prefix().second == m[0].first);
1020 assert(!m.suffix().matched);
1021 assert(m.suffix().first == m[0].second);
1022 assert(m.suffix().second == m[0].second);
1023 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1024 assert(m.position(0) == 0);
1025 assert(m.str(0) == s);
1026 }
1027 {
1028 std::wcmatch m;
1029 const wchar_t s[] = L"adefghc";
1030 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1031 assert(m.size() == 1);
1032 assert(!m.prefix().matched);
1033 assert(m.prefix().first == s);
1034 assert(m.prefix().second == m[0].first);
1035 assert(!m.suffix().matched);
1036 assert(m.suffix().first == m[0].second);
1037 assert(m.suffix().second == m[0].second);
1038 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1039 assert(m.position(0) == 0);
1040 assert(m.str(0) == s);
1041 }
1042 {
1043 std::wcmatch m;
1044 const wchar_t s[] = L"adefghic";
1045 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1046 assert(m.size() == 0);
1047 }
1048 {
1049 std::wcmatch m;
1050 const wchar_t s[] = L"tournament";
1051 assert(std::regex_match(s, m, std::wregex(L"tour|to|tournament",
1052 std::regex_constants::awk)));
1053 assert(m.size() == 1);
1054 assert(!m.prefix().matched);
1055 assert(m.prefix().first == s);
1056 assert(m.prefix().second == m[0].first);
1057 assert(!m.suffix().matched);
1058 assert(m.suffix().first == m[0].second);
1059 assert(m.suffix().second == m[0].second);
1060 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1061 assert(m.position(0) == 0);
1062 assert(m.str(0) == s);
1063 }
1064 {
1065 std::wcmatch m;
1066 const wchar_t s[] = L"tournamenttotour";
1067 assert(std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+",
1068 std::regex_constants::awk | std::regex_constants::nosubs)));
1069 assert(m.size() == 1);
1070 assert(!m.prefix().matched);
1071 assert(m.prefix().first == s);
1072 assert(m.prefix().second == m[0].first);
1073 assert(!m.suffix().matched);
1074 assert(m.suffix().first == m[0].second);
1075 assert(m.suffix().second == m[0].second);
1076 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1077 assert(m.position(0) == 0);
1078 assert(m.str(0) == s);
1079 }
1080 {
1081 std::wcmatch m;
1082 const wchar_t s[] = L"ttotour";
1083 assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+",
1084 std::regex_constants::awk)));
1085 assert(m.size() == 2);
1086 assert(!m.prefix().matched);
1087 assert(m.prefix().first == s);
1088 assert(m.prefix().second == m[0].first);
1089 assert(!m.suffix().matched);
1090 assert(m.suffix().first == m[0].second);
1091 assert(m.suffix().second == m[0].second);
1092 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1093 assert(m.position(0) == 0);
1094 assert(m.str(0) == s);
1095 assert(m.length(1) == 4);
1096 assert(m.position(1) == 3);
1097 assert(m.str(1) == L"tour");
1098 }
1099 {
1100 std::wcmatch m;
1101 const wchar_t s[] = L"-ab,ab-";
1102 assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-", std::regex_constants::awk)));
1103 assert(m.size() == 0);
1104 }
1105 {
1106 std::wcmatch m;
1107 const wchar_t s[] = L"-ab,ab-";
1108 assert(std::regex_match(s, m, std::wregex(L"-.*,.*-", std::regex_constants::awk)));
1109 assert(m.size() == 1);
1110 assert(!m.prefix().matched);
1111 assert(m.prefix().first == s);
1112 assert(m.prefix().second == m[0].first);
1113 assert(!m.suffix().matched);
1114 assert(m.suffix().first == m[0].second);
1115 assert(m.suffix().second == m[0].second);
1116 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1117 assert(m.position(0) == 0);
1118 assert(m.str(0) == s);
1119 }
1120 {
1121 std::wcmatch m;
1122 const wchar_t s[] = L"a";
1123 assert(std::regex_match(s, m, std::wregex(L"^[a]$",
1124 std::regex_constants::awk)));
1125 assert(m.size() == 1);
1126 assert(!m.prefix().matched);
1127 assert(m.prefix().first == s);
1128 assert(m.prefix().second == m[0].first);
1129 assert(!m.suffix().matched);
1130 assert(m.suffix().first == m[0].second);
1131 assert(m.suffix().second == m[0].second);
1132 assert(m.length(0) == 1);
1133 assert(m.position(0) == 0);
1134 assert(m.str(0) == L"a");
1135 }
1136 {
1137 std::wcmatch m;
1138 const wchar_t s[] = L"a";
1139 assert(std::regex_match(s, m, std::wregex(L"^[ab]$",
1140 std::regex_constants::awk)));
1141 assert(m.size() == 1);
1142 assert(!m.prefix().matched);
1143 assert(m.prefix().first == s);
1144 assert(m.prefix().second == m[0].first);
1145 assert(!m.suffix().matched);
1146 assert(m.suffix().first == m[0].second);
1147 assert(m.suffix().second == m[0].second);
1148 assert(m.length(0) == 1);
1149 assert(m.position(0) == 0);
1150 assert(m.str(0) == L"a");
1151 }
1152 {
1153 std::wcmatch m;
1154 const wchar_t s[] = L"c";
1155 assert(std::regex_match(s, m, std::wregex(L"^[a-f]$",
1156 std::regex_constants::awk)));
1157 assert(m.size() == 1);
1158 assert(!m.prefix().matched);
1159 assert(m.prefix().first == s);
1160 assert(m.prefix().second == m[0].first);
1161 assert(!m.suffix().matched);
1162 assert(m.suffix().first == m[0].second);
1163 assert(m.suffix().second == m[0].second);
1164 assert(m.length(0) == 1);
1165 assert(m.position(0) == 0);
1166 assert(m.str(0) == s);
1167 }
1168 {
1169 std::wcmatch m;
1170 const wchar_t s[] = L"g";
1171 assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$",
1172 std::regex_constants::awk)));
1173 assert(m.size() == 0);
1174 }
1175 {
1176 std::wcmatch m;
1177 const wchar_t s[] = L"Iraqi";
1178 assert(!std::regex_match(s, m, std::wregex(L"q[^u]",
1179 std::regex_constants::awk)));
1180 assert(m.size() == 0);
1181 }
1182 {
1183 std::wcmatch m;
1184 const wchar_t s[] = L"Iraq";
1185 assert(!std::regex_match(s, m, std::wregex(L"q[^u]",
1186 std::regex_constants::awk)));
1187 assert(m.size() == 0);
1188 }
1189 {
1190 std::wcmatch m;
1191 const wchar_t s[] = L"AmB";
1192 assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B",
1193 std::regex_constants::awk)));
1194 assert(m.size() == 1);
1195 assert(!m.prefix().matched);
1196 assert(m.prefix().first == s);
1197 assert(m.prefix().second == m[0].first);
1198 assert(!m.suffix().matched);
1199 assert(m.suffix().first == m[0].second);
1200 assert(m.suffix().second == m[0].second);
1201 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1202 assert(m.position(0) == 0);
1203 assert(m.str(0) == s);
1204 }
1205 {
1206 std::wcmatch m;
1207 const wchar_t s[] = L"AMB";
1208 assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B",
1209 std::regex_constants::awk)));
1210 assert(m.size() == 0);
1211 }
1212 {
1213 std::wcmatch m;
1214 const wchar_t s[] = L"AMB";
1215 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B",
1216 std::regex_constants::awk)));
1217 assert(m.size() == 1);
1218 assert(!m.prefix().matched);
1219 assert(m.prefix().first == s);
1220 assert(m.prefix().second == m[0].first);
1221 assert(!m.suffix().matched);
1222 assert(m.suffix().first == m[0].second);
1223 assert(m.suffix().second == m[0].second);
1224 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1225 assert(m.position(0) == 0);
1226 assert(m.str(0) == s);
1227 }
1228 {
1229 std::wcmatch m;
1230 const wchar_t s[] = L"AmB";
1231 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B",
1232 std::regex_constants::awk)));
1233 assert(m.size() == 0);
1234 }
1235 {
1236 std::wcmatch m;
1237 const wchar_t s[] = L"A5B";
1238 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1239 std::regex_constants::awk)));
1240 assert(m.size() == 0);
1241 }
1242 {
1243 std::wcmatch m;
1244 const wchar_t s[] = L"A?B";
1245 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1246 std::regex_constants::awk)));
1247 assert(m.size() == 1);
1248 assert(!m.prefix().matched);
1249 assert(m.prefix().first == s);
1250 assert(m.prefix().second == m[0].first);
1251 assert(!m.suffix().matched);
1252 assert(m.suffix().first == m[0].second);
1253 assert(m.suffix().second == m[0].second);
1254 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1255 assert(m.position(0) == 0);
1256 assert(m.str(0) == s);
1257 }
1258 {
1259 std::wcmatch m;
1260 const wchar_t s[] = L"-";
1261 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1262 std::regex_constants::awk)));
1263 assert(m.size() == 1);
1264 assert(!m.prefix().matched);
1265 assert(m.prefix().first == s);
1266 assert(m.prefix().second == m[0].first);
1267 assert(!m.suffix().matched);
1268 assert(m.suffix().first == m[0].second);
1269 assert(m.suffix().second == m[0].second);
1270 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1271 assert(m.position(0) == 0);
1272 assert(m.str(0) == s);
1273 }
1274 {
1275 std::wcmatch m;
1276 const wchar_t s[] = L"z";
1277 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1278 std::regex_constants::awk)));
1279 assert(m.size() == 1);
1280 assert(!m.prefix().matched);
1281 assert(m.prefix().first == s);
1282 assert(m.prefix().second == m[0].first);
1283 assert(!m.suffix().matched);
1284 assert(m.suffix().first == m[0].second);
1285 assert(m.suffix().second == m[0].second);
1286 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1287 assert(m.position(0) == 0);
1288 assert(m.str(0) == s);
1289 }
1290 {
1291 std::wcmatch m;
1292 const wchar_t s[] = L"m";
1293 assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1294 std::regex_constants::awk)));
1295 assert(m.size() == 0);
1296 }
1297 std::locale::global(std::locale("cs_CZ.ISO8859-2"));
1298 {
1299 std::wcmatch m;
1300 const wchar_t s[] = L"m";
1301 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
1302 std::regex_constants::awk)));
1303 assert(m.size() == 1);
1304 assert(!m.prefix().matched);
1305 assert(m.prefix().first == s);
1306 assert(m.prefix().second == m[0].first);
1307 assert(!m.suffix().matched);
1308 assert(m.suffix().first == m[0].second);
1309 assert(m.suffix().second == m[0].second);
1310 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1311 assert(m.position(0) == 0);
1312 assert(m.str(0) == s);
1313 }
1314 {
1315 std::wcmatch m;
1316 const wchar_t s[] = L"Ch";
1317 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
1318 std::regex_constants::awk | std::regex_constants::icase)));
1319 assert(m.size() == 1);
1320 assert(!m.prefix().matched);
1321 assert(m.prefix().first == s);
1322 assert(m.prefix().second == m[0].first);
1323 assert(!m.suffix().matched);
1324 assert(m.suffix().first == m[0].second);
1325 assert(m.suffix().second == m[0].second);
1326 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1327 assert(m.position(0) == 0);
1328 assert(m.str(0) == s);
1329 }
1330 std::locale::global(std::locale("C"));
1331 {
1332 std::wcmatch m;
1333 const wchar_t s[] = L"m";
1334 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
1335 std::regex_constants::awk)));
1336 assert(m.size() == 0);
1337 }
1338 {
1339 std::wcmatch m;
1340 const wchar_t s[] = L"01a45cef9";
1341 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*",
1342 std::regex_constants::awk)));
1343 assert(m.size() == 0);
1344 }
1345 {
1346 std::wcmatch m;
1347 const wchar_t s[] = L"01a45cef9";
1348 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+",
1349 std::regex_constants::awk)));
1350 assert(m.size() == 0);
1351 }
1352 {
1353 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
1354 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
1355 typedef forward_iterator<const wchar_t*> FI;
1356 typedef bidirectional_iterator<const wchar_t*> BI;
1357 std::wregex regex(FI(r), FI(r+sr), std::regex_constants::awk);
1358 std::match_results<BI> m;
1359 const wchar_t s[] = L"-40C";
1360 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
1361 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
1362 assert(m.size() == 1);
1363 assert(!m.prefix().matched);
1364 assert(m.prefix().first == BI(s));
1365 assert(m.prefix().second == m[0].first);
1366 assert(!m.suffix().matched);
1367 assert(m.suffix().first == m[0].second);
1368 assert(m.suffix().second == m[0].second);
1369 assert(m.length(0) == 4);
1370 assert(m.position(0) == 0);
1371 assert(m.str(0) == s);
1372 }
1373 {
1374 std::wcmatch m;
1375 const wchar_t s[] = L"\n\n\n";
1376 assert(std::regex_match(s, m, std::wregex(L"[\\n]+",
1377 std::regex_constants::awk)));
1378 assert(m.size() == 1);
1379 assert(!m.prefix().matched);
1380 assert(m.prefix().first == s);
1381 assert(m.prefix().second == m[0].first);
1382 assert(!m.suffix().matched);
1383 assert(m.suffix().first == m[0].second);
1384 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1385 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1386 assert(m.position(0) == 0);
1387 assert(m.str(0) == s);
1388 }
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001389*/}