The attributes of a start tag from src[p]; the tag's kind (CSX_OPEN, * CSX_EMPTY) or CSX_BAD. Moves the cursor past the tag. */
| 3243 | /* The attributes of a start tag from src[p]; the tag's kind (CSX_OPEN, |
| 3244 | * CSX_EMPTY) or CSX_BAD. Moves the cursor past the tag. */ |
| 3245 | static int csx_attributes(csx_t *x, uint32_t p, csx_tok_t *t) { |
| 3246 | const char *s = x->src; |
| 3247 | for (;;) { |
| 3248 | while (p < x->n && isspace((unsigned char)s[p])) { |
| 3249 | p++; |
| 3250 | } |
| 3251 | if (p >= x->n) { |
| 3252 | return CSX_BAD; |
| 3253 | } |
| 3254 | if (s[p] == '>') { |
| 3255 | x->i = p + SKIP_ONE; |
| 3256 | return CSX_OPEN; |
| 3257 | } |
| 3258 | if (s[p] == '/' && p + SKIP_ONE < x->n && s[p + SKIP_ONE] == '>') { |
| 3259 | x->i = p + PAIR_LEN; |
| 3260 | return CSX_EMPTY; |
| 3261 | } |
| 3262 | uint32_t as = p; |
| 3263 | while (p < x->n && csx_name_char((unsigned char)s[p])) { |
| 3264 | p++; |
| 3265 | } |
| 3266 | if (p == as) { |
| 3267 | return CSX_BAD; |
| 3268 | } |
| 3269 | csx_span_t an = csx_local(x, as, p); |
| 3270 | while (p < x->n && isspace((unsigned char)s[p])) { |
| 3271 | p++; |
| 3272 | } |
| 3273 | if (p >= x->n || s[p] != '=') { |
| 3274 | return CSX_BAD; |
| 3275 | } |
| 3276 | p++; |
| 3277 | while (p < x->n && isspace((unsigned char)s[p])) { |
| 3278 | p++; |
| 3279 | } |
| 3280 | if (p >= x->n || (s[p] != '"' && s[p] != '\'')) { |
| 3281 | return CSX_BAD; |
| 3282 | } |
| 3283 | char quote = s[p++]; |
| 3284 | uint32_t vs = p; |
| 3285 | while (p < x->n && s[p] != quote) { |
| 3286 | p++; |
| 3287 | } |
| 3288 | if (p >= x->n) { |
| 3289 | return CSX_BAD; |
| 3290 | } |
| 3291 | int ai = csx_attr_index(s + an.s, an.e - an.s); |
| 3292 | if (ai >= 0) { |
| 3293 | t->attr[ai] = (csx_span_t){.s = vs, .e = p, .has = true}; |
| 3294 | } |
| 3295 | p++; |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | /* The next token of the document. Every byte is passed once. */ |
| 3300 | static void csx_next(csx_t *x, csx_tok_t *t) { |
no test coverage detected