MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

better string parsing

+28 -4
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.0.8.2') 77 + version_conf.set('ANT_VERSION', '0.0.8.3') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+12 -1
src/ant.c
··· 914 914 915 915 static size_t strstring(struct js *js, jsval_t value, char *buf, size_t len) { 916 916 jsoff_t slen, off = vstr(js, value, &slen); 917 + const char *str = (const char *) &js->mem[off]; 917 918 size_t n = 0; 918 919 n += cpy(buf + n, len - n, "\"", 1); 919 - n += cpy(buf + n, len - n, (char *) &js->mem[off], slen); 920 + for (jsoff_t i = 0; i < slen && n < len - 1; i++) { 921 + char c = str[i]; 922 + if (c == '\n') { n += cpy(buf + n, len - n, "\\n", 2); } 923 + else if (c == '\r') { n += cpy(buf + n, len - n, "\\r", 2); } 924 + else if (c == '\t') { n += cpy(buf + n, len - n, "\\t", 2); } 925 + else if (c == '\\') { n += cpy(buf + n, len - n, "\\\\", 2); } 926 + else if (c == '"') { n += cpy(buf + n, len - n, "\\\"", 2); } 927 + else { if (n < len) buf[n++] = c; } 928 + } 920 929 n += cpy(buf + n, len - n, "\"", 1); 921 930 922 931 return n; ··· 3806 3815 is_xdigit(in[n2 + 3])) { 3807 3816 out[n1++] = (uint8_t) ((unhex(in[n2 + 2]) << 4U) | unhex(in[n2 + 3])); 3808 3817 n2 += 2; 3818 + } else if (in[n2 + 1] == '\\') { 3819 + out[n1++] = '\\'; 3809 3820 } else { 3810 3821 return js_mkerr(js, "bad str literal"); 3811 3822 }
+15 -2
src/modules/json.c
··· 87 87 88 88 case JS_NUM: { 89 89 double num = js_getnum(val); 90 + if (num == (int64_t)num) return yyjson_mut_sint(doc, (int64_t)num); 90 91 return yyjson_mut_real(doc, num); 91 92 } 92 93 ··· 181 182 yyjson_mut_doc_set_root(doc, root); 182 183 183 184 size_t len; 184 - yyjson_write_flag flg = YYJSON_WRITE_PRETTY; 185 - if (nargs >= 3 && js_type(args[2]) == JS_UNDEF) flg = 0; 185 + yyjson_write_flag flg = 0; 186 + if (nargs >= 3 && js_type(args[2]) != JS_UNDEF && js_type(args[2]) != JS_NULL) { 187 + int indent = 4; 188 + if (js_type(args[2]) == JS_NUM) { 189 + indent = (int)js_getnum(args[2]); 190 + if (indent < 0) indent = 0; 191 + if (indent > 10) indent = 10; 192 + } 193 + if (indent == 2) { 194 + flg = YYJSON_WRITE_PRETTY_TWO_SPACES; 195 + } else if (indent > 0) { 196 + flg = YYJSON_WRITE_PRETTY; 197 + } 198 + } 186 199 187 200 char *json_str = yyjson_mut_write(doc, flg, &len); 188 201 if (!json_str) {