MCPcopy Create free account
hub / github.com/defold/defold / json_append_string

Function json_append_string

engine/script/src/luacjson/lua_cjson.c:591–615  ·  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

589 *
590 * Returns nothing. Doesn't remove string from Lua stack */
591static void json_append_string(lua_State *l, strbuf_t *json, int lindex)
592{
593 const char *escstr;
594 unsigned i;
595 const char *str;
596 size_t len;
597
598 str = lua_tolstring(l, lindex, &len);
599
600 /* Worst case is len * 6 (all unicode escapes).
601 * This buffer is reused constantly for small strings
602 * If there are any excess pages, they won't be hit anyway.
603 * This gains ~5% speedup. */
604 strbuf_ensure_empty_length(json, len * 6 + 2);
605
606 strbuf_append_char_unsafe(json, '\"');
607 for (i = 0; i < len; i++) {
608 escstr = char2escape[(unsigned char)str[i]];
609 if (escstr)
610 strbuf_append_string(json, escstr);
611 else
612 strbuf_append_char_unsafe(json, str[i]);
613 }
614 strbuf_append_char_unsafe(json, '\"');
615}
616
617// DEFOLD
618static void json_append_metadata_string(lua_State *l, strbuf_t *json, int lindex)

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