1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // REQUIRES: locale.cs_CZ.ISO8859-2
11 
12 // <regex>
13 
14 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
15 //     bool
16 //     regex_search(BidirectionalIterator first, BidirectionalIterator last,
17 //                  match_results<BidirectionalIterator, Allocator>& m,
18 //                  const basic_regex<charT, traits>& e,
19 //                  regex_constants::match_flag_type flags = regex_constants::match_default);
20 
21 // TODO: investigation needed
22 // XFAIL: linux-gnu
23 
24 #include <regex>
25 #include <cassert>
26 #include "test_iterators.h"
27 
28 #include "platform_support.h" // locale name macros
29 
main()30 int main()
31 {
32     {
33         std::cmatch m;
34         const char s[] = "a";
35         assert(std::regex_search(s, m, std::regex("a", std::regex_constants::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk),
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
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::awk)));
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::awk)));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
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) == std::char_traits<char>::length(s));
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::awk)));
433         assert(m.size() == 0);
434     }
435     {
436         std::cmatch m;
437         const char s[] = "tournament";
438         assert(std::regex_search(s, m, std::regex("tour|to|tournament",
439                                               std::regex_constants::awk)));
440         assert(m.size() == 1);
441         assert(!m.prefix().matched);
442         assert(m.prefix().first == s);
443         assert(m.prefix().second == m[0].first);
444         assert(!m.suffix().matched);
445         assert(m.suffix().first == m[0].second);
446         assert(m.suffix().second == m[0].second);
447         assert(m.length(0) == std::char_traits<char>::length(s));
448         assert(m.position(0) == 0);
449         assert(m.str(0) == s);
450     }
451     {
452         std::cmatch m;
453         const char s[] = "tournamenttotour";
454         assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+",
455                std::regex_constants::awk | std::regex_constants::nosubs)));
456         assert(m.size() == 1);
457         assert(!m.prefix().matched);
458         assert(m.prefix().first == s);
459         assert(m.prefix().second == m[0].first);
460         assert(!m.suffix().matched);
461         assert(m.suffix().first == m[0].second);
462         assert(m.suffix().second == m[0].second);
463         assert(m.length(0) == std::char_traits<char>::length(s));
464         assert(m.position(0) == 0);
465         assert(m.str(0) == s);
466     }
467     {
468         std::cmatch m;
469         const char s[] = "ttotour";
470         assert(std::regex_search(s, m, std::regex("(tour|to|t)+",
471                                               std::regex_constants::awk)));
472         assert(m.size() == 2);
473         assert(!m.prefix().matched);
474         assert(m.prefix().first == s);
475         assert(m.prefix().second == m[0].first);
476         assert(!m.suffix().matched);
477         assert(m.suffix().first == m[0].second);
478         assert(m.suffix().second == m[0].second);
479         assert(m.length(0) == std::char_traits<char>::length(s));
480         assert(m.position(0) == 0);
481         assert(m.str(0) == s);
482         assert(m.length(1) == 4);
483         assert(m.position(1) == 3);
484         assert(m.str(1) == "tour");
485     }
486     {
487         std::cmatch m;
488         const char s[] = "-ab,ab-";
489         assert(!std::regex_search(s, m, std::regex("-(.*),\1-", std::regex_constants::awk)));
490         assert(m.size() == 0);
491     }
492     {
493         std::cmatch m;
494         const char s[] = "-ab,ab-";
495         assert(std::regex_search(s, m, std::regex("-.*,.*-", std::regex_constants::awk)));
496         assert(m.size() == 1);
497         assert(!m.prefix().matched);
498         assert(m.prefix().first == s);
499         assert(m.prefix().second == m[0].first);
500         assert(!m.suffix().matched);
501         assert(m.suffix().first == m[0].second);
502         assert(m.suffix().second == m[0].second);
503         assert(m.length(0) == std::char_traits<char>::length(s));
504         assert(m.position(0) == 0);
505         assert(m.str(0) == s);
506     }
507     {
508         std::cmatch m;
509         const char s[] = "a";
510         assert(std::regex_search(s, m, std::regex("^[a]$",
511                                                  std::regex_constants::awk)));
512         assert(m.size() == 1);
513         assert(!m.prefix().matched);
514         assert(m.prefix().first == s);
515         assert(m.prefix().second == m[0].first);
516         assert(!m.suffix().matched);
517         assert(m.suffix().first == m[0].second);
518         assert(m.suffix().second == m[0].second);
519         assert(m.length(0) == 1);
520         assert(m.position(0) == 0);
521         assert(m.str(0) == "a");
522     }
523     {
524         std::cmatch m;
525         const char s[] = "a";
526         assert(std::regex_search(s, m, std::regex("^[ab]$",
527                                                  std::regex_constants::awk)));
528         assert(m.size() == 1);
529         assert(!m.prefix().matched);
530         assert(m.prefix().first == s);
531         assert(m.prefix().second == m[0].first);
532         assert(!m.suffix().matched);
533         assert(m.suffix().first == m[0].second);
534         assert(m.suffix().second == m[0].second);
535         assert(m.length(0) == 1);
536         assert(m.position(0) == 0);
537         assert(m.str(0) == "a");
538     }
539     {
540         std::cmatch m;
541         const char s[] = "c";
542         assert(std::regex_search(s, m, std::regex("^[a-f]$",
543                                                  std::regex_constants::awk)));
544         assert(m.size() == 1);
545         assert(!m.prefix().matched);
546         assert(m.prefix().first == s);
547         assert(m.prefix().second == m[0].first);
548         assert(!m.suffix().matched);
549         assert(m.suffix().first == m[0].second);
550         assert(m.suffix().second == m[0].second);
551         assert(m.length(0) == 1);
552         assert(m.position(0) == 0);
553         assert(m.str(0) == s);
554     }
555     {
556         std::cmatch m;
557         const char s[] = "g";
558         assert(!std::regex_search(s, m, std::regex("^[a-f]$",
559                                                  std::regex_constants::awk)));
560         assert(m.size() == 0);
561     }
562     {
563         std::cmatch m;
564         const char s[] = "Iraqi";
565         assert(std::regex_search(s, m, std::regex("q[^u]",
566                                                  std::regex_constants::awk)));
567         assert(m.size() == 1);
568         assert(m.prefix().matched);
569         assert(m.prefix().first == s);
570         assert(m.prefix().second == m[0].first);
571         assert(!m.suffix().matched);
572         assert(m.suffix().first == m[0].second);
573         assert(m.suffix().second == m[0].second);
574         assert(m.length(0) == 2);
575         assert(m.position(0) == 3);
576         assert(m.str(0) == "qi");
577     }
578     {
579         std::cmatch m;
580         const char s[] = "Iraq";
581         assert(!std::regex_search(s, m, std::regex("q[^u]",
582                                                  std::regex_constants::awk)));
583         assert(m.size() == 0);
584     }
585     {
586         std::cmatch m;
587         const char s[] = "AmB";
588         assert(std::regex_search(s, m, std::regex("A[[:lower:]]B",
589                                                  std::regex_constants::awk)));
590         assert(m.size() == 1);
591         assert(!m.prefix().matched);
592         assert(m.prefix().first == s);
593         assert(m.prefix().second == m[0].first);
594         assert(!m.suffix().matched);
595         assert(m.suffix().first == m[0].second);
596         assert(m.suffix().second == m[0].second);
597         assert(m.length(0) == std::char_traits<char>::length(s));
598         assert(m.position(0) == 0);
599         assert(m.str(0) == s);
600     }
601     {
602         std::cmatch m;
603         const char s[] = "AMB";
604         assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B",
605                                                  std::regex_constants::awk)));
606         assert(m.size() == 0);
607     }
608     {
609         std::cmatch m;
610         const char s[] = "AMB";
611         assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B",
612                                                  std::regex_constants::awk)));
613         assert(m.size() == 1);
614         assert(!m.prefix().matched);
615         assert(m.prefix().first == s);
616         assert(m.prefix().second == m[0].first);
617         assert(!m.suffix().matched);
618         assert(m.suffix().first == m[0].second);
619         assert(m.suffix().second == m[0].second);
620         assert(m.length(0) == std::char_traits<char>::length(s));
621         assert(m.position(0) == 0);
622         assert(m.str(0) == s);
623     }
624     {
625         std::cmatch m;
626         const char s[] = "AmB";
627         assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B",
628                                                  std::regex_constants::awk)));
629         assert(m.size() == 0);
630     }
631     {
632         std::cmatch m;
633         const char s[] = "A5B";
634         assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B",
635                                                  std::regex_constants::awk)));
636         assert(m.size() == 0);
637     }
638     {
639         std::cmatch m;
640         const char s[] = "A?B";
641         assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B",
642                                                  std::regex_constants::awk)));
643         assert(m.size() == 1);
644         assert(!m.prefix().matched);
645         assert(m.prefix().first == s);
646         assert(m.prefix().second == m[0].first);
647         assert(!m.suffix().matched);
648         assert(m.suffix().first == m[0].second);
649         assert(m.suffix().second == m[0].second);
650         assert(m.length(0) == std::char_traits<char>::length(s));
651         assert(m.position(0) == 0);
652         assert(m.str(0) == s);
653     }
654     {
655         std::cmatch m;
656         const char s[] = "-";
657         assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]",
658                                                  std::regex_constants::awk)));
659         assert(m.size() == 1);
660         assert(!m.prefix().matched);
661         assert(m.prefix().first == s);
662         assert(m.prefix().second == m[0].first);
663         assert(!m.suffix().matched);
664         assert(m.suffix().first == m[0].second);
665         assert(m.suffix().second == m[0].second);
666         assert(m.length(0) == std::char_traits<char>::length(s));
667         assert(m.position(0) == 0);
668         assert(m.str(0) == s);
669     }
670     {
671         std::cmatch m;
672         const char s[] = "z";
673         assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]",
674                                                  std::regex_constants::awk)));
675         assert(m.size() == 1);
676         assert(!m.prefix().matched);
677         assert(m.prefix().first == s);
678         assert(m.prefix().second == m[0].first);
679         assert(!m.suffix().matched);
680         assert(m.suffix().first == m[0].second);
681         assert(m.suffix().second == m[0].second);
682         assert(m.length(0) == std::char_traits<char>::length(s));
683         assert(m.position(0) == 0);
684         assert(m.str(0) == s);
685     }
686     {
687         std::cmatch m;
688         const char s[] = "m";
689         assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]",
690                                                  std::regex_constants::awk)));
691         assert(m.size() == 0);
692     }
693     std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
694     {
695         std::cmatch m;
696         const char s[] = "m";
697         assert(std::regex_search(s, m, std::regex("[a[=M=]z]",
698                                                  std::regex_constants::awk)));
699         assert(m.size() == 1);
700         assert(!m.prefix().matched);
701         assert(m.prefix().first == s);
702         assert(m.prefix().second == m[0].first);
703         assert(!m.suffix().matched);
704         assert(m.suffix().first == m[0].second);
705         assert(m.suffix().second == m[0].second);
706         assert(m.length(0) == std::char_traits<char>::length(s));
707         assert(m.position(0) == 0);
708         assert(m.str(0) == s);
709     }
710     {
711         std::cmatch m;
712         const char s[] = "Ch";
713         assert(std::regex_search(s, m, std::regex("[a[.ch.]z]",
714                    std::regex_constants::awk | std::regex_constants::icase)));
715         assert(m.size() == 1);
716         assert(!m.prefix().matched);
717         assert(m.prefix().first == s);
718         assert(m.prefix().second == m[0].first);
719         assert(!m.suffix().matched);
720         assert(m.suffix().first == m[0].second);
721         assert(m.suffix().second == m[0].second);
722         assert(m.length(0) == std::char_traits<char>::length(s));
723         assert(m.position(0) == 0);
724         assert(m.str(0) == s);
725     }
726     std::locale::global(std::locale("C"));
727     {
728         std::cmatch m;
729         const char s[] = "m";
730         assert(!std::regex_search(s, m, std::regex("[a[=M=]z]",
731                                                  std::regex_constants::awk)));
732         assert(m.size() == 0);
733     }
734     {
735         std::cmatch m;
736         const char s[] = "01a45cef9";
737         assert(std::regex_search(s, m, std::regex("[ace1-9]*",
738                                                  std::regex_constants::awk)));
739         assert(m.size() == 1);
740         assert(!m.prefix().matched);
741         assert(m.prefix().first == s);
742         assert(m.prefix().second == m[0].first);
743         assert(m.suffix().matched);
744         assert(m.suffix().first == m[0].second);
745         assert(m.suffix().second == s + std::char_traits<char>::length(s));
746         assert(m.length(0) == 0);
747         assert(m.position(0) == 0);
748         assert(m.str(0) == "");
749     }
750     {
751         std::cmatch m;
752         const char s[] = "01a45cef9";
753         assert(std::regex_search(s, m, std::regex("[ace1-9]+",
754                                                  std::regex_constants::awk)));
755         assert(m.size() == 1);
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 + std::char_traits<char>::length(s));
762         assert(m.length(0) == 6);
763         assert(m.position(0) == 1);
764         assert(m.str(0) == "1a45ce");
765     }
766     {
767         const char r[] = "^[-+]?[0-9]+[CF]$";
768         std::ptrdiff_t sr = std::char_traits<char>::length(r);
769         typedef forward_iterator<const char*> FI;
770         typedef bidirectional_iterator<const char*> BI;
771         std::regex regex(FI(r), FI(r+sr), std::regex_constants::awk);
772         std::match_results<BI> m;
773         const char s[] = "-40C";
774         std::ptrdiff_t ss = std::char_traits<char>::length(s);
775         assert(std::regex_search(BI(s), BI(s+ss), m, regex));
776         assert(m.size() == 1);
777         assert(!m.prefix().matched);
778         assert(m.prefix().first == BI(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 == m[0].second);
783         assert(m.length(0) == 4);
784         assert(m.position(0) == 0);
785         assert(m.str(0) == s);
786     }
787     {
788         std::cmatch m;
789         const char s[] = "\n\n\n";
790         assert(std::regex_search(s, m, std::regex("[\\n]+",
791                                                  std::regex_constants::awk)));
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 + std::char_traits<char>::length(s));
799         assert(m.length(0) == std::char_traits<char>::length(s));
800         assert(m.position(0) == 0);
801         assert(m.str(0) == s);
802     }
803     {
804         std::wcmatch m;
805         const wchar_t s[] = L"a";
806         assert(std::regex_search(s, m, std::wregex(L"a", std::regex_constants::awk)));
807         assert(m.size() == 1);
808         assert(!m.empty());
809         assert(!m.prefix().matched);
810         assert(m.prefix().first == s);
811         assert(m.prefix().second == m[0].first);
812         assert(!m.suffix().matched);
813         assert(m.suffix().first == m[0].second);
814         assert(m.suffix().second == s+1);
815         assert(m.length(0) == 1);
816         assert(m.position(0) == 0);
817         assert(m.str(0) == L"a");
818     }
819     {
820         std::wcmatch m;
821         const wchar_t s[] = L"ab";
822         assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk)));
823         assert(m.size() == 1);
824         assert(!m.prefix().matched);
825         assert(m.prefix().first == s);
826         assert(m.prefix().second == m[0].first);
827         assert(!m.suffix().matched);
828         assert(m.suffix().first == m[0].second);
829         assert(m.suffix().second == s+2);
830         assert(m.length(0) == 2);
831         assert(m.position(0) == 0);
832         assert(m.str(0) == L"ab");
833     }
834     {
835         std::wcmatch m;
836         const wchar_t s[] = L"ab";
837         assert(!std::regex_search(s, m, std::wregex(L"ba", std::regex_constants::awk)));
838         assert(m.size() == 0);
839         assert(m.empty());
840     }
841     {
842         std::wcmatch m;
843         const wchar_t s[] = L"aab";
844         assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk)));
845         assert(m.size() == 1);
846         assert(m.prefix().matched);
847         assert(m.prefix().first == s);
848         assert(m.prefix().second == m[0].first);
849         assert(!m.suffix().matched);
850         assert(m.suffix().first == m[0].second);
851         assert(m.suffix().second == s+3);
852         assert(m.length(0) == 2);
853         assert(m.position(0) == 1);
854         assert(m.str(0) == L"ab");
855     }
856     {
857         std::wcmatch m;
858         const wchar_t s[] = L"aab";
859         assert(!std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk),
860                                             std::regex_constants::match_continuous));
861         assert(m.size() == 0);
862     }
863     {
864         std::wcmatch m;
865         const wchar_t s[] = L"abcd";
866         assert(std::regex_search(s, m, std::wregex(L"bc", std::regex_constants::awk)));
867         assert(m.size() == 1);
868         assert(m.prefix().matched);
869         assert(m.prefix().first == s);
870         assert(m.prefix().second == m[0].first);
871         assert(m.suffix().matched);
872         assert(m.suffix().first == m[0].second);
873         assert(m.suffix().second == s+4);
874         assert(m.length(0) == 2);
875         assert(m.position(0) == 1);
876         assert(m.str(0) == L"bc");
877     }
878     {
879         std::wcmatch m;
880         const wchar_t s[] = L"abbc";
881         assert(std::regex_search(s, m, std::wregex(L"ab*c", std::regex_constants::awk)));
882         assert(m.size() == 1);
883         assert(!m.prefix().matched);
884         assert(m.prefix().first == s);
885         assert(m.prefix().second == m[0].first);
886         assert(!m.suffix().matched);
887         assert(m.suffix().first == m[0].second);
888         assert(m.suffix().second == s+4);
889         assert(m.length(0) == 4);
890         assert(m.position(0) == 0);
891         assert(m.str(0) == s);
892     }
893     {
894         std::wcmatch m;
895         const wchar_t s[] = L"ababc";
896         assert(std::regex_search(s, m, std::wregex(L"(ab)*c", std::regex_constants::awk)));
897         assert(m.size() == 2);
898         assert(!m.prefix().matched);
899         assert(m.prefix().first == s);
900         assert(m.prefix().second == m[0].first);
901         assert(!m.suffix().matched);
902         assert(m.suffix().first == m[0].second);
903         assert(m.suffix().second == s+5);
904         assert(m.length(0) == 5);
905         assert(m.position(0) == 0);
906         assert(m.str(0) == s);
907         assert(m.length(1) == 2);
908         assert(m.position(1) == 2);
909         assert(m.str(1) == L"ab");
910     }
911     {
912         std::wcmatch m;
913         const wchar_t s[] = L"abcdefghijk";
914         assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi",
915                                  std::regex_constants::awk)));
916         assert(m.size() == 3);
917         assert(m.prefix().matched);
918         assert(m.prefix().first == s);
919         assert(m.prefix().second == m[0].first);
920         assert(m.suffix().matched);
921         assert(m.suffix().first == m[0].second);
922         assert(m.suffix().second == s+std::regex_traits<wchar_t>::length(s));
923         assert(m.length(0) == 7);
924         assert(m.position(0) == 2);
925         assert(m.str(0) == L"cdefghi");
926         assert(m.length(1) == 3);
927         assert(m.position(1) == 4);
928         assert(m.str(1) == L"efg");
929         assert(m.length(2) == 1);
930         assert(m.position(2) == 4);
931         assert(m.str(2) == L"e");
932     }
933     {
934         std::wcmatch m;
935         const wchar_t s[] = L"abc";
936         assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
937         assert(m.size() == 1);
938         assert(!m.prefix().matched);
939         assert(m.prefix().first == s);
940         assert(m.prefix().second == m[0].first);
941         assert(!m.suffix().matched);
942         assert(m.suffix().first == m[0].second);
943         assert(m.suffix().second == s+3);
944         assert(m.length(0) == 3);
945         assert(m.position(0) == 0);
946         assert(m.str(0) == s);
947     }
948     {
949         std::wcmatch m;
950         const wchar_t s[] = L"abcd";
951         assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
952         assert(m.size() == 1);
953         assert(!m.prefix().matched);
954         assert(m.prefix().first == s);
955         assert(m.prefix().second == m[0].first);
956         assert(m.suffix().matched);
957         assert(m.suffix().first == m[0].second);
958         assert(m.suffix().second == s+4);
959         assert(m.length(0) == 3);
960         assert(m.position(0) == 0);
961         assert(m.str(0) == L"abc");
962     }
963     {
964         std::wcmatch m;
965         const wchar_t s[] = L"aabc";
966         assert(!std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk)));
967         assert(m.size() == 0);
968     }
969     {
970         std::wcmatch m;
971         const wchar_t s[] = L"abc";
972         assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
973         assert(m.size() == 1);
974         assert(!m.prefix().matched);
975         assert(m.prefix().first == s);
976         assert(m.prefix().second == m[0].first);
977         assert(!m.suffix().matched);
978         assert(m.suffix().first == m[0].second);
979         assert(m.suffix().second == s+3);
980         assert(m.length(0) == 3);
981         assert(m.position(0) == 0);
982         assert(m.str(0) == s);
983     }
984     {
985         std::wcmatch m;
986         const wchar_t s[] = L"efabc";
987         assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
988         assert(m.size() == 1);
989         assert(m.prefix().matched);
990         assert(m.prefix().first == s);
991         assert(m.prefix().second == m[0].first);
992         assert(!m.suffix().matched);
993         assert(m.suffix().first == m[0].second);
994         assert(m.suffix().second == s+5);
995         assert(m.length(0) == 3);
996         assert(m.position(0) == 2);
997         assert(m.str(0) == s+2);
998     }
999     {
1000         std::wcmatch m;
1001         const wchar_t s[] = L"efabcg";
1002         assert(!std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk)));
1003         assert(m.size() == 0);
1004     }
1005     {
1006         std::wcmatch m;
1007         const wchar_t s[] = L"abc";
1008         assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
1009         assert(m.size() == 1);
1010         assert(!m.prefix().matched);
1011         assert(m.prefix().first == s);
1012         assert(m.prefix().second == m[0].first);
1013         assert(!m.suffix().matched);
1014         assert(m.suffix().first == m[0].second);
1015         assert(m.suffix().second == s+3);
1016         assert(m.length(0) == 3);
1017         assert(m.position(0) == 0);
1018         assert(m.str(0) == s);
1019     }
1020     {
1021         std::wcmatch m;
1022         const wchar_t s[] = L"acc";
1023         assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
1024         assert(m.size() == 1);
1025         assert(!m.prefix().matched);
1026         assert(m.prefix().first == s);
1027         assert(m.prefix().second == m[0].first);
1028         assert(!m.suffix().matched);
1029         assert(m.suffix().first == m[0].second);
1030         assert(m.suffix().second == s+3);
1031         assert(m.length(0) == 3);
1032         assert(m.position(0) == 0);
1033         assert(m.str(0) == s);
1034     }
1035     {
1036         std::wcmatch m;
1037         const wchar_t s[] = L"acc";
1038         assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk)));
1039         assert(m.size() == 1);
1040         assert(!m.prefix().matched);
1041         assert(m.prefix().first == s);
1042         assert(m.prefix().second == m[0].first);
1043         assert(!m.suffix().matched);
1044         assert(m.suffix().first == m[0].second);
1045         assert(m.suffix().second == s+3);
1046         assert(m.length(0) == 3);
1047         assert(m.position(0) == 0);
1048         assert(m.str(0) == s);
1049     }
1050     {
1051         std::wcmatch m;
1052         const wchar_t s[] = L"abcdef";
1053         assert(std::regex_search(s, m, std::wregex(L"(.*).*", std::regex_constants::awk)));
1054         assert(m.size() == 2);
1055         assert(!m.prefix().matched);
1056         assert(m.prefix().first == s);
1057         assert(m.prefix().second == m[0].first);
1058         assert(!m.suffix().matched);
1059         assert(m.suffix().first == m[0].second);
1060         assert(m.suffix().second == s+6);
1061         assert(m.length(0) == 6);
1062         assert(m.position(0) == 0);
1063         assert(m.str(0) == s);
1064         assert(m.length(1) == 6);
1065         assert(m.position(1) == 0);
1066         assert(m.str(1) == s);
1067     }
1068     {
1069         std::wcmatch m;
1070         const wchar_t s[] = L"bc";
1071         assert(std::regex_search(s, m, std::wregex(L"(a*)*", std::regex_constants::awk)));
1072         assert(m.size() == 2);
1073         assert(!m.prefix().matched);
1074         assert(m.prefix().first == s);
1075         assert(m.prefix().second == m[0].first);
1076         assert(m.suffix().matched);
1077         assert(m.suffix().first == m[0].second);
1078         assert(m.suffix().second == s+2);
1079         assert(m.length(0) == 0);
1080         assert(m.position(0) == 0);
1081         assert(m.str(0) == L"");
1082         assert(m.length(1) == 0);
1083         assert(m.position(1) == 0);
1084         assert(m.str(1) == L"");
1085     }
1086     {
1087         std::wcmatch m;
1088         const wchar_t s[] = L"abbc";
1089         assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1090         assert(m.size() == 0);
1091     }
1092     {
1093         std::wcmatch m;
1094         const wchar_t s[] = L"abbbc";
1095         assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1096         assert(m.size() == 1);
1097         assert(!m.prefix().matched);
1098         assert(m.prefix().first == s);
1099         assert(m.prefix().second == m[0].first);
1100         assert(!m.suffix().matched);
1101         assert(m.suffix().first == m[0].second);
1102         assert(m.suffix().second == m[0].second);
1103         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1104         assert(m.position(0) == 0);
1105         assert(m.str(0) == s);
1106     }
1107     {
1108         std::wcmatch m;
1109         const wchar_t s[] = L"abbbbc";
1110         assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1111         assert(m.size() == 1);
1112         assert(!m.prefix().matched);
1113         assert(m.prefix().first == s);
1114         assert(m.prefix().second == m[0].first);
1115         assert(!m.suffix().matched);
1116         assert(m.suffix().first == m[0].second);
1117         assert(m.suffix().second == m[0].second);
1118         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1119         assert(m.position(0) == 0);
1120         assert(m.str(0) == s);
1121     }
1122     {
1123         std::wcmatch m;
1124         const wchar_t s[] = L"abbbbbc";
1125         assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1126         assert(m.size() == 1);
1127         assert(!m.prefix().matched);
1128         assert(m.prefix().first == s);
1129         assert(m.prefix().second == m[0].first);
1130         assert(!m.suffix().matched);
1131         assert(m.suffix().first == m[0].second);
1132         assert(m.suffix().second == m[0].second);
1133         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1134         assert(m.position(0) == 0);
1135         assert(m.str(0) == s);
1136     }
1137     {
1138         std::wcmatch m;
1139         const wchar_t s[] = L"adefc";
1140         assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1141         assert(m.size() == 0);
1142     }
1143     {
1144         std::wcmatch m;
1145         const wchar_t s[] = L"abbbbbbc";
1146         assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk)));
1147         assert(m.size() == 0);
1148     }
1149     {
1150         std::wcmatch m;
1151         const wchar_t s[] = L"adec";
1152         assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1153         assert(m.size() == 0);
1154     }
1155     {
1156         std::wcmatch m;
1157         const wchar_t s[] = L"adefc";
1158         assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1159         assert(m.size() == 1);
1160         assert(!m.prefix().matched);
1161         assert(m.prefix().first == s);
1162         assert(m.prefix().second == m[0].first);
1163         assert(!m.suffix().matched);
1164         assert(m.suffix().first == m[0].second);
1165         assert(m.suffix().second == m[0].second);
1166         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1167         assert(m.position(0) == 0);
1168         assert(m.str(0) == s);
1169     }
1170     {
1171         std::wcmatch m;
1172         const wchar_t s[] = L"adefgc";
1173         assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1174         assert(m.size() == 1);
1175         assert(!m.prefix().matched);
1176         assert(m.prefix().first == s);
1177         assert(m.prefix().second == m[0].first);
1178         assert(!m.suffix().matched);
1179         assert(m.suffix().first == m[0].second);
1180         assert(m.suffix().second == m[0].second);
1181         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1182         assert(m.position(0) == 0);
1183         assert(m.str(0) == s);
1184     }
1185     {
1186         std::wcmatch m;
1187         const wchar_t s[] = L"adefghc";
1188         assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1189         assert(m.size() == 1);
1190         assert(!m.prefix().matched);
1191         assert(m.prefix().first == s);
1192         assert(m.prefix().second == m[0].first);
1193         assert(!m.suffix().matched);
1194         assert(m.suffix().first == m[0].second);
1195         assert(m.suffix().second == m[0].second);
1196         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1197         assert(m.position(0) == 0);
1198         assert(m.str(0) == s);
1199     }
1200     {
1201         std::wcmatch m;
1202         const wchar_t s[] = L"adefghic";
1203         assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk)));
1204         assert(m.size() == 0);
1205     }
1206     {
1207         std::wcmatch m;
1208         const wchar_t s[] = L"tournament";
1209         assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament",
1210                                               std::regex_constants::awk)));
1211         assert(m.size() == 1);
1212         assert(!m.prefix().matched);
1213         assert(m.prefix().first == s);
1214         assert(m.prefix().second == m[0].first);
1215         assert(!m.suffix().matched);
1216         assert(m.suffix().first == m[0].second);
1217         assert(m.suffix().second == m[0].second);
1218         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1219         assert(m.position(0) == 0);
1220         assert(m.str(0) == s);
1221     }
1222     {
1223         std::wcmatch m;
1224         const wchar_t s[] = L"tournamenttotour";
1225         assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+",
1226                std::regex_constants::awk | std::regex_constants::nosubs)));
1227         assert(m.size() == 1);
1228         assert(!m.prefix().matched);
1229         assert(m.prefix().first == s);
1230         assert(m.prefix().second == m[0].first);
1231         assert(!m.suffix().matched);
1232         assert(m.suffix().first == m[0].second);
1233         assert(m.suffix().second == m[0].second);
1234         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1235         assert(m.position(0) == 0);
1236         assert(m.str(0) == s);
1237     }
1238     {
1239         std::wcmatch m;
1240         const wchar_t s[] = L"ttotour";
1241         assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+",
1242                                               std::regex_constants::awk)));
1243         assert(m.size() == 2);
1244         assert(!m.prefix().matched);
1245         assert(m.prefix().first == s);
1246         assert(m.prefix().second == m[0].first);
1247         assert(!m.suffix().matched);
1248         assert(m.suffix().first == m[0].second);
1249         assert(m.suffix().second == m[0].second);
1250         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1251         assert(m.position(0) == 0);
1252         assert(m.str(0) == s);
1253         assert(m.length(1) == 4);
1254         assert(m.position(1) == 3);
1255         assert(m.str(1) == L"tour");
1256     }
1257     {
1258         std::wcmatch m;
1259         const wchar_t s[] = L"-ab,ab-";
1260         assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-", std::regex_constants::awk)));
1261         assert(m.size() == 0);
1262     }
1263     {
1264         std::wcmatch m;
1265         const wchar_t s[] = L"-ab,ab-";
1266         assert(std::regex_search(s, m, std::wregex(L"-.*,.*-", std::regex_constants::awk)));
1267         assert(m.size() == 1);
1268         assert(!m.prefix().matched);
1269         assert(m.prefix().first == s);
1270         assert(m.prefix().second == m[0].first);
1271         assert(!m.suffix().matched);
1272         assert(m.suffix().first == m[0].second);
1273         assert(m.suffix().second == m[0].second);
1274         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1275         assert(m.position(0) == 0);
1276         assert(m.str(0) == s);
1277     }
1278     {
1279         std::wcmatch m;
1280         const wchar_t s[] = L"a";
1281         assert(std::regex_search(s, m, std::wregex(L"^[a]$",
1282                                                  std::regex_constants::awk)));
1283         assert(m.size() == 1);
1284         assert(!m.prefix().matched);
1285         assert(m.prefix().first == s);
1286         assert(m.prefix().second == m[0].first);
1287         assert(!m.suffix().matched);
1288         assert(m.suffix().first == m[0].second);
1289         assert(m.suffix().second == m[0].second);
1290         assert(m.length(0) == 1);
1291         assert(m.position(0) == 0);
1292         assert(m.str(0) == L"a");
1293     }
1294     {
1295         std::wcmatch m;
1296         const wchar_t s[] = L"a";
1297         assert(std::regex_search(s, m, std::wregex(L"^[ab]$",
1298                                                  std::regex_constants::awk)));
1299         assert(m.size() == 1);
1300         assert(!m.prefix().matched);
1301         assert(m.prefix().first == s);
1302         assert(m.prefix().second == m[0].first);
1303         assert(!m.suffix().matched);
1304         assert(m.suffix().first == m[0].second);
1305         assert(m.suffix().second == m[0].second);
1306         assert(m.length(0) == 1);
1307         assert(m.position(0) == 0);
1308         assert(m.str(0) == L"a");
1309     }
1310     {
1311         std::wcmatch m;
1312         const wchar_t s[] = L"c";
1313         assert(std::regex_search(s, m, std::wregex(L"^[a-f]$",
1314                                                  std::regex_constants::awk)));
1315         assert(m.size() == 1);
1316         assert(!m.prefix().matched);
1317         assert(m.prefix().first == s);
1318         assert(m.prefix().second == m[0].first);
1319         assert(!m.suffix().matched);
1320         assert(m.suffix().first == m[0].second);
1321         assert(m.suffix().second == m[0].second);
1322         assert(m.length(0) == 1);
1323         assert(m.position(0) == 0);
1324         assert(m.str(0) == s);
1325     }
1326     {
1327         std::wcmatch m;
1328         const wchar_t s[] = L"g";
1329         assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$",
1330                                                  std::regex_constants::awk)));
1331         assert(m.size() == 0);
1332     }
1333     {
1334         std::wcmatch m;
1335         const wchar_t s[] = L"Iraqi";
1336         assert(std::regex_search(s, m, std::wregex(L"q[^u]",
1337                                                  std::regex_constants::awk)));
1338         assert(m.size() == 1);
1339         assert(m.prefix().matched);
1340         assert(m.prefix().first == s);
1341         assert(m.prefix().second == m[0].first);
1342         assert(!m.suffix().matched);
1343         assert(m.suffix().first == m[0].second);
1344         assert(m.suffix().second == m[0].second);
1345         assert(m.length(0) == 2);
1346         assert(m.position(0) == 3);
1347         assert(m.str(0) == L"qi");
1348     }
1349     {
1350         std::wcmatch m;
1351         const wchar_t s[] = L"Iraq";
1352         assert(!std::regex_search(s, m, std::wregex(L"q[^u]",
1353                                                  std::regex_constants::awk)));
1354         assert(m.size() == 0);
1355     }
1356     {
1357         std::wcmatch m;
1358         const wchar_t s[] = L"AmB";
1359         assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B",
1360                                                  std::regex_constants::awk)));
1361         assert(m.size() == 1);
1362         assert(!m.prefix().matched);
1363         assert(m.prefix().first == s);
1364         assert(m.prefix().second == m[0].first);
1365         assert(!m.suffix().matched);
1366         assert(m.suffix().first == m[0].second);
1367         assert(m.suffix().second == m[0].second);
1368         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1369         assert(m.position(0) == 0);
1370         assert(m.str(0) == s);
1371     }
1372     {
1373         std::wcmatch m;
1374         const wchar_t s[] = L"AMB";
1375         assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B",
1376                                                  std::regex_constants::awk)));
1377         assert(m.size() == 0);
1378     }
1379     {
1380         std::wcmatch m;
1381         const wchar_t s[] = L"AMB";
1382         assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B",
1383                                                  std::regex_constants::awk)));
1384         assert(m.size() == 1);
1385         assert(!m.prefix().matched);
1386         assert(m.prefix().first == s);
1387         assert(m.prefix().second == m[0].first);
1388         assert(!m.suffix().matched);
1389         assert(m.suffix().first == m[0].second);
1390         assert(m.suffix().second == m[0].second);
1391         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1392         assert(m.position(0) == 0);
1393         assert(m.str(0) == s);
1394     }
1395     {
1396         std::wcmatch m;
1397         const wchar_t s[] = L"AmB";
1398         assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B",
1399                                                  std::regex_constants::awk)));
1400         assert(m.size() == 0);
1401     }
1402     {
1403         std::wcmatch m;
1404         const wchar_t s[] = L"A5B";
1405         assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1406                                                  std::regex_constants::awk)));
1407         assert(m.size() == 0);
1408     }
1409     {
1410         std::wcmatch m;
1411         const wchar_t s[] = L"A?B";
1412         assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1413                                                  std::regex_constants::awk)));
1414         assert(m.size() == 1);
1415         assert(!m.prefix().matched);
1416         assert(m.prefix().first == s);
1417         assert(m.prefix().second == m[0].first);
1418         assert(!m.suffix().matched);
1419         assert(m.suffix().first == m[0].second);
1420         assert(m.suffix().second == m[0].second);
1421         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1422         assert(m.position(0) == 0);
1423         assert(m.str(0) == s);
1424     }
1425     {
1426         std::wcmatch m;
1427         const wchar_t s[] = L"-";
1428         assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]",
1429                                                  std::regex_constants::awk)));
1430         assert(m.size() == 1);
1431         assert(!m.prefix().matched);
1432         assert(m.prefix().first == s);
1433         assert(m.prefix().second == m[0].first);
1434         assert(!m.suffix().matched);
1435         assert(m.suffix().first == m[0].second);
1436         assert(m.suffix().second == m[0].second);
1437         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1438         assert(m.position(0) == 0);
1439         assert(m.str(0) == s);
1440     }
1441     {
1442         std::wcmatch m;
1443         const wchar_t s[] = L"z";
1444         assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]",
1445                                                  std::regex_constants::awk)));
1446         assert(m.size() == 1);
1447         assert(!m.prefix().matched);
1448         assert(m.prefix().first == s);
1449         assert(m.prefix().second == m[0].first);
1450         assert(!m.suffix().matched);
1451         assert(m.suffix().first == m[0].second);
1452         assert(m.suffix().second == m[0].second);
1453         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1454         assert(m.position(0) == 0);
1455         assert(m.str(0) == s);
1456     }
1457     {
1458         std::wcmatch m;
1459         const wchar_t s[] = L"m";
1460         assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]",
1461                                                  std::regex_constants::awk)));
1462         assert(m.size() == 0);
1463     }
1464     std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
1465     {
1466         std::wcmatch m;
1467         const wchar_t s[] = L"m";
1468         assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]",
1469                                                  std::regex_constants::awk)));
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) == 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"Ch";
1484         assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]",
1485                    std::regex_constants::awk | std::regex_constants::icase)));
1486         assert(m.size() == 1);
1487         assert(!m.prefix().matched);
1488         assert(m.prefix().first == s);
1489         assert(m.prefix().second == m[0].first);
1490         assert(!m.suffix().matched);
1491         assert(m.suffix().first == m[0].second);
1492         assert(m.suffix().second == m[0].second);
1493         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1494         assert(m.position(0) == 0);
1495         assert(m.str(0) == s);
1496     }
1497     std::locale::global(std::locale("C"));
1498     {
1499         std::wcmatch m;
1500         const wchar_t s[] = L"m";
1501         assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]",
1502                                                  std::regex_constants::awk)));
1503         assert(m.size() == 0);
1504     }
1505     {
1506         std::wcmatch m;
1507         const wchar_t s[] = L"01a45cef9";
1508         assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*",
1509                                                  std::regex_constants::awk)));
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 == s + std::char_traits<wchar_t>::length(s));
1517         assert(m.length(0) == 0);
1518         assert(m.position(0) == 0);
1519         assert(m.str(0) == L"");
1520     }
1521     {
1522         std::wcmatch m;
1523         const wchar_t s[] = L"01a45cef9";
1524         assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+",
1525                                                  std::regex_constants::awk)));
1526         assert(m.size() == 1);
1527         assert(m.prefix().matched);
1528         assert(m.prefix().first == s);
1529         assert(m.prefix().second == m[0].first);
1530         assert(m.suffix().matched);
1531         assert(m.suffix().first == m[0].second);
1532         assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1533         assert(m.length(0) == 6);
1534         assert(m.position(0) == 1);
1535         assert(m.str(0) == L"1a45ce");
1536     }
1537     {
1538         const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
1539         std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
1540         typedef forward_iterator<const wchar_t*> FI;
1541         typedef bidirectional_iterator<const wchar_t*> BI;
1542         std::wregex regex(FI(r), FI(r+sr), std::regex_constants::awk);
1543         std::match_results<BI> m;
1544         const wchar_t s[] = L"-40C";
1545         std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
1546         assert(std::regex_search(BI(s), BI(s+ss), m, regex));
1547         assert(m.size() == 1);
1548         assert(!m.prefix().matched);
1549         assert(m.prefix().first == BI(s));
1550         assert(m.prefix().second == m[0].first);
1551         assert(!m.suffix().matched);
1552         assert(m.suffix().first == m[0].second);
1553         assert(m.suffix().second == m[0].second);
1554         assert(m.length(0) == 4);
1555         assert(m.position(0) == 0);
1556         assert(m.str(0) == s);
1557     }
1558     {
1559         std::wcmatch m;
1560         const wchar_t s[] = L"\n\n\n";
1561         assert(std::regex_search(s, m, std::wregex(L"[\\n]+",
1562                                                  std::regex_constants::awk)));
1563         assert(m.size() == 1);
1564         assert(!m.prefix().matched);
1565         assert(m.prefix().first == s);
1566         assert(m.prefix().second == m[0].first);
1567         assert(!m.suffix().matched);
1568         assert(m.suffix().first == m[0].second);
1569         assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1570         assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1571         assert(m.position(0) == 0);
1572         assert(m.str(0) == s);
1573     }
1574 }
1575