yajl-ruby 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +7 -0
- data/VERSION.yml +2 -2
- data/benchmark/encode.rb +5 -1
- data/benchmark/parse.rb +5 -1
- data/benchmark/parse_stream.rb +5 -1
- data/ext/api/yajl_common.h +10 -10
- data/ext/api/yajl_gen.h +26 -26
- data/ext/api/yajl_parse.h +35 -21
- data/ext/extconf.rb +1 -1
- data/ext/yajl.c +19 -12
- data/ext/yajl_alloc.c +7 -7
- data/ext/yajl_alloc.h +7 -7
- data/ext/yajl_buf.c +8 -8
- data/ext/yajl_buf.h +8 -8
- data/ext/yajl_bytestack.h +11 -11
- data/ext/yajl_encode.c +14 -14
- data/ext/yajl_encode.h +8 -8
- data/ext/yajl_ext.c +7 -3
- data/ext/yajl_ext.h +1 -1
- data/ext/yajl_gen.c +16 -18
- data/ext/yajl_lex.c +74 -74
- data/ext/yajl_lex.h +15 -15
- data/ext/yajl_parser.c +42 -39
- data/ext/yajl_parser.h +14 -11
- data/lib/yajl.rb +1 -1
- data/lib/yajl/bzip2/stream_reader.rb +13 -0
- data/lib/yajl/deflate/stream_reader.rb +10 -3
- data/lib/yajl/gzip/stream_reader.rb +13 -0
- data/spec/encoding/encoding_spec.rb +13 -2
- data/spec/spec_helper.rb +1 -0
- data/yajl-ruby.gemspec +2 -2
- metadata +3 -3
data/ext/yajl_alloc.c
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
/**
|
34
34
|
* \file yajl_alloc.h
|
data/ext/yajl_alloc.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
/**
|
34
34
|
* \file yajl_alloc.h
|
data/ext/yajl_buf.c
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#include "yajl_buf.h"
|
34
34
|
|
@@ -49,7 +49,7 @@ static
|
|
49
49
|
void yajl_buf_ensure_available(yajl_buf buf, unsigned int want)
|
50
50
|
{
|
51
51
|
unsigned int need;
|
52
|
-
|
52
|
+
|
53
53
|
assert(buf != NULL);
|
54
54
|
|
55
55
|
/* first call */
|
data/ext/yajl_buf.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#ifndef __YAJL_BUF_H__
|
34
34
|
#define __YAJL_BUF_H__
|
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
/*
|
40
40
|
* Implementation/performance notes. If this were moved to a header
|
41
|
-
* only implementation using #define's where possible we might be
|
41
|
+
* only implementation using #define's where possible we might be
|
42
42
|
* able to sqeeze a little performance out of the guy by killing function
|
43
43
|
* call overhead. YMMV.
|
44
44
|
*/
|
data/ext/yajl_bytestack.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
/*
|
34
34
|
* A header only implementation of a simple stack of bytes, used in YAJL
|
@@ -61,7 +61,7 @@ typedef struct yajl_bytestack_t
|
|
61
61
|
|
62
62
|
/* initialize a bytestack */
|
63
63
|
#define yajl_bs_free(obs) \
|
64
|
-
if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);
|
64
|
+
if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);
|
65
65
|
|
66
66
|
#define yajl_bs_current(obs) \
|
67
67
|
(assert((obs).used > 0), (obs).stack[(obs).used - 1])
|
@@ -74,12 +74,12 @@ typedef struct yajl_bytestack_t
|
|
74
74
|
} \
|
75
75
|
(obs).stack[((obs).used)++] = (byte); \
|
76
76
|
}
|
77
|
-
|
77
|
+
|
78
78
|
/* removes the top item of the stack, returns nothing */
|
79
79
|
#define yajl_bs_pop(obs) { ((obs).used)--; }
|
80
80
|
|
81
81
|
#define yajl_bs_set(obs, byte) \
|
82
|
-
(obs).stack[((obs).used) - 1] = (byte);
|
83
|
-
|
82
|
+
(obs).stack[((obs).used) - 1] = (byte);
|
83
|
+
|
84
84
|
|
85
85
|
#endif
|
data/ext/yajl_encode.c
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#include "yajl_encode.h"
|
34
34
|
|
@@ -48,7 +48,7 @@ void
|
|
48
48
|
yajl_string_encode(yajl_buf buf, const unsigned char * str,
|
49
49
|
unsigned int len)
|
50
50
|
{
|
51
|
-
yajl_string_encode2((yajl_print_t) &yajl_buf_append, buf, str, len);
|
51
|
+
yajl_string_encode2((const yajl_print_t) &yajl_buf_append, buf, str, len);
|
52
52
|
}
|
53
53
|
|
54
54
|
void
|
@@ -58,7 +58,7 @@ yajl_string_encode2(const yajl_print_t print,
|
|
58
58
|
unsigned int len)
|
59
59
|
{
|
60
60
|
unsigned int beg = 0;
|
61
|
-
unsigned int end = 0;
|
61
|
+
unsigned int end = 0;
|
62
62
|
char hexBuf[7];
|
63
63
|
hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
|
64
64
|
hexBuf[6] = 0;
|
@@ -104,7 +104,7 @@ static void hexToDigit(unsigned int * val, const unsigned char * hex)
|
|
104
104
|
}
|
105
105
|
}
|
106
106
|
|
107
|
-
static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf)
|
107
|
+
static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf)
|
108
108
|
{
|
109
109
|
if (codepoint < 0x80) {
|
110
110
|
utf8Buf[0] = (char) codepoint;
|
@@ -134,7 +134,7 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
|
134
134
|
unsigned int len)
|
135
135
|
{
|
136
136
|
unsigned int beg = 0;
|
137
|
-
unsigned int end = 0;
|
137
|
+
unsigned int end = 0;
|
138
138
|
|
139
139
|
while (end < len) {
|
140
140
|
if (str[end] == '\\') {
|
@@ -161,8 +161,8 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
|
161
161
|
unsigned int surrogate = 0;
|
162
162
|
hexToDigit(&surrogate, str + end + 2);
|
163
163
|
codepoint =
|
164
|
-
(((codepoint & 0x3F) << 10) |
|
165
|
-
((((codepoint >> 6) & 0xF) + 1) << 16) |
|
164
|
+
(((codepoint & 0x3F) << 10) |
|
165
|
+
((((codepoint >> 6) & 0xF) + 1) << 16) |
|
166
166
|
(surrogate & 0x3FF));
|
167
167
|
end += 5;
|
168
168
|
} else {
|
@@ -170,7 +170,7 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
|
170
170
|
break;
|
171
171
|
}
|
172
172
|
}
|
173
|
-
|
173
|
+
|
174
174
|
Utf32toUtf8(codepoint, utf8Buf);
|
175
175
|
unescaped = utf8Buf;
|
176
176
|
break;
|
data/ext/yajl_encode.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#ifndef __YAJL_ENCODE_H__
|
34
34
|
#define __YAJL_ENCODE_H__
|
@@ -36,7 +36,7 @@
|
|
36
36
|
#include "yajl_buf.h"
|
37
37
|
#include "api/yajl_gen.h"
|
38
38
|
|
39
|
-
void yajl_string_encode2(yajl_print_t printer,
|
39
|
+
void yajl_string_encode2(const yajl_print_t printer,
|
40
40
|
void * ctx,
|
41
41
|
const unsigned char * str,
|
42
42
|
unsigned int length);
|
data/ext/yajl_ext.c
CHANGED
@@ -173,7 +173,10 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
173
173
|
status = yajl_gen_string(w->encoder, (const unsigned char *)cptr, len);
|
174
174
|
break;
|
175
175
|
default:
|
176
|
-
if (rb_respond_to(obj,
|
176
|
+
if (rb_respond_to(obj, intern_as_json)) {
|
177
|
+
obj = rb_funcall(obj, intern_as_json, 0);
|
178
|
+
yajl_encode_part(w, obj, io);
|
179
|
+
} else if (rb_respond_to(obj, intern_to_json)) {
|
177
180
|
str = rb_funcall(obj, intern_to_json, 0);
|
178
181
|
cptr = RSTRING_PTR(str);
|
179
182
|
len = RSTRING_LEN(str);
|
@@ -430,8 +433,8 @@ static VALUE rb_yajl_parser_parse(int argc, VALUE * argv, VALUE self) {
|
|
430
433
|
len = RSTRING_LEN(input);
|
431
434
|
yajl_parse_chunk((const unsigned char*)cptr, len, wrapper->parser);
|
432
435
|
} else if (rb_respond_to(input, intern_io_read)) {
|
433
|
-
VALUE parsed = rb_str_new(
|
434
|
-
while (
|
436
|
+
VALUE parsed = rb_str_new(0, FIX2LONG(rbufsize));
|
437
|
+
while (rb_funcall(input, intern_io_read, 2, rbufsize, parsed) != Qnil) {
|
435
438
|
cptr = RSTRING_PTR(parsed);
|
436
439
|
len = RSTRING_LEN(parsed);
|
437
440
|
yajl_parse_chunk((const unsigned char*)cptr, len, wrapper->parser);
|
@@ -886,6 +889,7 @@ void Init_yajl_ext() {
|
|
886
889
|
intern_to_json = rb_intern("to_json");
|
887
890
|
intern_to_sym = rb_intern("to_sym");
|
888
891
|
intern_has_key = rb_intern("has_key?");
|
892
|
+
intern_as_json = rb_intern("as_json");
|
889
893
|
|
890
894
|
sym_allow_comments = ID2SYM(rb_intern("allow_comments"));
|
891
895
|
sym_check_utf8 = ID2SYM(rb_intern("check_utf8"));
|
data/ext/yajl_ext.h
CHANGED
@@ -49,7 +49,7 @@ int utf8Encoding;
|
|
49
49
|
|
50
50
|
static VALUE cParseError, cEncodeError, mYajl, cParser, cEncoder;
|
51
51
|
static ID intern_io_read, intern_call, intern_keys, intern_to_s,
|
52
|
-
intern_to_json, intern_has_key, intern_to_sym;
|
52
|
+
intern_to_json, intern_has_key, intern_to_sym, intern_as_json;
|
53
53
|
static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys;
|
54
54
|
|
55
55
|
#define GetParser(obj, sval) (sval = (yajl_parser_wrapper*)DATA_PTR(obj));
|
data/ext/yajl_gen.c
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright
|
3
|
-
*
|
2
|
+
* Copyright 2010, Lloyd Hilaiel.
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#include "api/yajl_gen.h"
|
34
34
|
#include "yajl_buf.h"
|
@@ -50,7 +50,7 @@ typedef enum {
|
|
50
50
|
yajl_gen_error
|
51
51
|
} yajl_gen_state;
|
52
52
|
|
53
|
-
struct yajl_gen_t
|
53
|
+
struct yajl_gen_t
|
54
54
|
{
|
55
55
|
unsigned int depth;
|
56
56
|
unsigned int pretty;
|
@@ -70,7 +70,7 @@ yajl_gen_alloc(const yajl_gen_config * config,
|
|
70
70
|
}
|
71
71
|
|
72
72
|
yajl_gen
|
73
|
-
yajl_gen_alloc2(yajl_print_t callback,
|
73
|
+
yajl_gen_alloc2(const yajl_print_t callback,
|
74
74
|
const yajl_gen_config * config,
|
75
75
|
const yajl_alloc_funcs * afs,
|
76
76
|
void * ctx)
|
@@ -125,7 +125,7 @@ yajl_gen_free(yajl_gen g)
|
|
125
125
|
} else if (g->state[g->depth] == yajl_gen_map_val) { \
|
126
126
|
g->print(g->ctx, ":", 1); \
|
127
127
|
if (g->pretty) g->print(g->ctx, " ", 1); \
|
128
|
-
}
|
128
|
+
}
|
129
129
|
|
130
130
|
#define INSERT_WHITESPACE \
|
131
131
|
if (g->pretty) { \
|
@@ -187,14 +187,14 @@ yajl_gen_integer(yajl_gen g, long int number)
|
|
187
187
|
#ifdef WIN32
|
188
188
|
#include <float.h>
|
189
189
|
#define isnan _isnan
|
190
|
-
#define isinf _finite
|
190
|
+
#define isinf !_finite
|
191
191
|
#endif
|
192
192
|
|
193
193
|
yajl_gen_status
|
194
194
|
yajl_gen_double(yajl_gen g, double number)
|
195
195
|
{
|
196
196
|
char i[32];
|
197
|
-
ENSURE_VALID_STATE; ENSURE_NOT_KEY;
|
197
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY;
|
198
198
|
if (isnan(number) || isinf(number)) return yajl_gen_invalid_number;
|
199
199
|
INSERT_SEP; INSERT_WHITESPACE;
|
200
200
|
sprintf(i, "%g", number);
|
@@ -222,8 +222,6 @@ yajl_gen_string(yajl_gen g, const unsigned char * str,
|
|
222
222
|
g->print(g->ctx, "\"", 1);
|
223
223
|
yajl_string_encode2(g->print, g->ctx, str, len);
|
224
224
|
g->print(g->ctx, "\"", 1);
|
225
|
-
|
226
|
-
|
227
225
|
APPENDED_ATOM;
|
228
226
|
FINAL_NEWLINE;
|
229
227
|
return yajl_gen_status_ok;
|
@@ -255,8 +253,8 @@ yajl_gen_status
|
|
255
253
|
yajl_gen_map_open(yajl_gen g)
|
256
254
|
{
|
257
255
|
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
258
|
-
INCREMENT_DEPTH;
|
259
|
-
|
256
|
+
INCREMENT_DEPTH;
|
257
|
+
|
260
258
|
g->state[g->depth] = yajl_gen_map_start;
|
261
259
|
g->print(g->ctx, "{", 1);
|
262
260
|
if (g->pretty) g->print(g->ctx, "\n", 1);
|
@@ -267,7 +265,7 @@ yajl_gen_map_open(yajl_gen g)
|
|
267
265
|
yajl_gen_status
|
268
266
|
yajl_gen_map_close(yajl_gen g)
|
269
267
|
{
|
270
|
-
ENSURE_VALID_STATE;
|
268
|
+
ENSURE_VALID_STATE;
|
271
269
|
(g->depth)--;
|
272
270
|
if (g->pretty) g->print(g->ctx, "\n", 1);
|
273
271
|
APPENDED_ATOM;
|
@@ -281,7 +279,7 @@ yajl_gen_status
|
|
281
279
|
yajl_gen_array_open(yajl_gen g)
|
282
280
|
{
|
283
281
|
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
284
|
-
INCREMENT_DEPTH;
|
282
|
+
INCREMENT_DEPTH;
|
285
283
|
g->state[g->depth] = yajl_gen_array_start;
|
286
284
|
g->print(g->ctx, "[", 1);
|
287
285
|
if (g->pretty) g->print(g->ctx, "\n", 1);
|