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