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