… | |
… | |
825 | } |
825 | } |
826 | else |
826 | else |
827 | { |
827 | { |
828 | // large integer, use the (rather slow) snprintf way. |
828 | // large integer, use the (rather slow) snprintf way. |
829 | need (enc, IVUV_MAXCHARS); |
829 | need (enc, IVUV_MAXCHARS); |
830 | enc->cur += |
830 | enc->cur += |
831 | SvIsUV(sv) |
831 | SvIsUV(sv) |
832 | ? snprintf (enc->cur, IVUV_MAXCHARS, "%"UVuf, (UV)SvUVX (sv)) |
832 | ? snprintf (enc->cur, IVUV_MAXCHARS, "%"UVuf, (UV)SvUVX (sv)) |
833 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
833 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
834 | } |
834 | } |
835 | } |
835 | } |
… | |
… | |
1892 | } |
1892 | } |
1893 | |
1893 | |
1894 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
1894 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
1895 | PPCODE: |
1895 | PPCODE: |
1896 | { |
1896 | { |
1897 | if (!self->cb_sk_object) |
1897 | if (!self->cb_sk_object) |
1898 | self->cb_sk_object = newHV (); |
1898 | self->cb_sk_object = newHV (); |
1899 | |
1899 | |
1900 | if (SvOK (cb)) |
1900 | if (SvOK (cb)) |
1901 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
1901 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
1902 | else |
1902 | else |
… | |
… | |
1913 | XPUSHs (ST (0)); |
1913 | XPUSHs (ST (0)); |
1914 | } |
1914 | } |
1915 | |
1915 | |
1916 | void encode (JSON *self, SV *scalar) |
1916 | void encode (JSON *self, SV *scalar) |
1917 | PPCODE: |
1917 | PPCODE: |
1918 | XPUSHs (encode_json (scalar, self)); |
1918 | PUTBACK; scalar = encode_json (scalar, self); SPAGAIN; |
|
|
1919 | XPUSHs (scalar); |
1919 | |
1920 | |
1920 | void decode (JSON *self, SV *jsonstr) |
1921 | void decode (JSON *self, SV *jsonstr) |
1921 | PPCODE: |
1922 | PPCODE: |
1922 | XPUSHs (decode_json (jsonstr, self, 0)); |
1923 | PUTBACK; jsonstr = decode_json (jsonstr, self, 0); SPAGAIN; |
|
|
1924 | XPUSHs (jsonstr); |
1923 | |
1925 | |
1924 | void decode_prefix (JSON *self, SV *jsonstr) |
1926 | void decode_prefix (JSON *self, SV *jsonstr) |
1925 | PPCODE: |
1927 | PPCODE: |
1926 | { |
1928 | { |
|
|
1929 | SV *sv; |
1927 | char *offset; |
1930 | char *offset; |
|
|
1931 | PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; |
1928 | EXTEND (SP, 2); |
1932 | EXTEND (SP, 2); |
1929 | PUSHs (decode_json (jsonstr, self, &offset)); |
1933 | PUSHs (sv); |
1930 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); |
1934 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); |
1931 | } |
1935 | } |
1932 | |
1936 | |
1933 | void incr_parse (JSON *self, SV *jsonstr = 0) |
1937 | void incr_parse (JSON *self, SV *jsonstr = 0) |
1934 | PPCODE: |
1938 | PPCODE: |
… | |
… | |
1981 | } |
1985 | } |
1982 | |
1986 | |
1983 | if (GIMME_V != G_VOID) |
1987 | if (GIMME_V != G_VOID) |
1984 | do |
1988 | do |
1985 | { |
1989 | { |
|
|
1990 | SV *sv; |
1986 | char *offset; |
1991 | char *offset; |
1987 | |
1992 | |
1988 | if (!INCR_DONE (self)) |
1993 | if (!INCR_DONE (self)) |
1989 | { |
1994 | { |
1990 | incr_parse (self); |
1995 | incr_parse (self); |
… | |
… | |
2004 | |
2009 | |
2005 | break; |
2010 | break; |
2006 | } |
2011 | } |
2007 | } |
2012 | } |
2008 | |
2013 | |
2009 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
2014 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; |
|
|
2015 | XPUSHs (sv); |
2010 | |
2016 | |
2011 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2017 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2012 | self->incr_nest = 0; |
2018 | self->incr_nest = 0; |
2013 | self->incr_mode = 0; |
2019 | self->incr_mode = 0; |
2014 | |
2020 | |
… | |
… | |
2066 | PPCODE: |
2072 | PPCODE: |
2067 | { |
2073 | { |
2068 | JSON json; |
2074 | JSON json; |
2069 | json_init (&json); |
2075 | json_init (&json); |
2070 | json.flags |= ix; |
2076 | json.flags |= ix; |
2071 | XPUSHs (encode_json (scalar, &json)); |
2077 | PUTBACK; scalar = encode_json (scalar, &json); SPAGAIN; |
|
|
2078 | XPUSHs (scalar); |
2072 | } |
2079 | } |
2073 | |
2080 | |
2074 | void decode_json (SV *jsonstr) |
2081 | void decode_json (SV *jsonstr) |
2075 | ALIAS: |
2082 | ALIAS: |
2076 | from_json_ = 0 |
2083 | from_json_ = 0 |
… | |
… | |
2078 | PPCODE: |
2085 | PPCODE: |
2079 | { |
2086 | { |
2080 | JSON json; |
2087 | JSON json; |
2081 | json_init (&json); |
2088 | json_init (&json); |
2082 | json.flags |= ix; |
2089 | json.flags |= ix; |
2083 | XPUSHs (decode_json (jsonstr, &json, 0)); |
2090 | PUTBACK; jsonstr = decode_json (jsonstr, &json, 0); SPAGAIN; |
|
|
2091 | XPUSHs (jsonstr); |
2084 | } |
2092 | } |
2085 | |
2093 | |