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