Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jul 31, 2024
1 parent 2e6fd11 commit 97e57af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ext/oj/usual.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ static void close_object(ojParser p) {
}
rb_hash_bulk_insert(d->vtail - head, head, obj);
d->ktail = d->khead + c->ki;
if (0 == head - d->vhead && rb_block_given_p()) {
rb_yield(obj);
// TBD decrement vtail?
d->vtail--;
return;
}
d->vtail = head;
head--;
*head = obj;
Expand Down Expand Up @@ -572,7 +578,18 @@ static VALUE result(ojParser p) {
Usual d = (Usual)p->ctx;

if (d->vhead < d->vtail) {
return *d->vhead;
long cnt = d->vtail - d->vhead;
volatile VALUE ary;
volatile VALUE *vp;

if (1 == cnt) {
return *d->vhead;
}
ary = rb_ary_new();
for (vp = d->vhead; vp < d->vtail; vp++) {
rb_ary_push(ary, *vp);
}
return ary;
}
if (d->raise_on_empty) {
rb_raise(oj_parse_error_class, "empty string");
Expand Down
7 changes: 7 additions & 0 deletions test/test_parser_usual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def test_decimal
assert_equal(Float, doc.class)
end

def test_multi
p = Oj::Parser.new(:usual)
puts p.just_one
#puts p.parse('{"b":{"x":2}}')
puts p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| puts j }
end

def test_omit_null
p = Oj::Parser.new(:usual)
p.omit_null = true
Expand Down

0 comments on commit 97e57af

Please sign in to comment.