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