• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
16 //                      const std::vector<int>& submatches,
17 //                      regex_constants::match_flag_type m =
18 //                                              regex_constants::match_default);
19 
20 #include <regex>
21 #include <cassert>
22 #include "test_macros.h"
23 
main()24 int main()
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::vector<int> v;
30         v.push_back(-1);
31         v.push_back(-1);
32         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
33                                      phone_numbers, v);
34         assert(i != std::cregex_token_iterator());
35         assert(i->str() == "start ");
36         ++i;
37         assert(i != std::cregex_token_iterator());
38         assert(i->str() == "start ");
39         ++i;
40         assert(i != std::cregex_token_iterator());
41         assert(i->str() == ", ");
42         ++i;
43         assert(i != std::cregex_token_iterator());
44         assert(i->str() == ", ");
45         ++i;
46         assert(i != std::cregex_token_iterator());
47         assert(i->str() == ", ");
48         ++i;
49         assert(i != std::cregex_token_iterator());
50         assert(i->str() == ", ");
51         ++i;
52         assert(i != std::cregex_token_iterator());
53         assert(i->str() == " end");
54         ++i;
55         assert(i == std::cregex_token_iterator());
56     }
57     {
58         std::regex phone_numbers("\\d{3}-(\\d{4})");
59         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
60         std::vector<int> v;
61         v.push_back(-1);
62         v.push_back(0);
63         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
64                                      phone_numbers, v);
65         assert(i != std::cregex_token_iterator());
66         assert(i->str() == "start ");
67         ++i;
68         assert(i != std::cregex_token_iterator());
69         assert(i->str() == "555-1234");
70         ++i;
71         assert(i != std::cregex_token_iterator());
72         assert(i->str() == ", ");
73         ++i;
74         assert(i != std::cregex_token_iterator());
75         assert(i->str() == "555-2345");
76         ++i;
77         assert(i != std::cregex_token_iterator());
78         assert(i->str() == ", ");
79         ++i;
80         assert(i != std::cregex_token_iterator());
81         assert(i->str() == "555-3456");
82         ++i;
83         assert(i != std::cregex_token_iterator());
84         assert(i->str() == " end");
85         ++i;
86         assert(i == std::cregex_token_iterator());
87     }
88     {
89         std::regex phone_numbers("\\d{3}-(\\d{4})");
90         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
91         std::vector<int> v;
92         v.push_back(-1);
93         v.push_back(0);
94         v.push_back(1);
95         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
96                                      phone_numbers, v);
97         assert(i != std::cregex_token_iterator());
98         assert(i->str() == "start ");
99         ++i;
100         assert(i != std::cregex_token_iterator());
101         assert(i->str() == "555-1234");
102         ++i;
103         assert(i != std::cregex_token_iterator());
104         assert(i->str() == "1234");
105         ++i;
106         assert(i != std::cregex_token_iterator());
107         assert(i->str() == ", ");
108         ++i;
109         assert(i != std::cregex_token_iterator());
110         assert(i->str() == "555-2345");
111         ++i;
112         assert(i != std::cregex_token_iterator());
113         assert(i->str() == "2345");
114         ++i;
115         assert(i != std::cregex_token_iterator());
116         assert(i->str() == ", ");
117         ++i;
118         assert(i != std::cregex_token_iterator());
119         assert(i->str() == "555-3456");
120         ++i;
121         assert(i != std::cregex_token_iterator());
122         assert(i->str() == "3456");
123         ++i;
124         assert(i != std::cregex_token_iterator());
125         assert(i->str() == " end");
126         ++i;
127         assert(i == std::cregex_token_iterator());
128     }
129 }
130