jsonfmt: Add error reporting
This commit is contained in:
parent
3ae9347ad2
commit
e0161cd22c
2 changed files with 18 additions and 6 deletions
|
|
@ -12,7 +12,7 @@ static void fujson_fmt_str(pTHX_ fustr *out, const char *stri, size_t len, int u
|
|||
* strings, I suspect there's room for optimizations in
|
||||
* is_c9strict_utf8_string(). */
|
||||
if (utf8 && !is_c9strict_utf8_string(str, len)) {
|
||||
return; /* TODO: Throw error. */
|
||||
croak("invalid codepoint encountered in string, cannot format to JSON");
|
||||
}
|
||||
|
||||
fustr_write(out, "\"", 1);
|
||||
|
|
@ -151,9 +151,8 @@ static void fujson_fmt(pTHX_ fustr *out, SV *val) {
|
|||
} else if (SvPOKp(val)) {
|
||||
fujson_fmt_str(aTHX_ out, SvPVX(val), SvCUR(val), SvUTF8(val));
|
||||
} else if (SvNOKp(val)) { /* Must check before IOKp, because integer conversion might have been lossy */
|
||||
/* TODO: quadmath? */
|
||||
NV nv = SvNV_nomg(val);
|
||||
if (isinfnan(nv)) return; /* TODO: error */
|
||||
if (isinfnan(nv)) croak("unable to format floating point NaN or Inf as JSON");
|
||||
fustr_reserve(out, NV_DIG+1);
|
||||
Gconvert(nv, NV_DIG, 0, out->cur);
|
||||
out->cur += strlen(out->cur);
|
||||
|
|
@ -165,11 +164,11 @@ static void fujson_fmt(pTHX_ fustr *out, SV *val) {
|
|||
if (UNLIKELY(SvOBJECT(rv))) { /* TODO: Check for TO_JSON */ }
|
||||
else if (SvTYPE(rv) == SVt_PVHV) fujson_fmt_hv(aTHX_ out, (HV *)rv);
|
||||
else if (SvTYPE(rv) == SVt_PVAV) fujson_fmt_av(aTHX_ out, (AV *)rv);
|
||||
else return; /* TODO: error */
|
||||
else croak("unable to format reference '%s' as JSON", SvPV_nolen(val));
|
||||
} else if (!SvOK(val)) {
|
||||
fustr_write(out, "null", 4);
|
||||
} else {
|
||||
/* TODO: error */
|
||||
croak("unable to format unknown value '%s' as JSON", SvPV_nolen(val));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue