diff options
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -1210,6 +1210,7 @@ uc_printf_common(uc_vm *vm, size_t nargs, uc_stringbuf_t *buf) const char *fstr, *last, *p; uc_type_t t = UC_NULL; size_t argidx = 1; + int i, pad_size; if (ucv_type(fmt) == UC_STRING) fstr = ucv_string_get(fmt); @@ -1339,10 +1340,25 @@ uc_printf_common(uc_vm *vm, size_t nargs, uc_stringbuf_t *buf) case 'J': t = UC_STRING; - if (argidx < nargs) - arg.s = ucv_to_jsonstring(vm, uc_get_arg(argidx++)); - else + pad_size = 0; + + for (i = 0; sfmt + i < fp; i++) { + if (sfmt[i] == '.') { + pad_size = 1 + atoi(&sfmt[i + 1]); + fp = &sfmt[i]; + break; + } + } + + if (argidx < nargs) { + arg.s = ucv_to_jsonstring_formatted(vm, + uc_get_arg(argidx++), + pad_size > 0 ? (pad_size > 1 ? ' ' : '\t') : '\0', + pad_size > 0 ? (pad_size > 1 ? pad_size - 1 : 1) : 0); + } + else { arg.s = NULL; + } arg.s = arg.s ? arg.s : xstrdup("null"); |