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));
208 Assert::IsFalse(
p.is_valid);
209 Assert::IsTrue(
p.match(
L"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
210 Assert::IsTrue(
p.is_valid);
211 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
212 Assert::IsTrue(
p.is_valid);
219 Assert::IsTrue(
p.match(
L"RF18539007547034", 0,
SIZE_MAX));
220 Assert::IsTrue(
p.is_valid);
221 Assert::AreEqual(
L"18",
p.check_digits);
222 Assert::AreEqual(
L"000000000539007547034",
p.reference);
223 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
224 Assert::IsTrue(
p.is_valid);
225 Assert::AreEqual(
L"18",
p.check_digits);
226 Assert::AreEqual(
L"000000000539007547034",
p.reference);
227 Assert::IsFalse(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX));
228 Assert::IsFalse(
p.is_valid);
229 Assert::IsTrue(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
230 Assert::IsTrue(
p.is_valid);
231 Assert::IsTrue(
p.match(
L"RF18 5390 0754 70340", 0,
SIZE_MAX));
232 Assert::IsFalse(
p.is_valid);
233 Assert::IsTrue(
p.match(
L"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
234 Assert::IsTrue(
p.is_valid);
235 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
236 Assert::IsTrue(
p.is_valid);
243 Assert::IsTrue(
p.match(
L"SI121234567890120", 0,
SIZE_MAX));
244 Assert::IsTrue(
p.is_valid);
245 Assert::AreEqual(
L"12",
p.model);
247 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
248 Assert::IsTrue(
p.is_valid);
249 Assert::AreEqual(
L"12",
p.model);
251 Assert::IsFalse(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX));
252 Assert::IsTrue(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
253 Assert::IsTrue(
p.match(
L"...SI12 1234567890120...", 3,
SIZE_MAX));
254 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
261 static const char text[] =
"V kožuščku zlobnega mizarja stopiclja fant\nin kliče 1234567890.";
265 Assert::IsTrue(
p.match(
text));
272 Assert::IsFalse(
p.match(
text));
273 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
280 Assert::IsFalse(
p.match(
text, 4));
281 Assert::IsTrue(
p.match(
text, 4, _countof(
text), match_case_insensitive));
288 Assert::IsFalse(
p.match(
text));
289 Assert::IsTrue(
p.match(
text, 1));
292 Assert::IsTrue(
p.match(
text, 79));
299 Assert::IsFalse(
p.match(
text, 2));
300 Assert::IsTrue(
p.match(
text, 2, _countof(
text), match_case_insensitive));
301 Assert::AreEqual((
size_t)2,
p.hit_offset);
310 Assert::IsTrue(
p.match(
"SI56023120015226972", 0,
SIZE_MAX));
311 Assert::IsTrue(
p.is_valid);
312 Assert::AreEqual(
"SI",
p.country);
313 Assert::AreEqual(
"56",
p.check_digits);
314 Assert::AreEqual(
"023120015226972",
p.bban);
315 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
316 Assert::IsTrue(
p.is_valid);
317 Assert::AreEqual(
"SI",
p.country);
318 Assert::AreEqual(
"56",
p.check_digits);
319 Assert::AreEqual(
"023120015226972",
p.bban);
320 Assert::IsFalse(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX));
321 Assert::IsFalse(
p.is_valid);
322 Assert::IsTrue(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX, match_case_insensitive));
323 Assert::IsTrue(
p.is_valid);
324 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 9720", 0,
SIZE_MAX));
325 Assert::IsFalse(
p.is_valid);
326 Assert::IsTrue(
p.match(
"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
327 Assert::IsTrue(
p.is_valid);
328 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
329 Assert::IsTrue(
p.is_valid);
336 Assert::IsTrue(
p.match(
"RF18539007547034", 0,
SIZE_MAX));
337 Assert::IsTrue(
p.is_valid);
338 Assert::AreEqual(
"18",
p.check_digits);
339 Assert::AreEqual(
"000000000539007547034",
p.reference);
340 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
341 Assert::IsTrue(
p.is_valid);
342 Assert::AreEqual(
"18",
p.check_digits);
343 Assert::AreEqual(
"000000000539007547034",
p.reference);
344 Assert::IsFalse(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX));
345 Assert::IsFalse(
p.is_valid);
346 Assert::IsTrue(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
347 Assert::IsTrue(
p.is_valid);
348 Assert::IsTrue(
p.match(
"RF18 5390 0754 70340", 0,
SIZE_MAX));
349 Assert::IsFalse(
p.is_valid);
350 Assert::IsTrue(
p.match(
"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
351 Assert::IsTrue(
p.is_valid);
352 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
353 Assert::IsTrue(
p.is_valid);
360 Assert::IsTrue(
p.match(
"SI121234567890120", 0,
SIZE_MAX));
361 Assert::IsTrue(
p.is_valid);
362 Assert::AreEqual(
"12",
p.model);
364 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
365 Assert::IsTrue(
p.is_valid);
366 Assert::AreEqual(
"12",
p.model);
368 Assert::IsFalse(
p.match(
"si12 1234567890120", 0,
SIZE_MAX));
369 Assert::IsTrue(
p.match(
"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
370 Assert::IsTrue(
p.match(
"...SI12 1234567890120...", 3,
SIZE_MAX));
371 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
377 static const std::locale locale(
"en_US.UTF-8");
380 "Host: stackoverflow.com\r\n"
381 "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0\r\n"
382 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n"
383 "Accept-Language: sl,en-US;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2\r\n"
384 "Accept-Encoding: gzip, deflate, br\r\n"
386 "Connection: keep-alive\r\n"
387 "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"
388 "Upgrade-Insecure-Requests: 1\r\n"
389 "Sec-Fetch-Dest: document\r\n"
390 "Sec-Fetch-Mode: navigate\r\n"
391 "Sec-Fetch-Site: none\r\n"
392 "Sec-Fetch-User: ?1\r\n"
393 "Pragma: no-cache\r\n"
394 "Cache-Control: no-cache\r\n"
402 Assert::AreEqual((
size_t)0,
p.verb.start);
403 Assert::AreEqual((
size_t)3,
p.verb.end);
408 Assert::AreEqual((
uint16_t)0x200,
p.protocol.version);
412 std::list<http_header>
hdrs;
418 hdrs.push_back(std::move(
h));
423 Assert::AreEqual((
size_t)15,
hdrs.size());
425 for (
const auto&
h :
hdrs)
426 if (strnicmp(
request +
h.name.start,
h.name.size(),
"Accept-Language", (
size_t)-1, locale) == 0)
428 Assert::IsTrue(!
langs.empty());
431 "sl",
"en-US",
"en",
"de-DE",
"de"
437 Assert::IsTrue(
c ==
control.cend());
438 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:7018
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