| 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, int submatch = 0, |
| 15 |
// regex_constants::match_flag_type m = |
| 16 |
// regex_constants::match_default); |
| 17 |
|
| 18 |
#include <regex> |
| 19 |
#include <cassert> |
| 20 |
#include <iterator> |
| 21 |
|
| 22 |
#include "test_macros.h" |
| 23 |
|
| 24 |
int main(int, char**) |
| 25 |
{ |
| 26 |
{ |
| 27 |
std::regex phone_numbers("\\d{3}-\\d{4}"); |
| 28 |
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; |
| 29 |
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 30 |
phone_numbers, -1); |
| 31 |
assert(i != std::cregex_token_iterator()); |
| 32 |
assert(i->str() == "start "); |
| 33 |
++i; |
| 34 |
assert(i != std::cregex_token_iterator()); |
| 35 |
assert(i->str() == ", "); |
| 36 |
++i; |
| 37 |
assert(i != std::cregex_token_iterator()); |
| 38 |
assert(i->str() == ", "); |
| 39 |
++i; |
| 40 |
assert(i != std::cregex_token_iterator()); |
| 41 |
assert(i->str() == " end"); |
| 42 |
++i; |
| 43 |
assert(i == std::cregex_token_iterator()); |
| 44 |
} |
| 45 |
{ |
| 46 |
std::regex phone_numbers("\\d{3}-\\d{4}"); |
| 47 |
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; |
| 48 |
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 49 |
phone_numbers); |
| 50 |
assert(i != std::cregex_token_iterator()); |
| 51 |
assert(i->str() == "555-1234"); |
| 52 |
++i; |
| 53 |
assert(i != std::cregex_token_iterator()); |
| 54 |
assert(i->str() == "555-2345"); |
| 55 |
++i; |
| 56 |
assert(i != std::cregex_token_iterator()); |
| 57 |
assert(i->str() == "555-3456"); |
| 58 |
++i; |
| 59 |
assert(i == std::cregex_token_iterator()); |
| 60 |
} |
| 61 |
{ |
| 62 |
std::regex phone_numbers("\\d{3}-(\\d{4})"); |
| 63 |
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; |
| 64 |
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
| 65 |
phone_numbers, 1); |
| 66 |
assert(i != std::cregex_token_iterator()); |
| 67 |
assert(i->str() == "1234"); |
| 68 |
++i; |
| 69 |
assert(i != std::cregex_token_iterator()); |
| 70 |
assert(i->str() == "2345"); |
| 71 |
++i; |
| 72 |
assert(i != std::cregex_token_iterator()); |
| 73 |
assert(i->str() == "3456"); |
| 74 |
++i; |
| 75 |
assert(i == std::cregex_token_iterator()); |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |