blob: cb23cfa15d2412511a6fd1063dfb86f0ae495dbe [file] [log] [blame]
Howard Hinnant51e39672010-08-14 19:58:44 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant51e39672010-08-14 19:58:44 +00007//
8//===----------------------------------------------------------------------===//
9
Dan Alberta85b27f2014-08-04 18:44:48 +000010// REQUIRES: locale.cs_CZ.ISO8859-2
11
Howard Hinnant51e39672010-08-14 19:58:44 +000012// <regex>
13
14// template <class BidirectionalIterator, class Allocator, class charT, class traits>
15// bool
16// regex_match(BidirectionalIterator first, BidirectionalIterator last,
17// match_results<BidirectionalIterator, Allocator>& m,
18// const basic_regex<charT, traits>& e,
19// regex_constants::match_flag_type flags = regex_constants::match_default);
20
Eric Fiseliere608aed2014-10-23 21:17:36 +000021// TODO: investigation needed
22// XFAIL: linux-gnu
23
Howard Hinnant51e39672010-08-14 19:58:44 +000024#include <regex>
25#include <cassert>
Marshall Clowfd5ceb22016-04-26 16:24:44 +000026#include "test_macros.h"
Marshall Clow32227082013-01-05 03:21:01 +000027#include "test_iterators.h"
Howard Hinnant51e39672010-08-14 19:58:44 +000028
Ed Schoutenf4249902015-03-16 15:09:15 +000029#include "platform_support.h" // locale name macros
30
Howard Hinnant51e39672010-08-14 19:58:44 +000031int main()
32{
33 {
34 std::cmatch m;
35 assert(!std::regex_match("a", m, std::regex()));
36 assert(m.size() == 0);
37 assert(m.empty());
38 }
39 {
40 std::cmatch m;
41 const char s[] = "a";
42 assert(std::regex_match(s, m, std::regex("a", std::regex_constants::basic)));
43 assert(m.size() == 1);
44 assert(!m.empty());
45 assert(!m.prefix().matched);
46 assert(m.prefix().first == s);
47 assert(m.prefix().second == m[0].first);
48 assert(!m.suffix().matched);
49 assert(m.suffix().first == m[0].second);
50 assert(m.suffix().second == s+1);
51 assert(m.length(0) == 1);
52 assert(m.position(0) == 0);
53 assert(m.str(0) == "a");
54 }
55 {
56 std::cmatch m;
57 const char s[] = "ab";
58 assert(std::regex_match(s, m, std::regex("ab", std::regex_constants::basic)));
59 assert(m.size() == 1);
60 assert(!m.prefix().matched);
61 assert(m.prefix().first == s);
62 assert(m.prefix().second == m[0].first);
63 assert(!m.suffix().matched);
64 assert(m.suffix().first == m[0].second);
65 assert(m.suffix().second == s+2);
66 assert(m.length(0) == 2);
67 assert(m.position(0) == 0);
68 assert(m.str(0) == "ab");
69 }
70 {
71 std::cmatch m;
72 const char s[] = "ab";
73 assert(!std::regex_match(s, m, std::regex("ba", std::regex_constants::basic)));
74 assert(m.size() == 0);
75 assert(m.empty());
76 }
77 {
78 std::cmatch m;
79 const char s[] = "aab";
80 assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::basic)));
81 assert(m.size() == 0);
82 }
83 {
84 std::cmatch m;
85 const char s[] = "aab";
86 assert(!std::regex_match(s, m, std::regex("ab", std::regex_constants::basic),
87 std::regex_constants::match_continuous));
88 assert(m.size() == 0);
89 }
90 {
91 std::cmatch m;
92 const char s[] = "abcd";
93 assert(!std::regex_match(s, m, std::regex("bc", std::regex_constants::basic)));
94 assert(m.size() == 0);
95 }
96 {
97 std::cmatch m;
98 const char s[] = "abbc";
99 assert(std::regex_match(s, m, std::regex("ab*c", std::regex_constants::basic)));
100 assert(m.size() == 1);
101 assert(!m.prefix().matched);
102 assert(m.prefix().first == s);
103 assert(m.prefix().second == m[0].first);
104 assert(!m.suffix().matched);
105 assert(m.suffix().first == m[0].second);
106 assert(m.suffix().second == s+4);
107 assert(m.length(0) == 4);
108 assert(m.position(0) == 0);
109 assert(m.str(0) == s);
110 }
111 {
112 std::cmatch m;
113 const char s[] = "ababc";
114 assert(std::regex_match(s, m, std::regex("\\(ab\\)*c", std::regex_constants::basic)));
115 assert(m.size() == 2);
116 assert(!m.prefix().matched);
117 assert(m.prefix().first == s);
118 assert(m.prefix().second == m[0].first);
119 assert(!m.suffix().matched);
120 assert(m.suffix().first == m[0].second);
121 assert(m.suffix().second == s+5);
122 assert(m.length(0) == 5);
123 assert(m.position(0) == 0);
124 assert(m.str(0) == s);
125 assert(m.length(1) == 2);
126 assert(m.position(1) == 2);
127 assert(m.str(1) == "ab");
128 }
129 {
130 std::cmatch m;
131 const char s[] = "abcdefghijk";
132 assert(!std::regex_match(s, m, std::regex("cd\\(\\(e\\)fg\\)hi",
133 std::regex_constants::basic)));
134 assert(m.size() == 0);
135 }
136 {
137 std::cmatch m;
138 const char s[] = "abc";
139 assert(std::regex_match(s, m, std::regex("^abc", std::regex_constants::basic)));
140 assert(m.size() == 1);
141 assert(!m.prefix().matched);
142 assert(m.prefix().first == s);
143 assert(m.prefix().second == m[0].first);
144 assert(!m.suffix().matched);
145 assert(m.suffix().first == m[0].second);
146 assert(m.suffix().second == s+3);
147 assert(m.length(0) == 3);
148 assert(m.position(0) == 0);
149 assert(m.str(0) == s);
150 }
151 {
152 std::cmatch m;
153 const char s[] = "abcd";
154 assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::basic)));
155 assert(m.size() == 0);
156 }
157 {
158 std::cmatch m;
159 const char s[] = "aabc";
160 assert(!std::regex_match(s, m, std::regex("^abc", std::regex_constants::basic)));
161 assert(m.size() == 0);
162 }
163 {
164 std::cmatch m;
165 const char s[] = "abc";
166 assert(std::regex_match(s, m, std::regex("abc$", std::regex_constants::basic)));
167 assert(m.size() == 1);
168 assert(!m.prefix().matched);
169 assert(m.prefix().first == s);
170 assert(m.prefix().second == m[0].first);
171 assert(!m.suffix().matched);
172 assert(m.suffix().first == m[0].second);
173 assert(m.suffix().second == s+3);
174 assert(m.length(0) == 3);
175 assert(m.position(0) == 0);
176 assert(m.str(0) == s);
177 }
178 {
179 std::cmatch m;
180 const char s[] = "efabc";
181 assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::basic)));
182 assert(m.size() == 0);
183 }
184 {
185 std::cmatch m;
186 const char s[] = "efabcg";
187 assert(!std::regex_match(s, m, std::regex("abc$", std::regex_constants::basic)));
188 assert(m.size() == 0);
189 }
190 {
191 std::cmatch m;
192 const char s[] = "abc";
193 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::basic)));
194 assert(m.size() == 1);
195 assert(!m.prefix().matched);
196 assert(m.prefix().first == s);
197 assert(m.prefix().second == m[0].first);
198 assert(!m.suffix().matched);
199 assert(m.suffix().first == m[0].second);
200 assert(m.suffix().second == s+3);
201 assert(m.length(0) == 3);
202 assert(m.position(0) == 0);
203 assert(m.str(0) == s);
204 }
205 {
206 std::cmatch m;
207 const char s[] = "acc";
208 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::basic)));
209 assert(m.size() == 1);
210 assert(!m.prefix().matched);
211 assert(m.prefix().first == s);
212 assert(m.prefix().second == m[0].first);
213 assert(!m.suffix().matched);
214 assert(m.suffix().first == m[0].second);
215 assert(m.suffix().second == s+3);
216 assert(m.length(0) == 3);
217 assert(m.position(0) == 0);
218 assert(m.str(0) == s);
219 }
220 {
221 std::cmatch m;
222 const char s[] = "acc";
223 assert(std::regex_match(s, m, std::regex("a.c", std::regex_constants::basic)));
224 assert(m.size() == 1);
225 assert(!m.prefix().matched);
226 assert(m.prefix().first == s);
227 assert(m.prefix().second == m[0].first);
228 assert(!m.suffix().matched);
229 assert(m.suffix().first == m[0].second);
230 assert(m.suffix().second == s+3);
231 assert(m.length(0) == 3);
232 assert(m.position(0) == 0);
233 assert(m.str(0) == s);
234 }
235 {
236 std::cmatch m;
237 const char s[] = "abcdef";
238 assert(std::regex_match(s, m, std::regex("\\(.*\\).*", std::regex_constants::basic)));
239 assert(m.size() == 2);
240 assert(!m.prefix().matched);
241 assert(m.prefix().first == s);
242 assert(m.prefix().second == m[0].first);
243 assert(!m.suffix().matched);
244 assert(m.suffix().first == m[0].second);
245 assert(m.suffix().second == s+6);
246 assert(m.length(0) == 6);
247 assert(m.position(0) == 0);
248 assert(m.str(0) == s);
249 assert(m.length(1) == 6);
250 assert(m.position(1) == 0);
251 assert(m.str(1) == s);
252 }
253 {
254 std::cmatch m;
255 const char s[] = "bc";
256 assert(!std::regex_match(s, m, std::regex("\\(a*\\)*", std::regex_constants::basic)));
257 assert(m.size() == 0);
258 }
259 {
260 std::cmatch m;
261 const char s[] = "abbc";
262 assert(!std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
263 assert(m.size() == 0);
264 }
265 {
266 std::cmatch m;
267 const char s[] = "abbbc";
268 assert(std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
269 assert(m.size() == 1);
270 assert(!m.prefix().matched);
271 assert(m.prefix().first == s);
272 assert(m.prefix().second == m[0].first);
273 assert(!m.suffix().matched);
274 assert(m.suffix().first == m[0].second);
275 assert(m.suffix().second == m[0].second);
276 assert(m.length(0) == sizeof(s)-1);
277 assert(m.position(0) == 0);
278 assert(m.str(0) == s);
279 }
280 {
281 std::cmatch m;
282 const char s[] = "abbbbc";
283 assert(std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
284 assert(m.size() == 1);
285 assert(!m.prefix().matched);
286 assert(m.prefix().first == s);
287 assert(m.prefix().second == m[0].first);
288 assert(!m.suffix().matched);
289 assert(m.suffix().first == m[0].second);
290 assert(m.suffix().second == m[0].second);
291 assert(m.length(0) == sizeof(s)-1);
292 assert(m.position(0) == 0);
293 assert(m.str(0) == s);
294 }
295 {
296 std::cmatch m;
297 const char s[] = "abbbbbc";
298 assert(std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
299 assert(m.size() == 1);
300 assert(!m.prefix().matched);
301 assert(m.prefix().first == s);
302 assert(m.prefix().second == m[0].first);
303 assert(!m.suffix().matched);
304 assert(m.suffix().first == m[0].second);
305 assert(m.suffix().second == m[0].second);
306 assert(m.length(0) == sizeof(s)-1);
307 assert(m.position(0) == 0);
308 assert(m.str(0) == s);
309 }
310 {
311 std::cmatch m;
312 const char s[] = "adefc";
313 assert(!std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
314 assert(m.size() == 0);
315 }
316 {
317 std::cmatch m;
318 const char s[] = "abbbbbbc";
319 assert(!std::regex_match(s, m, std::regex("ab\\{3,5\\}c", std::regex_constants::basic)));
320 assert(m.size() == 0);
321 }
322 {
323 std::cmatch m;
324 const char s[] = "adec";
325 assert(!std::regex_match(s, m, std::regex("a.\\{3,5\\}c", std::regex_constants::basic)));
326 assert(m.size() == 0);
327 }
328 {
329 std::cmatch m;
330 const char s[] = "adefc";
331 assert(std::regex_match(s, m, std::regex("a.\\{3,5\\}c", std::regex_constants::basic)));
332 assert(m.size() == 1);
333 assert(!m.prefix().matched);
334 assert(m.prefix().first == s);
335 assert(m.prefix().second == m[0].first);
336 assert(!m.suffix().matched);
337 assert(m.suffix().first == m[0].second);
338 assert(m.suffix().second == m[0].second);
339 assert(m.length(0) == sizeof(s)-1);
340 assert(m.position(0) == 0);
341 assert(m.str(0) == s);
342 }
343 {
344 std::cmatch m;
345 const char s[] = "adefgc";
346 assert(std::regex_match(s, m, std::regex("a.\\{3,5\\}c", std::regex_constants::basic)));
347 assert(m.size() == 1);
348 assert(!m.prefix().matched);
349 assert(m.prefix().first == s);
350 assert(m.prefix().second == m[0].first);
351 assert(!m.suffix().matched);
352 assert(m.suffix().first == m[0].second);
353 assert(m.suffix().second == m[0].second);
354 assert(m.length(0) == sizeof(s)-1);
355 assert(m.position(0) == 0);
356 assert(m.str(0) == s);
357 }
358 {
359 std::cmatch m;
360 const char s[] = "adefghc";
361 assert(std::regex_match(s, m, std::regex("a.\\{3,5\\}c", std::regex_constants::basic)));
362 assert(m.size() == 1);
363 assert(!m.prefix().matched);
364 assert(m.prefix().first == s);
365 assert(m.prefix().second == m[0].first);
366 assert(!m.suffix().matched);
367 assert(m.suffix().first == m[0].second);
368 assert(m.suffix().second == m[0].second);
369 assert(m.length(0) == sizeof(s)-1);
370 assert(m.position(0) == 0);
371 assert(m.str(0) == s);
372 }
373 {
374 std::cmatch m;
375 const char s[] = "adefghic";
376 assert(!std::regex_match(s, m, std::regex("a.\\{3,5\\}c", std::regex_constants::basic)));
377 assert(m.size() == 0);
378 }
379 {
380 std::cmatch m;
381 const char s[] = "-ab,ab-";
382 assert(std::regex_match(s, m, std::regex("-\\(.*\\),\\1-", std::regex_constants::basic)));
383 assert(m.size() == 2);
384 assert(!m.prefix().matched);
385 assert(m.prefix().first == s);
386 assert(m.prefix().second == m[0].first);
387 assert(!m.suffix().matched);
388 assert(m.suffix().first == m[0].second);
389 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000390 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000391 assert(m.position(0) == 0);
392 assert(m.str(0) == s);
393 assert(m.length(1) == 2);
394 assert(m.position(1) == 1);
395 assert(m.str(1) == "ab");
396 }
397 {
398 std::cmatch m;
399 const char s[] = "ababbabb";
400 assert(std::regex_match(s, m, std::regex("^\\(ab*\\)*\\1$", std::regex_constants::basic)));
401 assert(m.size() == 2);
402 assert(!m.prefix().matched);
403 assert(m.prefix().first == s);
404 assert(m.prefix().second == m[0].first);
405 assert(!m.suffix().matched);
406 assert(m.suffix().first == m[0].second);
407 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000408 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000409 assert(m.position(0) == 0);
410 assert(m.str(0) == s);
411 assert(m.length(1) == 3);
412 assert(m.position(1) == 2);
413 assert(m.str(1) == "abb");
414 }
415 {
416 std::cmatch m;
417 const char s[] = "ababbab";
418 assert(!std::regex_match(s, m, std::regex("^\\(ab*\\)*\\1$", std::regex_constants::basic)));
419 assert(m.size() == 0);
420 }
421 {
422 std::cmatch m;
423 const char s[] = "aBAbbAbB";
424 assert(std::regex_match(s, m, std::regex("^\\(Ab*\\)*\\1$",
425 std::regex_constants::basic | std::regex_constants::icase)));
426 assert(m.size() == 2);
427 assert(!m.prefix().matched);
428 assert(m.prefix().first == s);
429 assert(m.prefix().second == m[0].first);
430 assert(!m.suffix().matched);
431 assert(m.suffix().first == m[0].second);
432 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000433 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000434 assert(m.position(0) == 0);
435 assert(m.str(0) == s);
436 assert(m.length(1) == 3);
437 assert(m.position(1) == 2);
438 assert(m.str(1) == "Abb");
439 }
440 {
441 std::cmatch m;
442 const char s[] = "aBAbbAbB";
443 assert(!std::regex_match(s, m, std::regex("^\\(Ab*\\)*\\1$",
444 std::regex_constants::basic)));
445 assert(m.size() == 0);
446 }
447 {
448 std::cmatch m;
449 const char s[] = "a";
450 assert(std::regex_match(s, m, std::regex("^[a]$",
451 std::regex_constants::basic)));
452 assert(m.size() == 1);
453 assert(!m.prefix().matched);
454 assert(m.prefix().first == s);
455 assert(m.prefix().second == m[0].first);
456 assert(!m.suffix().matched);
457 assert(m.suffix().first == m[0].second);
458 assert(m.suffix().second == m[0].second);
459 assert(m.length(0) == 1);
460 assert(m.position(0) == 0);
461 assert(m.str(0) == "a");
462 }
463 {
464 std::cmatch m;
465 const char s[] = "a";
466 assert(std::regex_match(s, m, std::regex("^[ab]$",
467 std::regex_constants::basic)));
468 assert(m.size() == 1);
469 assert(!m.prefix().matched);
470 assert(m.prefix().first == s);
471 assert(m.prefix().second == m[0].first);
472 assert(!m.suffix().matched);
473 assert(m.suffix().first == m[0].second);
474 assert(m.suffix().second == m[0].second);
475 assert(m.length(0) == 1);
476 assert(m.position(0) == 0);
477 assert(m.str(0) == "a");
478 }
479 {
480 std::cmatch m;
481 const char s[] = "c";
482 assert(std::regex_match(s, m, std::regex("^[a-f]$",
483 std::regex_constants::basic)));
484 assert(m.size() == 1);
485 assert(!m.prefix().matched);
486 assert(m.prefix().first == s);
487 assert(m.prefix().second == m[0].first);
488 assert(!m.suffix().matched);
489 assert(m.suffix().first == m[0].second);
490 assert(m.suffix().second == m[0].second);
491 assert(m.length(0) == 1);
492 assert(m.position(0) == 0);
493 assert(m.str(0) == s);
494 }
495 {
496 std::cmatch m;
497 const char s[] = "g";
498 assert(!std::regex_match(s, m, std::regex("^[a-f]$",
499 std::regex_constants::basic)));
500 assert(m.size() == 0);
501 }
502 {
503 std::cmatch m;
504 const char s[] = "Iraqi";
505 assert(!std::regex_match(s, m, std::regex("q[^u]",
506 std::regex_constants::basic)));
507 assert(m.size() == 0);
508 }
509 {
510 std::cmatch m;
511 const char s[] = "Iraq";
512 assert(!std::regex_match(s, m, std::regex("q[^u]",
513 std::regex_constants::basic)));
514 assert(m.size() == 0);
515 }
516 {
517 std::cmatch m;
518 const char s[] = "AmB";
519 assert(std::regex_match(s, m, std::regex("A[[:lower:]]B",
520 std::regex_constants::basic)));
521 assert(m.size() == 1);
522 assert(!m.prefix().matched);
523 assert(m.prefix().first == s);
524 assert(m.prefix().second == m[0].first);
525 assert(!m.suffix().matched);
526 assert(m.suffix().first == m[0].second);
527 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000528 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000529 assert(m.position(0) == 0);
530 assert(m.str(0) == s);
531 }
532 {
533 std::cmatch m;
534 const char s[] = "AMB";
535 assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B",
536 std::regex_constants::basic)));
537 assert(m.size() == 0);
538 }
539 {
540 std::cmatch m;
541 const char s[] = "AMB";
542 assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B",
543 std::regex_constants::basic)));
544 assert(m.size() == 1);
545 assert(!m.prefix().matched);
546 assert(m.prefix().first == s);
547 assert(m.prefix().second == m[0].first);
548 assert(!m.suffix().matched);
549 assert(m.suffix().first == m[0].second);
550 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000551 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000552 assert(m.position(0) == 0);
553 assert(m.str(0) == s);
554 }
555 {
556 std::cmatch m;
557 const char s[] = "AmB";
558 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B",
559 std::regex_constants::basic)));
560 assert(m.size() == 0);
561 }
562 {
563 std::cmatch m;
564 const char s[] = "A5B";
565 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B",
566 std::regex_constants::basic)));
567 assert(m.size() == 0);
568 }
569 {
570 std::cmatch m;
571 const char s[] = "A?B";
572 assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B",
573 std::regex_constants::basic)));
574 assert(m.size() == 1);
575 assert(!m.prefix().matched);
576 assert(m.prefix().first == s);
577 assert(m.prefix().second == m[0].first);
578 assert(!m.suffix().matched);
579 assert(m.suffix().first == m[0].second);
580 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000581 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000582 assert(m.position(0) == 0);
583 assert(m.str(0) == s);
584 }
585 {
586 std::cmatch m;
587 const char s[] = "-";
588 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
589 std::regex_constants::basic)));
590 assert(m.size() == 1);
591 assert(!m.prefix().matched);
592 assert(m.prefix().first == s);
593 assert(m.prefix().second == m[0].first);
594 assert(!m.suffix().matched);
595 assert(m.suffix().first == m[0].second);
596 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000597 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000598 assert(m.position(0) == 0);
599 assert(m.str(0) == s);
600 }
601 {
602 std::cmatch m;
603 const char s[] = "z";
604 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
605 std::regex_constants::basic)));
606 assert(m.size() == 1);
607 assert(!m.prefix().matched);
608 assert(m.prefix().first == s);
609 assert(m.prefix().second == m[0].first);
610 assert(!m.suffix().matched);
611 assert(m.suffix().first == m[0].second);
612 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000613 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000614 assert(m.position(0) == 0);
615 assert(m.str(0) == s);
616 }
617 {
618 std::cmatch m;
619 const char s[] = "m";
620 assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]",
621 std::regex_constants::basic)));
622 assert(m.size() == 0);
623 }
Ed Schoutenf4249902015-03-16 15:09:15 +0000624 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
Howard Hinnant51e39672010-08-14 19:58:44 +0000625 {
626 std::cmatch m;
627 const char s[] = "m";
628 assert(std::regex_match(s, m, std::regex("[a[=M=]z]",
629 std::regex_constants::basic)));
630 assert(m.size() == 1);
631 assert(!m.prefix().matched);
632 assert(m.prefix().first == s);
633 assert(m.prefix().second == m[0].first);
634 assert(!m.suffix().matched);
635 assert(m.suffix().first == m[0].second);
636 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000637 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000638 assert(m.position(0) == 0);
639 assert(m.str(0) == s);
640 }
641 {
642 std::cmatch m;
643 const char s[] = "Ch";
644 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
645 std::regex_constants::basic | std::regex_constants::icase)));
646 assert(m.size() == 1);
647 assert(!m.prefix().matched);
648 assert(m.prefix().first == s);
649 assert(m.prefix().second == m[0].first);
650 assert(!m.suffix().matched);
651 assert(m.suffix().first == m[0].second);
652 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000653 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000654 assert(m.position(0) == 0);
655 assert(m.str(0) == s);
656 }
657 std::locale::global(std::locale("C"));
658 {
659 std::cmatch m;
660 const char s[] = "m";
661 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]",
662 std::regex_constants::basic)));
663 assert(m.size() == 0);
664 }
665 {
666 std::cmatch m;
667 const char s[] = "01a45cef9";
668 assert(!std::regex_match(s, m, std::regex("[ace1-9]*",
669 std::regex_constants::basic)));
670 assert(m.size() == 0);
671 }
672 {
673 std::cmatch m;
674 const char s[] = "01a45cef9";
675 assert(!std::regex_match(s, m, std::regex("[ace1-9]\\{1,\\}",
676 std::regex_constants::basic)));
677 assert(m.size() == 0);
678 }
679 {
680 const char r[] = "^[-+]\\{0,1\\}[0-9]\\{1,\\}[CF]$";
681 std::ptrdiff_t sr = std::char_traits<char>::length(r);
682 typedef forward_iterator<const char*> FI;
683 typedef bidirectional_iterator<const char*> BI;
684 std::regex regex(FI(r), FI(r+sr), std::regex_constants::basic);
685 std::match_results<BI> m;
686 const char s[] = "-40C";
687 std::ptrdiff_t ss = std::char_traits<char>::length(s);
688 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
689 assert(m.size() == 1);
690 assert(!m.prefix().matched);
691 assert(m.prefix().first == BI(s));
692 assert(m.prefix().second == m[0].first);
693 assert(!m.suffix().matched);
694 assert(m.suffix().first == m[0].second);
695 assert(m.suffix().second == m[0].second);
696 assert(m.length(0) == 4);
697 assert(m.position(0) == 0);
698 assert(m.str(0) == s);
699 }
700
Howard Hinnant51e39672010-08-14 19:58:44 +0000701 {
702 std::wcmatch m;
703 assert(!std::regex_match(L"a", m, std::wregex()));
704 assert(m.size() == 0);
705 assert(m.empty());
706 }
707 {
708 std::wcmatch m;
709 const wchar_t s[] = L"a";
710 assert(std::regex_match(s, m, std::wregex(L"a", std::regex_constants::basic)));
711 assert(m.size() == 1);
712 assert(!m.empty());
713 assert(!m.prefix().matched);
714 assert(m.prefix().first == s);
715 assert(m.prefix().second == m[0].first);
716 assert(!m.suffix().matched);
717 assert(m.suffix().first == m[0].second);
718 assert(m.suffix().second == s+1);
719 assert(m.length(0) == 1);
720 assert(m.position(0) == 0);
721 assert(m.str(0) == L"a");
722 }
723 {
724 std::wcmatch m;
725 const wchar_t s[] = L"ab";
726 assert(std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::basic)));
727 assert(m.size() == 1);
728 assert(!m.prefix().matched);
729 assert(m.prefix().first == s);
730 assert(m.prefix().second == m[0].first);
731 assert(!m.suffix().matched);
732 assert(m.suffix().first == m[0].second);
733 assert(m.suffix().second == s+2);
734 assert(m.length(0) == 2);
735 assert(m.position(0) == 0);
736 assert(m.str(0) == L"ab");
737 }
738 {
739 std::wcmatch m;
740 const wchar_t s[] = L"ab";
741 assert(!std::regex_match(s, m, std::wregex(L"ba", std::regex_constants::basic)));
742 assert(m.size() == 0);
743 assert(m.empty());
744 }
745 {
746 std::wcmatch m;
747 const wchar_t s[] = L"aab";
748 assert(!std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::basic)));
749 assert(m.size() == 0);
750 }
751 {
752 std::wcmatch m;
753 const wchar_t s[] = L"aab";
754 assert(!std::regex_match(s, m, std::wregex(L"ab", std::regex_constants::basic),
755 std::regex_constants::match_continuous));
756 assert(m.size() == 0);
757 }
758 {
759 std::wcmatch m;
760 const wchar_t s[] = L"abcd";
761 assert(!std::regex_match(s, m, std::wregex(L"bc", std::regex_constants::basic)));
762 assert(m.size() == 0);
763 }
764 {
765 std::wcmatch m;
766 const wchar_t s[] = L"abbc";
767 assert(std::regex_match(s, m, std::wregex(L"ab*c", std::regex_constants::basic)));
768 assert(m.size() == 1);
769 assert(!m.prefix().matched);
770 assert(m.prefix().first == s);
771 assert(m.prefix().second == m[0].first);
772 assert(!m.suffix().matched);
773 assert(m.suffix().first == m[0].second);
774 assert(m.suffix().second == s+4);
775 assert(m.length(0) == 4);
776 assert(m.position(0) == 0);
777 assert(m.str(0) == s);
778 }
779 {
780 std::wcmatch m;
781 const wchar_t s[] = L"ababc";
782 assert(std::regex_match(s, m, std::wregex(L"\\(ab\\)*c", std::regex_constants::basic)));
783 assert(m.size() == 2);
784 assert(!m.prefix().matched);
785 assert(m.prefix().first == s);
786 assert(m.prefix().second == m[0].first);
787 assert(!m.suffix().matched);
788 assert(m.suffix().first == m[0].second);
789 assert(m.suffix().second == s+5);
790 assert(m.length(0) == 5);
791 assert(m.position(0) == 0);
792 assert(m.str(0) == s);
793 assert(m.length(1) == 2);
794 assert(m.position(1) == 2);
795 assert(m.str(1) == L"ab");
796 }
797 {
798 std::wcmatch m;
799 const wchar_t s[] = L"abcdefghijk";
800 assert(!std::regex_match(s, m, std::wregex(L"cd\\(\\(e\\)fg\\)hi",
801 std::regex_constants::basic)));
802 assert(m.size() == 0);
803 }
804 {
805 std::wcmatch m;
806 const wchar_t s[] = L"abc";
807 assert(std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::basic)));
808 assert(m.size() == 1);
809 assert(!m.prefix().matched);
810 assert(m.prefix().first == s);
811 assert(m.prefix().second == m[0].first);
812 assert(!m.suffix().matched);
813 assert(m.suffix().first == m[0].second);
814 assert(m.suffix().second == s+3);
815 assert(m.length(0) == 3);
816 assert(m.position(0) == 0);
817 assert(m.str(0) == s);
818 }
819 {
820 std::wcmatch m;
821 const wchar_t s[] = L"abcd";
822 assert(!std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::basic)));
823 assert(m.size() == 0);
824 }
825 {
826 std::wcmatch m;
827 const wchar_t s[] = L"aabc";
828 assert(!std::regex_match(s, m, std::wregex(L"^abc", std::regex_constants::basic)));
829 assert(m.size() == 0);
830 }
831 {
832 std::wcmatch m;
833 const wchar_t s[] = L"abc";
834 assert(std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::basic)));
835 assert(m.size() == 1);
836 assert(!m.prefix().matched);
837 assert(m.prefix().first == s);
838 assert(m.prefix().second == m[0].first);
839 assert(!m.suffix().matched);
840 assert(m.suffix().first == m[0].second);
841 assert(m.suffix().second == s+3);
842 assert(m.length(0) == 3);
843 assert(m.position(0) == 0);
844 assert(m.str(0) == s);
845 }
846 {
847 std::wcmatch m;
848 const wchar_t s[] = L"efabc";
849 assert(!std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::basic)));
850 assert(m.size() == 0);
851 }
852 {
853 std::wcmatch m;
854 const wchar_t s[] = L"efabcg";
855 assert(!std::regex_match(s, m, std::wregex(L"abc$", std::regex_constants::basic)));
856 assert(m.size() == 0);
857 }
858 {
859 std::wcmatch m;
860 const wchar_t s[] = L"abc";
861 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::basic)));
862 assert(m.size() == 1);
863 assert(!m.prefix().matched);
864 assert(m.prefix().first == s);
865 assert(m.prefix().second == m[0].first);
866 assert(!m.suffix().matched);
867 assert(m.suffix().first == m[0].second);
868 assert(m.suffix().second == s+3);
869 assert(m.length(0) == 3);
870 assert(m.position(0) == 0);
871 assert(m.str(0) == s);
872 }
873 {
874 std::wcmatch m;
875 const wchar_t s[] = L"acc";
876 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::basic)));
877 assert(m.size() == 1);
878 assert(!m.prefix().matched);
879 assert(m.prefix().first == s);
880 assert(m.prefix().second == m[0].first);
881 assert(!m.suffix().matched);
882 assert(m.suffix().first == m[0].second);
883 assert(m.suffix().second == s+3);
884 assert(m.length(0) == 3);
885 assert(m.position(0) == 0);
886 assert(m.str(0) == s);
887 }
888 {
889 std::wcmatch m;
890 const wchar_t s[] = L"acc";
891 assert(std::regex_match(s, m, std::wregex(L"a.c", std::regex_constants::basic)));
892 assert(m.size() == 1);
893 assert(!m.prefix().matched);
894 assert(m.prefix().first == s);
895 assert(m.prefix().second == m[0].first);
896 assert(!m.suffix().matched);
897 assert(m.suffix().first == m[0].second);
898 assert(m.suffix().second == s+3);
899 assert(m.length(0) == 3);
900 assert(m.position(0) == 0);
901 assert(m.str(0) == s);
902 }
903 {
904 std::wcmatch m;
905 const wchar_t s[] = L"abcdef";
906 assert(std::regex_match(s, m, std::wregex(L"\\(.*\\).*", std::regex_constants::basic)));
907 assert(m.size() == 2);
908 assert(!m.prefix().matched);
909 assert(m.prefix().first == s);
910 assert(m.prefix().second == m[0].first);
911 assert(!m.suffix().matched);
912 assert(m.suffix().first == m[0].second);
913 assert(m.suffix().second == s+6);
914 assert(m.length(0) == 6);
915 assert(m.position(0) == 0);
916 assert(m.str(0) == s);
917 assert(m.length(1) == 6);
918 assert(m.position(1) == 0);
919 assert(m.str(1) == s);
920 }
921 {
922 std::wcmatch m;
923 const wchar_t s[] = L"bc";
924 assert(!std::regex_match(s, m, std::wregex(L"\\(a*\\)*", std::regex_constants::basic)));
925 assert(m.size() == 0);
926 }
927 {
928 std::wcmatch m;
929 const wchar_t s[] = L"abbc";
930 assert(!std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
931 assert(m.size() == 0);
932 }
933 {
934 std::wcmatch m;
935 const wchar_t s[] = L"abbbc";
936 assert(std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
937 assert(m.size() == 1);
938 assert(!m.prefix().matched);
939 assert(m.prefix().first == s);
940 assert(m.prefix().second == m[0].first);
941 assert(!m.suffix().matched);
942 assert(m.suffix().first == m[0].second);
943 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000944 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000945 assert(m.position(0) == 0);
946 assert(m.str(0) == s);
947 }
948 {
949 std::wcmatch m;
950 const wchar_t s[] = L"abbbbc";
951 assert(std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
952 assert(m.size() == 1);
953 assert(!m.prefix().matched);
954 assert(m.prefix().first == s);
955 assert(m.prefix().second == m[0].first);
956 assert(!m.suffix().matched);
957 assert(m.suffix().first == m[0].second);
958 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000959 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000960 assert(m.position(0) == 0);
961 assert(m.str(0) == s);
962 }
963 {
964 std::wcmatch m;
965 const wchar_t s[] = L"abbbbbc";
966 assert(std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
967 assert(m.size() == 1);
968 assert(!m.prefix().matched);
969 assert(m.prefix().first == s);
970 assert(m.prefix().second == m[0].first);
971 assert(!m.suffix().matched);
972 assert(m.suffix().first == m[0].second);
973 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +0000974 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +0000975 assert(m.position(0) == 0);
976 assert(m.str(0) == s);
977 }
978 {
979 std::wcmatch m;
980 const wchar_t s[] = L"adefc";
981 assert(!std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
982 assert(m.size() == 0);
983 }
984 {
985 std::wcmatch m;
986 const wchar_t s[] = L"abbbbbbc";
987 assert(!std::regex_match(s, m, std::wregex(L"ab\\{3,5\\}c", std::regex_constants::basic)));
988 assert(m.size() == 0);
989 }
990 {
991 std::wcmatch m;
992 const wchar_t s[] = L"adec";
993 assert(!std::regex_match(s, m, std::wregex(L"a.\\{3,5\\}c", std::regex_constants::basic)));
994 assert(m.size() == 0);
995 }
996 {
997 std::wcmatch m;
998 const wchar_t s[] = L"adefc";
999 assert(std::regex_match(s, m, std::wregex(L"a.\\{3,5\\}c", std::regex_constants::basic)));
1000 assert(m.size() == 1);
1001 assert(!m.prefix().matched);
1002 assert(m.prefix().first == s);
1003 assert(m.prefix().second == m[0].first);
1004 assert(!m.suffix().matched);
1005 assert(m.suffix().first == m[0].second);
1006 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001007 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001008 assert(m.position(0) == 0);
1009 assert(m.str(0) == s);
1010 }
1011 {
1012 std::wcmatch m;
1013 const wchar_t s[] = L"adefgc";
1014 assert(std::regex_match(s, m, std::wregex(L"a.\\{3,5\\}c", std::regex_constants::basic)));
1015 assert(m.size() == 1);
1016 assert(!m.prefix().matched);
1017 assert(m.prefix().first == s);
1018 assert(m.prefix().second == m[0].first);
1019 assert(!m.suffix().matched);
1020 assert(m.suffix().first == m[0].second);
1021 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001022 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001023 assert(m.position(0) == 0);
1024 assert(m.str(0) == s);
1025 }
1026 {
1027 std::wcmatch m;
1028 const wchar_t s[] = L"adefghc";
1029 assert(std::regex_match(s, m, std::wregex(L"a.\\{3,5\\}c", std::regex_constants::basic)));
1030 assert(m.size() == 1);
1031 assert(!m.prefix().matched);
1032 assert(m.prefix().first == s);
1033 assert(m.prefix().second == m[0].first);
1034 assert(!m.suffix().matched);
1035 assert(m.suffix().first == m[0].second);
1036 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001037 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001038 assert(m.position(0) == 0);
1039 assert(m.str(0) == s);
1040 }
1041 {
1042 std::wcmatch m;
1043 const wchar_t s[] = L"adefghic";
1044 assert(!std::regex_match(s, m, std::wregex(L"a.\\{3,5\\}c", std::regex_constants::basic)));
1045 assert(m.size() == 0);
1046 }
1047 {
1048 std::wcmatch m;
1049 const wchar_t s[] = L"-ab,ab-";
1050 assert(std::regex_match(s, m, std::wregex(L"-\\(.*\\),\\1-", std::regex_constants::basic)));
1051 assert(m.size() == 2);
1052 assert(!m.prefix().matched);
1053 assert(m.prefix().first == s);
1054 assert(m.prefix().second == m[0].first);
1055 assert(!m.suffix().matched);
1056 assert(m.suffix().first == m[0].second);
1057 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001058 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001059 assert(m.position(0) == 0);
1060 assert(m.str(0) == s);
1061 assert(m.length(1) == 2);
1062 assert(m.position(1) == 1);
1063 assert(m.str(1) == L"ab");
1064 }
1065 {
1066 std::wcmatch m;
1067 const wchar_t s[] = L"ababbabb";
1068 assert(std::regex_match(s, m, std::wregex(L"^\\(ab*\\)*\\1$", std::regex_constants::basic)));
1069 assert(m.size() == 2);
1070 assert(!m.prefix().matched);
1071 assert(m.prefix().first == s);
1072 assert(m.prefix().second == m[0].first);
1073 assert(!m.suffix().matched);
1074 assert(m.suffix().first == m[0].second);
1075 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001076 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001077 assert(m.position(0) == 0);
1078 assert(m.str(0) == s);
1079 assert(m.length(1) == 3);
1080 assert(m.position(1) == 2);
1081 assert(m.str(1) == L"abb");
1082 }
1083 {
1084 std::wcmatch m;
1085 const wchar_t s[] = L"ababbab";
1086 assert(!std::regex_match(s, m, std::wregex(L"^\\(ab*\\)*\\1$", std::regex_constants::basic)));
1087 assert(m.size() == 0);
1088 }
1089 {
1090 std::wcmatch m;
1091 const wchar_t s[] = L"aBAbbAbB";
1092 assert(std::regex_match(s, m, std::wregex(L"^\\(Ab*\\)*\\1$",
1093 std::regex_constants::basic | std::regex_constants::icase)));
1094 assert(m.size() == 2);
1095 assert(!m.prefix().matched);
1096 assert(m.prefix().first == s);
1097 assert(m.prefix().second == m[0].first);
1098 assert(!m.suffix().matched);
1099 assert(m.suffix().first == m[0].second);
1100 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001101 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001102 assert(m.position(0) == 0);
1103 assert(m.str(0) == s);
1104 assert(m.length(1) == 3);
1105 assert(m.position(1) == 2);
1106 assert(m.str(1) == L"Abb");
1107 }
1108 {
1109 std::wcmatch m;
1110 const wchar_t s[] = L"aBAbbAbB";
1111 assert(!std::regex_match(s, m, std::wregex(L"^\\(Ab*\\)*\\1$",
1112 std::regex_constants::basic)));
1113 assert(m.size() == 0);
1114 }
1115 {
1116 std::wcmatch m;
1117 const wchar_t s[] = L"a";
1118 assert(std::regex_match(s, m, std::wregex(L"^[a]$",
1119 std::regex_constants::basic)));
1120 assert(m.size() == 1);
1121 assert(!m.prefix().matched);
1122 assert(m.prefix().first == s);
1123 assert(m.prefix().second == m[0].first);
1124 assert(!m.suffix().matched);
1125 assert(m.suffix().first == m[0].second);
1126 assert(m.suffix().second == m[0].second);
1127 assert(m.length(0) == 1);
1128 assert(m.position(0) == 0);
1129 assert(m.str(0) == L"a");
1130 }
1131 {
1132 std::wcmatch m;
1133 const wchar_t s[] = L"a";
1134 assert(std::regex_match(s, m, std::wregex(L"^[ab]$",
1135 std::regex_constants::basic)));
1136 assert(m.size() == 1);
1137 assert(!m.prefix().matched);
1138 assert(m.prefix().first == s);
1139 assert(m.prefix().second == m[0].first);
1140 assert(!m.suffix().matched);
1141 assert(m.suffix().first == m[0].second);
1142 assert(m.suffix().second == m[0].second);
1143 assert(m.length(0) == 1);
1144 assert(m.position(0) == 0);
1145 assert(m.str(0) == L"a");
1146 }
1147 {
1148 std::wcmatch m;
1149 const wchar_t s[] = L"c";
1150 assert(std::regex_match(s, m, std::wregex(L"^[a-f]$",
1151 std::regex_constants::basic)));
1152 assert(m.size() == 1);
1153 assert(!m.prefix().matched);
1154 assert(m.prefix().first == s);
1155 assert(m.prefix().second == m[0].first);
1156 assert(!m.suffix().matched);
1157 assert(m.suffix().first == m[0].second);
1158 assert(m.suffix().second == m[0].second);
1159 assert(m.length(0) == 1);
1160 assert(m.position(0) == 0);
1161 assert(m.str(0) == s);
1162 }
1163 {
1164 std::wcmatch m;
1165 const wchar_t s[] = L"g";
1166 assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$",
1167 std::regex_constants::basic)));
1168 assert(m.size() == 0);
1169 }
1170 {
1171 std::wcmatch m;
1172 const wchar_t s[] = L"Iraqi";
1173 assert(!std::regex_match(s, m, std::wregex(L"q[^u]",
1174 std::regex_constants::basic)));
1175 assert(m.size() == 0);
1176 }
1177 {
1178 std::wcmatch m;
1179 const wchar_t s[] = L"Iraq";
1180 assert(!std::regex_match(s, m, std::wregex(L"q[^u]",
1181 std::regex_constants::basic)));
1182 assert(m.size() == 0);
1183 }
1184 {
1185 std::wcmatch m;
1186 const wchar_t s[] = L"AmB";
1187 assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B",
1188 std::regex_constants::basic)));
1189 assert(m.size() == 1);
1190 assert(!m.prefix().matched);
1191 assert(m.prefix().first == s);
1192 assert(m.prefix().second == m[0].first);
1193 assert(!m.suffix().matched);
1194 assert(m.suffix().first == m[0].second);
1195 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001196 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001197 assert(m.position(0) == 0);
1198 assert(m.str(0) == s);
1199 }
1200 {
1201 std::wcmatch m;
1202 const wchar_t s[] = L"AMB";
1203 assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B",
1204 std::regex_constants::basic)));
1205 assert(m.size() == 0);
1206 }
1207 {
1208 std::wcmatch m;
1209 const wchar_t s[] = L"AMB";
1210 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B",
1211 std::regex_constants::basic)));
1212 assert(m.size() == 1);
1213 assert(!m.prefix().matched);
1214 assert(m.prefix().first == s);
1215 assert(m.prefix().second == m[0].first);
1216 assert(!m.suffix().matched);
1217 assert(m.suffix().first == m[0].second);
1218 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001219 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001220 assert(m.position(0) == 0);
1221 assert(m.str(0) == s);
1222 }
1223 {
1224 std::wcmatch m;
1225 const wchar_t s[] = L"AmB";
1226 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B",
1227 std::regex_constants::basic)));
1228 assert(m.size() == 0);
1229 }
1230 {
1231 std::wcmatch m;
1232 const wchar_t s[] = L"A5B";
1233 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1234 std::regex_constants::basic)));
1235 assert(m.size() == 0);
1236 }
1237 {
1238 std::wcmatch m;
1239 const wchar_t s[] = L"A?B";
1240 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B",
1241 std::regex_constants::basic)));
1242 assert(m.size() == 1);
1243 assert(!m.prefix().matched);
1244 assert(m.prefix().first == s);
1245 assert(m.prefix().second == m[0].first);
1246 assert(!m.suffix().matched);
1247 assert(m.suffix().first == m[0].second);
1248 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001249 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001250 assert(m.position(0) == 0);
1251 assert(m.str(0) == s);
1252 }
1253 {
1254 std::wcmatch m;
1255 const wchar_t s[] = L"-";
1256 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1257 std::regex_constants::basic)));
1258 assert(m.size() == 1);
1259 assert(!m.prefix().matched);
1260 assert(m.prefix().first == s);
1261 assert(m.prefix().second == m[0].first);
1262 assert(!m.suffix().matched);
1263 assert(m.suffix().first == m[0].second);
1264 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001265 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001266 assert(m.position(0) == 0);
1267 assert(m.str(0) == s);
1268 }
1269 {
1270 std::wcmatch m;
1271 const wchar_t s[] = L"z";
1272 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1273 std::regex_constants::basic)));
1274 assert(m.size() == 1);
1275 assert(!m.prefix().matched);
1276 assert(m.prefix().first == s);
1277 assert(m.prefix().second == m[0].first);
1278 assert(!m.suffix().matched);
1279 assert(m.suffix().first == m[0].second);
1280 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001281 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001282 assert(m.position(0) == 0);
1283 assert(m.str(0) == s);
1284 }
1285 {
1286 std::wcmatch m;
1287 const wchar_t s[] = L"m";
1288 assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]",
1289 std::regex_constants::basic)));
1290 assert(m.size() == 0);
1291 }
Ed Schoutenf4249902015-03-16 15:09:15 +00001292 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
Howard Hinnant51e39672010-08-14 19:58:44 +00001293 {
1294 std::wcmatch m;
1295 const wchar_t s[] = L"m";
1296 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
1297 std::regex_constants::basic)));
1298 assert(m.size() == 1);
1299 assert(!m.prefix().matched);
1300 assert(m.prefix().first == s);
1301 assert(m.prefix().second == m[0].first);
1302 assert(!m.suffix().matched);
1303 assert(m.suffix().first == m[0].second);
1304 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001305 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001306 assert(m.position(0) == 0);
1307 assert(m.str(0) == s);
1308 }
1309 {
1310 std::wcmatch m;
1311 const wchar_t s[] = L"Ch";
1312 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
1313 std::regex_constants::basic | std::regex_constants::icase)));
1314 assert(m.size() == 1);
1315 assert(!m.prefix().matched);
1316 assert(m.prefix().first == s);
1317 assert(m.prefix().second == m[0].first);
1318 assert(!m.suffix().matched);
1319 assert(m.suffix().first == m[0].second);
1320 assert(m.suffix().second == m[0].second);
Eric Fiseliere161f972016-12-24 03:20:53 +00001321 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
Howard Hinnant51e39672010-08-14 19:58:44 +00001322 assert(m.position(0) == 0);
1323 assert(m.str(0) == s);
1324 }
1325 std::locale::global(std::locale("C"));
1326 {
1327 std::wcmatch m;
1328 const wchar_t s[] = L"m";
1329 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
1330 std::regex_constants::basic)));
1331 assert(m.size() == 0);
1332 }
1333 {
1334 std::wcmatch m;
1335 const wchar_t s[] = L"01a45cef9";
1336 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*",
1337 std::regex_constants::basic)));
1338 assert(m.size() == 0);
1339 }
1340 {
1341 std::wcmatch m;
1342 const wchar_t s[] = L"01a45cef9";
1343 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]\\{1,\\}",
1344 std::regex_constants::basic)));
1345 assert(m.size() == 0);
1346 }
1347 {
1348 const wchar_t r[] = L"^[-+]\\{0,1\\}[0-9]\\{1,\\}[CF]$";
1349 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
1350 typedef forward_iterator<const wchar_t*> FI;
1351 typedef bidirectional_iterator<const wchar_t*> BI;
1352 std::wregex regex(FI(r), FI(r+sr), std::regex_constants::basic);
1353 std::match_results<BI> m;
1354 const wchar_t s[] = L"-40C";
1355 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
1356 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
1357 assert(m.size() == 1);
1358 assert(!m.prefix().matched);
1359 assert(m.prefix().first == BI(s));
1360 assert(m.prefix().second == m[0].first);
1361 assert(!m.suffix().matched);
1362 assert(m.suffix().first == m[0].second);
1363 assert(m.suffix().second == m[0].second);
1364 assert(m.length(0) == 4);
1365 assert(m.position(0) == 0);
1366 assert(m.str(0) == s);
1367 }
1368}