ext/oj/load.c in oj-0.5 vs ext/oj/load.c in oj-0.5.1
- old
+ new
@@ -42,11 +42,11 @@
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *encoding;
#else
void *encoding;
#endif
- int trace;
+ Options options;
} *ParseInfo;
static VALUE read_next(ParseInfo pi);
static VALUE read_obj(ParseInfo pi);
static VALUE read_array(ParseInfo pi);
@@ -104,25 +104,22 @@
}
}
}
VALUE
-parse(char *json, int trace) {
+parse(char *json, Options options) {
VALUE obj;
struct _ParseInfo pi;
if (0 == json) {
raise_error("Invalid arg, xml string can not be null", json, 0);
}
- if (trace) {
- printf("Parsing JSON:\n%s\n", json);
- }
/* initialize parse info */
pi.str = json;
pi.s = json;
pi.encoding = 0;
- pi.trace = trace;
+ pi.options = options;
if (Qundef == (obj = read_next(&pi))) {
raise_error("no object read", pi.str, pi.s);
}
next_non_white(&pi); // skip white space
if ('\0' != *pi.s) {
@@ -184,10 +181,15 @@
VALUE obj = Qundef;
VALUE key = Qundef;
VALUE val = Qundef;
pi->s++;
+ next_non_white(pi);
+ if ('}' == *pi->s) {
+ pi->s++;
+ return rb_hash_new();
+ }
while (1) {
next_non_white(pi);
if ('"' != *pi->s || Qundef == (key = read_str(pi))) {
raise_error("unexpected character", pi->str, pi->s);
}
@@ -221,9 +223,14 @@
read_array(ParseInfo pi) {
VALUE a = rb_ary_new();
VALUE e;
pi->s++;
+ next_non_white(pi);
+ if (']' == *pi->s) {
+ pi->s++;
+ return a;
+ }
while (1) {
if (Qundef == (e = read_next(pi))) {
raise_error("unexpected character", pi->str, pi->s);
}
rb_ary_push(a, e);