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

Function json_append_string

deps/lua/src/lua_cjson.c:463–487  ·  view source on GitHub ↗

json_append_string args: * - lua_State * - JSON strbuf * - String (Lua stack index) * * Returns nothing. Doesn't remove string from Lua stack */

Source from the content-addressed store, hash-verified

461 *
462 * Returns nothing. Doesn't remove string from Lua stack */
463static void json_append_string(lua_State *l, strbuf_t *json, int lindex)
464{
465 const char *escstr;
466 int i;
467 const char *str;
468 size_t len;
469
470 str = lua_tolstring(l, lindex, &len);
471
472 /* Worst case is len * 6 (all unicode escapes).
473 * This buffer is reused constantly for small strings
474 * If there are any excess pages, they won't be hit anyway.
475 * This gains ~5% speedup. */
476 strbuf_ensure_empty_length(json, len * 6 + 2);
477
478 strbuf_append_char_unsafe(json, '\"');
479 for (i = 0; i < len; i++) {
480 escstr = char2escape[(unsigned char)str[i]];
481 if (escstr)
482 strbuf_append_string(json, escstr);
483 else
484 strbuf_append_char_unsafe(json, str[i]);
485 }
486 strbuf_append_char_unsafe(json, '\"');
487}
488
489/* Find the size of the array on the top of the Lua stack
490 * -1 object (not a pure array)

Callers 2

json_append_objectFunction · 0.85
json_append_dataFunction · 0.85

Calls 4

lua_tolstringFunction · 0.85
strbuf_append_stringFunction · 0.85

Tested by

no test coverage detected