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