MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_append_string

Function json_append_string

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:466–490  ·  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

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

Callers 2

json_append_objectFunction · 0.85
json_append_dataFunction · 0.85

Calls 3

strbuf_append_stringFunction · 0.85

Tested by

no test coverage detected