rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
esc_json_int.h File Reference

The tokens of esc_json_lex.c and the functions esc_json.c reads them with. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  tok_t
 One JSON token, with its byte range and its links. More...
struct  lex_t
 State of one lexer run over a JSON text. More...

Enumerations

enum  ttype_t {
  T_OBJ , T_ARR , T_STR , T_NUM ,
  T_TRUE , T_FALSE , T_NULL
}
 Type of one JSON token.
enum  lex_why_t {
  LEX_SYNTAX = 0 , LEX_DUP , LEX_NUL , LEX_SURROGATE ,
  LEX_UTF8 , LEX_MEMBERS
}
 Why the text was refused, beyond its not being JSON. More...

Functions

bool esc_json_lex_all (lex_t *l)
 Cut lexer l's text into tokens.
const char * esc_json_lex_why_text (lex_why_t why)
 Why the lexer refused, as the text after "%s near byte".
unsigned esc_json_decode_unit (const char *s, uint32_t *i, uint8_t out[4])
 The UTF-8 bytes of the character at s[*i], into out; *i moves past it.
bool esc_json_text_is (const char *s, const tok_t *a, const char *lit)
 Whether a string token's text decodes to the plain lit.

Detailed Description

The tokens of esc_json_lex.c and the functions esc_json.c reads them with.

Private to shared/esc/: no other file includes it.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ lex_why_t

enum lex_why_t

Why the text was refused, beyond its not being JSON.

Enumerator
LEX_DUP 

a key an object already had

LEX_NUL 

\u0000, which would end a C string

LEX_SURROGATE 

half a surrogate pair

LEX_UTF8 

bytes that are not UTF-8

LEX_MEMBERS 

an object with more than 64 members

Function Documentation

◆ esc_json_decode_unit()

unsigned esc_json_decode_unit ( const char * s,
uint32_t * i,
uint8_t out[4] )

The UTF-8 bytes of the character at s[*i], into out; *i moves past it.

Only for text esc_json_lex_all() accepted. Returns the byte count, 1 to 4.

Parameters
sThe text.
iPosition of the character; moves past it.
outReceives the UTF-8 bytes.
Returns
The byte count, 1 to 4.

◆ esc_json_lex_all()

bool esc_json_lex_all ( lex_t * l)

Cut lexer l's text into tokens.

With l->tok NULL it only counts them into l->n; with l->tok set to l->cap tokens it stores them and refuses a key an object already had. False on a refusal, with l->pos and l->why saying where and why.

Parameters
lThe lexer state.
Returns
true when the text was accepted.

◆ esc_json_lex_why_text()

const char * esc_json_lex_why_text ( lex_why_t why)

Why the lexer refused, as the text after "%s near byte".

Parameters
whyThe refusal reason.
Returns
A static text.

◆ esc_json_text_is()

bool esc_json_text_is ( const char * s,
const tok_t * a,
const char * lit )

Whether a string token's text decodes to the plain lit.

Parameters
sThe text.
aThe string token.
litThe literal to compare with.
Returns
true when the decoded text equals lit.