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& operator++(int);
15
16 #include <regex>
17 #include <cassert>
18 #include "test_macros.h"
19
main()20 int main()
21 {
22 {
23 std::regex phone_numbers("\\d{3}-\\d{4}");
24 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
25 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
26 phone_numbers, -1);
27 std::cregex_token_iterator i2 = i;
28 std::cregex_token_iterator i3;
29 assert(i != std::cregex_token_iterator());
30 assert(i2 != std::cregex_token_iterator());
31 assert(i->str() == "start ");
32 assert(i2->str() == "start ");
33 i3 = i++;
34 assert(i != std::cregex_token_iterator());
35 assert(i2 != std::cregex_token_iterator());
36 assert(i3 != std::cregex_token_iterator());
37 assert(i->str() == ", ");
38 assert(i2->str() == "start ");
39 assert(i3->str() == "start ");
40 i3 = i++;
41 assert(i != std::cregex_token_iterator());
42 assert(i2 != std::cregex_token_iterator());
43 assert(i3 != std::cregex_token_iterator());
44 assert(i->str() == ", ");
45 assert(i2->str() == "start ");
46 assert(i3->str() == ", ");
47 i3 = i++;
48 assert(i != std::cregex_token_iterator());
49 assert(i2 != std::cregex_token_iterator());
50 assert(i3 != std::cregex_token_iterator());
51 assert(i->str() == " end");
52 assert(i2->str() == "start ");
53 assert(i3->str() == ", ");
54 i3 = i++;
55 assert(i == std::cregex_token_iterator());
56 assert(i2 != std::cregex_token_iterator());
57 assert(i3 != std::cregex_token_iterator());
58 assert(i2->str() == "start ");
59 assert(i3->str() == " end");
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 std::cregex_token_iterator i2 = i;
67 std::cregex_token_iterator i3;
68 assert(i != std::cregex_token_iterator());
69 assert(i2 != std::cregex_token_iterator());
70 assert(i->str() == "start ");
71 assert(i2->str() == "start ");
72 i3 = i;
73 ++i;
74 assert(i != std::cregex_token_iterator());
75 assert(i2 != std::cregex_token_iterator());
76 assert(i3 != std::cregex_token_iterator());
77 assert(i->str() == ", ");
78 assert(i2->str() == "start ");
79 assert(i3->str() == "start ");
80 i3 = i;
81 ++i;
82 assert(i != std::cregex_token_iterator());
83 assert(i2 != std::cregex_token_iterator());
84 assert(i3 != std::cregex_token_iterator());
85 assert(i->str() == ", ");
86 assert(i2->str() == "start ");
87 assert(i3->str() == ", ");
88 i3 = i;
89 ++i;
90 assert(i != std::cregex_token_iterator());
91 assert(i2 != std::cregex_token_iterator());
92 assert(i3 != std::cregex_token_iterator());
93 assert(i->str() == " end");
94 assert(i2->str() == "start ");
95 assert(i3->str() == ", ");
96 i3 = i;
97 ++i;
98 assert(i == std::cregex_token_iterator());
99 assert(i2 != std::cregex_token_iterator());
100 assert(i3 != std::cregex_token_iterator());
101 assert(i2->str() == "start ");
102 assert(i3->str() == " end");
103 }
104 {
105 std::regex phone_numbers("\\d{3}-\\d{4}");
106 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
107 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
108 phone_numbers);
109 assert(i != std::cregex_token_iterator());
110 assert(i->str() == "555-1234");
111 i++;
112 assert(i != std::cregex_token_iterator());
113 assert(i->str() == "555-2345");
114 i++;
115 assert(i != std::cregex_token_iterator());
116 assert(i->str() == "555-3456");
117 i++;
118 assert(i == std::cregex_token_iterator());
119 }
120 {
121 std::regex phone_numbers("\\d{3}-(\\d{4})");
122 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
123 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
124 phone_numbers, 1);
125 assert(i != std::cregex_token_iterator());
126 assert(i->str() == "1234");
127 i++;
128 assert(i != std::cregex_token_iterator());
129 assert(i->str() == "2345");
130 i++;
131 assert(i != std::cregex_token_iterator());
132 assert(i->str() == "3456");
133 i++;
134 assert(i == std::cregex_token_iterator());
135 }
136 }
137