--- JSON-XS/XS.xs 2007/03/22 16:40:16 1.1 +++ JSON-XS/XS.xs 2007/03/22 17:28:50 1.2 @@ -14,6 +14,7 @@ #define F_SPACE_AFTER 0x00000020 #define F_JSON_RPC 0x00000040 +#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER #define F_DEFAULT 0 #define INIT_SIZE 32 // initial scalar size to be allocated @@ -148,7 +149,7 @@ } \ SE -#define SPACE SB if (enc->flags & F_INDENT) { need (enc, 1); encode_ch (enc, ' '); } SE +#define SPACE SB need (enc, 1); encode_ch (enc, ' '); SE #define NL SB if (enc->flags & F_INDENT) { need (enc, 1); encode_ch (enc, '\n'); } SE #define COMMA SB \ encode_ch (enc, ','); \ @@ -811,6 +812,7 @@ space_before = F_SPACE_BEFORE space_after = F_SPACE_AFTER json_rpc = F_JSON_RPC + pretty = F_PRETTY CODE: { UV *uv = SvJSON (self); @@ -828,7 +830,15 @@ PPCODE: XPUSHs (encode_json (scalar, *SvJSON (self))); -void decode (SV *self, SV *jsondata) +void decode (SV *self, SV *jsonstr) PPCODE: - XPUSHs (decode_json (jsondata, *SvJSON (self))); + XPUSHs (decode_json (jsonstr, *SvJSON (self))); + +void to_json (SV *scalar) + PPCODE: + XPUSHs (encode_json (scalar, F_UTF8)); + +void from_json (SV *jsonstr) + PPCODE: + XPUSHs (decode_json (jsonstr, F_UTF8));