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