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