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