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