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