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