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.26 by root, Fri Apr 6 21:17:09 2007 UTC vs.
Revision 1.29 by root, Wed May 9 15:34:04 2007 UTC

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
109 if (enc->cur + len >= enc->end) 108 if (enc->cur + len >= enc->end)
110 { 109 {
111 STRLEN cur = enc->cur - SvPVX (enc->sv); 110 STRLEN cur = enc->cur - SvPVX (enc->sv);
112 SvGROW (enc->sv, cur + len + 1); 111 SvGROW (enc->sv, cur + len + 1);
113 enc->cur = SvPVX (enc->sv) + cur; 112 enc->cur = SvPVX (enc->sv) + cur;
114 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv); 113 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
115 } 114 }
116} 115}
117 116
118static void 117static void
119encode_ch (enc_t *enc, char ch) 118encode_ch (enc_t *enc, char ch)
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 }
519 518
520 if (!(flags & (F_ASCII | F_UTF8))) 519 if (!(flags & (F_ASCII | F_UTF8)))
521 SvUTF8_on (enc.sv); 520 SvUTF8_on (enc.sv);
522 521
523 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 522 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
523 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings
524 524
525 if (enc.flags & F_SHRINK) 525 if (enc.flags & F_SHRINK)
526 shrink (enc.sv); 526 shrink (enc.sv);
527 527
528 return enc.sv; 528 return enc.sv;
600 SV *sv = 0; 600 SV *sv = 0;
601 int utf8 = 0; 601 int utf8 = 0;
602 602
603 do 603 do
604 { 604 {
605 char buf [SHORT_STRING_LEN + UTF8_MAX_LEN]; 605 char buf [SHORT_STRING_LEN + UTF8_MAXBYTES];
606 char *cur = buf; 606 char *cur = buf;
607 607
608 do 608 do
609 { 609 {
610 unsigned char ch = *(unsigned char *)dec->cur++; 610 unsigned char ch = *(unsigned char *)dec->cur++;
982decode_json (SV *string, U32 flags) 982decode_json (SV *string, U32 flags)
983{ 983{
984 dec_t dec; 984 dec_t dec;
985 SV *sv; 985 SV *sv;
986 986
987 SvGETMAGIC (string);
987 SvUPGRADE (string, SVt_PV); 988 SvUPGRADE (string, SVt_PV);
988 989
989 if (flags & F_UTF8) 990 if (flags & F_UTF8)
990 sv_utf8_downgrade (string, 0); 991 sv_utf8_downgrade (string, 0);
991 else 992 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines