yaji 0.3.0-x86-mingw32 → 0.3.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +8 -0
- data/ext/yaji/parser_ext.c +37 -38
- data/ext/yaji/parser_ext.h +3 -0
- data/lib/yaji/version.rb +1 -1
- metadata +5 -5
data/HISTORY.markdown
CHANGED
data/ext/yaji/parser_ext.c
CHANGED
@@ -156,7 +156,7 @@ static int yaji_end_array(void *ctx)
|
|
156
156
|
return STATUS_CONTINUE;
|
157
157
|
}
|
158
158
|
|
159
|
-
static VALUE rb_yaji_each_iter(VALUE chunk, VALUE
|
159
|
+
static VALUE rb_yaji_each_iter(VALUE chunk, VALUE parser);
|
160
160
|
|
161
161
|
static VALUE rb_yaji_parser_parse_chunk(VALUE chunk, VALUE self)
|
162
162
|
{
|
@@ -178,12 +178,10 @@ static VALUE rb_yaji_parser_parse_chunk(VALUE chunk, VALUE self)
|
|
178
178
|
}
|
179
179
|
for (i=0; i<RARRAY_LEN(p->events); i++) {
|
180
180
|
if (NIL_P(p->input)) {
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
params[3] = p->with_path ? Qtrue : Qfalse;
|
186
|
-
rb_yaji_each_iter(RARRAY_PTR(p->events)[i], params);
|
181
|
+
p->effective_proc = p->on_object_cb;
|
182
|
+
p->effective_filter = p->filter;
|
183
|
+
p->effective_with_path = p->with_path ? Qtrue : Qfalse;
|
184
|
+
rb_yaji_each_iter(RARRAY_PTR(p->events)[i], self);
|
187
185
|
} else {
|
188
186
|
rb_funcall(p->parser_cb, id_call, 1, RARRAY_PTR(p->events)[i]);
|
189
187
|
}
|
@@ -335,59 +333,55 @@ static int rb_yaji_str_start_with(VALUE str, VALUE filter)
|
|
335
333
|
return 0;
|
336
334
|
}
|
337
335
|
|
338
|
-
static VALUE rb_yaji_each_iter(VALUE chunk, VALUE
|
336
|
+
static VALUE rb_yaji_each_iter(VALUE chunk, VALUE parser)
|
339
337
|
{
|
340
|
-
|
338
|
+
yaji_parser* p = (yaji_parser*) DATA_PTR(parser);
|
341
339
|
VALUE path = rb_ary_shift(chunk);
|
342
340
|
VALUE event = rb_ary_shift(chunk);
|
343
341
|
VALUE value = rb_ary_shift(chunk);
|
344
|
-
VALUE proc = params[0];
|
345
|
-
VALUE stack = params[1];
|
346
|
-
VALUE filter = params[2];
|
347
|
-
VALUE with_path = params[3];
|
348
342
|
VALUE last_entry, object, container, key, hash;
|
349
343
|
|
350
|
-
if (NIL_P(
|
344
|
+
if (NIL_P(p->effective_filter) || rb_yaji_str_start_with(path, p->effective_filter)) {
|
351
345
|
if (event == sym_hash_key) {
|
352
|
-
rb_ary_push(
|
346
|
+
rb_ary_push(p->object_stack, value);
|
353
347
|
} else if (event == sym_start_hash || event == sym_start_array) {
|
354
348
|
container = (event == sym_start_hash) ? rb_hash_new() : rb_ary_new();
|
355
|
-
last_entry = rb_ary_entry(
|
349
|
+
last_entry = rb_ary_entry(p->object_stack, -1);
|
356
350
|
switch(TYPE(last_entry)) {
|
357
351
|
case T_STRING:
|
358
|
-
key = rb_ary_pop(
|
359
|
-
hash = rb_ary_entry(
|
352
|
+
key = rb_ary_pop(p->object_stack);
|
353
|
+
hash = rb_ary_entry(p->object_stack, -1);
|
360
354
|
rb_hash_aset(hash, key, container);
|
361
355
|
break;
|
362
356
|
case T_ARRAY:
|
363
357
|
rb_ary_push(last_entry, container);
|
364
358
|
}
|
365
|
-
rb_ary_push(
|
359
|
+
rb_ary_push(p->object_stack, container);
|
366
360
|
} else if (event == sym_end_hash || event == sym_end_array) {
|
367
|
-
object = rb_ary_pop(
|
368
|
-
if (RARRAY_LEN(
|
369
|
-
if (
|
370
|
-
rb_funcall(
|
361
|
+
object = rb_ary_pop(p->object_stack);
|
362
|
+
if (RARRAY_LEN(p->object_stack) == 0) {
|
363
|
+
if (RTEST(p->effective_with_path)) {
|
364
|
+
rb_funcall(p->effective_proc, id_call, 1, rb_ary_new3(2, path, object));
|
371
365
|
} else {
|
372
|
-
rb_funcall(
|
366
|
+
rb_funcall(p->effective_proc, id_call, 1, object);
|
373
367
|
}
|
374
368
|
}
|
375
369
|
} else {
|
376
|
-
last_entry = rb_ary_entry(
|
370
|
+
last_entry = rb_ary_entry(p->object_stack, -1);
|
377
371
|
switch(TYPE(last_entry)) {
|
378
372
|
case T_STRING:
|
379
|
-
key = rb_ary_pop(
|
380
|
-
hash = rb_ary_entry(
|
373
|
+
key = rb_ary_pop(p->object_stack);
|
374
|
+
hash = rb_ary_entry(p->object_stack, -1);
|
381
375
|
rb_hash_aset(hash, key, value);
|
382
376
|
break;
|
383
377
|
case T_ARRAY:
|
384
378
|
rb_ary_push(last_entry, value);
|
385
379
|
break;
|
386
380
|
case T_NIL:
|
387
|
-
if (
|
388
|
-
rb_funcall(
|
381
|
+
if (RTEST(p->effective_with_path)) {
|
382
|
+
rb_funcall(p->effective_proc, id_call, 1, rb_ary_new3(2, path, value));
|
389
383
|
} else {
|
390
|
-
rb_funcall(
|
384
|
+
rb_funcall(p->effective_proc, id_call, 1, value);
|
391
385
|
}
|
392
386
|
break;
|
393
387
|
}
|
@@ -398,7 +392,7 @@ static VALUE rb_yaji_each_iter(VALUE chunk, VALUE* params_p)
|
|
398
392
|
|
399
393
|
static VALUE rb_yaji_parser_each(int argc, VALUE* argv, VALUE self)
|
400
394
|
{
|
401
|
-
VALUE filter, proc, options
|
395
|
+
VALUE filter, proc, options;
|
402
396
|
yaji_parser* p = (yaji_parser*) DATA_PTR(self);
|
403
397
|
|
404
398
|
if (NIL_P(p->input)) {
|
@@ -406,23 +400,23 @@ static VALUE rb_yaji_parser_each(int argc, VALUE* argv, VALUE self)
|
|
406
400
|
}
|
407
401
|
RETURN_ENUMERATOR(self, argc, argv);
|
408
402
|
rb_scan_args(argc, argv, "02&", &filter, &options, &proc);
|
409
|
-
|
410
|
-
|
403
|
+
p->effective_proc = proc;
|
404
|
+
p->object_stack = rb_ary_new();
|
411
405
|
if (NIL_P(filter)) {
|
412
|
-
|
406
|
+
p->effective_filter = p->filter;
|
413
407
|
} else {
|
414
|
-
|
408
|
+
p->effective_filter = filter;
|
415
409
|
}
|
416
|
-
|
410
|
+
p->effective_with_path = p->with_path ? Qtrue : Qfalse;
|
417
411
|
if (options != Qnil) {
|
418
412
|
VALUE arg;
|
419
413
|
Check_Type(options, T_HASH);
|
420
414
|
arg = rb_hash_aref(options, sym_with_path);
|
421
415
|
if (!NIL_P(arg)) {
|
422
|
-
|
416
|
+
p->effective_with_path = arg;
|
423
417
|
}
|
424
418
|
}
|
425
|
-
rb_block_call(self, id_parse, 0, NULL, rb_yaji_each_iter,
|
419
|
+
rb_block_call(self, id_parse, 0, NULL, rb_yaji_each_iter, self);
|
426
420
|
return Qnil;
|
427
421
|
}
|
428
422
|
|
@@ -457,7 +451,12 @@ static void rb_yaji_parser_mark(void *parser)
|
|
457
451
|
rb_gc_mark(p->path);
|
458
452
|
rb_gc_mark(p->path_str);
|
459
453
|
rb_gc_mark(p->parser_cb);
|
454
|
+
rb_gc_mark(p->on_object_cb);
|
460
455
|
rb_gc_mark(p->chunk);
|
456
|
+
rb_gc_mark(p->object_stack);
|
457
|
+
rb_gc_mark(p->effective_filter);
|
458
|
+
rb_gc_mark(p->effective_with_path);
|
459
|
+
rb_gc_mark(p->effective_proc);
|
461
460
|
}
|
462
461
|
}
|
463
462
|
|
data/ext/yaji/parser_ext.h
CHANGED
data/lib/yaji/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: x86-mingw32
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -152,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
segments:
|
154
154
|
- 0
|
155
|
-
hash:
|
155
|
+
hash: 967307934979714977
|
156
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
157
|
none: false
|
158
158
|
requirements:
|
@@ -161,10 +161,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
version: '0'
|
162
162
|
segments:
|
163
163
|
- 0
|
164
|
-
hash:
|
164
|
+
hash: 967307934979714977
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project: yaji
|
167
|
-
rubygems_version: 1.8.
|
167
|
+
rubygems_version: 1.8.24
|
168
168
|
signing_key:
|
169
169
|
specification_version: 3
|
170
170
|
summary: Yet another JSON iterator
|