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));
191 wiban p(make_shared_no_delete(&space));
192 Assert::IsTrue(
p.match(
L"SI56023120015226972", 0,
SIZE_MAX));
193 Assert::IsTrue(
p.is_valid);
194 Assert::AreEqual(
L"SI",
p.country);
195 Assert::AreEqual(
L"56",
p.check_digits);
196 Assert::AreEqual(
L"023120015226972",
p.bban);
197 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
198 Assert::IsTrue(
p.is_valid);
199 Assert::AreEqual(
L"SI",
p.country);
200 Assert::AreEqual(
L"56",
p.check_digits);
201 Assert::AreEqual(
L"023120015226972",
p.bban);
202 Assert::IsFalse(
p.match(
L"si56 0231 2001 5226 972", 0,
SIZE_MAX));
203 Assert::IsFalse(
p.is_valid);
204 Assert::IsTrue(
p.match(
L"si56 0231 2001 5226 972", 0,
SIZE_MAX, match_case_insensitive));
205 Assert::IsTrue(
p.is_valid);
206 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 9720", 0,
SIZE_MAX));
207 Assert::IsFalse(
p.is_valid);
208 Assert::IsTrue(
p.match(
L"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
209 Assert::IsTrue(
p.is_valid);
210 Assert::IsTrue(
p.match(
L"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
211 Assert::IsTrue(
p.is_valid);
217 Assert::IsTrue(
p.match(
L"RF18539007547034", 0,
SIZE_MAX));
218 Assert::IsTrue(
p.is_valid);
219 Assert::AreEqual(
L"18",
p.check_digits);
220 Assert::AreEqual(
L"000000000539007547034",
p.reference);
221 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
222 Assert::IsTrue(
p.is_valid);
223 Assert::AreEqual(
L"18",
p.check_digits);
224 Assert::AreEqual(
L"000000000539007547034",
p.reference);
225 Assert::IsFalse(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX));
226 Assert::IsFalse(
p.is_valid);
227 Assert::IsTrue(
p.match(
L"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
228 Assert::IsTrue(
p.is_valid);
229 Assert::IsTrue(
p.match(
L"RF18 5390 0754 70340", 0,
SIZE_MAX));
230 Assert::IsFalse(
p.is_valid);
231 Assert::IsTrue(
p.match(
L"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
232 Assert::IsTrue(
p.is_valid);
233 Assert::IsTrue(
p.match(
L"RF18 5390 0754 7034", 0,
SIZE_MAX));
234 Assert::IsTrue(
p.is_valid);
240 Assert::IsTrue(
p.match(
L"SI121234567890120", 0,
SIZE_MAX));
241 Assert::IsTrue(
p.is_valid);
242 Assert::AreEqual(
L"12",
p.model);
244 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
245 Assert::IsTrue(
p.is_valid);
246 Assert::AreEqual(
L"12",
p.model);
248 Assert::IsFalse(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX));
249 Assert::IsTrue(
p.match(
L"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
250 Assert::IsTrue(
p.match(
L"...SI12 1234567890120...", 3,
SIZE_MAX));
251 Assert::IsTrue(
p.match(
L"SI12 1234567890120", 0,
SIZE_MAX));
258 static const char text[] =
"V kožuščku zlobnega mizarja stopiclja fant\nin kliče 1234567890.";
262 Assert::IsTrue(
p.match(
text));
269 Assert::IsFalse(
p.match(
text));
270 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
277 Assert::IsFalse(
p.match(
text, 4));
278 Assert::IsTrue(
p.match(
text, 4, _countof(
text), match_case_insensitive));
285 Assert::IsFalse(
p.match(
text));
286 Assert::IsTrue(
p.match(
text, 1));
289 Assert::IsTrue(
p.match(
text, 79));
296 Assert::IsFalse(
p.match(
text, 2));
297 Assert::IsTrue(
p.match(
text, 2, _countof(
text), match_case_insensitive));
298 Assert::AreEqual((
size_t)2,
p.hit_offset);
306 Assert::IsTrue(
p.match(
"SI56023120015226972", 0,
SIZE_MAX));
307 Assert::IsTrue(
p.is_valid);
308 Assert::AreEqual(
"SI",
p.country);
309 Assert::AreEqual(
"56",
p.check_digits);
310 Assert::AreEqual(
"023120015226972",
p.bban);
311 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
312 Assert::IsTrue(
p.is_valid);
313 Assert::AreEqual(
"SI",
p.country);
314 Assert::AreEqual(
"56",
p.check_digits);
315 Assert::AreEqual(
"023120015226972",
p.bban);
316 Assert::IsFalse(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX));
317 Assert::IsFalse(
p.is_valid);
318 Assert::IsTrue(
p.match(
"si56 0231 2001 5226 972", 0,
SIZE_MAX, match_case_insensitive));
319 Assert::IsTrue(
p.is_valid);
320 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 9720", 0,
SIZE_MAX));
321 Assert::IsFalse(
p.is_valid);
322 Assert::IsTrue(
p.match(
"...SI56 0231 2001 5226 972...", 3,
SIZE_MAX));
323 Assert::IsTrue(
p.is_valid);
324 Assert::IsTrue(
p.match(
"SI56 0231 2001 5226 972", 0,
SIZE_MAX));
325 Assert::IsTrue(
p.is_valid);
331 Assert::IsTrue(
p.match(
"RF18539007547034", 0,
SIZE_MAX));
332 Assert::IsTrue(
p.is_valid);
333 Assert::AreEqual(
"18",
p.check_digits);
334 Assert::AreEqual(
"000000000539007547034",
p.reference);
335 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
336 Assert::IsTrue(
p.is_valid);
337 Assert::AreEqual(
"18",
p.check_digits);
338 Assert::AreEqual(
"000000000539007547034",
p.reference);
339 Assert::IsFalse(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX));
340 Assert::IsFalse(
p.is_valid);
341 Assert::IsTrue(
p.match(
"rf18 5390 0754 7034", 0,
SIZE_MAX, match_case_insensitive));
342 Assert::IsTrue(
p.is_valid);
343 Assert::IsTrue(
p.match(
"RF18 5390 0754 70340", 0,
SIZE_MAX));
344 Assert::IsFalse(
p.is_valid);
345 Assert::IsTrue(
p.match(
"...RF18 5390 0754 7034...", 3,
SIZE_MAX));
346 Assert::IsTrue(
p.is_valid);
347 Assert::IsTrue(
p.match(
"RF18 5390 0754 7034", 0,
SIZE_MAX));
348 Assert::IsTrue(
p.is_valid);
354 Assert::IsTrue(
p.match(
"SI121234567890120", 0,
SIZE_MAX));
355 Assert::IsTrue(
p.is_valid);
356 Assert::AreEqual(
"12",
p.model);
358 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
359 Assert::IsTrue(
p.is_valid);
360 Assert::AreEqual(
"12",
p.model);
362 Assert::IsFalse(
p.match(
"si12 1234567890120", 0,
SIZE_MAX));
363 Assert::IsTrue(
p.match(
"si12 1234567890120", 0,
SIZE_MAX, match_case_insensitive));
364 Assert::IsTrue(
p.match(
"...SI12 1234567890120...", 3,
SIZE_MAX));
365 Assert::IsTrue(
p.match(
"SI12 1234567890120", 0,
SIZE_MAX));
371 static const std::locale locale(
"en_US.UTF-8");
374 "Host: stackoverflow.com\r\n"
375 "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0\r\n"
376 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n"
377 "Accept-Language: sl,en-US;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2\r\n"
378 "Accept-Encoding: gzip, deflate, br\r\n"
380 "Connection: keep-alive\r\n"
381 "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"
382 "Upgrade-Insecure-Requests: 1\r\n"
383 "Sec-Fetch-Dest: document\r\n"
384 "Sec-Fetch-Mode: navigate\r\n"
385 "Sec-Fetch-Site: none\r\n"
386 "Sec-Fetch-User: ?1\r\n"
387 "Pragma: no-cache\r\n"
388 "Cache-Control: no-cache\r\n"
396 Assert::AreEqual((
size_t)0,
p.verb.start);
397 Assert::AreEqual((
size_t)3,
p.verb.end);
402 Assert::AreEqual((
uint16_t)0x200,
p.protocol.version);
406 std::list<http_header>
hdrs;
412 hdrs.push_back(std::move(
h));
417 Assert::AreEqual((
size_t)15,
hdrs.size());
419 for (
const auto&
h :
hdrs)
420 if (strnicmp(
request +
h.name.start,
h.name.size(),
"Accept-Language", (
size_t)-1, locale) == 0)
422 Assert::IsTrue(!
langs.empty());
425 "sl",
"en-US",
"en",
"de-DE",
"de"
431 Assert::IsTrue(
c ==
control.cend());
432 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:7019
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