Outputs the token to open file fp. When do_quote is > 0, output token double-quoted, when do_quote is < 0, output token without double-quotes, otherwise first investigate and quote appropriately when needed. */
| 280 | otherwise first investigate and quote appropriately when needed. |
| 281 | */ |
| 282 | void show(FILE *fp, jsmntok_t *tok, int do_quote) |
| 283 | { |
| 284 | /* start (0-based), end (= 1 beyond last): byte positions in input |
| 285 | meaning of size depends on token type: |
| 286 | object: number of keys |
| 287 | array: number of elements |
| 288 | string: 0 for value, 1 for key |
| 289 | primitive (number,false,true,null): no meaning, 0 |
| 290 | */ |
| 291 | if (!do_quote) { |
| 292 | /* Observe dot ID syntax; must quote when non-alnum. */ |
| 293 | const char *p; |
| 294 | for (p = input + tok->start; p < input + tok->end; p++) |
| 295 | if (isspace(*p) || ispunct(*p) && *p != '_') { |
| 296 | do_quote = 1; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | if (do_quote > 0) fputc('"', fp); |
| 301 | fwrite(input + tok->start, 1, tok->end - tok->start, fp); |
| 302 | if (do_quote > 0) fputc('"', fp); |
| 303 | } |
| 304 | |
| 305 | /** Outputs up to the first 16 chars of token to fp. */ |
| 306 | static void show_16(FILE *fp, jsmntok_t *tok) |
no outgoing calls
no test coverage detected