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