1// Copyright 2021 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/core/detail/string_view.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <algorithm>
8#include <cstddef>
9
10int main()
11{
12 std::size_t const npos = boost::core::string_view::npos;
13
14 {
15 boost::core::string_view sv( "" );
16
17 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view() ), npos );
18 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 1 ), npos );
19
20 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ) ), npos );
21 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 1 ), npos );
22
23 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ) ), npos );
24 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 1 ), npos );
25
26 BOOST_TEST_EQ( sv.find_first_of( '1' ), npos );
27 BOOST_TEST_EQ( sv.find_first_of( '1', 1 ), npos );
28
29 BOOST_TEST_EQ( sv.find_first_of( "" ), npos );
30 BOOST_TEST_EQ( sv.find_first_of( "", 1 ), npos );
31
32 BOOST_TEST_EQ( sv.find_first_of( "1" ), npos );
33 BOOST_TEST_EQ( sv.find_first_of( "1", 1 ), npos );
34
35 BOOST_TEST_EQ( sv.find_first_of( "12", 0, 0 ), npos );
36 BOOST_TEST_EQ( sv.find_first_of( "12", 1, 0 ), npos );
37
38 BOOST_TEST_EQ( sv.find_first_of( "12", 0, 1 ), npos );
39 BOOST_TEST_EQ( sv.find_first_of( "12", 1, 1 ), npos );
40
41 BOOST_TEST_EQ( sv.find_first_of( "12", 0, 2 ), npos );
42 BOOST_TEST_EQ( sv.find_first_of( "12", 1, 2 ), npos );
43 }
44
45 {
46 boost::core::wstring_view sv( L"" );
47
48 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view() ), npos );
49 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view(), 1 ), npos );
50
51 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ) ), npos );
52 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ), 1 ), npos );
53
54 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ) ), npos );
55 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 1 ), npos );
56
57 BOOST_TEST_EQ( sv.find_first_of( L'1' ), npos );
58 BOOST_TEST_EQ( sv.find_first_of( L'1', 1 ), npos );
59
60 BOOST_TEST_EQ( sv.find_first_of( L"" ), npos );
61 BOOST_TEST_EQ( sv.find_first_of( L"", 1 ), npos );
62
63 BOOST_TEST_EQ( sv.find_first_of( L"1" ), npos );
64 BOOST_TEST_EQ( sv.find_first_of( L"1", 1 ), npos );
65
66 BOOST_TEST_EQ( sv.find_first_of( L"12", 0, 0 ), npos );
67 BOOST_TEST_EQ( sv.find_first_of( L"12", 1, 0 ), npos );
68
69 BOOST_TEST_EQ( sv.find_first_of( L"12", 0, 1 ), npos );
70 BOOST_TEST_EQ( sv.find_first_of( L"12", 1, 1 ), npos );
71
72 BOOST_TEST_EQ( sv.find_first_of( L"12", 0, 2 ), npos );
73 BOOST_TEST_EQ( sv.find_first_of( L"12", 1, 2 ), npos );
74 }
75
76 {
77 boost::core::string_view sv( "123123" );
78
79 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view() ), npos );
80 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 1 ), npos );
81 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 6 ), npos );
82 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 7 ), npos );
83
84 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ) ), npos );
85 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 1 ), npos );
86 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 6 ), npos );
87 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 7 ), npos );
88
89 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ) ), 0 );
90 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 1 ), 3 );
91 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 2 ), 3 );
92 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 3 ), 3 );
93 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 4 ), npos );
94 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 5 ), npos );
95 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 6 ), npos );
96 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 7 ), npos );
97
98 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ) ), npos );
99 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 1 ), npos );
100 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 6 ), npos );
101 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 7 ), npos );
102
103 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ) ), 1 );
104 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 1 ), 1 );
105 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 2 ), 2 );
106 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 3 ), 4 );
107 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 4 ), 4 );
108 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 5 ), 5 );
109 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 6 ), npos );
110 BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 7 ), npos );
111
112 BOOST_TEST_EQ( sv.find_first_of( '1' ), 0 );
113 BOOST_TEST_EQ( sv.find_first_of( '1', 1 ), 3 );
114 BOOST_TEST_EQ( sv.find_first_of( '1', 2 ), 3 );
115 BOOST_TEST_EQ( sv.find_first_of( '1', 3 ), 3 );
116 BOOST_TEST_EQ( sv.find_first_of( '1', 4 ), npos );
117 BOOST_TEST_EQ( sv.find_first_of( '1', 5 ), npos );
118 BOOST_TEST_EQ( sv.find_first_of( '1', 6 ), npos );
119 BOOST_TEST_EQ( sv.find_first_of( '1', 7 ), npos );
120
121 BOOST_TEST_EQ( sv.find_first_of( '3' ), 2 );
122 BOOST_TEST_EQ( sv.find_first_of( '3', 1 ), 2 );
123 BOOST_TEST_EQ( sv.find_first_of( '3', 2 ), 2 );
124 BOOST_TEST_EQ( sv.find_first_of( '3', 3 ), 5 );
125 BOOST_TEST_EQ( sv.find_first_of( '3', 4 ), 5 );
126 BOOST_TEST_EQ( sv.find_first_of( '3', 5 ), 5 );
127 BOOST_TEST_EQ( sv.find_first_of( '3', 6 ), npos );
128 BOOST_TEST_EQ( sv.find_first_of( '3', 7 ), npos );
129
130 BOOST_TEST_EQ( sv.find_first_of( '9' ), npos );
131
132 BOOST_TEST_EQ( sv.find_first_of( "" ), npos );
133 BOOST_TEST_EQ( sv.find_first_of( "", 1 ), npos );
134 BOOST_TEST_EQ( sv.find_first_of( "", 6 ), npos );
135 BOOST_TEST_EQ( sv.find_first_of( "", 7 ), npos );
136
137 BOOST_TEST_EQ( sv.find_first_of( "1" ), 0 );
138 BOOST_TEST_EQ( sv.find_first_of( "1", 1 ), 3 );
139 BOOST_TEST_EQ( sv.find_first_of( "1", 2 ), 3 );
140 BOOST_TEST_EQ( sv.find_first_of( "1", 3 ), 3 );
141 BOOST_TEST_EQ( sv.find_first_of( "1", 4 ), npos );
142 BOOST_TEST_EQ( sv.find_first_of( "1", 5 ), npos );
143 BOOST_TEST_EQ( sv.find_first_of( "1", 6 ), npos );
144 BOOST_TEST_EQ( sv.find_first_of( "1", 7 ), npos );
145
146 BOOST_TEST_EQ( sv.find_first_of( "23" ), 1 );
147 BOOST_TEST_EQ( sv.find_first_of( "23", 1 ), 1 );
148 BOOST_TEST_EQ( sv.find_first_of( "23", 2 ), 2 );
149 BOOST_TEST_EQ( sv.find_first_of( "23", 3 ), 4 );
150 BOOST_TEST_EQ( sv.find_first_of( "23", 4 ), 4 );
151 BOOST_TEST_EQ( sv.find_first_of( "23", 5 ), 5 );
152 BOOST_TEST_EQ( sv.find_first_of( "23", 6 ), npos );
153 BOOST_TEST_EQ( sv.find_first_of( "23", 7 ), npos );
154
155 BOOST_TEST_EQ( sv.find_first_of( "123", 0, 0 ), npos );
156 BOOST_TEST_EQ( sv.find_first_of( "123", 1, 0 ), npos );
157 BOOST_TEST_EQ( sv.find_first_of( "123", 2, 0 ), npos );
158 BOOST_TEST_EQ( sv.find_first_of( "123", 3, 0 ), npos );
159 BOOST_TEST_EQ( sv.find_first_of( "123", 4, 0 ), npos );
160 BOOST_TEST_EQ( sv.find_first_of( "123", 5, 0 ), npos );
161 BOOST_TEST_EQ( sv.find_first_of( "123", 6, 0 ), npos );
162 BOOST_TEST_EQ( sv.find_first_of( "123", 7, 0 ), npos );
163
164 BOOST_TEST_EQ( sv.find_first_of( "123", 0, 1 ), 0 );
165 BOOST_TEST_EQ( sv.find_first_of( "123", 1, 1 ), 3 );
166 BOOST_TEST_EQ( sv.find_first_of( "123", 2, 1 ), 3 );
167 BOOST_TEST_EQ( sv.find_first_of( "123", 3, 1 ), 3 );
168 BOOST_TEST_EQ( sv.find_first_of( "123", 4, 1 ), npos );
169 BOOST_TEST_EQ( sv.find_first_of( "123", 5, 1 ), npos );
170 BOOST_TEST_EQ( sv.find_first_of( "123", 6, 1 ), npos );
171 BOOST_TEST_EQ( sv.find_first_of( "123", 7, 1 ), npos );
172
173 BOOST_TEST_EQ( sv.find_first_of( "123", 0, 2 ), 0 );
174 BOOST_TEST_EQ( sv.find_first_of( "123", 1, 2 ), 1 );
175 BOOST_TEST_EQ( sv.find_first_of( "123", 2, 2 ), 3 );
176 BOOST_TEST_EQ( sv.find_first_of( "123", 3, 2 ), 3 );
177 BOOST_TEST_EQ( sv.find_first_of( "123", 4, 2 ), 4 );
178 BOOST_TEST_EQ( sv.find_first_of( "123", 5, 2 ), npos );
179 BOOST_TEST_EQ( sv.find_first_of( "123", 6, 2 ), npos );
180 BOOST_TEST_EQ( sv.find_first_of( "123", 7, 2 ), npos );
181
182 BOOST_TEST_EQ( sv.find_first_of( "123", 0, 3 ), 0 );
183 BOOST_TEST_EQ( sv.find_first_of( "123", 1, 3 ), 1 );
184 BOOST_TEST_EQ( sv.find_first_of( "123", 2, 3 ), 2 );
185 BOOST_TEST_EQ( sv.find_first_of( "123", 3, 3 ), 3 );
186 BOOST_TEST_EQ( sv.find_first_of( "123", 4, 3 ), 4 );
187 BOOST_TEST_EQ( sv.find_first_of( "123", 5, 3 ), 5 );
188 BOOST_TEST_EQ( sv.find_first_of( "123", 6, 3 ), npos );
189 BOOST_TEST_EQ( sv.find_first_of( "123", 7, 3 ), npos );
190 }
191
192 {
193 boost::core::wstring_view sv( L"123123" );
194
195 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view() ), npos );
196 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view(), 1 ), npos );
197 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view(), 6 ), npos );
198 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view(), 7 ), npos );
199
200 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ) ), npos );
201 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ), 1 ), npos );
202 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ), 6 ), npos );
203 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"" ), 7 ), npos );
204
205 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ) ), 0 );
206 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 1 ), 3 );
207 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 2 ), 3 );
208 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 3 ), 3 );
209 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 4 ), npos );
210 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 5 ), npos );
211 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 6 ), npos );
212 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"1" ), 7 ), npos );
213
214 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"4" ) ), npos );
215 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"4" ), 1 ), npos );
216 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"4" ), 6 ), npos );
217 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"4" ), 7 ), npos );
218
219 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ) ), 1 );
220 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 1 ), 1 );
221 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 2 ), 2 );
222 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 3 ), 4 );
223 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 4 ), 4 );
224 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 5 ), 5 );
225 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 6 ), npos );
226 BOOST_TEST_EQ( sv.find_first_of( boost::core::wstring_view( L"23" ), 7 ), npos );
227
228 BOOST_TEST_EQ( sv.find_first_of( L'1' ), 0 );
229 BOOST_TEST_EQ( sv.find_first_of( L'1', 1 ), 3 );
230 BOOST_TEST_EQ( sv.find_first_of( L'1', 2 ), 3 );
231 BOOST_TEST_EQ( sv.find_first_of( L'1', 3 ), 3 );
232 BOOST_TEST_EQ( sv.find_first_of( L'1', 4 ), npos );
233 BOOST_TEST_EQ( sv.find_first_of( L'1', 5 ), npos );
234 BOOST_TEST_EQ( sv.find_first_of( L'1', 6 ), npos );
235 BOOST_TEST_EQ( sv.find_first_of( L'1', 7 ), npos );
236
237 BOOST_TEST_EQ( sv.find_first_of( L'3' ), 2 );
238 BOOST_TEST_EQ( sv.find_first_of( L'3', 1 ), 2 );
239 BOOST_TEST_EQ( sv.find_first_of( L'3', 2 ), 2 );
240 BOOST_TEST_EQ( sv.find_first_of( L'3', 3 ), 5 );
241 BOOST_TEST_EQ( sv.find_first_of( L'3', 4 ), 5 );
242 BOOST_TEST_EQ( sv.find_first_of( L'3', 5 ), 5 );
243 BOOST_TEST_EQ( sv.find_first_of( L'3', 6 ), npos );
244 BOOST_TEST_EQ( sv.find_first_of( L'3', 7 ), npos );
245
246 BOOST_TEST_EQ( sv.find_first_of( L'9' ), npos );
247
248 BOOST_TEST_EQ( sv.find_first_of( L"" ), npos );
249 BOOST_TEST_EQ( sv.find_first_of( L"", 1 ), npos );
250 BOOST_TEST_EQ( sv.find_first_of( L"", 6 ), npos );
251 BOOST_TEST_EQ( sv.find_first_of( L"", 7 ), npos );
252
253 BOOST_TEST_EQ( sv.find_first_of( L"1" ), 0 );
254 BOOST_TEST_EQ( sv.find_first_of( L"1", 1 ), 3 );
255 BOOST_TEST_EQ( sv.find_first_of( L"1", 2 ), 3 );
256 BOOST_TEST_EQ( sv.find_first_of( L"1", 3 ), 3 );
257 BOOST_TEST_EQ( sv.find_first_of( L"1", 4 ), npos );
258 BOOST_TEST_EQ( sv.find_first_of( L"1", 5 ), npos );
259 BOOST_TEST_EQ( sv.find_first_of( L"1", 6 ), npos );
260 BOOST_TEST_EQ( sv.find_first_of( L"1", 7 ), npos );
261
262 BOOST_TEST_EQ( sv.find_first_of( L"23" ), 1 );
263 BOOST_TEST_EQ( sv.find_first_of( L"23", 1 ), 1 );
264 BOOST_TEST_EQ( sv.find_first_of( L"23", 2 ), 2 );
265 BOOST_TEST_EQ( sv.find_first_of( L"23", 3 ), 4 );
266 BOOST_TEST_EQ( sv.find_first_of( L"23", 4 ), 4 );
267 BOOST_TEST_EQ( sv.find_first_of( L"23", 5 ), 5 );
268 BOOST_TEST_EQ( sv.find_first_of( L"23", 6 ), npos );
269 BOOST_TEST_EQ( sv.find_first_of( L"23", 7 ), npos );
270
271 BOOST_TEST_EQ( sv.find_first_of( L"123", 0, 0 ), npos );
272 BOOST_TEST_EQ( sv.find_first_of( L"123", 1, 0 ), npos );
273 BOOST_TEST_EQ( sv.find_first_of( L"123", 2, 0 ), npos );
274 BOOST_TEST_EQ( sv.find_first_of( L"123", 3, 0 ), npos );
275 BOOST_TEST_EQ( sv.find_first_of( L"123", 4, 0 ), npos );
276 BOOST_TEST_EQ( sv.find_first_of( L"123", 5, 0 ), npos );
277 BOOST_TEST_EQ( sv.find_first_of( L"123", 6, 0 ), npos );
278 BOOST_TEST_EQ( sv.find_first_of( L"123", 7, 0 ), npos );
279
280 BOOST_TEST_EQ( sv.find_first_of( L"123", 0, 1 ), 0 );
281 BOOST_TEST_EQ( sv.find_first_of( L"123", 1, 1 ), 3 );
282 BOOST_TEST_EQ( sv.find_first_of( L"123", 2, 1 ), 3 );
283 BOOST_TEST_EQ( sv.find_first_of( L"123", 3, 1 ), 3 );
284 BOOST_TEST_EQ( sv.find_first_of( L"123", 4, 1 ), npos );
285 BOOST_TEST_EQ( sv.find_first_of( L"123", 5, 1 ), npos );
286 BOOST_TEST_EQ( sv.find_first_of( L"123", 6, 1 ), npos );
287 BOOST_TEST_EQ( sv.find_first_of( L"123", 7, 1 ), npos );
288
289 BOOST_TEST_EQ( sv.find_first_of( L"123", 0, 2 ), 0 );
290 BOOST_TEST_EQ( sv.find_first_of( L"123", 1, 2 ), 1 );
291 BOOST_TEST_EQ( sv.find_first_of( L"123", 2, 2 ), 3 );
292 BOOST_TEST_EQ( sv.find_first_of( L"123", 3, 2 ), 3 );
293 BOOST_TEST_EQ( sv.find_first_of( L"123", 4, 2 ), 4 );
294 BOOST_TEST_EQ( sv.find_first_of( L"123", 5, 2 ), npos );
295 BOOST_TEST_EQ( sv.find_first_of( L"123", 6, 2 ), npos );
296 BOOST_TEST_EQ( sv.find_first_of( L"123", 7, 2 ), npos );
297
298 BOOST_TEST_EQ( sv.find_first_of( L"123", 0, 3 ), 0 );
299 BOOST_TEST_EQ( sv.find_first_of( L"123", 1, 3 ), 1 );
300 BOOST_TEST_EQ( sv.find_first_of( L"123", 2, 3 ), 2 );
301 BOOST_TEST_EQ( sv.find_first_of( L"123", 3, 3 ), 3 );
302 BOOST_TEST_EQ( sv.find_first_of( L"123", 4, 3 ), 4 );
303 BOOST_TEST_EQ( sv.find_first_of( L"123", 5, 3 ), 5 );
304 BOOST_TEST_EQ( sv.find_first_of( L"123", 6, 3 ), npos );
305 BOOST_TEST_EQ( sv.find_first_of( L"123", 7, 3 ), npos );
306 }
307
308 {
309 boost::core::wstring_view sv( L"\x101\x102\x103\x101\x102\x103" );
310
311 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 0, 0 ), npos );
312 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 1, 0 ), npos );
313 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 2, 0 ), npos );
314 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 3, 0 ), npos );
315 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 4, 0 ), npos );
316 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 5, 0 ), npos );
317 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 6, 0 ), npos );
318 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 7, 0 ), npos );
319
320 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 0, 1 ), 0 );
321 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 1, 1 ), 3 );
322 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 2, 1 ), 3 );
323 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 3, 1 ), 3 );
324 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 4, 1 ), npos );
325 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 5, 1 ), npos );
326 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 6, 1 ), npos );
327 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 7, 1 ), npos );
328
329 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 0, 2 ), 0 );
330 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 1, 2 ), 1 );
331 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 2, 2 ), 3 );
332 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 3, 2 ), 3 );
333 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 4, 2 ), 4 );
334 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 5, 2 ), npos );
335 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 6, 2 ), npos );
336 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 7, 2 ), npos );
337
338 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 0, 3 ), 0 );
339 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 1, 3 ), 1 );
340 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 2, 3 ), 2 );
341 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 3, 3 ), 3 );
342 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 4, 3 ), 4 );
343 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 5, 3 ), 5 );
344 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 6, 3 ), npos );
345 BOOST_TEST_EQ( sv.find_first_of( L"\x101\x102\x103", 7, 3 ), npos );
346 }
347
348 {
349 boost::core::string_view sv( "abc1abc2abc3" );
350
351 BOOST_TEST_EQ( sv.find_first_of( "0123456789" ), 3 );
352 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 0 ), 3 );
353 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 1 ), 3 );
354 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 2 ), 3 );
355 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 3 ), 3 );
356 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 4 ), 7 );
357 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 5 ), 7 );
358 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 6 ), 7 );
359 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 7 ), 7 );
360 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 8 ), 11 );
361 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 9 ), 11 );
362 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 10 ), 11 );
363 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 11 ), 11 );
364 BOOST_TEST_EQ( sv.find_first_of( "0123456789", 12 ), npos );
365 }
366
367 {
368 boost::core::wstring_view sv( L"abc1abc2abc3" );
369
370 BOOST_TEST_EQ( sv.find_first_of( L"0123456789" ), 3 );
371 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 0 ), 3 );
372 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 1 ), 3 );
373 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 2 ), 3 );
374 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 3 ), 3 );
375 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 4 ), 7 );
376 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 5 ), 7 );
377 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 6 ), 7 );
378 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 7 ), 7 );
379 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 8 ), 11 );
380 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 9 ), 11 );
381 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 10 ), 11 );
382 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 11 ), 11 );
383 BOOST_TEST_EQ( sv.find_first_of( L"0123456789", 12 ), npos );
384 }
385
386 {
387 boost::core::string_view sv( "123a123B123c" );
388
389 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ), 3 );
390 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 0 ), 3 );
391 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 1 ), 3 );
392 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 2 ), 3 );
393 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 3 ), 3 );
394 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 4 ), 7 );
395 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 5 ), 7 );
396 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 6 ), 7 );
397 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 7 ), 7 );
398 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 8 ), 11 );
399 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 9 ), 11 );
400 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 10 ), 11 );
401 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 11 ), 11 );
402 BOOST_TEST_EQ( sv.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 12 ), npos );
403 }
404
405 {
406 boost::core::wstring_view sv( L"123a123B123c" );
407
408 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ), 3 );
409 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 0 ), 3 );
410 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 1 ), 3 );
411 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 2 ), 3 );
412 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 3 ), 3 );
413 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 4 ), 7 );
414 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 5 ), 7 );
415 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 6 ), 7 );
416 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 7 ), 7 );
417 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 8 ), 11 );
418 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 9 ), 11 );
419 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 10 ), 11 );
420 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 11 ), 11 );
421 BOOST_TEST_EQ( sv.find_first_of( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 12 ), npos );
422 }
423
424 {
425 char str[ 256 ];
426
427 for( int i = 0; i < 256; ++i )
428 {
429 str[ i ] = static_cast< unsigned char >( i );
430 }
431
432 boost::core::string_view sv( str, 256 );
433
434 for( int i = 0; i < 256; ++i )
435 {
436 std::string needle( 12, static_cast< unsigned char >( i ) );
437 BOOST_TEST_EQ( sv.find_first_of( needle ), i );
438 }
439
440 std::reverse( first: str, last: str + 256 );
441
442 for( int i = 0; i < 256; ++i )
443 {
444 std::string needle( 12, static_cast< unsigned char >( i ) );
445 BOOST_TEST_EQ( sv.find_first_of( needle ), 255 - i );
446 }
447 }
448
449 {
450 wchar_t str[ 256 ];
451
452 for( int i = 0; i < 256; ++i )
453 {
454 str[ i ] = static_cast< wchar_t >( 0x100 + i );
455 }
456
457 boost::core::wstring_view sv( str, 256 );
458
459 for( int i = 0; i < 256; ++i )
460 {
461 std::wstring needle( 12, static_cast< wchar_t >( 0x100 + i ) );
462 BOOST_TEST_EQ( sv.find_first_of( needle ), i );
463 }
464
465 std::reverse( first: str, last: str + 256 );
466
467 for( int i = 0; i < 256; ++i )
468 {
469 std::wstring needle( 12, static_cast< wchar_t >( 0x100 + i ) );
470 BOOST_TEST_EQ( sv.find_first_of( needle ), 255 - i );
471 }
472 }
473
474#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
475
476 {
477 boost::core::u8string_view sv( u8"123123" );
478
479 BOOST_TEST_EQ( sv.find_first_of( u8"" ), npos );
480 BOOST_TEST_EQ( sv.find_first_of( u8"", 1 ), npos );
481 BOOST_TEST_EQ( sv.find_first_of( u8"", 6 ), npos );
482 BOOST_TEST_EQ( sv.find_first_of( u8"", 7 ), npos );
483
484 BOOST_TEST_EQ( sv.find_first_of( u8"1" ), 0 );
485 BOOST_TEST_EQ( sv.find_first_of( u8"1", 1 ), 3 );
486 BOOST_TEST_EQ( sv.find_first_of( u8"1", 2 ), 3 );
487 BOOST_TEST_EQ( sv.find_first_of( u8"1", 3 ), 3 );
488 BOOST_TEST_EQ( sv.find_first_of( u8"1", 4 ), npos );
489 BOOST_TEST_EQ( sv.find_first_of( u8"1", 5 ), npos );
490 BOOST_TEST_EQ( sv.find_first_of( u8"1", 6 ), npos );
491 BOOST_TEST_EQ( sv.find_first_of( u8"1", 7 ), npos );
492
493 BOOST_TEST_EQ( sv.find_first_of( u8"23" ), 1 );
494 BOOST_TEST_EQ( sv.find_first_of( u8"23", 1 ), 1 );
495 BOOST_TEST_EQ( sv.find_first_of( u8"23", 2 ), 2 );
496 BOOST_TEST_EQ( sv.find_first_of( u8"23", 3 ), 4 );
497 BOOST_TEST_EQ( sv.find_first_of( u8"23", 4 ), 4 );
498 BOOST_TEST_EQ( sv.find_first_of( u8"23", 5 ), 5 );
499 BOOST_TEST_EQ( sv.find_first_of( u8"23", 6 ), npos );
500 BOOST_TEST_EQ( sv.find_first_of( u8"23", 7 ), npos );
501
502 BOOST_TEST_EQ( sv.find_first_of( u8"123", 0 ), 0 );
503 BOOST_TEST_EQ( sv.find_first_of( u8"123", 1 ), 1 );
504 BOOST_TEST_EQ( sv.find_first_of( u8"123", 2 ), 2 );
505 BOOST_TEST_EQ( sv.find_first_of( u8"123", 3 ), 3 );
506 BOOST_TEST_EQ( sv.find_first_of( u8"123", 4 ), 4 );
507 BOOST_TEST_EQ( sv.find_first_of( u8"123", 5 ), 5 );
508 BOOST_TEST_EQ( sv.find_first_of( u8"123", 6 ), npos );
509 BOOST_TEST_EQ( sv.find_first_of( u8"123", 7 ), npos );
510 }
511
512 {
513 boost::core::u8string_view sv( u8"abc1abc2abc3" );
514
515 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789" ), 3 );
516 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 0 ), 3 );
517 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 1 ), 3 );
518 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 2 ), 3 );
519 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 3 ), 3 );
520 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 4 ), 7 );
521 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 5 ), 7 );
522 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 6 ), 7 );
523 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 7 ), 7 );
524 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 8 ), 11 );
525 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 9 ), 11 );
526 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 10 ), 11 );
527 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 11 ), 11 );
528 BOOST_TEST_EQ( sv.find_first_of( u8"0123456789", 12 ), npos );
529 }
530
531 {
532 boost::core::u8string_view sv( u8"123a123B123c" );
533
534 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ), 3 );
535 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 0 ), 3 );
536 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 1 ), 3 );
537 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 2 ), 3 );
538 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 3 ), 3 );
539 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 4 ), 7 );
540 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 5 ), 7 );
541 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 6 ), 7 );
542 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 7 ), 7 );
543 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 8 ), 11 );
544 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 9 ), 11 );
545 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 10 ), 11 );
546 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 11 ), 11 );
547 BOOST_TEST_EQ( sv.find_first_of( u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 12 ), npos );
548 }
549
550#endif
551
552 return boost::report_errors();
553}
554

source code of boost/libs/core/test/sv_find_first_of_test.cpp