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