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