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