… | |
… | |
318 | if (len == 1) |
318 | if (len == 1) |
319 | if (*pv == '1') |
319 | if (*pv == '1') |
320 | return 1; |
320 | return 1; |
321 | else if (*pv == '0') |
321 | else if (*pv == '0') |
322 | return 0; |
322 | return 0; |
323 | |
|
|
324 | } |
323 | } |
325 | |
324 | |
326 | return -1; |
325 | return -1; |
327 | } |
326 | } |
328 | |
327 | |
… | |
… | |
333 | if (!SvROK (scalar)) |
332 | if (!SvROK (scalar)) |
334 | return 1; |
333 | return 1; |
335 | |
334 | |
336 | scalar = SvRV (scalar); |
335 | scalar = SvRV (scalar); |
337 | |
336 | |
|
|
337 | if (SvTYPE (scalar) >= SVt_PVMG) |
|
|
338 | { |
338 | if (SvSTASH (scalar) == bool_stash) |
339 | if (SvSTASH (scalar) == bool_stash) |
339 | return 1; |
340 | return 1; |
340 | |
341 | |
341 | if (!SvOBJECT (scalar) && ref_bool_type (scalar) >= 0) |
342 | if (!SvOBJECT (scalar) && ref_bool_type (scalar) >= 0) |
342 | return 1; |
343 | return 1; |
|
|
344 | } |
343 | |
345 | |
344 | return 0; |
346 | return 0; |
345 | } |
347 | } |
346 | |
348 | |
347 | ///////////////////////////////////////////////////////////////////////////// |
349 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1687 | fail: |
1689 | fail: |
1688 | return 0; |
1690 | return 0; |
1689 | } |
1691 | } |
1690 | |
1692 | |
1691 | static SV * |
1693 | static SV * |
1692 | decode_json (SV *string, JSON *json, char **offset_return) |
1694 | decode_json (SV *string, JSON *json, STRLEN *offset_return) |
1693 | { |
1695 | { |
1694 | dec_t dec; |
1696 | dec_t dec; |
1695 | SV *sv; |
1697 | SV *sv; |
1696 | |
1698 | |
1697 | /* work around bugs in 5.10 where manipulating magic values |
1699 | /* work around bugs in 5.10 where manipulating magic values |
1698 | * makes perl ignore the magic in subsequent accesses. |
1700 | * makes perl ignore the magic in subsequent accesses. |
1699 | * also make a copy of non-PV values, to get them into a clean |
1701 | * also make a copy of non-PV values, to get them into a clean |
1700 | * state (SvPV should do that, but it's buggy, see below). |
1702 | * state (SvPV should do that, but it's buggy, see below). |
|
|
1703 | * |
|
|
1704 | * SvIsCOW_shared_hash works around a bug in perl (possibly 5.16), |
|
|
1705 | * as reported by Reini Urban. |
1701 | */ |
1706 | */ |
1702 | /*SvGETMAGIC (string);*/ |
1707 | /*SvGETMAGIC (string);*/ |
1703 | if (SvMAGICAL (string) || !SvPOK (string)) |
1708 | if (SvMAGICAL (string) || !SvPOK (string) || SvIsCOW_shared_hash (string)) |
1704 | string = sv_2mortal (newSVsv (string)); |
1709 | string = sv_2mortal (newSVsv (string)); |
1705 | |
1710 | |
1706 | SvUPGRADE (string, SVt_PV); |
1711 | SvUPGRADE (string, SVt_PV); |
1707 | |
1712 | |
1708 | /* work around a bug in perl 5.10, which causes SvCUR to fail an |
1713 | /* work around a bug in perl 5.10, which causes SvCUR to fail an |
… | |
… | |
1747 | |
1752 | |
1748 | decode_ws (&dec); |
1753 | decode_ws (&dec); |
1749 | sv = decode_sv (&dec); |
1754 | sv = decode_sv (&dec); |
1750 | |
1755 | |
1751 | if (offset_return) |
1756 | if (offset_return) |
1752 | *offset_return = dec.cur; |
1757 | *offset_return = dec.cur - SvPVX (string); |
1753 | |
1758 | else if (sv) |
1754 | if (!(offset_return || !sv)) |
|
|
1755 | { |
1759 | { |
1756 | // check for trailing garbage |
1760 | // check for trailing garbage |
1757 | decode_ws (&dec); |
1761 | decode_ws (&dec); |
1758 | |
1762 | |
1759 | if (*dec.cur) |
1763 | if (*dec.cur) |
… | |
… | |
2106 | |
2110 | |
2107 | void decode_prefix (JSON *self, SV *jsonstr) |
2111 | void decode_prefix (JSON *self, SV *jsonstr) |
2108 | PPCODE: |
2112 | PPCODE: |
2109 | { |
2113 | { |
2110 | SV *sv; |
2114 | SV *sv; |
2111 | char *offset; |
2115 | STRLEN offset; |
2112 | PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; |
2116 | PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; |
2113 | EXTEND (SP, 2); |
2117 | EXTEND (SP, 2); |
2114 | PUSHs (sv); |
2118 | PUSHs (sv); |
2115 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); |
2119 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, SvPV_nolen (jsonstr) + offset)))); |
2116 | } |
2120 | } |
2117 | |
2121 | |
2118 | void incr_parse (JSON *self, SV *jsonstr = 0) |
2122 | void incr_parse (JSON *self, SV *jsonstr = 0) |
2119 | PPCODE: |
2123 | PPCODE: |
2120 | { |
2124 | { |
… | |
… | |
2167 | |
2171 | |
2168 | if (GIMME_V != G_VOID) |
2172 | if (GIMME_V != G_VOID) |
2169 | do |
2173 | do |
2170 | { |
2174 | { |
2171 | SV *sv; |
2175 | SV *sv; |
2172 | char *offset; |
2176 | STRLEN offset; |
2173 | |
2177 | |
2174 | if (!INCR_DONE (self)) |
2178 | if (!INCR_DONE (self)) |
2175 | { |
2179 | { |
2176 | incr_parse (self); |
2180 | incr_parse (self); |
2177 | |
2181 | |
… | |
… | |
2193 | } |
2197 | } |
2194 | |
2198 | |
2195 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; |
2199 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; |
2196 | XPUSHs (sv); |
2200 | XPUSHs (sv); |
2197 | |
2201 | |
2198 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2202 | self->incr_pos -= offset; |
2199 | self->incr_nest = 0; |
2203 | self->incr_nest = 0; |
2200 | self->incr_mode = 0; |
2204 | self->incr_mode = 0; |
2201 | |
2205 | |
2202 | sv_chop (self->incr_text, offset); |
2206 | sv_chop (self->incr_text, SvPVX (self->incr_text) + offset); |
2203 | } |
2207 | } |
2204 | while (GIMME_V == G_ARRAY); |
2208 | while (GIMME_V == G_ARRAY); |
2205 | } |
2209 | } |
2206 | |
2210 | |
2207 | SV *incr_text (JSON *self) |
2211 | SV *incr_text (JSON *self) |