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