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