MCPcopy Create free account
hub / github.com/axmolengine/axmol / json_append_string

Function json_append_string

3rdparty/lua/lua-cjson/lua_cjson.c:474–498  ·  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

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