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