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