1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// REQUIRES: locale.cs_CZ.ISO8859-2 11 12// <regex> 13 14// template <class BidirectionalIterator, class Allocator, class charT, class traits> 15// bool 16// regex_search(BidirectionalIterator first, BidirectionalIterator last, 17// match_results<BidirectionalIterator, Allocator>& m, 18// const basic_regex<charT, traits>& e, 19// regex_constants::match_flag_type flags = regex_constants::match_default); 20 21// TODO: investigation needed 22// XFAIL: linux-gnu 23 24#include <regex> 25#include <cassert> 26#include "test_macros.h" 27#include "test_iterators.h" 28 29#include "platform_support.h" // locale name macros 30 31int main() 32{ 33 { 34 std::cmatch m; 35 const char s[] = "a"; 36 assert(std::regex_search(s, m, std::regex("a", std::regex_constants::awk))); 37 assert(m.size() == 1); 38 assert(!m.empty()); 39 assert(!m.prefix().matched); 40 assert(m.prefix().first == s); 41 assert(m.prefix().second == m[0].first); 42 assert(!m.suffix().matched); 43 assert(m.suffix().first == m[0].second); 44 assert(m.suffix().second == s+1); 45 assert(m.length(0) == 1); 46 assert(m.position(0) == 0); 47 assert(m.str(0) == "a"); 48 } 49 { 50 std::cmatch m; 51 const char s[] = "ab"; 52 assert(std::regex_search(s, m, std::regex("ab", std::regex_constants::awk))); 53 assert(m.size() == 1); 54 assert(!m.prefix().matched); 55 assert(m.prefix().first == s); 56 assert(m.prefix().second == m[0].first); 57 assert(!m.suffix().matched); 58 assert(m.suffix().first == m[0].second); 59 assert(m.suffix().second == s+2); 60 assert(m.length(0) == 2); 61 assert(m.position(0) == 0); 62 assert(m.str(0) == "ab"); 63 } 64 { 65 std::cmatch m; 66 const char s[] = "ab"; 67 assert(!std::regex_search(s, m, std::regex("ba", std::regex_constants::awk))); 68 assert(m.size() == 0); 69 assert(m.empty()); 70 } 71 { 72 std::cmatch m; 73 const char s[] = "aab"; 74 assert(std::regex_search(s, m, std::regex("ab", std::regex_constants::awk))); 75 assert(m.size() == 1); 76 assert(m.prefix().matched); 77 assert(m.prefix().first == s); 78 assert(m.prefix().second == m[0].first); 79 assert(!m.suffix().matched); 80 assert(m.suffix().first == m[0].second); 81 assert(m.suffix().second == s+3); 82 assert(m.length(0) == 2); 83 assert(m.position(0) == 1); 84 assert(m.str(0) == "ab"); 85 } 86 { 87 std::cmatch m; 88 const char s[] = "aab"; 89 assert(!std::regex_search(s, m, std::regex("ab", std::regex_constants::awk), 90 std::regex_constants::match_continuous)); 91 assert(m.size() == 0); 92 } 93 { 94 std::cmatch m; 95 const char s[] = "abcd"; 96 assert(std::regex_search(s, m, std::regex("bc", std::regex_constants::awk))); 97 assert(m.size() == 1); 98 assert(m.prefix().matched); 99 assert(m.prefix().first == s); 100 assert(m.prefix().second == m[0].first); 101 assert(m.suffix().matched); 102 assert(m.suffix().first == m[0].second); 103 assert(m.suffix().second == s+4); 104 assert(m.length(0) == 2); 105 assert(m.position(0) == 1); 106 assert(m.str(0) == "bc"); 107 } 108 { 109 std::cmatch m; 110 const char s[] = "abbc"; 111 assert(std::regex_search(s, m, std::regex("ab*c", std::regex_constants::awk))); 112 assert(m.size() == 1); 113 assert(!m.prefix().matched); 114 assert(m.prefix().first == s); 115 assert(m.prefix().second == m[0].first); 116 assert(!m.suffix().matched); 117 assert(m.suffix().first == m[0].second); 118 assert(m.suffix().second == s+4); 119 assert(m.length(0) == 4); 120 assert(m.position(0) == 0); 121 assert(m.str(0) == s); 122 } 123 { 124 std::cmatch m; 125 const char s[] = "ababc"; 126 assert(std::regex_search(s, m, std::regex("(ab)*c", std::regex_constants::awk))); 127 assert(m.size() == 2); 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+5); 134 assert(m.length(0) == 5); 135 assert(m.position(0) == 0); 136 assert(m.str(0) == s); 137 assert(m.length(1) == 2); 138 assert(m.position(1) == 2); 139 assert(m.str(1) == "ab"); 140 } 141 { 142 std::cmatch m; 143 const char s[] = "abcdefghijk"; 144 assert(std::regex_search(s, m, std::regex("cd((e)fg)hi", 145 std::regex_constants::awk))); 146 assert(m.size() == 3); 147 assert(m.prefix().matched); 148 assert(m.prefix().first == s); 149 assert(m.prefix().second == m[0].first); 150 assert(m.suffix().matched); 151 assert(m.suffix().first == m[0].second); 152 assert(m.suffix().second == s+std::regex_traits<char>::length(s)); 153 assert(m.length(0) == 7); 154 assert(m.position(0) == 2); 155 assert(m.str(0) == "cdefghi"); 156 assert(m.length(1) == 3); 157 assert(m.position(1) == 4); 158 assert(m.str(1) == "efg"); 159 assert(m.length(2) == 1); 160 assert(m.position(2) == 4); 161 assert(m.str(2) == "e"); 162 } 163 { 164 std::cmatch m; 165 const char s[] = "abc"; 166 assert(std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); 167 assert(m.size() == 1); 168 assert(!m.prefix().matched); 169 assert(m.prefix().first == s); 170 assert(m.prefix().second == m[0].first); 171 assert(!m.suffix().matched); 172 assert(m.suffix().first == m[0].second); 173 assert(m.suffix().second == s+3); 174 assert(m.length(0) == 3); 175 assert(m.position(0) == 0); 176 assert(m.str(0) == s); 177 } 178 { 179 std::cmatch m; 180 const char s[] = "abcd"; 181 assert(std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); 182 assert(m.size() == 1); 183 assert(!m.prefix().matched); 184 assert(m.prefix().first == s); 185 assert(m.prefix().second == m[0].first); 186 assert(m.suffix().matched); 187 assert(m.suffix().first == m[0].second); 188 assert(m.suffix().second == s+4); 189 assert(m.length(0) == 3); 190 assert(m.position(0) == 0); 191 assert(m.str(0) == "abc"); 192 } 193 { 194 std::cmatch m; 195 const char s[] = "aabc"; 196 assert(!std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); 197 assert(m.size() == 0); 198 } 199 { 200 std::cmatch m; 201 const char s[] = "abc"; 202 assert(std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); 203 assert(m.size() == 1); 204 assert(!m.prefix().matched); 205 assert(m.prefix().first == s); 206 assert(m.prefix().second == m[0].first); 207 assert(!m.suffix().matched); 208 assert(m.suffix().first == m[0].second); 209 assert(m.suffix().second == s+3); 210 assert(m.length(0) == 3); 211 assert(m.position(0) == 0); 212 assert(m.str(0) == s); 213 } 214 { 215 std::cmatch m; 216 const char s[] = "efabc"; 217 assert(std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); 218 assert(m.size() == 1); 219 assert(m.prefix().matched); 220 assert(m.prefix().first == s); 221 assert(m.prefix().second == m[0].first); 222 assert(!m.suffix().matched); 223 assert(m.suffix().first == m[0].second); 224 assert(m.suffix().second == s+5); 225 assert(m.length(0) == 3); 226 assert(m.position(0) == 2); 227 assert(m.str(0) == s+2); 228 } 229 { 230 std::cmatch m; 231 const char s[] = "efabcg"; 232 assert(!std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); 233 assert(m.size() == 0); 234 } 235 { 236 std::cmatch m; 237 const char s[] = "abc"; 238 assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); 239 assert(m.size() == 1); 240 assert(!m.prefix().matched); 241 assert(m.prefix().first == s); 242 assert(m.prefix().second == m[0].first); 243 assert(!m.suffix().matched); 244 assert(m.suffix().first == m[0].second); 245 assert(m.suffix().second == s+3); 246 assert(m.length(0) == 3); 247 assert(m.position(0) == 0); 248 assert(m.str(0) == s); 249 } 250 { 251 std::cmatch m; 252 const char s[] = "acc"; 253 assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); 254 assert(m.size() == 1); 255 assert(!m.prefix().matched); 256 assert(m.prefix().first == s); 257 assert(m.prefix().second == m[0].first); 258 assert(!m.suffix().matched); 259 assert(m.suffix().first == m[0].second); 260 assert(m.suffix().second == s+3); 261 assert(m.length(0) == 3); 262 assert(m.position(0) == 0); 263 assert(m.str(0) == s); 264 } 265 { 266 std::cmatch m; 267 const char s[] = "acc"; 268 assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); 269 assert(m.size() == 1); 270 assert(!m.prefix().matched); 271 assert(m.prefix().first == s); 272 assert(m.prefix().second == m[0].first); 273 assert(!m.suffix().matched); 274 assert(m.suffix().first == m[0].second); 275 assert(m.suffix().second == s+3); 276 assert(m.length(0) == 3); 277 assert(m.position(0) == 0); 278 assert(m.str(0) == s); 279 } 280 { 281 std::cmatch m; 282 const char s[] = "abcdef"; 283 assert(std::regex_search(s, m, std::regex("(.*).*", std::regex_constants::awk))); 284 assert(m.size() == 2); 285 assert(!m.prefix().matched); 286 assert(m.prefix().first == s); 287 assert(m.prefix().second == m[0].first); 288 assert(!m.suffix().matched); 289 assert(m.suffix().first == m[0].second); 290 assert(m.suffix().second == s+6); 291 assert(m.length(0) == 6); 292 assert(m.position(0) == 0); 293 assert(m.str(0) == s); 294 assert(m.length(1) == 6); 295 assert(m.position(1) == 0); 296 assert(m.str(1) == s); 297 } 298 { 299 std::cmatch m; 300 const char s[] = "bc"; 301 assert(std::regex_search(s, m, std::regex("(a*)*", std::regex_constants::awk))); 302 assert(m.size() == 2); 303 assert(!m.prefix().matched); 304 assert(m.prefix().first == s); 305 assert(m.prefix().second == m[0].first); 306 assert(m.suffix().matched); 307 assert(m.suffix().first == m[0].second); 308 assert(m.suffix().second == s+2); 309 assert(m.length(0) == 0); 310 assert(m.position(0) == 0); 311 assert(m.str(0) == ""); 312 assert(m.length(1) == 0); 313 assert(m.position(1) == 0); 314 assert(m.str(1) == ""); 315 } 316 { 317 std::cmatch m; 318 const char s[] = "abbc"; 319 assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 320 assert(m.size() == 0); 321 } 322 { 323 std::cmatch m; 324 const char s[] = "abbbc"; 325 assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 326 assert(m.size() == 1); 327 assert(!m.prefix().matched); 328 assert(m.prefix().first == s); 329 assert(m.prefix().second == m[0].first); 330 assert(!m.suffix().matched); 331 assert(m.suffix().first == m[0].second); 332 assert(m.suffix().second == m[0].second); 333 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 334 assert(m.position(0) == 0); 335 assert(m.str(0) == s); 336 } 337 { 338 std::cmatch m; 339 const char s[] = "abbbbc"; 340 assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 341 assert(m.size() == 1); 342 assert(!m.prefix().matched); 343 assert(m.prefix().first == s); 344 assert(m.prefix().second == m[0].first); 345 assert(!m.suffix().matched); 346 assert(m.suffix().first == m[0].second); 347 assert(m.suffix().second == m[0].second); 348 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 349 assert(m.position(0) == 0); 350 assert(m.str(0) == s); 351 } 352 { 353 std::cmatch m; 354 const char s[] = "abbbbbc"; 355 assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 356 assert(m.size() == 1); 357 assert(!m.prefix().matched); 358 assert(m.prefix().first == s); 359 assert(m.prefix().second == m[0].first); 360 assert(!m.suffix().matched); 361 assert(m.suffix().first == m[0].second); 362 assert(m.suffix().second == m[0].second); 363 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 364 assert(m.position(0) == 0); 365 assert(m.str(0) == s); 366 } 367 { 368 std::cmatch m; 369 const char s[] = "adefc"; 370 assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 371 assert(m.size() == 0); 372 } 373 { 374 std::cmatch m; 375 const char s[] = "abbbbbbc"; 376 assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); 377 assert(m.size() == 0); 378 } 379 { 380 std::cmatch m; 381 const char s[] = "adec"; 382 assert(!std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); 383 assert(m.size() == 0); 384 } 385 { 386 std::cmatch m; 387 const char s[] = "adefc"; 388 assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); 389 assert(m.size() == 1); 390 assert(!m.prefix().matched); 391 assert(m.prefix().first == s); 392 assert(m.prefix().second == m[0].first); 393 assert(!m.suffix().matched); 394 assert(m.suffix().first == m[0].second); 395 assert(m.suffix().second == m[0].second); 396 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 397 assert(m.position(0) == 0); 398 assert(m.str(0) == s); 399 } 400 { 401 std::cmatch m; 402 const char s[] = "adefgc"; 403 assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); 404 assert(m.size() == 1); 405 assert(!m.prefix().matched); 406 assert(m.prefix().first == s); 407 assert(m.prefix().second == m[0].first); 408 assert(!m.suffix().matched); 409 assert(m.suffix().first == m[0].second); 410 assert(m.suffix().second == m[0].second); 411 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 412 assert(m.position(0) == 0); 413 assert(m.str(0) == s); 414 } 415 { 416 std::cmatch m; 417 const char s[] = "adefghc"; 418 assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); 419 assert(m.size() == 1); 420 assert(!m.prefix().matched); 421 assert(m.prefix().first == s); 422 assert(m.prefix().second == m[0].first); 423 assert(!m.suffix().matched); 424 assert(m.suffix().first == m[0].second); 425 assert(m.suffix().second == m[0].second); 426 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 427 assert(m.position(0) == 0); 428 assert(m.str(0) == s); 429 } 430 { 431 std::cmatch m; 432 const char s[] = "adefghic"; 433 assert(!std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); 434 assert(m.size() == 0); 435 } 436 { 437 std::cmatch m; 438 const char s[] = "tournament"; 439 assert(std::regex_search(s, m, std::regex("tour|to|tournament", 440 std::regex_constants::awk))); 441 assert(m.size() == 1); 442 assert(!m.prefix().matched); 443 assert(m.prefix().first == s); 444 assert(m.prefix().second == m[0].first); 445 assert(!m.suffix().matched); 446 assert(m.suffix().first == m[0].second); 447 assert(m.suffix().second == m[0].second); 448 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 449 assert(m.position(0) == 0); 450 assert(m.str(0) == s); 451 } 452 { 453 std::cmatch m; 454 const char s[] = "tournamenttotour"; 455 assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+", 456 std::regex_constants::awk | std::regex_constants::nosubs))); 457 assert(m.size() == 1); 458 assert(!m.prefix().matched); 459 assert(m.prefix().first == s); 460 assert(m.prefix().second == m[0].first); 461 assert(!m.suffix().matched); 462 assert(m.suffix().first == m[0].second); 463 assert(m.suffix().second == m[0].second); 464 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 465 assert(m.position(0) == 0); 466 assert(m.str(0) == s); 467 } 468 { 469 std::cmatch m; 470 const char s[] = "ttotour"; 471 assert(std::regex_search(s, m, std::regex("(tour|to|t)+", 472 std::regex_constants::awk))); 473 assert(m.size() == 2); 474 assert(!m.prefix().matched); 475 assert(m.prefix().first == s); 476 assert(m.prefix().second == m[0].first); 477 assert(!m.suffix().matched); 478 assert(m.suffix().first == m[0].second); 479 assert(m.suffix().second == m[0].second); 480 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 481 assert(m.position(0) == 0); 482 assert(m.str(0) == s); 483 assert(m.length(1) == 4); 484 assert(m.position(1) == 3); 485 assert(m.str(1) == "tour"); 486 } 487 { 488 std::cmatch m; 489 const char s[] = "-ab,ab-"; 490 assert(!std::regex_search(s, m, std::regex("-(.*),\1-", std::regex_constants::awk))); 491 assert(m.size() == 0); 492 } 493 { 494 std::cmatch m; 495 const char s[] = "-ab,ab-"; 496 assert(std::regex_search(s, m, std::regex("-.*,.*-", std::regex_constants::awk))); 497 assert(m.size() == 1); 498 assert(!m.prefix().matched); 499 assert(m.prefix().first == s); 500 assert(m.prefix().second == m[0].first); 501 assert(!m.suffix().matched); 502 assert(m.suffix().first == m[0].second); 503 assert(m.suffix().second == m[0].second); 504 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 505 assert(m.position(0) == 0); 506 assert(m.str(0) == s); 507 } 508 { 509 std::cmatch m; 510 const char s[] = "a"; 511 assert(std::regex_search(s, m, std::regex("^[a]$", 512 std::regex_constants::awk))); 513 assert(m.size() == 1); 514 assert(!m.prefix().matched); 515 assert(m.prefix().first == s); 516 assert(m.prefix().second == m[0].first); 517 assert(!m.suffix().matched); 518 assert(m.suffix().first == m[0].second); 519 assert(m.suffix().second == m[0].second); 520 assert(m.length(0) == 1); 521 assert(m.position(0) == 0); 522 assert(m.str(0) == "a"); 523 } 524 { 525 std::cmatch m; 526 const char s[] = "a"; 527 assert(std::regex_search(s, m, std::regex("^[ab]$", 528 std::regex_constants::awk))); 529 assert(m.size() == 1); 530 assert(!m.prefix().matched); 531 assert(m.prefix().first == s); 532 assert(m.prefix().second == m[0].first); 533 assert(!m.suffix().matched); 534 assert(m.suffix().first == m[0].second); 535 assert(m.suffix().second == m[0].second); 536 assert(m.length(0) == 1); 537 assert(m.position(0) == 0); 538 assert(m.str(0) == "a"); 539 } 540 { 541 std::cmatch m; 542 const char s[] = "c"; 543 assert(std::regex_search(s, m, std::regex("^[a-f]$", 544 std::regex_constants::awk))); 545 assert(m.size() == 1); 546 assert(!m.prefix().matched); 547 assert(m.prefix().first == s); 548 assert(m.prefix().second == m[0].first); 549 assert(!m.suffix().matched); 550 assert(m.suffix().first == m[0].second); 551 assert(m.suffix().second == m[0].second); 552 assert(m.length(0) == 1); 553 assert(m.position(0) == 0); 554 assert(m.str(0) == s); 555 } 556 { 557 std::cmatch m; 558 const char s[] = "g"; 559 assert(!std::regex_search(s, m, std::regex("^[a-f]$", 560 std::regex_constants::awk))); 561 assert(m.size() == 0); 562 } 563 { 564 std::cmatch m; 565 const char s[] = "Iraqi"; 566 assert(std::regex_search(s, m, std::regex("q[^u]", 567 std::regex_constants::awk))); 568 assert(m.size() == 1); 569 assert(m.prefix().matched); 570 assert(m.prefix().first == s); 571 assert(m.prefix().second == m[0].first); 572 assert(!m.suffix().matched); 573 assert(m.suffix().first == m[0].second); 574 assert(m.suffix().second == m[0].second); 575 assert(m.length(0) == 2); 576 assert(m.position(0) == 3); 577 assert(m.str(0) == "qi"); 578 } 579 { 580 std::cmatch m; 581 const char s[] = "Iraq"; 582 assert(!std::regex_search(s, m, std::regex("q[^u]", 583 std::regex_constants::awk))); 584 assert(m.size() == 0); 585 } 586 { 587 std::cmatch m; 588 const char s[] = "AmB"; 589 assert(std::regex_search(s, m, std::regex("A[[:lower:]]B", 590 std::regex_constants::awk))); 591 assert(m.size() == 1); 592 assert(!m.prefix().matched); 593 assert(m.prefix().first == s); 594 assert(m.prefix().second == m[0].first); 595 assert(!m.suffix().matched); 596 assert(m.suffix().first == m[0].second); 597 assert(m.suffix().second == m[0].second); 598 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 599 assert(m.position(0) == 0); 600 assert(m.str(0) == s); 601 } 602 { 603 std::cmatch m; 604 const char s[] = "AMB"; 605 assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B", 606 std::regex_constants::awk))); 607 assert(m.size() == 0); 608 } 609 { 610 std::cmatch m; 611 const char s[] = "AMB"; 612 assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B", 613 std::regex_constants::awk))); 614 assert(m.size() == 1); 615 assert(!m.prefix().matched); 616 assert(m.prefix().first == s); 617 assert(m.prefix().second == m[0].first); 618 assert(!m.suffix().matched); 619 assert(m.suffix().first == m[0].second); 620 assert(m.suffix().second == m[0].second); 621 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 622 assert(m.position(0) == 0); 623 assert(m.str(0) == s); 624 } 625 { 626 std::cmatch m; 627 const char s[] = "AmB"; 628 assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B", 629 std::regex_constants::awk))); 630 assert(m.size() == 0); 631 } 632 { 633 std::cmatch m; 634 const char s[] = "A5B"; 635 assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", 636 std::regex_constants::awk))); 637 assert(m.size() == 0); 638 } 639 { 640 std::cmatch m; 641 const char s[] = "A?B"; 642 assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", 643 std::regex_constants::awk))); 644 assert(m.size() == 1); 645 assert(!m.prefix().matched); 646 assert(m.prefix().first == s); 647 assert(m.prefix().second == m[0].first); 648 assert(!m.suffix().matched); 649 assert(m.suffix().first == m[0].second); 650 assert(m.suffix().second == m[0].second); 651 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 652 assert(m.position(0) == 0); 653 assert(m.str(0) == s); 654 } 655 { 656 std::cmatch m; 657 const char s[] = "-"; 658 assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", 659 std::regex_constants::awk))); 660 assert(m.size() == 1); 661 assert(!m.prefix().matched); 662 assert(m.prefix().first == s); 663 assert(m.prefix().second == m[0].first); 664 assert(!m.suffix().matched); 665 assert(m.suffix().first == m[0].second); 666 assert(m.suffix().second == m[0].second); 667 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 668 assert(m.position(0) == 0); 669 assert(m.str(0) == s); 670 } 671 { 672 std::cmatch m; 673 const char s[] = "z"; 674 assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", 675 std::regex_constants::awk))); 676 assert(m.size() == 1); 677 assert(!m.prefix().matched); 678 assert(m.prefix().first == s); 679 assert(m.prefix().second == m[0].first); 680 assert(!m.suffix().matched); 681 assert(m.suffix().first == m[0].second); 682 assert(m.suffix().second == m[0].second); 683 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 684 assert(m.position(0) == 0); 685 assert(m.str(0) == s); 686 } 687 { 688 std::cmatch m; 689 const char s[] = "m"; 690 assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]", 691 std::regex_constants::awk))); 692 assert(m.size() == 0); 693 } 694 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2)); 695 { 696 std::cmatch m; 697 const char s[] = "m"; 698 assert(std::regex_search(s, m, std::regex("[a[=M=]z]", 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 == m[0].second); 707 assert(m.length(0) >= 0 && static_cast<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::cmatch m; 713 const char s[] = "Ch"; 714 assert(std::regex_search(s, m, std::regex("[a[.ch.]z]", 715 std::regex_constants::awk | std::regex_constants::icase))); 716 assert(m.size() == 1); 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 == m[0].second); 723 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 724 assert(m.position(0) == 0); 725 assert(m.str(0) == s); 726 } 727 std::locale::global(std::locale("C")); 728 { 729 std::cmatch m; 730 const char s[] = "m"; 731 assert(!std::regex_search(s, m, std::regex("[a[=M=]z]", 732 std::regex_constants::awk))); 733 assert(m.size() == 0); 734 } 735 { 736 std::cmatch m; 737 const char s[] = "01a45cef9"; 738 assert(std::regex_search(s, m, std::regex("[ace1-9]*", 739 std::regex_constants::awk))); 740 assert(m.size() == 1); 741 assert(!m.prefix().matched); 742 assert(m.prefix().first == s); 743 assert(m.prefix().second == m[0].first); 744 assert(m.suffix().matched); 745 assert(m.suffix().first == m[0].second); 746 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 747 assert(m.length(0) == 0); 748 assert(m.position(0) == 0); 749 assert(m.str(0) == ""); 750 } 751 { 752 std::cmatch m; 753 const char s[] = "01a45cef9"; 754 assert(std::regex_search(s, m, std::regex("[ace1-9]+", 755 std::regex_constants::awk))); 756 assert(m.size() == 1); 757 assert(m.prefix().matched); 758 assert(m.prefix().first == s); 759 assert(m.prefix().second == m[0].first); 760 assert(m.suffix().matched); 761 assert(m.suffix().first == m[0].second); 762 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 763 assert(m.length(0) == 6); 764 assert(m.position(0) == 1); 765 assert(m.str(0) == "1a45ce"); 766 } 767 { 768 const char r[] = "^[-+]?[0-9]+[CF]$"; 769 std::ptrdiff_t sr = std::char_traits<char>::length(r); 770 typedef forward_iterator<const char*> FI; 771 typedef bidirectional_iterator<const char*> BI; 772 std::regex regex(FI(r), FI(r+sr), std::regex_constants::awk); 773 std::match_results<BI> m; 774 const char s[] = "-40C"; 775 std::ptrdiff_t ss = std::char_traits<char>::length(s); 776 assert(std::regex_search(BI(s), BI(s+ss), m, regex)); 777 assert(m.size() == 1); 778 assert(!m.prefix().matched); 779 assert(m.prefix().first == BI(s)); 780 assert(m.prefix().second == m[0].first); 781 assert(!m.suffix().matched); 782 assert(m.suffix().first == m[0].second); 783 assert(m.suffix().second == m[0].second); 784 assert(m.length(0) == 4); 785 assert(m.position(0) == 0); 786 assert(m.str(0) == s); 787 } 788 { 789 std::cmatch m; 790 const char s[] = "\n\n\n"; 791 assert(std::regex_search(s, m, std::regex("[\\n]+", 792 std::regex_constants::awk))); 793 assert(m.size() == 1); 794 assert(!m.prefix().matched); 795 assert(m.prefix().first == s); 796 assert(m.prefix().second == m[0].first); 797 assert(!m.suffix().matched); 798 assert(m.suffix().first == m[0].second); 799 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 800 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 801 assert(m.position(0) == 0); 802 assert(m.str(0) == s); 803 } 804 { 805 std::wcmatch m; 806 const wchar_t s[] = L"a"; 807 assert(std::regex_search(s, m, std::wregex(L"a", std::regex_constants::awk))); 808 assert(m.size() == 1); 809 assert(!m.empty()); 810 assert(!m.prefix().matched); 811 assert(m.prefix().first == s); 812 assert(m.prefix().second == m[0].first); 813 assert(!m.suffix().matched); 814 assert(m.suffix().first == m[0].second); 815 assert(m.suffix().second == s+1); 816 assert(m.length(0) == 1); 817 assert(m.position(0) == 0); 818 assert(m.str(0) == L"a"); 819 } 820 { 821 std::wcmatch m; 822 const wchar_t s[] = L"ab"; 823 assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk))); 824 assert(m.size() == 1); 825 assert(!m.prefix().matched); 826 assert(m.prefix().first == s); 827 assert(m.prefix().second == m[0].first); 828 assert(!m.suffix().matched); 829 assert(m.suffix().first == m[0].second); 830 assert(m.suffix().second == s+2); 831 assert(m.length(0) == 2); 832 assert(m.position(0) == 0); 833 assert(m.str(0) == L"ab"); 834 } 835 { 836 std::wcmatch m; 837 const wchar_t s[] = L"ab"; 838 assert(!std::regex_search(s, m, std::wregex(L"ba", std::regex_constants::awk))); 839 assert(m.size() == 0); 840 assert(m.empty()); 841 } 842 { 843 std::wcmatch m; 844 const wchar_t s[] = L"aab"; 845 assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk))); 846 assert(m.size() == 1); 847 assert(m.prefix().matched); 848 assert(m.prefix().first == s); 849 assert(m.prefix().second == m[0].first); 850 assert(!m.suffix().matched); 851 assert(m.suffix().first == m[0].second); 852 assert(m.suffix().second == s+3); 853 assert(m.length(0) == 2); 854 assert(m.position(0) == 1); 855 assert(m.str(0) == L"ab"); 856 } 857 { 858 std::wcmatch m; 859 const wchar_t s[] = L"aab"; 860 assert(!std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk), 861 std::regex_constants::match_continuous)); 862 assert(m.size() == 0); 863 } 864 { 865 std::wcmatch m; 866 const wchar_t s[] = L"abcd"; 867 assert(std::regex_search(s, m, std::wregex(L"bc", std::regex_constants::awk))); 868 assert(m.size() == 1); 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+4); 875 assert(m.length(0) == 2); 876 assert(m.position(0) == 1); 877 assert(m.str(0) == L"bc"); 878 } 879 { 880 std::wcmatch m; 881 const wchar_t s[] = L"abbc"; 882 assert(std::regex_search(s, m, std::wregex(L"ab*c", std::regex_constants::awk))); 883 assert(m.size() == 1); 884 assert(!m.prefix().matched); 885 assert(m.prefix().first == s); 886 assert(m.prefix().second == m[0].first); 887 assert(!m.suffix().matched); 888 assert(m.suffix().first == m[0].second); 889 assert(m.suffix().second == s+4); 890 assert(m.length(0) == 4); 891 assert(m.position(0) == 0); 892 assert(m.str(0) == s); 893 } 894 { 895 std::wcmatch m; 896 const wchar_t s[] = L"ababc"; 897 assert(std::regex_search(s, m, std::wregex(L"(ab)*c", std::regex_constants::awk))); 898 assert(m.size() == 2); 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 == s+5); 905 assert(m.length(0) == 5); 906 assert(m.position(0) == 0); 907 assert(m.str(0) == s); 908 assert(m.length(1) == 2); 909 assert(m.position(1) == 2); 910 assert(m.str(1) == L"ab"); 911 } 912 { 913 std::wcmatch m; 914 const wchar_t s[] = L"abcdefghijk"; 915 assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi", 916 std::regex_constants::awk))); 917 assert(m.size() == 3); 918 assert(m.prefix().matched); 919 assert(m.prefix().first == s); 920 assert(m.prefix().second == m[0].first); 921 assert(m.suffix().matched); 922 assert(m.suffix().first == m[0].second); 923 assert(m.suffix().second == s+std::regex_traits<wchar_t>::length(s)); 924 assert(m.length(0) == 7); 925 assert(m.position(0) == 2); 926 assert(m.str(0) == L"cdefghi"); 927 assert(m.length(1) == 3); 928 assert(m.position(1) == 4); 929 assert(m.str(1) == L"efg"); 930 assert(m.length(2) == 1); 931 assert(m.position(2) == 4); 932 assert(m.str(2) == L"e"); 933 } 934 { 935 std::wcmatch m; 936 const wchar_t s[] = L"abc"; 937 assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 938 assert(m.size() == 1); 939 assert(!m.prefix().matched); 940 assert(m.prefix().first == s); 941 assert(m.prefix().second == m[0].first); 942 assert(!m.suffix().matched); 943 assert(m.suffix().first == m[0].second); 944 assert(m.suffix().second == s+3); 945 assert(m.length(0) == 3); 946 assert(m.position(0) == 0); 947 assert(m.str(0) == s); 948 } 949 { 950 std::wcmatch m; 951 const wchar_t s[] = L"abcd"; 952 assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 953 assert(m.size() == 1); 954 assert(!m.prefix().matched); 955 assert(m.prefix().first == s); 956 assert(m.prefix().second == m[0].first); 957 assert(m.suffix().matched); 958 assert(m.suffix().first == m[0].second); 959 assert(m.suffix().second == s+4); 960 assert(m.length(0) == 3); 961 assert(m.position(0) == 0); 962 assert(m.str(0) == L"abc"); 963 } 964 { 965 std::wcmatch m; 966 const wchar_t s[] = L"aabc"; 967 assert(!std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 968 assert(m.size() == 0); 969 } 970 { 971 std::wcmatch m; 972 const wchar_t s[] = L"abc"; 973 assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 974 assert(m.size() == 1); 975 assert(!m.prefix().matched); 976 assert(m.prefix().first == s); 977 assert(m.prefix().second == m[0].first); 978 assert(!m.suffix().matched); 979 assert(m.suffix().first == m[0].second); 980 assert(m.suffix().second == s+3); 981 assert(m.length(0) == 3); 982 assert(m.position(0) == 0); 983 assert(m.str(0) == s); 984 } 985 { 986 std::wcmatch m; 987 const wchar_t s[] = L"efabc"; 988 assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 989 assert(m.size() == 1); 990 assert(m.prefix().matched); 991 assert(m.prefix().first == s); 992 assert(m.prefix().second == m[0].first); 993 assert(!m.suffix().matched); 994 assert(m.suffix().first == m[0].second); 995 assert(m.suffix().second == s+5); 996 assert(m.length(0) == 3); 997 assert(m.position(0) == 2); 998 assert(m.str(0) == s+2); 999 } 1000 { 1001 std::wcmatch m; 1002 const wchar_t s[] = L"efabcg"; 1003 assert(!std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 1004 assert(m.size() == 0); 1005 } 1006 { 1007 std::wcmatch m; 1008 const wchar_t s[] = L"abc"; 1009 assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk))); 1010 assert(m.size() == 1); 1011 assert(!m.prefix().matched); 1012 assert(m.prefix().first == s); 1013 assert(m.prefix().second == m[0].first); 1014 assert(!m.suffix().matched); 1015 assert(m.suffix().first == m[0].second); 1016 assert(m.suffix().second == s+3); 1017 assert(m.length(0) == 3); 1018 assert(m.position(0) == 0); 1019 assert(m.str(0) == s); 1020 } 1021 { 1022 std::wcmatch m; 1023 const wchar_t s[] = L"acc"; 1024 assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk))); 1025 assert(m.size() == 1); 1026 assert(!m.prefix().matched); 1027 assert(m.prefix().first == s); 1028 assert(m.prefix().second == m[0].first); 1029 assert(!m.suffix().matched); 1030 assert(m.suffix().first == m[0].second); 1031 assert(m.suffix().second == s+3); 1032 assert(m.length(0) == 3); 1033 assert(m.position(0) == 0); 1034 assert(m.str(0) == s); 1035 } 1036 { 1037 std::wcmatch m; 1038 const wchar_t s[] = L"acc"; 1039 assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk))); 1040 assert(m.size() == 1); 1041 assert(!m.prefix().matched); 1042 assert(m.prefix().first == s); 1043 assert(m.prefix().second == m[0].first); 1044 assert(!m.suffix().matched); 1045 assert(m.suffix().first == m[0].second); 1046 assert(m.suffix().second == s+3); 1047 assert(m.length(0) == 3); 1048 assert(m.position(0) == 0); 1049 assert(m.str(0) == s); 1050 } 1051 { 1052 std::wcmatch m; 1053 const wchar_t s[] = L"abcdef"; 1054 assert(std::regex_search(s, m, std::wregex(L"(.*).*", std::regex_constants::awk))); 1055 assert(m.size() == 2); 1056 assert(!m.prefix().matched); 1057 assert(m.prefix().first == s); 1058 assert(m.prefix().second == m[0].first); 1059 assert(!m.suffix().matched); 1060 assert(m.suffix().first == m[0].second); 1061 assert(m.suffix().second == s+6); 1062 assert(m.length(0) == 6); 1063 assert(m.position(0) == 0); 1064 assert(m.str(0) == s); 1065 assert(m.length(1) == 6); 1066 assert(m.position(1) == 0); 1067 assert(m.str(1) == s); 1068 } 1069 { 1070 std::wcmatch m; 1071 const wchar_t s[] = L"bc"; 1072 assert(std::regex_search(s, m, std::wregex(L"(a*)*", std::regex_constants::awk))); 1073 assert(m.size() == 2); 1074 assert(!m.prefix().matched); 1075 assert(m.prefix().first == s); 1076 assert(m.prefix().second == m[0].first); 1077 assert(m.suffix().matched); 1078 assert(m.suffix().first == m[0].second); 1079 assert(m.suffix().second == s+2); 1080 assert(m.length(0) == 0); 1081 assert(m.position(0) == 0); 1082 assert(m.str(0) == L""); 1083 assert(m.length(1) == 0); 1084 assert(m.position(1) == 0); 1085 assert(m.str(1) == L""); 1086 } 1087 { 1088 std::wcmatch m; 1089 const wchar_t s[] = L"abbc"; 1090 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1091 assert(m.size() == 0); 1092 } 1093 { 1094 std::wcmatch m; 1095 const wchar_t s[] = L"abbbc"; 1096 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1097 assert(m.size() == 1); 1098 assert(!m.prefix().matched); 1099 assert(m.prefix().first == s); 1100 assert(m.prefix().second == m[0].first); 1101 assert(!m.suffix().matched); 1102 assert(m.suffix().first == m[0].second); 1103 assert(m.suffix().second == m[0].second); 1104 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1105 assert(m.position(0) == 0); 1106 assert(m.str(0) == s); 1107 } 1108 { 1109 std::wcmatch m; 1110 const wchar_t s[] = L"abbbbc"; 1111 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", 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(m.length(0) >= 0 && static_cast<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"abbbbbc"; 1126 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1127 assert(m.size() == 1); 1128 assert(!m.prefix().matched); 1129 assert(m.prefix().first == s); 1130 assert(m.prefix().second == m[0].first); 1131 assert(!m.suffix().matched); 1132 assert(m.suffix().first == m[0].second); 1133 assert(m.suffix().second == m[0].second); 1134 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1135 assert(m.position(0) == 0); 1136 assert(m.str(0) == s); 1137 } 1138 { 1139 std::wcmatch m; 1140 const wchar_t s[] = L"adefc"; 1141 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1142 assert(m.size() == 0); 1143 } 1144 { 1145 std::wcmatch m; 1146 const wchar_t s[] = L"abbbbbbc"; 1147 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1148 assert(m.size() == 0); 1149 } 1150 { 1151 std::wcmatch m; 1152 const wchar_t s[] = L"adec"; 1153 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1154 assert(m.size() == 0); 1155 } 1156 { 1157 std::wcmatch m; 1158 const wchar_t s[] = L"adefc"; 1159 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", 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) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1168 assert(m.position(0) == 0); 1169 assert(m.str(0) == s); 1170 } 1171 { 1172 std::wcmatch m; 1173 const wchar_t s[] = L"adefgc"; 1174 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1175 assert(m.size() == 1); 1176 assert(!m.prefix().matched); 1177 assert(m.prefix().first == s); 1178 assert(m.prefix().second == m[0].first); 1179 assert(!m.suffix().matched); 1180 assert(m.suffix().first == m[0].second); 1181 assert(m.suffix().second == m[0].second); 1182 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1183 assert(m.position(0) == 0); 1184 assert(m.str(0) == s); 1185 } 1186 { 1187 std::wcmatch m; 1188 const wchar_t s[] = L"adefghc"; 1189 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1190 assert(m.size() == 1); 1191 assert(!m.prefix().matched); 1192 assert(m.prefix().first == s); 1193 assert(m.prefix().second == m[0].first); 1194 assert(!m.suffix().matched); 1195 assert(m.suffix().first == m[0].second); 1196 assert(m.suffix().second == m[0].second); 1197 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1198 assert(m.position(0) == 0); 1199 assert(m.str(0) == s); 1200 } 1201 { 1202 std::wcmatch m; 1203 const wchar_t s[] = L"adefghic"; 1204 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1205 assert(m.size() == 0); 1206 } 1207 { 1208 std::wcmatch m; 1209 const wchar_t s[] = L"tournament"; 1210 assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament", 1211 std::regex_constants::awk))); 1212 assert(m.size() == 1); 1213 assert(!m.prefix().matched); 1214 assert(m.prefix().first == s); 1215 assert(m.prefix().second == m[0].first); 1216 assert(!m.suffix().matched); 1217 assert(m.suffix().first == m[0].second); 1218 assert(m.suffix().second == m[0].second); 1219 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1220 assert(m.position(0) == 0); 1221 assert(m.str(0) == s); 1222 } 1223 { 1224 std::wcmatch m; 1225 const wchar_t s[] = L"tournamenttotour"; 1226 assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+", 1227 std::regex_constants::awk | std::regex_constants::nosubs))); 1228 assert(m.size() == 1); 1229 assert(!m.prefix().matched); 1230 assert(m.prefix().first == s); 1231 assert(m.prefix().second == m[0].first); 1232 assert(!m.suffix().matched); 1233 assert(m.suffix().first == m[0].second); 1234 assert(m.suffix().second == m[0].second); 1235 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1236 assert(m.position(0) == 0); 1237 assert(m.str(0) == s); 1238 } 1239 { 1240 std::wcmatch m; 1241 const wchar_t s[] = L"ttotour"; 1242 assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+", 1243 std::regex_constants::awk))); 1244 assert(m.size() == 2); 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 assert(m.length(1) == 4); 1255 assert(m.position(1) == 3); 1256 assert(m.str(1) == L"tour"); 1257 } 1258 { 1259 std::wcmatch m; 1260 const wchar_t s[] = L"-ab,ab-"; 1261 assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-", std::regex_constants::awk))); 1262 assert(m.size() == 0); 1263 } 1264 { 1265 std::wcmatch m; 1266 const wchar_t s[] = L"-ab,ab-"; 1267 assert(std::regex_search(s, m, std::wregex(L"-.*,.*-", std::regex_constants::awk))); 1268 assert(m.size() == 1); 1269 assert(!m.prefix().matched); 1270 assert(m.prefix().first == s); 1271 assert(m.prefix().second == m[0].first); 1272 assert(!m.suffix().matched); 1273 assert(m.suffix().first == m[0].second); 1274 assert(m.suffix().second == m[0].second); 1275 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1276 assert(m.position(0) == 0); 1277 assert(m.str(0) == s); 1278 } 1279 { 1280 std::wcmatch m; 1281 const wchar_t s[] = L"a"; 1282 assert(std::regex_search(s, m, std::wregex(L"^[a]$", 1283 std::regex_constants::awk))); 1284 assert(m.size() == 1); 1285 assert(!m.prefix().matched); 1286 assert(m.prefix().first == s); 1287 assert(m.prefix().second == m[0].first); 1288 assert(!m.suffix().matched); 1289 assert(m.suffix().first == m[0].second); 1290 assert(m.suffix().second == m[0].second); 1291 assert(m.length(0) == 1); 1292 assert(m.position(0) == 0); 1293 assert(m.str(0) == L"a"); 1294 } 1295 { 1296 std::wcmatch m; 1297 const wchar_t s[] = L"a"; 1298 assert(std::regex_search(s, m, std::wregex(L"^[ab]$", 1299 std::regex_constants::awk))); 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) == 1); 1308 assert(m.position(0) == 0); 1309 assert(m.str(0) == L"a"); 1310 } 1311 { 1312 std::wcmatch m; 1313 const wchar_t s[] = L"c"; 1314 assert(std::regex_search(s, m, std::wregex(L"^[a-f]$", 1315 std::regex_constants::awk))); 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) == 1); 1324 assert(m.position(0) == 0); 1325 assert(m.str(0) == s); 1326 } 1327 { 1328 std::wcmatch m; 1329 const wchar_t s[] = L"g"; 1330 assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$", 1331 std::regex_constants::awk))); 1332 assert(m.size() == 0); 1333 } 1334 { 1335 std::wcmatch m; 1336 const wchar_t s[] = L"Iraqi"; 1337 assert(std::regex_search(s, m, std::wregex(L"q[^u]", 1338 std::regex_constants::awk))); 1339 assert(m.size() == 1); 1340 assert(m.prefix().matched); 1341 assert(m.prefix().first == s); 1342 assert(m.prefix().second == m[0].first); 1343 assert(!m.suffix().matched); 1344 assert(m.suffix().first == m[0].second); 1345 assert(m.suffix().second == m[0].second); 1346 assert(m.length(0) == 2); 1347 assert(m.position(0) == 3); 1348 assert(m.str(0) == L"qi"); 1349 } 1350 { 1351 std::wcmatch m; 1352 const wchar_t s[] = L"Iraq"; 1353 assert(!std::regex_search(s, m, std::wregex(L"q[^u]", 1354 std::regex_constants::awk))); 1355 assert(m.size() == 0); 1356 } 1357 { 1358 std::wcmatch m; 1359 const wchar_t s[] = L"AmB"; 1360 assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", 1361 std::regex_constants::awk))); 1362 assert(m.size() == 1); 1363 assert(!m.prefix().matched); 1364 assert(m.prefix().first == s); 1365 assert(m.prefix().second == m[0].first); 1366 assert(!m.suffix().matched); 1367 assert(m.suffix().first == m[0].second); 1368 assert(m.suffix().second == m[0].second); 1369 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1370 assert(m.position(0) == 0); 1371 assert(m.str(0) == s); 1372 } 1373 { 1374 std::wcmatch m; 1375 const wchar_t s[] = L"AMB"; 1376 assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", 1377 std::regex_constants::awk))); 1378 assert(m.size() == 0); 1379 } 1380 { 1381 std::wcmatch m; 1382 const wchar_t s[] = L"AMB"; 1383 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", 1384 std::regex_constants::awk))); 1385 assert(m.size() == 1); 1386 assert(!m.prefix().matched); 1387 assert(m.prefix().first == s); 1388 assert(m.prefix().second == m[0].first); 1389 assert(!m.suffix().matched); 1390 assert(m.suffix().first == m[0].second); 1391 assert(m.suffix().second == m[0].second); 1392 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1393 assert(m.position(0) == 0); 1394 assert(m.str(0) == s); 1395 } 1396 { 1397 std::wcmatch m; 1398 const wchar_t s[] = L"AmB"; 1399 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", 1400 std::regex_constants::awk))); 1401 assert(m.size() == 0); 1402 } 1403 { 1404 std::wcmatch m; 1405 const wchar_t s[] = L"A5B"; 1406 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", 1407 std::regex_constants::awk))); 1408 assert(m.size() == 0); 1409 } 1410 { 1411 std::wcmatch m; 1412 const wchar_t s[] = L"A?B"; 1413 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", 1414 std::regex_constants::awk))); 1415 assert(m.size() == 1); 1416 assert(!m.prefix().matched); 1417 assert(m.prefix().first == s); 1418 assert(m.prefix().second == m[0].first); 1419 assert(!m.suffix().matched); 1420 assert(m.suffix().first == m[0].second); 1421 assert(m.suffix().second == m[0].second); 1422 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1423 assert(m.position(0) == 0); 1424 assert(m.str(0) == s); 1425 } 1426 { 1427 std::wcmatch m; 1428 const wchar_t s[] = L"-"; 1429 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1430 std::regex_constants::awk))); 1431 assert(m.size() == 1); 1432 assert(!m.prefix().matched); 1433 assert(m.prefix().first == s); 1434 assert(m.prefix().second == m[0].first); 1435 assert(!m.suffix().matched); 1436 assert(m.suffix().first == m[0].second); 1437 assert(m.suffix().second == m[0].second); 1438 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1439 assert(m.position(0) == 0); 1440 assert(m.str(0) == s); 1441 } 1442 { 1443 std::wcmatch m; 1444 const wchar_t s[] = L"z"; 1445 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1446 std::regex_constants::awk))); 1447 assert(m.size() == 1); 1448 assert(!m.prefix().matched); 1449 assert(m.prefix().first == s); 1450 assert(m.prefix().second == m[0].first); 1451 assert(!m.suffix().matched); 1452 assert(m.suffix().first == m[0].second); 1453 assert(m.suffix().second == m[0].second); 1454 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1455 assert(m.position(0) == 0); 1456 assert(m.str(0) == s); 1457 } 1458 { 1459 std::wcmatch m; 1460 const wchar_t s[] = L"m"; 1461 assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1462 std::regex_constants::awk))); 1463 assert(m.size() == 0); 1464 } 1465 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2)); 1466 { 1467 std::wcmatch m; 1468 const wchar_t s[] = L"m"; 1469 assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]", 1470 std::regex_constants::awk))); 1471 assert(m.size() == 1); 1472 assert(!m.prefix().matched); 1473 assert(m.prefix().first == s); 1474 assert(m.prefix().second == m[0].first); 1475 assert(!m.suffix().matched); 1476 assert(m.suffix().first == m[0].second); 1477 assert(m.suffix().second == m[0].second); 1478 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1479 assert(m.position(0) == 0); 1480 assert(m.str(0) == s); 1481 } 1482 { 1483 std::wcmatch m; 1484 const wchar_t s[] = L"Ch"; 1485 assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]", 1486 std::regex_constants::awk | std::regex_constants::icase))); 1487 assert(m.size() == 1); 1488 assert(!m.prefix().matched); 1489 assert(m.prefix().first == s); 1490 assert(m.prefix().second == m[0].first); 1491 assert(!m.suffix().matched); 1492 assert(m.suffix().first == m[0].second); 1493 assert(m.suffix().second == m[0].second); 1494 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1495 assert(m.position(0) == 0); 1496 assert(m.str(0) == s); 1497 } 1498 std::locale::global(std::locale("C")); 1499 { 1500 std::wcmatch m; 1501 const wchar_t s[] = L"m"; 1502 assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]", 1503 std::regex_constants::awk))); 1504 assert(m.size() == 0); 1505 } 1506 { 1507 std::wcmatch m; 1508 const wchar_t s[] = L"01a45cef9"; 1509 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", 1510 std::regex_constants::awk))); 1511 assert(m.size() == 1); 1512 assert(!m.prefix().matched); 1513 assert(m.prefix().first == s); 1514 assert(m.prefix().second == m[0].first); 1515 assert(m.suffix().matched); 1516 assert(m.suffix().first == m[0].second); 1517 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1518 assert(m.length(0) == 0); 1519 assert(m.position(0) == 0); 1520 assert(m.str(0) == L""); 1521 } 1522 { 1523 std::wcmatch m; 1524 const wchar_t s[] = L"01a45cef9"; 1525 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+", 1526 std::regex_constants::awk))); 1527 assert(m.size() == 1); 1528 assert(m.prefix().matched); 1529 assert(m.prefix().first == s); 1530 assert(m.prefix().second == m[0].first); 1531 assert(m.suffix().matched); 1532 assert(m.suffix().first == m[0].second); 1533 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1534 assert(m.length(0) == 6); 1535 assert(m.position(0) == 1); 1536 assert(m.str(0) == L"1a45ce"); 1537 } 1538 { 1539 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$"; 1540 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r); 1541 typedef forward_iterator<const wchar_t*> FI; 1542 typedef bidirectional_iterator<const wchar_t*> BI; 1543 std::wregex regex(FI(r), FI(r+sr), std::regex_constants::awk); 1544 std::match_results<BI> m; 1545 const wchar_t s[] = L"-40C"; 1546 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s); 1547 assert(std::regex_search(BI(s), BI(s+ss), m, regex)); 1548 assert(m.size() == 1); 1549 assert(!m.prefix().matched); 1550 assert(m.prefix().first == BI(s)); 1551 assert(m.prefix().second == m[0].first); 1552 assert(!m.suffix().matched); 1553 assert(m.suffix().first == m[0].second); 1554 assert(m.suffix().second == m[0].second); 1555 assert(m.length(0) == 4); 1556 assert(m.position(0) == 0); 1557 assert(m.str(0) == s); 1558 } 1559 { 1560 std::wcmatch m; 1561 const wchar_t s[] = L"\n\n\n"; 1562 assert(std::regex_search(s, m, std::wregex(L"[\\n]+", 1563 std::regex_constants::awk))); 1564 assert(m.size() == 1); 1565 assert(!m.prefix().matched); 1566 assert(m.prefix().first == s); 1567 assert(m.prefix().second == m[0].first); 1568 assert(!m.suffix().matched); 1569 assert(m.suffix().first == m[0].second); 1570 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1571 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 1572 assert(m.position(0) == 0); 1573 assert(m.str(0) == s); 1574 } 1575} 1576