… | |
… | |
76 | { |
76 | { |
77 | *clen = 2; |
77 | *clen = 2; |
78 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
78 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
79 | } |
79 | } |
80 | else |
80 | else |
|
|
81 | { |
|
|
82 | *clen = (STRLEN)-1; |
81 | return (UV)-1; |
83 | return (UV)-1; |
|
|
84 | } |
82 | } |
85 | } |
83 | |
86 | |
84 | ///////////////////////////////////////////////////////////////////////////// |
87 | ///////////////////////////////////////////////////////////////////////////// |
85 | // encoder |
88 | // encoder |
86 | |
89 | |
… | |
… | |
675 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
678 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
676 | if (clen == (STRLEN)-1) |
679 | if (clen == (STRLEN)-1) |
677 | ERR ("malformed UTF-8 character in JSON string"); |
680 | ERR ("malformed UTF-8 character in JSON string"); |
678 | |
681 | |
679 | do |
682 | do |
680 | { |
|
|
681 | *cur++ = *dec->cur++; |
683 | *cur++ = *dec->cur++; |
682 | } |
|
|
683 | while (--clen); |
684 | while (--clen); |
684 | |
685 | |
685 | utf8 = 1; |
686 | utf8 = 1; |
686 | } |
687 | } |
687 | else if (!ch) |
|
|
688 | ERR ("unexpected end of string while parsing json string"); |
|
|
689 | else |
688 | else |
|
|
689 | { |
|
|
690 | --dec->cur; |
|
|
691 | |
|
|
692 | if (!ch) |
|
|
693 | ERR ("unexpected end of string while parsing json string"); |
|
|
694 | else |
690 | ERR ("invalid character encountered"); |
695 | ERR ("invalid character encountered while parsing json string"); |
691 | |
696 | } |
692 | } |
697 | } |
693 | while (cur < buf + SHORT_STRING_LEN); |
698 | while (cur < buf + SHORT_STRING_LEN); |
694 | |
699 | |
695 | STRLEN len = cur - buf; |
700 | STRLEN len = cur - buf; |
696 | |
701 | |
… | |
… | |
966 | static SV * |
971 | static SV * |
967 | decode_json (SV *string, U32 flags) |
972 | decode_json (SV *string, U32 flags) |
968 | { |
973 | { |
969 | SV *sv; |
974 | SV *sv; |
970 | |
975 | |
|
|
976 | SvUPGRADE (string, SVt_PV); |
|
|
977 | |
971 | if (flags & F_UTF8) |
978 | if (flags & F_UTF8) |
972 | sv_utf8_downgrade (string, 0); |
979 | sv_utf8_downgrade (string, 0); |
973 | else |
980 | else |
974 | sv_utf8_upgrade (string); |
981 | sv_utf8_upgrade (string); |
975 | |
982 | |
… | |
… | |
1000 | SAVEVPTR (PL_curcop); |
1007 | SAVEVPTR (PL_curcop); |
1001 | PL_curcop = &cop; |
1008 | PL_curcop = &cop; |
1002 | 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); |
1003 | LEAVE; |
1010 | LEAVE; |
1004 | |
1011 | |
1005 | croak ("%s, at character offset %d (%s)", |
1012 | croak ("%s, at character offset %d [\"%s\"]", |
1006 | dec.err, |
1013 | dec.err, |
1007 | (int)offset, |
1014 | (int)offset, |
1008 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1015 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1009 | } |
1016 | } |
1010 | |
1017 | |