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.107 by root, Wed Mar 17 01:45:43 2010 UTC vs.
Revision 1.108 by root, Tue Aug 17 23:27:36 2010 UTC

41 41
42#define INIT_SIZE 32 // initial scalar size to be allocated 42#define INIT_SIZE 32 // initial scalar size to be allocated
43#define INDENT_STEP 3 // spaces per indentation level 43#define INDENT_STEP 3 // spaces per indentation level
44 44
45#define SHORT_STRING_LEN 16384 // special-case strings of up to this size 45#define SHORT_STRING_LEN 16384 // special-case strings of up to this size
46
47#define DECODE_WANTS_OCTETS(json) ((json)->flags & F_UTF8)
46 48
47#define SB do { 49#define SB do {
48#define SE } while (0) 50#define SE } while (0)
49 51
50#if __GNUC__ >= 3 52#if __GNUC__ >= 3
1548 if (offset > json->max_size && json->max_size) 1550 if (offset > json->max_size && json->max_size)
1549 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", 1551 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu",
1550 (unsigned long)SvCUR (string), (unsigned long)json->max_size); 1552 (unsigned long)SvCUR (string), (unsigned long)json->max_size);
1551 } 1553 }
1552 1554
1553 if (json->flags & F_UTF8) 1555 if (DECODE_WANTS_OCTETS (json))
1554 sv_utf8_downgrade (string, 0); 1556 sv_utf8_downgrade (string, 0);
1555 else 1557 else
1556 sv_utf8_upgrade (string); 1558 sv_utf8_upgrade (string);
1557 1559
1558 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP 1560 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP
1929 PPCODE: 1931 PPCODE:
1930{ 1932{
1931 if (!self->incr_text) 1933 if (!self->incr_text)
1932 self->incr_text = newSVpvn ("", 0); 1934 self->incr_text = newSVpvn ("", 0);
1933 1935
1936 /* if utf8-ness doesn't match the decoder, need to upgrade/downgrade */
1937 if (!DECODE_WANTS_OCTETS (self) == !SvUTF8 (self->incr_text))
1938 if (DECODE_WANTS_OCTETS (self))
1939 {
1940 if (self->incr_pos)
1941 self->incr_pos = utf8_length ((U8 *)SvPVX (self->incr_text),
1942 (U8 *)SvPVX (self->incr_text) + self->incr_pos);
1943
1944 sv_utf8_downgrade (self->incr_text, 0);
1945 }
1946 else
1947 {
1948 sv_utf8_upgrade (self->incr_text);
1949
1950 if (self->incr_pos)
1951 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1952 - (U8 *)SvPVX (self->incr_text);
1953 }
1954
1934 // append data, if any 1955 // append data, if any
1935 if (jsonstr) 1956 if (jsonstr)
1936 { 1957 {
1958 /* make sure both strings have same encoding */
1959 if (SvUTF8 (jsonstr) != SvUTF8 (self->incr_text))
1937 if (SvUTF8 (jsonstr)) 1960 if (SvUTF8 (jsonstr))
1961 sv_utf8_downgrade (jsonstr, 0);
1938 { 1962 else
1939 if (!SvUTF8 (self->incr_text))
1940 {
1941 /* utf-8-ness differs, need to upgrade */
1942 sv_utf8_upgrade (self->incr_text);
1943
1944 if (self->incr_pos)
1945 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1946 - (U8 *)SvPVX (self->incr_text);
1947 }
1948 }
1949 else if (SvUTF8 (self->incr_text))
1950 sv_utf8_upgrade (jsonstr); 1963 sv_utf8_upgrade (jsonstr);
1951 1964
1965 /* and then just blindly append */
1952 { 1966 {
1953 STRLEN len; 1967 STRLEN len;
1954 const char *str = SvPV (jsonstr, len); 1968 const char *str = SvPV (jsonstr, len);
1955 STRLEN cur = SvCUR (self->incr_text); 1969 STRLEN cur = SvCUR (self->incr_text);
1956 1970

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines