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