… | |
… | |
4 | |
4 | |
5 | #include "assert.h" |
5 | #include "assert.h" |
6 | #include "string.h" |
6 | #include "string.h" |
7 | #include "stdlib.h" |
7 | #include "stdlib.h" |
8 | |
8 | |
9 | #define F_ASCII 0x00000001 |
9 | #define F_ASCII 0x00000001UL |
10 | #define F_UTF8 0x00000002 |
10 | #define F_UTF8 0x00000002UL |
11 | #define F_INDENT 0x00000004 |
11 | #define F_INDENT 0x00000004UL |
12 | #define F_CANONICAL 0x00000008 |
12 | #define F_CANONICAL 0x00000008UL |
13 | #define F_SPACE_BEFORE 0x00000010 |
13 | #define F_SPACE_BEFORE 0x00000010UL |
14 | #define F_SPACE_AFTER 0x00000020 |
14 | #define F_SPACE_AFTER 0x00000020UL |
15 | #define F_ALLOW_NONREF 0x00000080 |
15 | #define F_ALLOW_NONREF 0x00000080UL |
16 | #define F_SHRINK 0x00000100 |
16 | #define F_SHRINK 0x00000100UL |
|
|
17 | #define F_MAXDEPTH 0xf8000000UL |
|
|
18 | #define S_MAXDEPTH 27 |
|
|
19 | |
|
|
20 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
|
|
21 | |
|
|
22 | // F_SELFCONVERT? <=> to_json/toJson |
|
|
23 | // F_BLESSED? <=> { $__class__$ => } |
17 | |
24 | |
18 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
25 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
19 | #define F_DEFAULT 0 |
26 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
20 | |
27 | |
21 | #define INIT_SIZE 32 // initial scalar size to be allocated |
28 | #define INIT_SIZE 32 // initial scalar size to be allocated |
22 | #define INDENT_STEP 3 // spaces per indentation level |
29 | #define INDENT_STEP 3 // spaces per indentation level |
23 | |
30 | |
24 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
31 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
… | |
… | |
69 | { |
76 | { |
70 | *clen = 2; |
77 | *clen = 2; |
71 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
78 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
72 | } |
79 | } |
73 | else |
80 | else |
|
|
81 | { |
|
|
82 | *clen = (STRLEN)-1; |
74 | return (UV)-1; |
83 | return (UV)-1; |
|
|
84 | } |
75 | } |
85 | } |
76 | |
86 | |
77 | ///////////////////////////////////////////////////////////////////////////// |
87 | ///////////////////////////////////////////////////////////////////////////// |
78 | // encoder |
88 | // encoder |
79 | |
89 | |
… | |
… | |
81 | typedef struct |
91 | typedef struct |
82 | { |
92 | { |
83 | char *cur; // SvPVX (sv) + current output position |
93 | char *cur; // SvPVX (sv) + current output position |
84 | char *end; // SvEND (sv) |
94 | char *end; // SvEND (sv) |
85 | SV *sv; // result scalar |
95 | SV *sv; // result scalar |
86 | UV flags; // F_* |
96 | U32 flags; // F_* |
87 | int indent; // indentation level |
97 | U32 indent; // indentation level |
88 | int max_depth; // max. recursion level |
98 | U32 maxdepth; // max. indentation/recursion level |
89 | } enc_t; |
99 | } enc_t; |
90 | |
100 | |
91 | static void |
101 | static void |
92 | need (enc_t *enc, STRLEN len) |
102 | need (enc_t *enc, STRLEN len) |
93 | { |
103 | { |
… | |
… | |
261 | static void |
271 | static void |
262 | encode_av (enc_t *enc, AV *av) |
272 | encode_av (enc_t *enc, AV *av) |
263 | { |
273 | { |
264 | int i, len = av_len (av); |
274 | int i, len = av_len (av); |
265 | |
275 | |
|
|
276 | if (enc->indent >= enc->maxdepth) |
|
|
277 | croak ("data structure too deep (hit recursion limit)"); |
|
|
278 | |
266 | encode_ch (enc, '['); encode_nl (enc); |
279 | encode_ch (enc, '['); encode_nl (enc); |
267 | ++enc->indent; |
280 | ++enc->indent; |
268 | |
281 | |
269 | for (i = 0; i <= len; ++i) |
282 | for (i = 0; i <= len; ++i) |
270 | { |
283 | { |
… | |
… | |
335 | |
348 | |
336 | static void |
349 | static void |
337 | encode_hv (enc_t *enc, HV *hv) |
350 | encode_hv (enc_t *enc, HV *hv) |
338 | { |
351 | { |
339 | int count, i; |
352 | int count, i; |
|
|
353 | |
|
|
354 | if (enc->indent >= enc->maxdepth) |
|
|
355 | croak ("data structure too deep (hit recursion limit)"); |
340 | |
356 | |
341 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
357 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
342 | |
358 | |
343 | if ((count = hv_iterinit (hv))) |
359 | if ((count = hv_iterinit (hv))) |
344 | { |
360 | { |
… | |
… | |
413 | } |
429 | } |
414 | |
430 | |
415 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
431 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
416 | } |
432 | } |
417 | |
433 | |
|
|
434 | // encode objects, arrays and special \0=false and \1=true values. |
|
|
435 | static void |
|
|
436 | encode_rv (enc_t *enc, SV *sv) |
|
|
437 | { |
|
|
438 | SvGETMAGIC (sv); |
|
|
439 | |
|
|
440 | svtype svt = SvTYPE (sv); |
|
|
441 | |
|
|
442 | if (svt == SVt_PVHV) |
|
|
443 | encode_hv (enc, (HV *)sv); |
|
|
444 | else if (svt == SVt_PVAV) |
|
|
445 | encode_av (enc, (AV *)sv); |
|
|
446 | else if (svt < SVt_PVAV) |
|
|
447 | { |
|
|
448 | if (SvNIOK (sv) && SvIV (sv) == 0) |
|
|
449 | encode_str (enc, "false", 5, 0); |
|
|
450 | else if (SvNIOK (sv) && SvIV (sv) == 1) |
|
|
451 | encode_str (enc, "true", 4, 0); |
|
|
452 | else |
|
|
453 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
|
|
454 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
455 | } |
|
|
456 | else |
|
|
457 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
458 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
459 | } |
|
|
460 | |
418 | static void |
461 | static void |
419 | encode_sv (enc_t *enc, SV *sv) |
462 | encode_sv (enc_t *enc, SV *sv) |
420 | { |
463 | { |
421 | SvGETMAGIC (sv); |
464 | SvGETMAGIC (sv); |
422 | |
465 | |
… | |
… | |
441 | SvIsUV(sv) |
484 | SvIsUV(sv) |
442 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
485 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
443 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
486 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
444 | } |
487 | } |
445 | else if (SvROK (sv)) |
488 | else if (SvROK (sv)) |
446 | { |
489 | encode_rv (enc, SvRV (sv)); |
447 | SV *rv = SvRV (sv); |
|
|
448 | |
|
|
449 | if (enc->indent >= enc->max_depth) |
|
|
450 | croak ("data structure too deep (hit recursion limit)"); |
|
|
451 | |
|
|
452 | switch (SvTYPE (rv)) |
|
|
453 | { |
|
|
454 | case SVt_PVAV: encode_av (enc, (AV *)rv); break; |
|
|
455 | case SVt_PVHV: encode_hv (enc, (HV *)rv); break; |
|
|
456 | |
|
|
457 | default: |
|
|
458 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
459 | SvPV_nolen (sv)); |
|
|
460 | } |
|
|
461 | } |
|
|
462 | else if (!SvOK (sv)) |
490 | else if (!SvOK (sv)) |
463 | encode_str (enc, "null", 4, 0); |
491 | encode_str (enc, "null", 4, 0); |
464 | else |
492 | else |
465 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
493 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
466 | SvPV_nolen (sv), SvFLAGS (sv)); |
494 | SvPV_nolen (sv), SvFLAGS (sv)); |
467 | } |
495 | } |
468 | |
496 | |
469 | static SV * |
497 | static SV * |
470 | encode_json (SV *scalar, UV flags) |
498 | encode_json (SV *scalar, U32 flags) |
471 | { |
499 | { |
472 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
500 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
473 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
501 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
474 | |
502 | |
475 | enc_t enc; |
503 | enc_t enc; |
476 | enc.flags = flags; |
504 | enc.flags = flags; |
477 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
505 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
478 | enc.cur = SvPVX (enc.sv); |
506 | enc.cur = SvPVX (enc.sv); |
479 | enc.end = SvEND (enc.sv); |
507 | enc.end = SvEND (enc.sv); |
480 | enc.indent = 0; |
508 | enc.indent = 0; |
481 | enc.max_depth = 0x7fffffffUL; |
509 | enc.maxdepth = DEC_DEPTH (flags); |
482 | |
510 | |
483 | SvPOK_only (enc.sv); |
511 | SvPOK_only (enc.sv); |
484 | encode_sv (&enc, scalar); |
512 | encode_sv (&enc, scalar); |
485 | |
513 | |
486 | if (!(flags & (F_ASCII | F_UTF8))) |
514 | if (!(flags & (F_ASCII | F_UTF8))) |
… | |
… | |
501 | typedef struct |
529 | typedef struct |
502 | { |
530 | { |
503 | char *cur; // current parser pointer |
531 | char *cur; // current parser pointer |
504 | char *end; // end of input string |
532 | char *end; // end of input string |
505 | const char *err; // parse error, if != 0 |
533 | const char *err; // parse error, if != 0 |
506 | UV flags; // F_* |
534 | U32 flags; // F_* |
|
|
535 | U32 depth; // recursion depth |
|
|
536 | U32 maxdepth; // recursion depth limit |
507 | } dec_t; |
537 | } dec_t; |
508 | |
538 | |
509 | static void |
539 | static void |
510 | decode_ws (dec_t *dec) |
540 | decode_ws (dec_t *dec) |
511 | { |
541 | { |
… | |
… | |
520 | ++dec->cur; |
550 | ++dec->cur; |
521 | } |
551 | } |
522 | } |
552 | } |
523 | |
553 | |
524 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
554 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
|
|
555 | |
525 | #define EXPECT_CH(ch) SB \ |
556 | #define EXPECT_CH(ch) SB \ |
526 | if (*dec->cur != ch) \ |
557 | if (*dec->cur != ch) \ |
527 | ERR (# ch " expected"); \ |
558 | ERR (# ch " expected"); \ |
528 | ++dec->cur; \ |
559 | ++dec->cur; \ |
529 | SE |
560 | SE |
|
|
561 | |
|
|
562 | #define DEC_INC_DEPTH if (++dec->depth > dec->maxdepth) ERR ("json datastructure exceeds maximum nesting level (set a higher max_depth)") |
|
|
563 | #define DEC_DEC_DEPTH --dec->depth |
530 | |
564 | |
531 | static SV *decode_sv (dec_t *dec); |
565 | static SV *decode_sv (dec_t *dec); |
532 | |
566 | |
533 | static signed char decode_hexdigit[256]; |
567 | static signed char decode_hexdigit[256]; |
534 | |
568 | |
… | |
… | |
644 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
678 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
645 | if (clen == (STRLEN)-1) |
679 | if (clen == (STRLEN)-1) |
646 | ERR ("malformed UTF-8 character in JSON string"); |
680 | ERR ("malformed UTF-8 character in JSON string"); |
647 | |
681 | |
648 | do |
682 | do |
649 | { |
|
|
650 | *cur++ = *dec->cur++; |
683 | *cur++ = *dec->cur++; |
651 | } |
|
|
652 | while (--clen); |
684 | while (--clen); |
653 | |
685 | |
654 | utf8 = 1; |
686 | utf8 = 1; |
655 | } |
687 | } |
656 | else if (!ch) |
|
|
657 | ERR ("unexpected end of string while parsing json string"); |
|
|
658 | else |
688 | else |
|
|
689 | { |
|
|
690 | --dec->cur; |
|
|
691 | |
|
|
692 | if (!ch) |
|
|
693 | ERR ("unexpected end of string while parsing JSON string"); |
|
|
694 | else |
659 | ERR ("invalid character encountered"); |
695 | ERR ("invalid character encountered while parsing JSON string"); |
660 | |
696 | } |
661 | } |
697 | } |
662 | while (cur < buf + SHORT_STRING_LEN); |
698 | while (cur < buf + SHORT_STRING_LEN); |
663 | |
699 | |
664 | STRLEN len = cur - buf; |
700 | STRLEN len = cur - buf; |
665 | |
701 | |
… | |
… | |
778 | static SV * |
814 | static SV * |
779 | decode_av (dec_t *dec) |
815 | decode_av (dec_t *dec) |
780 | { |
816 | { |
781 | AV *av = newAV (); |
817 | AV *av = newAV (); |
782 | |
818 | |
|
|
819 | DEC_INC_DEPTH; |
783 | decode_ws (dec); |
820 | decode_ws (dec); |
|
|
821 | |
784 | if (*dec->cur == ']') |
822 | if (*dec->cur == ']') |
785 | ++dec->cur; |
823 | ++dec->cur; |
786 | else |
824 | else |
787 | for (;;) |
825 | for (;;) |
788 | { |
826 | { |
… | |
… | |
806 | ERR (", or ] expected while parsing array"); |
844 | ERR (", or ] expected while parsing array"); |
807 | |
845 | |
808 | ++dec->cur; |
846 | ++dec->cur; |
809 | } |
847 | } |
810 | |
848 | |
|
|
849 | DEC_DEC_DEPTH; |
811 | return newRV_noinc ((SV *)av); |
850 | return newRV_noinc ((SV *)av); |
812 | |
851 | |
813 | fail: |
852 | fail: |
814 | SvREFCNT_dec (av); |
853 | SvREFCNT_dec (av); |
|
|
854 | DEC_DEC_DEPTH; |
815 | return 0; |
855 | return 0; |
816 | } |
856 | } |
817 | |
857 | |
818 | static SV * |
858 | static SV * |
819 | decode_hv (dec_t *dec) |
859 | decode_hv (dec_t *dec) |
820 | { |
860 | { |
821 | HV *hv = newHV (); |
861 | HV *hv = newHV (); |
822 | |
862 | |
|
|
863 | DEC_INC_DEPTH; |
823 | decode_ws (dec); |
864 | decode_ws (dec); |
|
|
865 | |
824 | if (*dec->cur == '}') |
866 | if (*dec->cur == '}') |
825 | ++dec->cur; |
867 | ++dec->cur; |
826 | else |
868 | else |
827 | for (;;) |
869 | for (;;) |
828 | { |
870 | { |
… | |
… | |
841 | { |
883 | { |
842 | SvREFCNT_dec (key); |
884 | SvREFCNT_dec (key); |
843 | goto fail; |
885 | goto fail; |
844 | } |
886 | } |
845 | |
887 | |
846 | //TODO: optimise |
|
|
847 | hv_store_ent (hv, key, value, 0); |
888 | hv_store_ent (hv, key, value, 0); |
|
|
889 | SvREFCNT_dec (key); |
848 | |
890 | |
849 | decode_ws (dec); |
891 | decode_ws (dec); |
850 | |
892 | |
851 | if (*dec->cur == '}') |
893 | if (*dec->cur == '}') |
852 | { |
894 | { |
… | |
… | |
858 | ERR (", or } expected while parsing object/hash"); |
900 | ERR (", or } expected while parsing object/hash"); |
859 | |
901 | |
860 | ++dec->cur; |
902 | ++dec->cur; |
861 | } |
903 | } |
862 | |
904 | |
|
|
905 | DEC_DEC_DEPTH; |
863 | return newRV_noinc ((SV *)hv); |
906 | return newRV_noinc ((SV *)hv); |
864 | |
907 | |
865 | fail: |
908 | fail: |
866 | SvREFCNT_dec (hv); |
909 | SvREFCNT_dec (hv); |
|
|
910 | DEC_DEC_DEPTH; |
867 | return 0; |
911 | return 0; |
868 | } |
912 | } |
869 | |
913 | |
870 | static SV * |
914 | static SV * |
871 | decode_sv (dec_t *dec) |
915 | decode_sv (dec_t *dec) |
… | |
… | |
914 | ERR ("'null' expected"); |
958 | ERR ("'null' expected"); |
915 | |
959 | |
916 | break; |
960 | break; |
917 | |
961 | |
918 | default: |
962 | default: |
919 | ERR ("malformed json string, neither array, object, number, string or atom"); |
963 | ERR ("malformed JSON string, neither array, object, number, string or atom"); |
920 | break; |
964 | break; |
921 | } |
965 | } |
922 | |
966 | |
923 | fail: |
967 | fail: |
924 | return 0; |
968 | return 0; |
925 | } |
969 | } |
926 | |
970 | |
927 | static SV * |
971 | static SV * |
928 | decode_json (SV *string, UV flags) |
972 | decode_json (SV *string, U32 flags) |
929 | { |
973 | { |
930 | SV *sv; |
974 | SV *sv; |
|
|
975 | |
|
|
976 | SvUPGRADE (string, SVt_PV); |
931 | |
977 | |
932 | if (flags & F_UTF8) |
978 | if (flags & F_UTF8) |
933 | sv_utf8_downgrade (string, 0); |
979 | sv_utf8_downgrade (string, 0); |
934 | else |
980 | else |
935 | sv_utf8_upgrade (string); |
981 | sv_utf8_upgrade (string); |
936 | |
982 | |
937 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
983 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
938 | |
984 | |
939 | dec_t dec; |
985 | dec_t dec; |
940 | dec.flags = flags; |
986 | dec.flags = flags; |
941 | dec.cur = SvPVX (string); |
987 | dec.cur = SvPVX (string); |
942 | dec.end = SvEND (string); |
988 | dec.end = SvEND (string); |
943 | dec.err = 0; |
989 | dec.err = 0; |
|
|
990 | dec.depth = 0; |
|
|
991 | dec.maxdepth = DEC_DEPTH (dec.flags); |
944 | |
992 | |
|
|
993 | *dec.end = 0; // this should basically be a nop, too, but make sure its there |
945 | sv = decode_sv (&dec); |
994 | sv = decode_sv (&dec); |
946 | |
995 | |
947 | if (!sv) |
996 | if (!sv) |
948 | { |
997 | { |
949 | IV offset = dec.flags & F_UTF8 |
998 | IV offset = dec.flags & F_UTF8 |
… | |
… | |
958 | SAVEVPTR (PL_curcop); |
1007 | SAVEVPTR (PL_curcop); |
959 | PL_curcop = &cop; |
1008 | PL_curcop = &cop; |
960 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1009 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
961 | LEAVE; |
1010 | LEAVE; |
962 | |
1011 | |
963 | croak ("%s, at character offset %d (%s)", |
1012 | croak ("%s, at character offset %d [\"%s\"]", |
964 | dec.err, |
1013 | dec.err, |
965 | (int)offset, |
1014 | (int)offset, |
966 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1015 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
967 | } |
1016 | } |
968 | |
1017 | |
… | |
… | |
982 | BOOT: |
1031 | BOOT: |
983 | { |
1032 | { |
984 | int i; |
1033 | int i; |
985 | |
1034 | |
986 | memset (decode_hexdigit, 0xff, 256); |
1035 | memset (decode_hexdigit, 0xff, 256); |
|
|
1036 | |
987 | for (i = 10; i--; ) |
1037 | for (i = 0; i < 256; ++i) |
988 | decode_hexdigit ['0' + i] = i; |
1038 | decode_hexdigit [i] = |
989 | |
1039 | i >= '0' && i <= '9' ? i - '0' |
990 | for (i = 7; i--; ) |
1040 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
991 | { |
1041 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
992 | decode_hexdigit ['a' + i] = 10 + i; |
1042 | : -1; |
993 | decode_hexdigit ['A' + i] = 10 + i; |
|
|
994 | } |
|
|
995 | |
1043 | |
996 | json_stash = gv_stashpv ("JSON::XS", 1); |
1044 | json_stash = gv_stashpv ("JSON::XS", 1); |
997 | } |
1045 | } |
998 | |
1046 | |
999 | PROTOTYPES: DISABLE |
1047 | PROTOTYPES: DISABLE |
… | |
… | |
1026 | RETVAL = newSVsv (self); |
1074 | RETVAL = newSVsv (self); |
1027 | } |
1075 | } |
1028 | OUTPUT: |
1076 | OUTPUT: |
1029 | RETVAL |
1077 | RETVAL |
1030 | |
1078 | |
|
|
1079 | SV *max_depth (SV *self, int max_depth = 0x80000000UL) |
|
|
1080 | CODE: |
|
|
1081 | { |
|
|
1082 | UV *uv = SvJSON (self); |
|
|
1083 | UV log2 = 0; |
|
|
1084 | |
|
|
1085 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
|
|
1086 | |
|
|
1087 | while ((1UL << log2) < max_depth) |
|
|
1088 | ++log2; |
|
|
1089 | |
|
|
1090 | *uv = *uv & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
|
|
1091 | |
|
|
1092 | RETVAL = newSVsv (self); |
|
|
1093 | } |
|
|
1094 | OUTPUT: |
|
|
1095 | RETVAL |
|
|
1096 | |
1031 | void encode (SV *self, SV *scalar) |
1097 | void encode (SV *self, SV *scalar) |
1032 | PPCODE: |
1098 | PPCODE: |
1033 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1099 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1034 | |
1100 | |
1035 | void decode (SV *self, SV *jsonstr) |
1101 | void decode (SV *self, SV *jsonstr) |
… | |
… | |
1040 | |
1106 | |
1041 | void to_json (SV *scalar) |
1107 | void to_json (SV *scalar) |
1042 | ALIAS: |
1108 | ALIAS: |
1043 | objToJson = 0 |
1109 | objToJson = 0 |
1044 | PPCODE: |
1110 | PPCODE: |
1045 | XPUSHs (encode_json (scalar, F_UTF8)); |
1111 | XPUSHs (encode_json (scalar, F_DEFAULT | F_UTF8)); |
1046 | |
1112 | |
1047 | void from_json (SV *jsonstr) |
1113 | void from_json (SV *jsonstr) |
1048 | ALIAS: |
1114 | ALIAS: |
1049 | jsonToObj = 0 |
1115 | jsonToObj = 0 |
1050 | PPCODE: |
1116 | PPCODE: |
1051 | XPUSHs (decode_json (jsonstr, F_UTF8)); |
1117 | XPUSHs (decode_json (jsonstr, F_DEFAULT | F_UTF8)); |
1052 | |
1118 | |