10using namespace stdex::parser;
12using namespace Microsoft::VisualStudio::CppUnitTestFramework;
19 return stdex::sprintf(
L"<%zu, %zu>",
nullptr,
q.start,
q.end);
33 static const wchar_t text[] =
L"This is a test.\nSecond line.";
37 Assert::IsTrue(
p.match(
text));
44 Assert::IsFalse(
p.match(
text));
45 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
52 Assert::IsFalse(
p.match(
text));
53 Assert::IsTrue(
p.match(
text, 4));
60 Assert::IsFalse(
p.match(
text));
61 Assert::IsTrue(
p.match(
text, 14));
68 Assert::IsFalse(
p.match(
text));
69 Assert::IsTrue(
p.match(
text, 4));
72 Assert::IsTrue(
p.match(
text, 14));
79 Assert::IsTrue(
p.match(
text));
82 Assert::IsFalse(
p.match(
text, 1));
83 Assert::IsFalse(
p.match(
text, 15));
84 Assert::IsTrue(
p.match(
text, 16));
91 Assert::IsFalse(
p.match(
text));
92 Assert::IsFalse(
p.match(
text, 1));
93 Assert::IsTrue(
p.match(
text, 15));
96 Assert::IsFalse(
p.match(
text, 16));
101 Assert::IsFalse(
p.match(
text));
102 Assert::IsTrue(
p.match(
text, 8));
105 Assert::AreEqual((
size_t)0,
p.hit_offset);
106 Assert::IsFalse(
p.match(
text, 21));
107 Assert::IsTrue(
p.match(
text, 21, _countof(
text), match_case_insensitive));
110 Assert::AreEqual((
size_t)3,
p.hit_offset);
114 stdex::parser::wstring
p(
L"this");
115 Assert::IsFalse(
p.match(
text));
116 Assert::IsTrue(
p.match(
text, 0,
sizeof(
text), match_case_insensitive));
124 Assert::IsTrue(
p.match(
text));
132 Assert::IsTrue(
p.match(
text));
141 make_shared_no_delete(&
chr_t),
142 make_shared_no_delete(&
chr_h),
143 make_shared_no_delete(&
chr_i),
144 make_shared_no_delete(&
chr_s),
145 make_shared_no_delete(&space) });
146 Assert::IsFalse(
p.match(
text));
147 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
156 make_shared_no_delete(&
apple),
157 make_shared_no_delete(&
orange),
158 make_shared_no_delete(&
_this),
159 make_shared_no_delete(&space) });
160 Assert::IsFalse(
p.match(
text));
161 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
162 Assert::AreEqual((
size_t)2,
p.hit_offset);
169 Assert::IsFalse(
p.match(
text));
170 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
171 Assert::AreEqual((
size_t)2,
p.hit_offset);
179 make_shared_no_delete(&
chr_s),
180 make_shared_no_delete(&
chr_h),
181 make_shared_no_delete(&
chr_i),
182 make_shared_no_delete(&
chr_t) });
183 Assert::IsFalse(
p.match(
text));
184 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
193 Assert::IsTrue(
p.match(
L"SI56023120015226972", 0,
SIZE_MAX));
194 Assert::IsTrue(
p.is_valid);
195 Assert::AreEqual(
L"SI",
p.country);
196 Assert::AreEqual(
L"56",
p.check_digits);
197 Assert::AreEqual(
L"023120015226972",
p.bban);
198 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
199 Assert::IsTrue(
p.is_valid);
200 Assert::AreEqual(
L"SI",
p.country);
201 Assert::AreEqual(
L"56",
p.check_digits);
202 Assert::AreEqual(
L"023120015226972",
p.bban);
203 Assert::IsFalse(
p.match(
L"si56 0231 2001 5226 972", 0,
SIZE_MAX));
204 Assert::IsFalse(
p.is_valid);
205 Assert::IsTrue(
p.match(
L"si56 0231 2001 5226 972", 0,
SIZE_MAX, match_case_insensitive));
206 Assert::IsTrue(
p.is_valid);
207 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 9720", 0,
SIZE_MAX));
209 Assert::IsTrue(
p.is_valid);
210 Assert::IsTrue(
p.match(
L"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
211 Assert::IsTrue(
p.is_valid);
212 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
213 Assert::IsTrue(
p.is_valid);
215 Assert::IsTrue(
p.match(
L"BE71 0961 2345 6769", 0,
SIZE_MAX));
216 Assert::IsTrue(
p.is_valid);
217 Assert::IsTrue(
p.match(
L"BR15 0000 0000 0000 1093 2840 814 P2", 0,
SIZE_MAX));
218 Assert::IsTrue(
p.is_valid);
219 Assert::IsTrue(
p.match(
L"CR99 0000 0000 0000 8888 88", 0,
SIZE_MAX));
220 Assert::IsFalse(
p.is_valid);
221 Assert::IsTrue(
p.match(
L"FR76 3000 6000 0112 3456 7890 189", 0,
SIZE_MAX));
222 Assert::IsTrue(
p.is_valid);
223 Assert::IsTrue(
p.match(
L"IE12 BOFI 9000 0112 3456 78", 0,
SIZE_MAX));
224 Assert::IsFalse(
p.is_valid);
225 Assert::IsTrue(
p.match(
L"DE91 1000 0000 0123 4567 89", 0,
SIZE_MAX));
226 Assert::IsTrue(
p.is_valid);
227 Assert::IsTrue(
p.match(
L"GR96 0810 0010 0000 0123 4567 890", 0,
SIZE_MAX));
228 Assert::IsTrue(
p.is_valid);
229 Assert::IsTrue(
p.match(
L"MU43 BOMM 0101 1234 5678 9101 000 MUR", 0,
SIZE_MAX));
230 Assert::IsTrue(
p.is_valid);
231 Assert::IsTrue(
p.match(
L"PK70 BANK 0000 1234 5678 9000", 0,
SIZE_MAX));
232 Assert::IsTrue(
p.is_valid);
233 Assert::IsTrue(
p.match(
L"PL10 1050 0099 7603 1234 5678 9123", 0,
SIZE_MAX));
234 Assert::IsTrue(
p.is_valid);
235 Assert::IsTrue(
p.match(
L"RO09 BCYP 0000 0012 3456 7890", 0,
SIZE_MAX));
236 Assert::IsTrue(
p.is_valid);
237 Assert::IsTrue(
p.match(
L"LC14 BOSL 1234 5678 9012 3456 7890 1234", 0,
SIZE_MAX));
238 Assert::IsTrue(
p.is_valid);
239 Assert::IsTrue(
p.match(
L"SA44 2000 0001 2345 6789 1234", 0,
SIZE_MAX));
240 Assert::IsTrue(
p.is_valid);
241 Assert::IsTrue(
p.match(
L"ES79 2100 0813 6101 2345 6789", 0,
SIZE_MAX));
242 Assert::IsTrue(
p.is_valid);
243 Assert::IsTrue(
p.match(
L"SE87 3000 0000 0101 2345 6789", 0,
SIZE_MAX));
244 Assert::IsFalse(
p.is_valid);
245 Assert::IsTrue(
p.match(
L"CH56 0483 5012 3456 7800 9", 0,
SIZE_MAX));
246 Assert::IsTrue(
p.is_valid);
247 Assert::IsTrue(
p.match(
L"GB98 MIDL 0700 9312 3456 78", 0,
SIZE_MAX));
248 Assert::IsTrue(
p.is_valid);
255 Assert::IsTrue(
p.match(
L"RF18539007547034", 0,
SIZE_MAX));
256 Assert::IsTrue(
p.is_valid);
257 Assert::AreEqual(
L"18",
p.check_digits);
258 Assert::AreEqual(
L"000000000539007547034",
p.reference);
259 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
260 Assert::IsTrue(
p.is_valid);
261 Assert::AreEqual(
L"18",
p.check_digits);
262 Assert::AreEqual(
L"000000000539007547034",
p.reference);
263 Assert::IsFalse(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX));
264 Assert::IsFalse(
p.is_valid);
265 Assert::IsTrue(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
266 Assert::IsTrue(
p.is_valid);
267 Assert::IsTrue(
p.match(
L"RF18 5390 0754 70340", 0,
SIZE_MAX));
268 Assert::IsFalse(
p.is_valid);
269 Assert::IsTrue(
p.match(
L"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
270 Assert::IsTrue(
p.is_valid);
271 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
272 Assert::IsTrue(
p.is_valid);
279 Assert::IsTrue(
p.match(
L"SI121234567890120", 0,
SIZE_MAX));
280 Assert::IsTrue(
p.is_valid);
281 Assert::AreEqual(
L"12",
p.model);
283 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
284 Assert::IsTrue(
p.is_valid);
285 Assert::AreEqual(
L"12",
p.model);
287 Assert::IsFalse(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX));
288 Assert::IsTrue(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
289 Assert::IsTrue(
p.match(
L"...SI12 1234567890120...", 3,
SIZE_MAX));
290 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
297 static const char text[] =
"V kožuščku zlobnega mizarja stopiclja fant\nin kliče 1234567890.";
301 Assert::IsTrue(
p.match(
text));
308 Assert::IsFalse(
p.match(
text));
309 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
316 Assert::IsFalse(
p.match(
text, 4));
317 Assert::IsTrue(
p.match(
text, 4, _countof(
text), match_case_insensitive));
324 Assert::IsFalse(
p.match(
text));
325 Assert::IsTrue(
p.match(
text, 1));
328 Assert::IsTrue(
p.match(
text, 79));
335 Assert::IsFalse(
p.match(
text, 2));
336 Assert::IsTrue(
p.match(
text, 2, _countof(
text), match_case_insensitive));
337 Assert::AreEqual((
size_t)2,
p.hit_offset);
346 Assert::IsTrue(
p.match(
"SI56023120015226972", 0,
SIZE_MAX));
347 Assert::IsTrue(
p.is_valid);
348 Assert::AreEqual(
"SI",
p.country);
349 Assert::AreEqual(
"56",
p.check_digits);
350 Assert::AreEqual(
"023120015226972",
p.bban);
351 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
352 Assert::IsTrue(
p.is_valid);
353 Assert::AreEqual(
"SI",
p.country);
354 Assert::AreEqual(
"56",
p.check_digits);
355 Assert::AreEqual(
"023120015226972",
p.bban);
356 Assert::IsFalse(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX));
357 Assert::IsFalse(
p.is_valid);
358 Assert::IsTrue(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX, match_case_insensitive));
359 Assert::IsTrue(
p.is_valid);
360 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 9720", 0,
SIZE_MAX));
362 Assert::IsTrue(
p.is_valid);
363 Assert::IsTrue(
p.match(
"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
364 Assert::IsTrue(
p.is_valid);
365 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
366 Assert::IsTrue(
p.is_valid);
373 Assert::IsTrue(
p.match(
"RF18539007547034", 0,
SIZE_MAX));
374 Assert::IsTrue(
p.is_valid);
375 Assert::AreEqual(
"18",
p.check_digits);
376 Assert::AreEqual(
"000000000539007547034",
p.reference);
377 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
378 Assert::IsTrue(
p.is_valid);
379 Assert::AreEqual(
"18",
p.check_digits);
380 Assert::AreEqual(
"000000000539007547034",
p.reference);
381 Assert::IsFalse(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX));
382 Assert::IsFalse(
p.is_valid);
383 Assert::IsTrue(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
384 Assert::IsTrue(
p.is_valid);
385 Assert::IsTrue(
p.match(
"RF18 5390 0754 70340", 0,
SIZE_MAX));
386 Assert::IsFalse(
p.is_valid);
387 Assert::IsTrue(
p.match(
"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
388 Assert::IsTrue(
p.is_valid);
389 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
390 Assert::IsTrue(
p.is_valid);
397 Assert::IsTrue(
p.match(
"SI121234567890120", 0,
SIZE_MAX));
398 Assert::IsTrue(
p.is_valid);
399 Assert::AreEqual(
"12",
p.model);
401 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
402 Assert::IsTrue(
p.is_valid);
403 Assert::AreEqual(
"12",
p.model);
405 Assert::IsFalse(
p.match(
"si12 1234567890120", 0,
SIZE_MAX));
406 Assert::IsTrue(
p.match(
"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
407 Assert::IsTrue(
p.match(
"...SI12 1234567890120...", 3,
SIZE_MAX));
408 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
414 static const std::locale locale(
"en_US.UTF-8");
417 "Host: stackoverflow.com\r\n"
418 "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0\r\n"
419 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n"
420 "Accept-Language: sl,en-US;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2\r\n"
421 "Accept-Encoding: gzip, deflate, br\r\n"
423 "Connection: keep-alive\r\n"
424 "Cookie: prov=00000000-0000-0000-0000-000000000000; acct=t=00000000000000000%2f%2f0000%2b0000%2b000&s=00000000000000000000000000000000; OptanonConsent=isGpcEnabled=0&datestamp=Fri+Feb+03+2023+11%3A11%3A08+GMT%2B0100+(Srednjeevropski+standardni+%C4%8Das)&version=6.37.0&isIABGlobal=false&hosts=&consentId=00000000-0000-0000-0000-000000000000&interactionCount=1&landingPath=NotLandingPage&groups=00000%3A0%2C00000%3A0%2C00000%3A0%2C00000%3A0; OptanonAlertBoxClosed=2023-02-03T10:11:08.683Z\r\n"
425 "Upgrade-Insecure-Requests: 1\r\n"
426 "Sec-Fetch-Dest: document\r\n"
427 "Sec-Fetch-Mode: navigate\r\n"
428 "Sec-Fetch-Site: none\r\n"
429 "Sec-Fetch-User: ?1\r\n"
430 "Pragma: no-cache\r\n"
431 "Cache-Control: no-cache\r\n"
439 Assert::AreEqual((
size_t)0,
p.verb.start);
440 Assert::AreEqual((
size_t)3,
p.verb.end);
445 Assert::AreEqual((
uint16_t)0x200,
p.protocol.version);
449 std::list<http_header>
hdrs;
455 hdrs.push_back(std::move(
h));
460 Assert::AreEqual((
size_t)15,
hdrs.size());
462 for (
const auto&
h :
hdrs)
463 if (strnicmp(
request +
h.name.start,
h.name.size(),
"Accept-Language", (
size_t)-1, locale) == 0)
465 Assert::IsTrue(!
langs.empty());
468 "sl",
"en-US",
"en",
"de-DE",
"de"
474 Assert::IsTrue(
c ==
control.cend());
475 Assert::IsTrue(
l ==
langs.cend());
interval< size_t > interval
Region of the last match.
Definition parser.hpp:170
Test for given string.
Definition parser.hpp:816
Test for HTTP request.
Definition parser.hpp:7010
Test for specific SGML code point.
Definition parser.hpp:341
Test for any SGML space code point.
Definition parser.hpp:428
Numerical interval.
Definition interval.hpp:18
T size() const
Returns interval size.
Definition interval.hpp:47
T end
interval end
Definition interval.hpp:20
T start
interval start
Definition interval.hpp:19