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.39 by root, Mon Jun 11 03:42:57 2007 UTC vs.
Revision 1.40 by root, Tue Jun 12 01:27:02 2007 UTC

178 STRLEN clen; 178 STRLEN clen;
179 UV uch; 179 UV uch;
180 180
181 if (is_utf8) 181 if (is_utf8)
182 { 182 {
183 //uch = utf8n_to_uvuni (str, end - str, &clen, UTF8_CHECK_ONLY);
184 uch = decode_utf8 (str, end - str, &clen); 183 uch = decode_utf8 (str, end - str, &clen);
185 if (clen == (STRLEN)-1) 184 if (clen == (STRLEN)-1)
186 croak ("malformed or illegal unicode character in string [%.11s], cannot convert to JSON", str); 185 croak ("malformed or illegal unicode character in string [%.11s], cannot convert to JSON", str);
187 } 186 }
188 else 187 else
631decode_4hex (dec_t *dec) 630decode_4hex (dec_t *dec)
632{ 631{
633 signed char d1, d2, d3, d4; 632 signed char d1, d2, d3, d4;
634 unsigned char *cur = (unsigned char *)dec->cur; 633 unsigned char *cur = (unsigned char *)dec->cur;
635 634
636 d1 = decode_hexdigit [cur [0]]; if (expect_false (d1 < 0)) ERR ("four hexadecimal digits expected"); 635 d1 = decode_hexdigit [cur [0]]; if (expect_false (d1 < 0)) ERR ("exactly four hexadecimal digits expected");
637 d2 = decode_hexdigit [cur [1]]; if (expect_false (d2 < 0)) ERR ("four hexadecimal digits expected"); 636 d2 = decode_hexdigit [cur [1]]; if (expect_false (d2 < 0)) ERR ("exactly four hexadecimal digits expected");
638 d3 = decode_hexdigit [cur [2]]; if (expect_false (d3 < 0)) ERR ("four hexadecimal digits expected"); 637 d3 = decode_hexdigit [cur [2]]; if (expect_false (d3 < 0)) ERR ("exactly four hexadecimal digits expected");
639 d4 = decode_hexdigit [cur [3]]; if (expect_false (d4 < 0)) ERR ("four hexadecimal digits expected"); 638 d4 = decode_hexdigit [cur [3]]; if (expect_false (d4 < 0)) ERR ("exactly four hexadecimal digits expected");
640 639
641 dec->cur += 4; 640 dec->cur += 4;
642 641
643 return ((UV)d1) << 12 642 return ((UV)d1) << 12
644 | ((UV)d2) << 8 643 | ((UV)d2) << 8
867 { 866 {
868 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so 867 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so
869 if (*start == '-') 868 if (*start == '-')
870 switch (dec->cur - start) 869 switch (dec->cur - start)
871 { 870 {
872 case 2: return newSViv (-( start [1] - '0' )); 871 case 2: return newSViv (-( start [1] - '0' * 1));
873 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 872 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
874 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 873 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
875 case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 874 case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
876 } 875 }
877 else 876 else
878 switch (dec->cur - start) 877 switch (dec->cur - start)
879 { 878 {
880 case 1: return newSViv ( start [0] - '0' ); 879 case 1: return newSViv ( start [0] - '0' * 1);
881 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 880 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
882 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 881 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
883 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 882 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
884 } 883 }
885 884
892 if (uv < (UV)IV_MIN) 891 if (uv < (UV)IV_MIN)
893 return newSViv (-(IV)uv); 892 return newSViv (-(IV)uv);
894 } 893 }
895 else 894 else
896 return newSVuv (uv); 895 return newSVuv (uv);
896
897 // here would likely be the place for bigint support
897 } 898 }
898 } 899 }
899 900
901 // if we ever support bigint or bigfloat, this is the place for bigfloat
900 return newSVnv (Atof (start)); 902 return newSVnv (Atof (start));
901 903
902fail: 904fail:
903 return 0; 905 return 0;
904} 906}
1005 1007
1006static SV * 1008static SV *
1007decode_sv (dec_t *dec) 1009decode_sv (dec_t *dec)
1008{ 1010{
1009 decode_ws (dec); 1011 decode_ws (dec);
1012
1013 // the beauty of JSON: you need exactly one character lookahead
1014 // to parse anything.
1010 switch (*dec->cur) 1015 switch (*dec->cur)
1011 { 1016 {
1012 case '"': ++dec->cur; return decode_str (dec); 1017 case '"': ++dec->cur; return decode_str (dec);
1013 case '[': ++dec->cur; return decode_av (dec); 1018 case '[': ++dec->cur; return decode_av (dec);
1014 case '{': ++dec->cur; return decode_hv (dec); 1019 case '{': ++dec->cur; return decode_hv (dec);
1143MODULE = JSON::XS PACKAGE = JSON::XS 1148MODULE = JSON::XS PACKAGE = JSON::XS
1144 1149
1145BOOT: 1150BOOT:
1146{ 1151{
1147 int i; 1152 int i;
1148
1149 memset (decode_hexdigit, 0xff, 256);
1150 1153
1151 for (i = 0; i < 256; ++i) 1154 for (i = 0; i < 256; ++i)
1152 decode_hexdigit [i] = 1155 decode_hexdigit [i] =
1153 i >= '0' && i <= '9' ? i - '0' 1156 i >= '0' && i <= '9' ? i - '0'
1154 : i >= 'a' && i <= 'f' ? i - 'a' + 10 1157 : i >= 'a' && i <= 'f' ? i - 'a' + 10

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines