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.65 by root, Sat Oct 13 01:55:31 2007 UTC vs.
Revision 1.70 by root, Wed Mar 19 00:44:54 2008 UTC

1000 1000
1001 if (!is_nv) 1001 if (!is_nv)
1002 { 1002 {
1003 int len = dec->cur - start; 1003 int len = dec->cur - start;
1004 1004
1005 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so 1005 // special case the rather common 1..5-digit-int case
1006 if (*start == '-') 1006 if (*start == '-')
1007 switch (len) 1007 switch (len)
1008 { 1008 {
1009 case 2: return newSViv (-( start [1] - '0' * 1)); 1009 case 2: return newSViv (-( start [1] - '0' * 1));
1010 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1010 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
1011 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 1011 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
1012 case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 1012 case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
1013 case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111));
1013 } 1014 }
1014 else 1015 else
1015 switch (len) 1016 switch (len)
1016 { 1017 {
1017 case 1: return newSViv ( start [0] - '0' * 1); 1018 case 1: return newSViv ( start [0] - '0' * 1);
1018 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1019 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
1019 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1020 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
1020 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1021 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
1022 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111);
1021 } 1023 }
1022 1024
1023 { 1025 {
1024 UV uv; 1026 UV uv;
1025 int numtype = grok_number (start, len, &uv); 1027 int numtype = grok_number (start, len, &uv);
1457{ 1459{
1458 SV *pv = NEWSV (0, sizeof (JSON)); 1460 SV *pv = NEWSV (0, sizeof (JSON));
1459 SvPOK_only (pv); 1461 SvPOK_only (pv);
1460 Zero (SvPVX (pv), 1, JSON); 1462 Zero (SvPVX (pv), 1, JSON);
1461 ((JSON *)SvPVX (pv))->flags = F_DEFAULT; 1463 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1462 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH))); 1464 XPUSHs (sv_2mortal (sv_bless (
1465 newRV_noinc (pv),
1466 strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1)
1467 )));
1463} 1468}
1464 1469
1465void ascii (JSON *self, int enable = 1) 1470void ascii (JSON *self, int enable = 1)
1466 ALIAS: 1471 ALIAS:
1467 ascii = F_ASCII 1472 ascii = F_ASCII
1485 self->flags &= ~ix; 1490 self->flags &= ~ix;
1486 1491
1487 XPUSHs (ST (0)); 1492 XPUSHs (ST (0));
1488} 1493}
1489 1494
1495void get_ascii (JSON *self)
1496 ALIAS:
1497 get_ascii = F_ASCII
1498 get_latin1 = F_LATIN1
1499 get_utf8 = F_UTF8
1500 get_indent = F_INDENT
1501 get_canonical = F_CANONICAL
1502 get_space_before = F_SPACE_BEFORE
1503 get_space_after = F_SPACE_AFTER
1504 get_allow_nonref = F_ALLOW_NONREF
1505 get_shrink = F_SHRINK
1506 get_allow_blessed = F_ALLOW_BLESSED
1507 get_convert_blessed = F_CONV_BLESSED
1508 get_relaxed = F_RELAXED
1509 PPCODE:
1510 XPUSHs (boolSV (self->flags & ix));
1511
1490void max_depth (JSON *self, UV max_depth = 0x80000000UL) 1512void max_depth (JSON *self, UV max_depth = 0x80000000UL)
1491 PPCODE: 1513 PPCODE:
1492{ 1514{
1493 UV log2 = 0; 1515 UV log2 = 0;
1494 1516
1500 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); 1522 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH);
1501 1523
1502 XPUSHs (ST (0)); 1524 XPUSHs (ST (0));
1503} 1525}
1504 1526
1527U32 get_max_depth (JSON *self)
1528 CODE:
1529 RETVAL = DEC_DEPTH (self->flags);
1530 OUTPUT:
1531 RETVAL
1532
1505void max_size (JSON *self, UV max_size = 0) 1533void max_size (JSON *self, UV max_size = 0)
1506 PPCODE: 1534 PPCODE:
1507{ 1535{
1508 UV log2 = 0; 1536 UV log2 = 0;
1509 1537
1515 1543
1516 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); 1544 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE);
1517 1545
1518 XPUSHs (ST (0)); 1546 XPUSHs (ST (0));
1519} 1547}
1548
1549int get_max_size (JSON *self)
1550 CODE:
1551 RETVAL = DEC_SIZE (self->flags);
1552 OUTPUT:
1553 RETVAL
1520 1554
1521void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) 1555void filter_json_object (JSON *self, SV *cb = &PL_sv_undef)
1522 PPCODE: 1556 PPCODE:
1523{ 1557{
1524 SvREFCNT_dec (self->cb_object); 1558 SvREFCNT_dec (self->cb_object);
1571 SvREFCNT_dec (self->cb_sk_object); 1605 SvREFCNT_dec (self->cb_sk_object);
1572 SvREFCNT_dec (self->cb_object); 1606 SvREFCNT_dec (self->cb_object);
1573 1607
1574PROTOTYPES: ENABLE 1608PROTOTYPES: ENABLE
1575 1609
1576void to_json (SV *scalar) 1610void encode_json (SV *scalar)
1577 PPCODE: 1611 PPCODE:
1578{ 1612{
1579 JSON json = { F_DEFAULT | F_UTF8 }; 1613 JSON json = { F_DEFAULT | F_UTF8 };
1580 XPUSHs (encode_json (scalar, &json)); 1614 XPUSHs (encode_json (scalar, &json));
1581} 1615}
1582 1616
1583void from_json (SV *jsonstr) 1617void decode_json (SV *jsonstr)
1584 PPCODE: 1618 PPCODE:
1585{ 1619{
1586 JSON json = { F_DEFAULT | F_UTF8 }; 1620 JSON json = { F_DEFAULT | F_UTF8 };
1587 XPUSHs (decode_json (jsonstr, &json, 0)); 1621 XPUSHs (decode_json (jsonstr, &json, 0));
1588} 1622}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines