… | |
… | |
31 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
31 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
32 | |
32 | |
33 | #define INIT_SIZE 32 // initial scalar size to be allocated |
33 | #define INIT_SIZE 32 // initial scalar size to be allocated |
34 | #define INDENT_STEP 3 // spaces per indentation level |
34 | #define INDENT_STEP 3 // spaces per indentation level |
35 | |
35 | |
36 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
|
|
37 | #define SHORT_STRING_LEN 512 // special-case strings of up to this size |
36 | #define SHORT_STRING_LEN 512 // special-case strings of up to this size |
38 | |
37 | |
39 | #define SB do { |
38 | #define SB do { |
40 | #define SE } while (0) |
39 | #define SE } while (0) |
41 | |
40 | |
… | |
… | |
216 | } |
215 | } |
217 | while (--clen); |
216 | while (--clen); |
218 | } |
217 | } |
219 | else |
218 | else |
220 | { |
219 | { |
221 | need (enc, len += UTF8_MAX_LEN - 1); // never more than 11 bytes needed |
220 | need (enc, len += UTF8_MAXBYTES - 1); // never more than 11 bytes needed |
222 | enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0); |
221 | enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0); |
223 | ++str; |
222 | ++str; |
224 | } |
223 | } |
225 | } |
224 | } |
226 | } |
225 | } |
… | |
… | |
601 | SV *sv = 0; |
600 | SV *sv = 0; |
602 | int utf8 = 0; |
601 | int utf8 = 0; |
603 | |
602 | |
604 | do |
603 | do |
605 | { |
604 | { |
606 | char buf [SHORT_STRING_LEN + UTF8_MAX_LEN]; |
605 | char buf [SHORT_STRING_LEN + UTF8_MAXBYTES]; |
607 | char *cur = buf; |
606 | char *cur = buf; |
608 | |
607 | |
609 | do |
608 | do |
610 | { |
609 | { |
611 | unsigned char ch = *(unsigned char *)dec->cur++; |
610 | unsigned char ch = *(unsigned char *)dec->cur++; |
… | |
… | |
983 | decode_json (SV *string, U32 flags) |
982 | decode_json (SV *string, U32 flags) |
984 | { |
983 | { |
985 | dec_t dec; |
984 | dec_t dec; |
986 | SV *sv; |
985 | SV *sv; |
987 | |
986 | |
|
|
987 | SvGETMAGIC (string); |
988 | SvUPGRADE (string, SVt_PV); |
988 | SvUPGRADE (string, SVt_PV); |
989 | |
989 | |
990 | if (flags & F_UTF8) |
990 | if (flags & F_UTF8) |
991 | sv_utf8_downgrade (string, 0); |
991 | sv_utf8_downgrade (string, 0); |
992 | else |
992 | else |