Util: Add to_bool() and use it for JSON, Pg & query encoding
To improve interop with legacy modules.
This commit is contained in:
parent
06e2f950fe
commit
c7a3415485
10 changed files with 141 additions and 37 deletions
|
|
@ -231,10 +231,9 @@ static void fujson_fmt_obj(pTHX_ fujson_fmt_ctx *ctx, SV *rv, SV *obj) {
|
|||
static void fujson_fmt(pTHX_ fujson_fmt_ctx *ctx, SV *val) {
|
||||
SvGETMAGIC(val);
|
||||
|
||||
/* XXX: &PL_sv_yes and &PL_sv_no are proper booleans under 5.40, so no need
|
||||
* to explicitly check for those; does this work in 5.36 as well? */
|
||||
if (SvIsBOOL(val)) { /* Must check before IOKp & POKp, because bool implies both flags */
|
||||
if (BOOL_INTERNALS_sv_isbool_true(val)) fustr_write(ctx->out, "true", 4);
|
||||
int r = fu_2bool(val);
|
||||
if (r != -1) { /* Must check SvISBOOL() before IOKp & POKp, because it implies both flags */
|
||||
if (r) fustr_write(ctx->out, "true", 4);
|
||||
else fustr_write(ctx->out, "false", 5);
|
||||
} else if (SvPOKp(val)) {
|
||||
fujson_fmt_str(aTHX_ ctx, SvPVX(val), SvCUR(val), SvUTF8(val));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue