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