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