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