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