json_append_string args: * - lua_State * - JSON strbuf * - String (Lua stack index) * * Returns nothing. Doesn't remove string from Lua stack */
| 589 | * |
| 590 | * Returns nothing. Doesn't remove string from Lua stack */ |
| 591 | static 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 |
| 618 | static void json_append_metadata_string(lua_State *l, strbuf_t *json, int lindex) |
no test coverage detected