| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <regex> |
| 10 | |
| 11 | // class regex_token_iterator<BidirectionalIterator, charT, traits> |
| 12 | |
| 13 | // regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 14 | // const regex_type& re, |
| 15 | // const std::vector<int>& submatches, |
| 16 | // regex_constants::match_flag_type m = |
| 17 | // regex_constants::match_default); |
| 18 | |
| 19 | #include <regex> |
| 20 | #include <cassert> |
| 21 | #include <iterator> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 25 | int main(int, char**) |
| 26 | { |
| 27 | { |
| 28 | std::regex phone_numbers("\\d{3}-(\\d{4})" ); |
| 29 | const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end" ; |
| 30 | std::vector<int> v; |
| 31 | v.push_back(-1); |
| 32 | v.push_back(-1); |
| 33 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 34 | phone_numbers, v); |
| 35 | assert(i != std::cregex_token_iterator()); |
| 36 | assert(i->str() == "start " ); |
| 37 | ++i; |
| 38 | assert(i != std::cregex_token_iterator()); |
| 39 | assert(i->str() == "start " ); |
| 40 | ++i; |
| 41 | assert(i != std::cregex_token_iterator()); |
| 42 | assert(i->str() == ", " ); |
| 43 | ++i; |
| 44 | assert(i != std::cregex_token_iterator()); |
| 45 | assert(i->str() == ", " ); |
| 46 | ++i; |
| 47 | assert(i != std::cregex_token_iterator()); |
| 48 | assert(i->str() == ", " ); |
| 49 | ++i; |
| 50 | assert(i != std::cregex_token_iterator()); |
| 51 | assert(i->str() == ", " ); |
| 52 | ++i; |
| 53 | assert(i != std::cregex_token_iterator()); |
| 54 | assert(i->str() == " end" ); |
| 55 | ++i; |
| 56 | assert(i == std::cregex_token_iterator()); |
| 57 | } |
| 58 | { |
| 59 | std::regex phone_numbers("\\d{3}-(\\d{4})" ); |
| 60 | const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end" ; |
| 61 | std::vector<int> v; |
| 62 | v.push_back(-1); |
| 63 | v.push_back(0); |
| 64 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 65 | phone_numbers, v); |
| 66 | assert(i != std::cregex_token_iterator()); |
| 67 | assert(i->str() == "start " ); |
| 68 | ++i; |
| 69 | assert(i != std::cregex_token_iterator()); |
| 70 | assert(i->str() == "555-1234" ); |
| 71 | ++i; |
| 72 | assert(i != std::cregex_token_iterator()); |
| 73 | assert(i->str() == ", " ); |
| 74 | ++i; |
| 75 | assert(i != std::cregex_token_iterator()); |
| 76 | assert(i->str() == "555-2345" ); |
| 77 | ++i; |
| 78 | assert(i != std::cregex_token_iterator()); |
| 79 | assert(i->str() == ", " ); |
| 80 | ++i; |
| 81 | assert(i != std::cregex_token_iterator()); |
| 82 | assert(i->str() == "555-3456" ); |
| 83 | ++i; |
| 84 | assert(i != std::cregex_token_iterator()); |
| 85 | assert(i->str() == " end" ); |
| 86 | ++i; |
| 87 | assert(i == std::cregex_token_iterator()); |
| 88 | } |
| 89 | { |
| 90 | std::regex phone_numbers("\\d{3}-(\\d{4})" ); |
| 91 | const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end" ; |
| 92 | std::vector<int> v; |
| 93 | v.push_back(-1); |
| 94 | v.push_back(0); |
| 95 | v.push_back(1); |
| 96 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 97 | phone_numbers, v); |
| 98 | assert(i != std::cregex_token_iterator()); |
| 99 | assert(i->str() == "start " ); |
| 100 | ++i; |
| 101 | assert(i != std::cregex_token_iterator()); |
| 102 | assert(i->str() == "555-1234" ); |
| 103 | ++i; |
| 104 | assert(i != std::cregex_token_iterator()); |
| 105 | assert(i->str() == "1234" ); |
| 106 | ++i; |
| 107 | assert(i != std::cregex_token_iterator()); |
| 108 | assert(i->str() == ", " ); |
| 109 | ++i; |
| 110 | assert(i != std::cregex_token_iterator()); |
| 111 | assert(i->str() == "555-2345" ); |
| 112 | ++i; |
| 113 | assert(i != std::cregex_token_iterator()); |
| 114 | assert(i->str() == "2345" ); |
| 115 | ++i; |
| 116 | assert(i != std::cregex_token_iterator()); |
| 117 | assert(i->str() == ", " ); |
| 118 | ++i; |
| 119 | assert(i != std::cregex_token_iterator()); |
| 120 | assert(i->str() == "555-3456" ); |
| 121 | ++i; |
| 122 | assert(i != std::cregex_token_iterator()); |
| 123 | assert(i->str() == "3456" ); |
| 124 | ++i; |
| 125 | assert(i != std::cregex_token_iterator()); |
| 126 | assert(i->str() == " end" ); |
| 127 | ++i; |
| 128 | assert(i == std::cregex_token_iterator()); |
| 129 | } |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |