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.116 by root, Thu May 23 09:31:32 2013 UTC vs.
Revision 1.117 by root, Fri Oct 25 20:19:57 2013 UTC

483 483
484 if (enc->indent >= enc->json.max_depth) 484 if (enc->indent >= enc->json.max_depth)
485 croak (ERR_NESTING_EXCEEDED); 485 croak (ERR_NESTING_EXCEEDED);
486 486
487 encode_ch (enc, '['); 487 encode_ch (enc, '[');
488 488
489 if (len >= 0) 489 if (len >= 0)
490 { 490 {
491 encode_nl (enc); ++enc->indent; 491 encode_nl (enc); ++enc->indent;
492 492
493 for (i = 0; i <= len; ++i) 493 for (i = 0; i <= len; ++i)
505 encode_comma (enc); 505 encode_comma (enc);
506 } 506 }
507 507
508 encode_nl (enc); --enc->indent; encode_indent (enc); 508 encode_nl (enc); --enc->indent; encode_indent (enc);
509 } 509 }
510 510
511 encode_ch (enc, ']'); 511 encode_ch (enc, ']');
512} 512}
513 513
514static void 514static void
515encode_hk (enc_t *enc, HE *he) 515encode_hk (enc_t *enc, HE *he)
519 if (HeKLEN (he) == HEf_SVKEY) 519 if (HeKLEN (he) == HEf_SVKEY)
520 { 520 {
521 SV *sv = HeSVKEY (he); 521 SV *sv = HeSVKEY (he);
522 STRLEN len; 522 STRLEN len;
523 char *str; 523 char *str;
524 524
525 SvGETMAGIC (sv); 525 SvGETMAGIC (sv);
526 str = SvPV (sv, len); 526 str = SvPV (sv, len);
527 527
528 encode_str (enc, str, len, SvUTF8 (sv)); 528 encode_str (enc, str, len, SvUTF8 (sv));
529 } 529 }
597 if (count) 597 if (count)
598 { 598 {
599 int i, fast = 1; 599 int i, fast = 1;
600 HE *hes_stack [STACK_HES]; 600 HE *hes_stack [STACK_HES];
601 HE **hes = hes_stack; 601 HE **hes = hes_stack;
602 602
603 // allocate larger arrays on the heap 603 // allocate larger arrays on the heap
604 if (count > STACK_HES) 604 if (count > STACK_HES)
605 { 605 {
606 SV *sv = sv_2mortal (NEWSV (0, count * sizeof (*hes))); 606 SV *sv = sv_2mortal (NEWSV (0, count * sizeof (*hes)));
607 hes = (HE **)SvPVX (sv); 607 hes = (HE **)SvPVX (sv);
843 else if (SvROK (sv)) 843 else if (SvROK (sv))
844 encode_rv (enc, SvRV (sv)); 844 encode_rv (enc, SvRV (sv));
845 else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) 845 else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN)
846 encode_str (enc, "null", 4, 0); 846 encode_str (enc, "null", 4, 0);
847 else 847 else
848 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", 848 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, check your input data",
849 SvPV_nolen (sv), (unsigned int)SvFLAGS (sv)); 849 SvPV_nolen (sv), (unsigned int)SvFLAGS (sv));
850} 850}
851 851
852static SV * 852static SV *
853encode_json (SV *scalar, JSON *json) 853encode_json (SV *scalar, JSON *json)
1266 if (*dec->cur == ']') 1266 if (*dec->cur == ']')
1267 { 1267 {
1268 ++dec->cur; 1268 ++dec->cur;
1269 break; 1269 break;
1270 } 1270 }
1271 1271
1272 if (*dec->cur != ',') 1272 if (*dec->cur != ',')
1273 ERR (", or ] expected while parsing array"); 1273 ERR (", or ] expected while parsing array");
1274 1274
1275 ++dec->cur; 1275 ++dec->cur;
1276 1276
1464{ 1464{
1465 // the beauty of JSON: you need exactly one character lookahead 1465 // the beauty of JSON: you need exactly one character lookahead
1466 // to parse everything. 1466 // to parse everything.
1467 switch (*dec->cur) 1467 switch (*dec->cur)
1468 { 1468 {
1469 case '"': ++dec->cur; return decode_str (dec); 1469 case '"': ++dec->cur; return decode_str (dec);
1470 case '[': ++dec->cur; return decode_av (dec); 1470 case '[': ++dec->cur; return decode_av (dec);
1471 case '{': ++dec->cur; return decode_hv (dec); 1471 case '{': ++dec->cur; return decode_hv (dec);
1472 1472
1473 case '-': 1473 case '-':
1474 case '0': case '1': case '2': case '3': case '4': 1474 case '0': case '1': case '2': case '3': case '4':
1475 case '5': case '6': case '7': case '8': case '9': 1475 case '5': case '6': case '7': case '8': case '9':

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines