--- JSON-XS/XS.xs 2007/08/27 02:03:23 1.64 +++ JSON-XS/XS.xs 2007/11/28 14:01:01 1.67 @@ -314,28 +314,31 @@ if (enc->indent >= enc->maxdepth) croak ("data structure too deep (hit recursion limit)"); - encode_ch (enc, '['); encode_nl (enc); - ++enc->indent; - - for (i = 0; i <= len; ++i) + encode_ch (enc, '['); + + if (len >= 0) { - SV **svp = av_fetch (av, i, 0); + encode_nl (enc); ++enc->indent; - encode_indent (enc); + for (i = 0; i <= len; ++i) + { + SV **svp = av_fetch (av, i, 0); - if (svp) - encode_sv (enc, *svp); - else - encode_str (enc, "null", 4, 0); + encode_indent (enc); - if (i < len) - encode_comma (enc); - } + if (svp) + encode_sv (enc, *svp); + else + encode_str (enc, "null", 4, 0); - encode_nl (enc); + if (i < len) + encode_comma (enc); + } - --enc->indent; - encode_indent (enc); encode_ch (enc, ']'); + encode_nl (enc); --enc->indent; encode_indent (enc); + } + + encode_ch (enc, ']'); } static void @@ -398,7 +401,7 @@ if (enc->indent >= enc->maxdepth) croak ("data structure too deep (hit recursion limit)"); - encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; + encode_ch (enc, '{'); // for canonical output we have to sort by keys first // actually, this is mostly due to the stupid so-called @@ -461,6 +464,8 @@ LEAVE; } + encode_nl (enc); ++enc->indent; + while (count--) { encode_indent (enc); @@ -471,28 +476,34 @@ if (count) encode_comma (enc); } + + encode_nl (enc); --enc->indent; encode_indent (enc); } } else { if (hv_iterinit (hv) || SvMAGICAL (hv)) if ((he = hv_iternext (hv))) - for (;;) - { - encode_indent (enc); - encode_hk (enc, he); - encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); + { + encode_nl (enc); ++enc->indent; - if (!(he = hv_iternext (hv))) - break; + for (;;) + { + encode_indent (enc); + encode_hk (enc, he); + encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); - encode_comma (enc); - } - } + if (!(he = hv_iternext (hv))) + break; - encode_nl (enc); + encode_comma (enc); + } + + encode_nl (enc); --enc->indent; encode_indent (enc); + } + } - --enc->indent; encode_indent (enc); encode_ch (enc, '}'); + encode_ch (enc, '}'); } // encode objects, arrays and special \0=false and \1=true values. @@ -1476,6 +1487,24 @@ XPUSHs (ST (0)); } +void get_ascii (JSON *self) + ALIAS: + get_ascii = F_ASCII + get_latin1 = F_LATIN1 + get_utf8 = F_UTF8 + get_indent = F_INDENT + get_canonical = F_CANONICAL + get_space_before = F_SPACE_BEFORE + get_space_after = F_SPACE_AFTER + get_pretty = F_PRETTY + get_allow_nonref = F_ALLOW_NONREF + get_shrink = F_SHRINK + get_allow_blessed = F_ALLOW_BLESSED + get_convert_blessed = F_CONV_BLESSED + get_relaxed = F_RELAXED + PPCODE: + XPUSHs (boolSV (self->flags & ix)); + void max_depth (JSON *self, UV max_depth = 0x80000000UL) PPCODE: { @@ -1491,6 +1520,12 @@ XPUSHs (ST (0)); } +U32 get_max_depth (JSON *self) + CODE: + RETVAL = DEC_DEPTH (self->flags); + OUTPUT: + RETVAL + void max_size (JSON *self, UV max_size = 0) PPCODE: { @@ -1507,6 +1542,12 @@ XPUSHs (ST (0)); } +int get_max_size (JSON *self) + CODE: + RETVAL = DEC_SIZE (self->flags); + OUTPUT: + RETVAL + void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) PPCODE: {