text
stringlengths 0
14.1k
|
---|
S_DONE,
|
MAX_STATES,
|
};
|
/*
|
* Tokens that change state.
|
*/
|
enum TokenTypes {
|
T_STRING,
|
T_OTHER,
|
T_COMMA,
|
T_COLON,
|
T_OPEN_DICT,
|
T_OPEN_LIST,
|
T_CLOSE_DICT,
|
T_CLOSE_LIST,
|
MAX_TOKENS
|
};
|
/*
|
* 4-byte ints for small string tokens.
|
*/
|
#define C_NULL FOURCC('n','u','l','l')
|
#define C_TRUE FOURCC('t','r','u','e')
|
#define C_ALSE FOURCC('a','l','s','e')
|
/*
|
* Signature for render functions.
|
*/
|
typedef bool (*render_func_t)(struct RenderState *rs, struct JsonValue *jv);
|
static bool render_any(struct RenderState *rs, struct JsonValue *jv);
|
/*
|
* Header manipulation
|
*/
|
static inline enum JsonValueType get_type(struct JsonValue *jv)
|
{
|
return jv->v_next_and_type & TYPE_MASK;
|
}
|
static inline bool has_type(struct JsonValue *jv, enum JsonValueType type)
|
{
|
if (!jv)
|
return false;
|
return get_type(jv) == type;
|
}
|
static inline struct JsonValue *get_next(struct JsonValue *jv)
|
{
|
return (struct JsonValue *)(jv->v_next_and_type & ~(uintptr_t)TYPE_MASK);
|
}
|
static inline void set_next(struct JsonValue *jv, struct JsonValue *next)
|
{
|
jv->v_next_and_type = (uintptr_t)next | get_type(jv);
|
}
|
static inline bool is_unattached(struct JsonValue *jv)
|
{
|
return get_next(jv) == UNATTACHED;
|
}
|
static inline void *get_extra(struct JsonValue *jv)
|
{
|
return (void *)(jv + 1);
|
}
|
static inline char *get_cstring(struct JsonValue *jv)
|
{
|
enum JsonValueType type = get_type(jv);
|
if (type != JSON_STRING)
|
return NULL;
|
return get_extra(jv);
|
}
|
/*
|
* Collection header manipulation.
|
*/
|
static inline struct JsonContainer *get_container(struct JsonValue *jv)
|
{
|
enum JsonValueType type = get_type(jv);
|
if (type != JSON_DICT && type != JSON_LIST)
|
return NULL;
|
return get_extra(jv);
|
}
|
static inline void set_parent(struct JsonValue *jv, struct JsonValue *parent)
|
{
|
struct JsonContainer *c = get_container(jv);
|
if (c)
|
c->c_parent = parent;
|
}
|
static inline struct JsonContext *get_context(struct JsonValue *jv)
|
{
|
struct JsonContainer *c = get_container(jv);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.