teptris 0.3.19.1-aarch64-linux → 0.3.21.0-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,656 @@
1
+ /* The format battery: the exact set of format names the jsonschema
2
+ * crate (taplo's validation engine, 0.17) asserts on, mirrored
3
+ * per-format from its implementations. Names outside this set are
4
+ * annotations on both sides. Only plain strings reach this file
5
+ * (TOML datetime values get their formats by kind, policy 3); every
6
+ * check is byte- and length-based because document strings may carry
7
+ * embedded NULs and UTF-8. */
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "schema_internal.h"
13
+
14
+ static bool is_digit(char c) { return c >= '0' && c <= '9'; }
15
+
16
+ static bool is_hex(char c) {
17
+ return is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
18
+ }
19
+
20
+ static bool is_ascii_alnum(char c) {
21
+ return is_digit(c) || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
22
+ }
23
+
24
+ static bool all_digits(const char *s, size_t from, size_t n) {
25
+ for (size_t i = from; i < from + n; i++) {
26
+ if (!is_digit(s[i])) return false;
27
+ }
28
+ return true;
29
+ }
30
+
31
+ static int two_digits(const char *s, size_t from) {
32
+ return (s[from] - '0') * 10 + (s[from + 1] - '0');
33
+ }
34
+
35
+ static size_t cp_count(const char *s, size_t len) {
36
+ size_t count = 0;
37
+ size_t i = 0;
38
+ while (i < len) {
39
+ unsigned char b = (unsigned char)s[i];
40
+ size_t step = b < 0x80 ? 1
41
+ : b < 0xE0 ? 2
42
+ : b < 0xF0 ? 3
43
+ : 4;
44
+ i += step > len - i ? 1 : step;
45
+ count++;
46
+ }
47
+ return count;
48
+ }
49
+
50
+ static bool is_ascii_space(char c) {
51
+ return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' ||
52
+ c == '\f';
53
+ }
54
+
55
+ /* ------------------------------------------------- date / time atoms -- */
56
+
57
+ static bool leap_year(int y) {
58
+ return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
59
+ }
60
+
61
+ static int days_in_month(int y, int m) {
62
+ static const int dim[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
63
+ if (m == 2 && leap_year(y)) return 29;
64
+ return dim[m - 1];
65
+ }
66
+
67
+ /* YYYY-MM-DD with real calendar ranges (the crate parses the date,
68
+ * then re-checks the zero-padded shape; a strict digits+range check
69
+ * answers both) */
70
+ static bool check_date(const char *s, size_t len) {
71
+ if (len != 10 || s[4] != '-' || s[7] != '-') return false;
72
+ if (!all_digits(s, 0, 4) || !all_digits(s, 5, 2) ||
73
+ !all_digits(s, 8, 2)) {
74
+ return false;
75
+ }
76
+ int y = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 +
77
+ (s[3] - '0');
78
+ int m = two_digits(s, 5);
79
+ int d = two_digits(s, 8);
80
+ return m >= 1 && m <= 12 && d >= 1 && d <= days_in_month(y, m);
81
+ }
82
+
83
+ /* HH:MM:SS with ranges; answers the consumed length (8) or 0 */
84
+ static size_t check_hms(const char *s, size_t len) {
85
+ if (len < 8 || s[2] != ':' || s[5] != ':') return 0;
86
+ if (!all_digits(s, 0, 2) || !all_digits(s, 3, 2) ||
87
+ !all_digits(s, 6, 2)) {
88
+ return 0;
89
+ }
90
+ int h = two_digits(s, 0);
91
+ int m = two_digits(s, 3);
92
+ int sec = two_digits(s, 6);
93
+ if (h > 23 || m > 59 || sec > 59) return 0;
94
+ return 8;
95
+ }
96
+
97
+ /* the offset tail: Z/z or +HH:MM / -HH:MM; answers its length or 0 */
98
+ static size_t check_offset(const char *s, size_t len) {
99
+ if (len == 0) return 0;
100
+ if (s[0] == 'Z' || s[0] == 'z') return 1;
101
+ if (s[0] != '+' && s[0] != '-') return 0;
102
+ if (len < 6 || s[3] != ':') return 0;
103
+ if (!all_digits(s, 1, 2) || !all_digits(s, 4, 2)) return 0;
104
+ int h = two_digits(s, 1);
105
+ int m = two_digits(s, 4);
106
+ return h <= 23 && m <= 59 ? 6 : 0;
107
+ }
108
+
109
+ /* full-date "T" full-time: the offset is mandatory (RFC 3339, and the
110
+ * crate parses with its RFC 3339 parser); lowercase t/z allowed */
111
+ static bool check_datetime(const char *s, size_t len) {
112
+ if (len < 20) return false;
113
+ if (!check_date(s, 10)) return false;
114
+ if (s[10] != 'T' && s[10] != 't') return false;
115
+ size_t used = check_hms(s + 11, len - 11);
116
+ if (used == 0) return false;
117
+ size_t pos = 11 + used;
118
+ if (pos < len && s[pos] == '.') {
119
+ size_t frac = 0;
120
+ pos++;
121
+ while (pos < len && is_digit(s[pos])) {
122
+ pos++;
123
+ frac++;
124
+ }
125
+ if (frac == 0) return false;
126
+ }
127
+ return len > pos && check_offset(s + pos, len - pos) == len - pos;
128
+ }
129
+
130
+ /* ------------------------------------------------------- rfc atoms -- */
131
+
132
+ /* the crate's email check: a leading dot fails, ".." fails, a dot
133
+ * directly before "@" fails, an "@" ends the (unvalidated) domain;
134
+ * everything else about the domain is accepted */
135
+ static bool check_email(const char *s, size_t len) {
136
+ if (len == 0 || s[0] == '.') return false;
137
+ for (size_t i = 1; i < len; i++) {
138
+ if (s[i] == '@') {
139
+ return s[i - 1] != '.';
140
+ }
141
+ if (s[i] == '.' && s[i - 1] == '.') return false;
142
+ }
143
+ return false; /* no @ */
144
+ }
145
+
146
+ /* the crate's hostname/idn-hostname check (one body for both):
147
+ * nonempty, at most 255 characters, only alphanumerics, '-' and '.',
148
+ * no leading/trailing '-', labels of at most 63 characters. The
149
+ * crate's alphanumeric test is Unicode-wide; the practical subset
150
+ * here is ASCII (flagged as a divergence in SCHEMAS.md) */
151
+ static bool check_hostname(const char *s, size_t len) {
152
+ if (len == 0 || s[0] == '-' || s[len - 1] == '-') return false;
153
+ if (cp_count(s, len) > 255) return false;
154
+ for (size_t i = 0; i < len; i++) {
155
+ char c = s[i];
156
+ if (!(is_ascii_alnum(c) || c == '-' || c == '.')) return false;
157
+ }
158
+ size_t label = 0;
159
+ for (size_t i = 0; i <= len; i++) {
160
+ if (i == len || s[i] == '.') {
161
+ if (cp_count(s + i - label, label) > 63) return false;
162
+ label = 0;
163
+ } else {
164
+ label++;
165
+ }
166
+ }
167
+ return true;
168
+ }
169
+
170
+ /* dotted quad, each group 1-3 digits without a leading zero (unless
171
+ * the group is exactly "0"), at most 255 */
172
+ static bool check_ipv4(const char *s, size_t len) {
173
+ size_t pos = 0;
174
+ for (int g = 0; g < 4; g++) {
175
+ if (g > 0) {
176
+ if (pos >= len || s[pos] != '.') return false;
177
+ pos++;
178
+ }
179
+ size_t start = pos;
180
+ while (pos < len && is_digit(s[pos])) pos++;
181
+ size_t n = pos - start;
182
+ if (n < 1 || n > 3) return false;
183
+ if (n > 1 && s[start] == '0') return false;
184
+ int v = 0;
185
+ for (size_t i = start; i < pos; i++) v = v * 10 + (s[i] - '0');
186
+ if (v > 255) return false;
187
+ }
188
+ return pos == len;
189
+ }
190
+
191
+ /* IPv6 per the std parser the crate uses: 8 groups of 1-4 hex digits
192
+ * with one optional "::" compression and an optional IPv4 tail */
193
+ static bool group_ok(const char *t, size_t n) {
194
+ if (n < 1 || n > 4) return false;
195
+ for (size_t i = 0; i < n; i++) {
196
+ if (!is_hex(t[i])) return false;
197
+ }
198
+ return true;
199
+ }
200
+
201
+ static bool check_ipv6(const char *s, size_t len) {
202
+ const char *tok[9];
203
+ size_t tl[9];
204
+ size_t n = 0, start = 0;
205
+ for (size_t i = 0; i <= len; i++) {
206
+ if (i == len || s[i] == ':') {
207
+ if (n >= 9) return false;
208
+ tok[n] = s + start;
209
+ tl[n] = i - start;
210
+ n++;
211
+ start = i + 1;
212
+ }
213
+ }
214
+ size_t empty_pos[9], ne = 0;
215
+ for (size_t i = 0; i < n; i++) {
216
+ if (tl[i] == 0) empty_pos[ne++] = i;
217
+ }
218
+ bool v4 = tl[n - 1] > 0 && memchr(tok[n - 1], '.', tl[n - 1]) != NULL;
219
+ if (ne == 0) {
220
+ if (n != (v4 ? 7 : 8)) return false;
221
+ } else if (ne == 1) {
222
+ /* a single empty token is a mid-string "::" ("a::b"); at the
223
+ * ends it would be a lone leading/trailing colon */
224
+ if (empty_pos[0] == 0 || empty_pos[0] == n - 1) return false;
225
+ } else if (ne == 2) {
226
+ if (empty_pos[1] != empty_pos[0] + 1) return false;
227
+ } else if (ne == 3) {
228
+ if (n != 3) return false; /* the bare "::" */
229
+ } else {
230
+ return false;
231
+ }
232
+ size_t groups = 0;
233
+ for (size_t i = 0; i < n; i++) {
234
+ if (tl[i] == 0) continue;
235
+ if (i == n - 1 && v4) {
236
+ if (!check_ipv4(tok[i], tl[i])) return false;
237
+ groups += 2;
238
+ } else {
239
+ if (!group_ok(tok[i], tl[i])) return false;
240
+ groups += 1;
241
+ }
242
+ }
243
+ return ne == 0 ? groups == 8 : groups <= 7;
244
+ }
245
+
246
+ /* absolute URL, the practical shape of the url-crate parse: a scheme
247
+ * (letter-first, alnum/+/-/.), a colon, and no control characters or
248
+ * spaces anywhere */
249
+ static bool check_uri(const char *s, size_t len) {
250
+ size_t i = 0;
251
+ if (len == 0 || !((s[0] >= 'a' && s[0] <= 'z') ||
252
+ (s[0] >= 'A' && s[0] <= 'Z'))) {
253
+ return false;
254
+ }
255
+ for (i = 1; i < len; i++) {
256
+ char c = s[i];
257
+ if (c == ':') break;
258
+ if (!(is_ascii_alnum(c) || c == '+' || c == '-' || c == '.')) {
259
+ return false;
260
+ }
261
+ }
262
+ if (i == len || i == 0) return false;
263
+ for (size_t k = 0; k < len; k++) {
264
+ unsigned char c = (unsigned char)s[k];
265
+ if (c < 0x21 || c == 0x7F) return false; /* controls + space */
266
+ }
267
+ return true;
268
+ }
269
+
270
+ /* URI-reference (and iri-reference): the crate's regex reduces to
271
+ * "at most one '#', no backslash, no whitespace" - the optional
272
+ * scheme part cannot make an otherwise-valid string fail because the
273
+ * colon is legal in the reference body */
274
+ static bool check_uri_reference(const char *s, size_t len) {
275
+ bool hash = false;
276
+ for (size_t i = 0; i < len; i++) {
277
+ char c = s[i];
278
+ if (c == '\\') return false;
279
+ if (is_ascii_space(c)) return false;
280
+ if (c == '#') {
281
+ if (hash) return false;
282
+ hash = true;
283
+ }
284
+ }
285
+ return true;
286
+ }
287
+
288
+ /* JSON pointer (RFC 6901): empty, or '/'-led with '~' only in the
289
+ * escapes ~0/~1 */
290
+ static bool check_json_pointer(const char *s, size_t len) {
291
+ if (len == 0) return true;
292
+ if (s[0] != '/') return false;
293
+ for (size_t i = 1; i < len; i++) {
294
+ if (s[i] == '~') {
295
+ if (i + 1 >= len || (s[i + 1] != '0' && s[i + 1] != '1')) {
296
+ return false;
297
+ }
298
+ i++;
299
+ }
300
+ }
301
+ return true;
302
+ }
303
+
304
+ /* relative-json-pointer: non-negative base-10 index without a
305
+ * leading zero, then "#" or a '/'-led pointer tail */
306
+ static bool check_relative_json_pointer(const char *s, size_t len) {
307
+ size_t i = 0;
308
+ if (len == 0) return false;
309
+ if (s[0] == '0') {
310
+ i = 1;
311
+ } else if (s[0] >= '1' && s[0] <= '9') {
312
+ i = 1;
313
+ while (i < len && is_digit(s[i])) i++;
314
+ } else {
315
+ return false;
316
+ }
317
+ if (i == len) return false;
318
+ if (s[i] == '#') return i + 1 == len;
319
+ if (s[i] != '/') return false;
320
+ return check_json_pointer(s + i, len - i);
321
+ }
322
+
323
+ /* uuid: the crate's FromStr accepts the simple (32 hex) and
324
+ * hyphenated (8-4-4-4-12) spellings, case-insensitive */
325
+ static bool check_uuid(const char *s, size_t len) {
326
+ if (len != 32 && len != 36) return false;
327
+ size_t hex_seen = 0;
328
+ for (size_t i = 0; i < len; i++) {
329
+ if (len == 36 && (i == 8 || i == 13 || i == 18 || i == 23)) {
330
+ if (s[i] != '-') return false;
331
+ continue;
332
+ }
333
+ if (!is_hex(s[i])) return false;
334
+ hex_seen++;
335
+ }
336
+ return hex_seen == 32;
337
+ }
338
+
339
+ /* ISO 8601 duration, the practical core the iso8601 crate accepts:
340
+ * an optional sign, P, then at least one nY/nM/nW/nD component and an
341
+ * optional T-section of nH/nM/nS; a fraction is allowed on any unit */
342
+ static bool check_duration(const char *s, size_t len) {
343
+ size_t i = 0;
344
+ if (len == 0) return false;
345
+ if (s[0] == '+' || s[0] == '-') i++;
346
+ if (i >= len || s[i] != 'P') return false;
347
+ i++;
348
+ bool any = false;
349
+ bool in_time = false;
350
+ while (i < len) {
351
+ if (!in_time && s[i] == 'T') {
352
+ in_time = true;
353
+ i++;
354
+ continue;
355
+ }
356
+ size_t start = i;
357
+ while (i < len && is_digit(s[i])) i++;
358
+ if (i == start) return false;
359
+ if (i < len && (s[i] == '.' || s[i] == ',')) {
360
+ i++;
361
+ size_t fs = i;
362
+ while (i < len && is_digit(s[i])) i++;
363
+ if (i == fs) return false;
364
+ }
365
+ if (i >= len) return false;
366
+ char unit = s[i];
367
+ i++;
368
+ if (unit == 'Y' || unit == 'W' || unit == 'D') {
369
+ if (in_time) return false;
370
+ } else if (unit == 'M') {
371
+ /* months before T, minutes after; both fine */
372
+ } else if (unit == 'H' || unit == 'S') {
373
+ if (!in_time) return false;
374
+ } else {
375
+ return false;
376
+ }
377
+ any = true;
378
+ }
379
+ return any;
380
+ }
381
+
382
+ /* ----------------------------------------------------- uri-template -- */
383
+
384
+ /* the crate's template regex: literal characters (nothing in the
385
+ * control/space range or "'<>%\^`{|}) or %XX pairs, plus {…}
386
+ * expressions with an optional operator, comma-separated variable
387
+ * names (word characters or %XX) and :N or * modifiers. Uppercase
388
+ * hex and uppercase variable letters are accepted here (a superset
389
+ * of the crate's lowercase-only spellings) */
390
+ static bool check_uri_template(const char *s, size_t len) {
391
+ size_t i = 0;
392
+ while (i < len) {
393
+ char c = s[i];
394
+ if (c == '%') {
395
+ if (i + 2 >= len || !is_hex(s[i + 1]) || !is_hex(s[i + 2])) {
396
+ return false;
397
+ }
398
+ i += 3;
399
+ continue;
400
+ }
401
+ if (c == '{') {
402
+ i++;
403
+ if (i < len && s[i] != '\0' &&
404
+ strchr("+./;?&=,!@|", s[i]) != NULL) {
405
+ i++;
406
+ }
407
+ bool varspec = false;
408
+ while (i < len && s[i] != '}') {
409
+ /* one varspec: name (:N or *)? */
410
+ size_t name = 0;
411
+ while (i < len && s[i] != '}' && s[i] != ',' &&
412
+ s[i] != ':' && s[i] != '*') {
413
+ if (s[i] == '%') {
414
+ if (i + 2 >= len || !is_hex(s[i + 1]) ||
415
+ !is_hex(s[i + 2])) {
416
+ return false;
417
+ }
418
+ i += 3;
419
+ } else if (is_ascii_alnum(s[i]) || s[i] == '_') {
420
+ i++;
421
+ } else {
422
+ return false;
423
+ }
424
+ name++;
425
+ }
426
+ if (name == 0) return false;
427
+ if (i < len && s[i] == ':') {
428
+ i++;
429
+ size_t ds = i;
430
+ while (i < len && is_digit(s[i])) i++;
431
+ size_t dn = i - ds;
432
+ if (dn < 1 || dn > 4) return false;
433
+ if (s[ds] == '0') return false;
434
+ } else if (i < len && s[i] == '*') {
435
+ i++;
436
+ }
437
+ varspec = true;
438
+ if (i < len && s[i] == ',') {
439
+ i++;
440
+ }
441
+ }
442
+ if (i >= len || !varspec) return false;
443
+ i++; /* the closing brace */
444
+ continue;
445
+ }
446
+ unsigned char b = (unsigned char)c;
447
+ if (b <= 0x20 || b == 0x7F || c == '"' || c == '\'' || c == '<' ||
448
+ c == '>' || c == '\\' || c == '^' || c == '`' || c == '|' ||
449
+ c == '}') {
450
+ return false;
451
+ }
452
+ i++;
453
+ }
454
+ return true;
455
+ }
456
+
457
+ /* --------------------------------------------------------- semver -- */
458
+
459
+ /* numeric identifier: "0" or [1-9][0-9]* (no leading zeros) */
460
+ static bool semver_numeric(const char *s, size_t len) {
461
+ if (len == 0 || len > 19) return false;
462
+ if (s[0] == '0' && len > 1) return false;
463
+ return all_digits(s, 0, len);
464
+ }
465
+
466
+ static bool pre_ident_ok(const char *s, size_t len) {
467
+ for (size_t i = 0; i < len; i++) {
468
+ char c = s[i];
469
+ if (!(is_ascii_alnum(c) || c == '-')) return false;
470
+ }
471
+ return len > 0;
472
+ }
473
+
474
+ /* a dot-separated identifier list; numeric identifiers must not
475
+ * carry leading zeros (semver spec 9/11) */
476
+ static bool pre_list_ok(const char *s, size_t len) {
477
+ size_t start = 0;
478
+ for (size_t i = 0; i <= len; i++) {
479
+ if (i == len || s[i] == '.') {
480
+ size_t n = i - start;
481
+ if (!pre_ident_ok(s + start, n)) return false;
482
+ bool numeric = true;
483
+ for (size_t k = 0; k < n; k++) {
484
+ if (!is_digit(s[start + k])) numeric = false;
485
+ }
486
+ if (numeric && !semver_numeric(s + start, n)) return false;
487
+ start = i + 1;
488
+ }
489
+ }
490
+ return true;
491
+ }
492
+
493
+ /* MAJOR.MINOR.PATCH, then an optional -prerelease and +build */
494
+ static bool check_semver(const char *s, size_t len) {
495
+ size_t num_start[3] = {0, 0, 0}, num_len[3] = {0, 0, 0};
496
+ size_t i = 0;
497
+ for (int part = 0; part < 3; part++) {
498
+ num_start[part] = i;
499
+ while (i < len && is_digit(s[i])) i++;
500
+ num_len[part] = i - num_start[part];
501
+ if (!semver_numeric(s + num_start[part], num_len[part])) return false;
502
+ if (part < 2) {
503
+ if (i >= len || s[i] != '.') return false;
504
+ i++;
505
+ }
506
+ }
507
+ if (i == len) return true;
508
+ if (s[i] == '-') {
509
+ i++;
510
+ size_t start = i;
511
+ while (i < len && s[i] != '+') i++;
512
+ if (!pre_list_ok(s + start, i - start)) return false;
513
+ }
514
+ if (i < len) {
515
+ if (s[i] != '+') return false;
516
+ i++;
517
+ size_t start = i;
518
+ while (i < len && s[i] != '+') i++;
519
+ if (i != len) return false; /* a second '+' is invalid */
520
+ if (!pre_list_ok(s + start, len - start)) return false;
521
+ }
522
+ return i == len;
523
+ }
524
+
525
+ /* semver requirement (the semver crate's VersionReq grammar): a
526
+ * comma-separated comparator list; each is a version with an
527
+ * optional operator (= > >= < <= ^ ~; bare means ^), where MINOR or
528
+ * PATCH may be a wildcard (*, x, X), or a bare wildcard */
529
+ static bool check_semver_req(const char *s, size_t len) {
530
+ size_t i = 0;
531
+ bool any = false; /* at least one comparator */
532
+ while (i < len) {
533
+ while (i < len && (s[i] == ' ' || s[i] == '\t')) i++;
534
+ if (i == len) break;
535
+ if (s[i] == ',') return false; /* empty comparator */
536
+ /* operator */
537
+ if (s[i] == '=' || s[i] == '>' || s[i] == '<' || s[i] == '^' ||
538
+ s[i] == '~') {
539
+ i++;
540
+ if (i < len && (s[i] == '=')) i++; /* >= or <= */
541
+ }
542
+ while (i < len && (s[i] == ' ' || s[i] == '\t')) i++;
543
+ if (i >= len) return false;
544
+ /* MAJOR */
545
+ size_t start = i;
546
+ while (i < len && is_digit(s[i])) i++;
547
+ if (i > start) {
548
+ if (!semver_numeric(s + start, i - start)) return false;
549
+ } else if (s[i] == '*' || s[i] == 'x' || s[i] == 'X') {
550
+ i++;
551
+ any = true;
552
+ /* a bare wildcard ends the comparator */
553
+ while (i < len && (s[i] == ' ' || s[i] == '\t')) i++;
554
+ if (i == len) return true;
555
+ if (s[i] != ',') return false;
556
+ i++;
557
+ continue;
558
+ } else {
559
+ return false;
560
+ }
561
+ any = true;
562
+ /* optional .MINOR */
563
+ if (i < len && s[i] == '.') {
564
+ i++;
565
+ start = i;
566
+ while (i < len && is_digit(s[i])) i++;
567
+ if (i > start) {
568
+ if (!semver_numeric(s + start, i - start)) return false;
569
+ } else if (i < len && (s[i] == '*' || s[i] == 'x' ||
570
+ s[i] == 'X')) {
571
+ i++;
572
+ any = true;
573
+ } else {
574
+ return false;
575
+ }
576
+ /* optional .PATCH */
577
+ if (i < len && s[i] == '.') {
578
+ i++;
579
+ start = i;
580
+ while (i < len && is_digit(s[i])) i++;
581
+ if (i > start) {
582
+ if (!semver_numeric(s + start, i - start)) return false;
583
+ } else if (i < len && (s[i] == '*' || s[i] == 'x' ||
584
+ s[i] == 'X')) {
585
+ i++;
586
+ any = true;
587
+ } else {
588
+ return false;
589
+ }
590
+ /* a full version may carry -prerelease */
591
+ if (i < len && s[i] == '-') {
592
+ i++;
593
+ size_t ps = i;
594
+ while (i < len && s[i] != '+') i++;
595
+ if (!pre_list_ok(s + ps, i - ps)) return false;
596
+ }
597
+ }
598
+ }
599
+ while (i < len && (s[i] == ' ' || s[i] == '\t')) i++;
600
+ if (i == len) break;
601
+ if (s[i] != ',') return false;
602
+ i++;
603
+ }
604
+ return any;
605
+ }
606
+
607
+ /* ----------------------------------------------------------- entry -- */
608
+
609
+ bool sch_format_string_check(int format, const char *s, size_t len,
610
+ teptris_arena *scratch) {
611
+ switch (format) {
612
+ case FMT_DATE: return check_date(s, len);
613
+ case FMT_DATETIME: return check_datetime(s, len);
614
+ case FMT_TIME: {
615
+ size_t used = check_hms(s, len);
616
+ if (used == 0) return false;
617
+ size_t pos = used;
618
+ if (pos < len && s[pos] == '.') {
619
+ size_t frac = 0;
620
+ pos++;
621
+ while (pos < len && is_digit(s[pos])) {
622
+ pos++;
623
+ frac++;
624
+ }
625
+ if (frac != 6) return false; /* the crate's exact 6 digits */
626
+ }
627
+ return len > pos && check_offset(s + pos, len - pos) == len - pos;
628
+ }
629
+ case FMT_EMAIL:
630
+ case FMT_IDN_EMAIL: return check_email(s, len);
631
+ case FMT_HOSTNAME:
632
+ case FMT_IDN_HOSTNAME: return check_hostname(s, len);
633
+ case FMT_IPV4: return check_ipv4(s, len);
634
+ case FMT_IPV6: return check_ipv6(s, len);
635
+ case FMT_URI:
636
+ case FMT_IRI: return check_uri(s, len);
637
+ case FMT_URI_REFERENCE:
638
+ case FMT_IRI_REFERENCE: return check_uri_reference(s, len);
639
+ case FMT_JSON_POINTER: return check_json_pointer(s, len);
640
+ case FMT_RELATIVE_JSON_POINTER:
641
+ return check_relative_json_pointer(s, len);
642
+ case FMT_REGEX: {
643
+ char rerr[128] = {0};
644
+ /* a compile trial in the engine's own NFA: the dialect is
645
+ * teptris's (backreferences and lookaround reject here even
646
+ * though the crate's engine takes them) */
647
+ return sch_regex_compile(scratch, s, len, rerr, sizeof rerr) != NULL;
648
+ }
649
+ case FMT_URI_TEMPLATE: return check_uri_template(s, len);
650
+ case FMT_UUID: return check_uuid(s, len);
651
+ case FMT_DURATION: return check_duration(s, len);
652
+ case FMT_SEMVER: return check_semver(s, len);
653
+ case FMT_SEMVER_REQUIREMENT: return check_semver_req(s, len);
654
+ default: return true;
655
+ }
656
+ }