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