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