MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_append_number

Function json_append_number

deps/lua/src/lua_cjson.c:588–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586}
587
588static void json_append_number(lua_State *l, json_config_t *cfg,
589 strbuf_t *json, int lindex)
590{
591 double num = lua_tonumber(l, lindex);
592 int len;
593
594 if (cfg->encode_invalid_numbers == 0) {
595 /* Prevent encoding invalid numbers */
596 if (isinf(num) || isnan(num))
597 json_encode_exception(l, cfg, json, lindex, "must not be NaN or Inf");
598 } else if (cfg->encode_invalid_numbers == 1) {
599 /* Encode invalid numbers, but handle "nan" separately
600 * since some platforms may encode as "-nan". */
601 if (isnan(num)) {
602 strbuf_append_mem(json, "nan", 3);
603 return;
604 }
605 } else {
606 /* Encode invalid numbers as "null" */
607 if (isinf(num) || isnan(num)) {
608 strbuf_append_mem(json, "null", 4);
609 return;
610 }
611 }
612
613 strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE);
614 len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision);
615 strbuf_extend_length(json, len);
616}
617
618static void json_append_object(lua_State *l, json_config_t *cfg,
619 int current_depth, strbuf_t *json)

Callers 2

json_append_objectFunction · 0.85
json_append_dataFunction · 0.85

Calls 7

lua_tonumberFunction · 0.85
json_encode_exceptionFunction · 0.85
strbuf_append_memFunction · 0.85
fpconv_g_fmtFunction · 0.85
strbuf_empty_ptrFunction · 0.85
strbuf_extend_lengthFunction · 0.85

Tested by

no test coverage detected