… | |
… | |
1504 | |
1504 | |
1505 | DEC_DEC_DEPTH; |
1505 | DEC_DEC_DEPTH; |
1506 | sv = newRV_noinc ((SV *)hv); |
1506 | sv = newRV_noinc ((SV *)hv); |
1507 | |
1507 | |
1508 | // check filter callbacks |
1508 | // check filter callbacks |
1509 | if (dec->json.flags & F_HOOK) |
1509 | if (expect_false (dec->json.flags & F_HOOK)) |
1510 | { |
1510 | { |
1511 | if (dec->json.cb_sk_object && HvKEYS (hv) == 1) |
1511 | if (dec->json.cb_sk_object && HvKEYS (hv) == 1) |
1512 | { |
1512 | { |
1513 | HE *cb, *he; |
1513 | HE *cb, *he; |
1514 | |
1514 | |
… | |
… | |
1556 | XPUSHs (sv_2mortal (sv)); |
1556 | XPUSHs (sv_2mortal (sv)); |
1557 | |
1557 | |
1558 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1558 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1559 | |
1559 | |
1560 | if (count == 1) |
1560 | if (count == 1) |
1561 | { |
|
|
1562 | sv = newSVsv (POPs); |
1561 | sv = newSVsv (POPs); |
1563 | FREETMPS; LEAVE; |
|
|
1564 | return sv; |
|
|
1565 | } |
|
|
1566 | else if (count) |
1562 | else if (count == 0) |
|
|
1563 | SvREFCNT_inc (sv); |
|
|
1564 | else |
1567 | croak ("filter_json_object callbacks must not return more than one scalar"); |
1565 | croak ("filter_json_object callbacks must not return more than one scalar"); |
1568 | |
1566 | |
1569 | SvREFCNT_inc (sv); |
|
|
1570 | FREETMPS; LEAVE; |
1567 | FREETMPS; LEAVE; |
1571 | } |
1568 | } |
1572 | } |
1569 | } |
1573 | |
1570 | |
1574 | return sv; |
1571 | return sv; |
… | |
… | |
2209 | XPUSHs (ST (0)); |
2206 | XPUSHs (ST (0)); |
2210 | } |
2207 | } |
2211 | |
2208 | |
2212 | void encode (JSON *self, SV *scalar) |
2209 | void encode (JSON *self, SV *scalar) |
2213 | PPCODE: |
2210 | PPCODE: |
2214 | PUTBACK; scalar = encode_json (scalar, self); SPAGAIN; |
2211 | PUTBACK; XPUSHs (encode_json (scalar, self)); |
2215 | XPUSHs (scalar); |
|
|
2216 | |
2212 | |
2217 | void decode (JSON *self, SV *jsonstr) |
2213 | void decode (JSON *self, SV *jsonstr) |
2218 | PPCODE: |
2214 | PPCODE: |
2219 | PUTBACK; jsonstr = decode_json (jsonstr, self, 0); SPAGAIN; |
2215 | PUTBACK; XPUSHs (decode_json (jsonstr, self, 0)); |
2220 | XPUSHs (jsonstr); |
|
|
2221 | |
2216 | |
2222 | void decode_prefix (JSON *self, SV *jsonstr) |
2217 | void decode_prefix (JSON *self, SV *jsonstr) |
2223 | PPCODE: |
2218 | PPCODE: |
2224 | { |
2219 | { |
2225 | SV *sv; |
2220 | SV *sv; |
2226 | STRLEN offset; |
2221 | STRLEN offset; |
2227 | PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; |
2222 | PUTBACK; sv = decode_json (jsonstr, self, &offset); |
2228 | EXTEND (SP, 2); |
2223 | EXTEND (SP, 2); |
2229 | PUSHs (sv); |
2224 | PUSHs (sv); |
2230 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, SvPV_nolen (jsonstr) + offset)))); |
2225 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, SvPV_nolen (jsonstr) + offset)))); |
2231 | } |
2226 | } |
2232 | |
2227 | |
… | |
… | |
2305 | |
2300 | |
2306 | break; |
2301 | break; |
2307 | } |
2302 | } |
2308 | } |
2303 | } |
2309 | |
2304 | |
2310 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; |
2305 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); |
2311 | XPUSHs (sv); |
2306 | XPUSHs (sv); |
2312 | |
2307 | |
2313 | self->incr_pos -= offset; |
2308 | self->incr_pos -= offset; |
2314 | self->incr_nest = 0; |
2309 | self->incr_nest = 0; |
2315 | self->incr_mode = 0; |
2310 | self->incr_mode = 0; |
… | |
… | |
2367 | PPCODE: |
2362 | PPCODE: |
2368 | { |
2363 | { |
2369 | JSON json; |
2364 | JSON json; |
2370 | json_init (&json); |
2365 | json_init (&json); |
2371 | json.flags |= F_UTF8; |
2366 | json.flags |= F_UTF8; |
2372 | PUTBACK; scalar = encode_json (scalar, &json); SPAGAIN; |
2367 | PUTBACK; XPUSHs (encode_json (scalar, &json)); |
2373 | XPUSHs (scalar); |
|
|
2374 | } |
2368 | } |
2375 | |
2369 | |
2376 | void decode_json (SV *jsonstr) |
2370 | void decode_json (SV *jsonstr) |
2377 | PPCODE: |
2371 | PPCODE: |
2378 | { |
2372 | { |
2379 | JSON json; |
2373 | JSON json; |
2380 | json_init (&json); |
2374 | json_init (&json); |
2381 | json.flags |= F_UTF8; |
2375 | json.flags |= F_UTF8; |
2382 | PUTBACK; jsonstr = decode_json (jsonstr, &json, 0); SPAGAIN; |
2376 | PUTBACK; XPUSHs (decode_json (jsonstr, &json, 0)); |
2383 | XPUSHs (jsonstr); |
|
|
2384 | } |
2377 | } |
2385 | |
2378 | |