ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.xs
(Generate patch)

Comparing JSON-XS/XS.xs (file contents):
Revision 1.2 by root, Thu Mar 22 17:28:50 2007 UTC vs.
Revision 1.3 by root, Thu Mar 22 18:10:29 2007 UTC

11#define F_INDENT 0x00000004 11#define F_INDENT 0x00000004
12#define F_CANONICAL 0x00000008 12#define F_CANONICAL 0x00000008
13#define F_SPACE_BEFORE 0x00000010 13#define F_SPACE_BEFORE 0x00000010
14#define F_SPACE_AFTER 0x00000020 14#define F_SPACE_AFTER 0x00000020
15#define F_JSON_RPC 0x00000040 15#define F_JSON_RPC 0x00000040
16#define F_ALLOW_NONREF 0x00000080
16 17
17#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER 18#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER
18#define F_DEFAULT 0 19#define F_DEFAULT 0
19 20
20#define INIT_SIZE 32 // initial scalar size to be allocated 21#define INIT_SIZE 32 // initial scalar size to be allocated
359} 360}
360 361
361static SV * 362static SV *
362encode_json (SV *scalar, UV flags) 363encode_json (SV *scalar, UV flags)
363{ 364{
365 if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar))
366 croak ("hash- or arraref required (not a simple scalar, use allow_nonref to allow this)");
367
364 enc_t enc; 368 enc_t enc;
365 enc.flags = flags; 369 enc.flags = flags;
366 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 370 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
367 enc.cur = SvPVX (enc.sv); 371 enc.cur = SvPVX (enc.sv);
368 enc.end = SvEND (enc.sv); 372 enc.end = SvEND (enc.sv);
772 dec.err, 776 dec.err,
773 (int)offset, 777 (int)offset,
774 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); 778 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)");
775 } 779 }
776 780
777 sv_dump (sv);//D
778 return sv_2mortal (sv); 781 sv = sv_2mortal (sv);
782
783 if (!(dec.flags & F_ALLOW_NONREF) && !SvROK (sv))
784 croak ("JSON object or array expected (but number, string, true, false or null found, use allow_nonref to allow this)");
785
786 return sv;
779} 787}
780 788
781MODULE = JSON::XS PACKAGE = JSON::XS 789MODULE = JSON::XS PACKAGE = JSON::XS
782 790
783BOOT: 791BOOT:
811 canonical = F_CANONICAL 819 canonical = F_CANONICAL
812 space_before = F_SPACE_BEFORE 820 space_before = F_SPACE_BEFORE
813 space_after = F_SPACE_AFTER 821 space_after = F_SPACE_AFTER
814 json_rpc = F_JSON_RPC 822 json_rpc = F_JSON_RPC
815 pretty = F_PRETTY 823 pretty = F_PRETTY
824 allow_nonref = F_ALLOW_NONREF
816 CODE: 825 CODE:
817{ 826{
818 UV *uv = SvJSON (self); 827 UV *uv = SvJSON (self);
819 if (enable) 828 if (enable)
820 *uv |= ix; 829 *uv |= ix;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines