Lines Matching refs:cfg

138     json_config_t *cfg;  member
196 json_config_t *cfg; in json_fetch_config() local
198 cfg = lua_touserdata(l, lua_upvalueindex(1)); in json_fetch_config()
199 if (!cfg) in json_fetch_config()
202 return cfg; in json_fetch_config()
270 json_config_t *cfg = json_arg_init(l, 3); in json_cfg_encode_sparse_array() local
272 json_enum_option(l, 1, &cfg->encode_sparse_convert, NULL, 1); in json_cfg_encode_sparse_array()
273 json_integer_option(l, 2, &cfg->encode_sparse_ratio, 0, INT_MAX); in json_cfg_encode_sparse_array()
274 json_integer_option(l, 3, &cfg->encode_sparse_safe, 0, INT_MAX); in json_cfg_encode_sparse_array()
283 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_encode_max_depth() local
285 return json_integer_option(l, 1, &cfg->encode_max_depth, 1, INT_MAX); in json_cfg_encode_max_depth()
292 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_decode_max_depth() local
294 return json_integer_option(l, 1, &cfg->decode_max_depth, 1, INT_MAX); in json_cfg_decode_max_depth()
300 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_encode_number_precision() local
302 return json_integer_option(l, 1, &cfg->encode_number_precision, 1, 14); in json_cfg_encode_number_precision()
308 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_encode_keep_buffer() local
311 old_value = cfg->encode_keep_buffer; in json_cfg_encode_keep_buffer()
313 json_enum_option(l, 1, &cfg->encode_keep_buffer, NULL, 1); in json_cfg_encode_keep_buffer()
316 if (old_value ^ cfg->encode_keep_buffer) { in json_cfg_encode_keep_buffer()
317 if (cfg->encode_keep_buffer) in json_cfg_encode_keep_buffer()
318 strbuf_init(&cfg->encode_buf, 0); in json_cfg_encode_keep_buffer()
320 strbuf_free(&cfg->encode_buf); in json_cfg_encode_keep_buffer()
341 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_encode_invalid_numbers() local
343 json_enum_option(l, 1, &cfg->encode_invalid_numbers, options, 1); in json_cfg_encode_invalid_numbers()
345 json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers); in json_cfg_encode_invalid_numbers()
352 json_config_t *cfg = json_arg_init(l, 1); in json_cfg_decode_invalid_numbers() local
354 json_enum_option(l, 1, &cfg->decode_invalid_numbers, NULL, 1); in json_cfg_decode_invalid_numbers()
356 json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers); in json_cfg_decode_invalid_numbers()
363 json_config_t *cfg; in json_destroy_config() local
365 cfg = lua_touserdata(l, 1); in json_destroy_config()
366 if (cfg) in json_destroy_config()
367 strbuf_free(&cfg->encode_buf); in json_destroy_config()
368 cfg = NULL; in json_destroy_config()
375 json_config_t *cfg; in json_create_config() local
378 cfg = lua_newuserdata(l, sizeof(*cfg)); in json_create_config()
386 cfg->encode_sparse_convert = DEFAULT_SPARSE_CONVERT; in json_create_config()
387 cfg->encode_sparse_ratio = DEFAULT_SPARSE_RATIO; in json_create_config()
388 cfg->encode_sparse_safe = DEFAULT_SPARSE_SAFE; in json_create_config()
389 cfg->encode_max_depth = DEFAULT_ENCODE_MAX_DEPTH; in json_create_config()
390 cfg->decode_max_depth = DEFAULT_DECODE_MAX_DEPTH; in json_create_config()
391 cfg->encode_invalid_numbers = DEFAULT_ENCODE_INVALID_NUMBERS; in json_create_config()
392 cfg->decode_invalid_numbers = DEFAULT_DECODE_INVALID_NUMBERS; in json_create_config()
393 cfg->encode_keep_buffer = DEFAULT_ENCODE_KEEP_BUFFER; in json_create_config()
394 cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION; in json_create_config()
397 strbuf_init(&cfg->encode_buf, 0); in json_create_config()
404 cfg->ch2token[i] = T_ERROR; in json_create_config()
407 cfg->ch2token['{'] = T_OBJ_BEGIN; in json_create_config()
408 cfg->ch2token['}'] = T_OBJ_END; in json_create_config()
409 cfg->ch2token['['] = T_ARR_BEGIN; in json_create_config()
410 cfg->ch2token[']'] = T_ARR_END; in json_create_config()
411 cfg->ch2token[','] = T_COMMA; in json_create_config()
412 cfg->ch2token[':'] = T_COLON; in json_create_config()
413 cfg->ch2token['\0'] = T_END; in json_create_config()
414 cfg->ch2token[' '] = T_WHITESPACE; in json_create_config()
415 cfg->ch2token['\t'] = T_WHITESPACE; in json_create_config()
416 cfg->ch2token['\n'] = T_WHITESPACE; in json_create_config()
417 cfg->ch2token['\r'] = T_WHITESPACE; in json_create_config()
420 cfg->ch2token['f'] = T_UNKNOWN; /* false? */ in json_create_config()
421 cfg->ch2token['i'] = T_UNKNOWN; /* inf, ininity? */ in json_create_config()
422 cfg->ch2token['I'] = T_UNKNOWN; in json_create_config()
423 cfg->ch2token['n'] = T_UNKNOWN; /* null, nan? */ in json_create_config()
424 cfg->ch2token['N'] = T_UNKNOWN; in json_create_config()
425 cfg->ch2token['t'] = T_UNKNOWN; /* true? */ in json_create_config()
426 cfg->ch2token['"'] = T_UNKNOWN; /* string? */ in json_create_config()
427 cfg->ch2token['+'] = T_UNKNOWN; /* number? */ in json_create_config()
428 cfg->ch2token['-'] = T_UNKNOWN; in json_create_config()
430 cfg->ch2token['0' + i] = T_UNKNOWN; in json_create_config()
434 cfg->escape2char[i] = 0; /* String error */ in json_create_config()
435 cfg->escape2char['"'] = '"'; in json_create_config()
436 cfg->escape2char['\\'] = '\\'; in json_create_config()
437 cfg->escape2char['/'] = '/'; in json_create_config()
438 cfg->escape2char['b'] = '\b'; in json_create_config()
439 cfg->escape2char['t'] = '\t'; in json_create_config()
440 cfg->escape2char['n'] = '\n'; in json_create_config()
441 cfg->escape2char['f'] = '\f'; in json_create_config()
442 cfg->escape2char['r'] = '\r'; in json_create_config()
443 cfg->escape2char['u'] = 'u'; /* Unicode parsing required */ in json_create_config()
448 static void json_encode_exception(lua_State *l, json_config_t *cfg, strbuf_t *json, int lindex, in json_encode_exception() argument
451 if (!cfg->encode_keep_buffer) in json_encode_exception()
493 static int lua_array_length(lua_State *l, json_config_t *cfg, strbuf_t *json) in lua_array_length() argument
524 if (cfg->encode_sparse_ratio > 0 && in lua_array_length()
525 max > items * cfg->encode_sparse_ratio && in lua_array_length()
526 max > cfg->encode_sparse_safe) { in lua_array_length()
527 if (!cfg->encode_sparse_convert) in lua_array_length()
528 json_encode_exception(l, cfg, json, -1, "excessively sparse array"); in lua_array_length()
536 static void json_check_encode_depth(lua_State *l, json_config_t *cfg, in json_check_encode_depth() argument
549 if (current_depth <= cfg->encode_max_depth && lua_checkstack(l, 3)) in json_check_encode_depth()
552 if (!cfg->encode_keep_buffer) in json_check_encode_depth()
559 static void json_append_data(lua_State *l, json_config_t *cfg,
566 static void json_append_array(lua_State *l, json_config_t *cfg, int current_depth, in json_append_array() argument
581 json_append_data(l, cfg, current_depth, json); in json_append_array()
588 static void json_append_number(lua_State *l, json_config_t *cfg, in json_append_number() argument
594 if (cfg->encode_invalid_numbers == 0) { in json_append_number()
597 json_encode_exception(l, cfg, json, lindex, "must not be NaN or Inf"); in json_append_number()
598 } else if (cfg->encode_invalid_numbers == 1) { in json_append_number()
614 len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); in json_append_number()
618 static void json_append_object(lua_State *l, json_config_t *cfg, in json_append_object() argument
639 json_append_number(l, cfg, json, -2); in json_append_object()
645 json_encode_exception(l, cfg, json, -2, in json_append_object()
651 json_append_data(l, cfg, current_depth, json); in json_append_object()
660 static void json_append_data(lua_State *l, json_config_t *cfg, in json_append_data() argument
670 json_append_number(l, cfg, json, -1); in json_append_data()
680 json_check_encode_depth(l, cfg, current_depth, json); in json_append_data()
681 len = lua_array_length(l, cfg, json); in json_append_data()
683 json_append_array(l, cfg, current_depth, json, len); in json_append_data()
685 json_append_object(l, cfg, current_depth, json); in json_append_data()
698 json_encode_exception(l, cfg, json, -1, "type not supported"); in json_append_data()
705 json_config_t *cfg = json_fetch_config(l); in json_encode() local
713 if (!cfg->encode_keep_buffer) { in json_encode()
719 encode_buf = &cfg->encode_buf; in json_encode()
723 json_append_data(l, cfg, 0, encode_buf); in json_encode()
728 if (!cfg->encode_keep_buffer) in json_encode()
887 char *escape2char = json->cfg->escape2char; in json_next_string_token()
1016 const json_token_type_t *ch2token = json->cfg->ch2token; in json_next_token()
1058 if (!json->cfg->decode_invalid_numbers && json_is_invalid_number(json)) { in json_next_token()
1078 } else if (json->cfg->decode_invalid_numbers && in json_next_token()
1125 if (json->current_depth <= json->cfg->decode_max_depth && in json_decode_descend()
1261 json.cfg = json_fetch_config(l); in json_decode()