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