Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mimic is completed, ready for merge

  • Loading branch information...
commit 28ab9ce9fc5f8a68502d83cd93f45d96e966f283 1 parent db2a9be
Peter Ohler authored
Showing with 52 additions and 4 deletions.
  1. +34 −1 ext/oj/fast.c
  2. +1 −1  lib/oj/version.rb
  3. +0 −2  notes
  4. +17 −0 test/test_fast.rb
35 ext/oj/fast.c
View
@@ -88,6 +88,7 @@ static Leaf read_false(ParseInfo pi);
static Leaf read_nil(ParseInfo pi);
static void next_non_white(ParseInfo pi);
static char* read_quoted_value(ParseInfo pi);
+static void skip_comment(ParseInfo pi);
static VALUE protect_open_proc(VALUE x);
static VALUE parse_json(VALUE clas, char *json);
@@ -125,6 +126,9 @@ next_non_white(ParseInfo pi) {
case '\n':
case '\r':
break;
+ case '/':
+ skip_comment(pi);
+ break;
default:
return;
}
@@ -272,6 +276,36 @@ leaf_value(Doc doc, Leaf leaf) {
return leaf->value;
}
+static void
+skip_comment(ParseInfo pi) {
+ pi->s++; // skip first /
+ if ('*' == *pi->s) {
+ pi->s++;
+ for (; '\0' != *pi->s; pi->s++) {
+ if ('*' == *pi->s && '/' == *(pi->s + 1)) {
+ pi->s++;
+ return;
+ } else if ('\0' == *pi->s) {
+ raise_error("comment not terminated", pi->str, pi->s);
+ }
+ }
+ } else if ('/' == *pi->s) {
+ for (; 1; pi->s++) {
+ switch (*pi->s) {
+ case '\n':
+ case '\r':
+ case '\f':
+ case '\0':
+ return;
+ default:
+ break;
+ }
+ }
+ } else {
+ raise_error("invalid comment", pi->str, pi->s);
+ }
+}
+
#ifdef RUBINIUS
#define NUM_MAX 0x07FFFFFF
#else
@@ -1039,7 +1073,6 @@ doc_open(VALUE clas, VALUE str) {
json = ALLOCA_N(char, len);
}
memcpy(json, StringValuePtr(str), len);
-
obj = parse_json(clas, json);
if (SMALL_XML < len) {
xfree(json);
2  lib/oj/version.rb
View
@@ -1,5 +1,5 @@
module Oj
# Current version of the module.
- VERSION = '1.0.6'
+ VERSION = '1.1.0'
end
2  notes
View
@@ -4,8 +4,6 @@
^c^s show subtree
- next
- - Oj::Doc should ignore comments
-
- implement Oj::Doc.new or open without a block given
- requires a close
17 test/test_fast.rb
View
@@ -328,4 +328,21 @@ def test_each_leaf
assert_equal({'/1' => 1, '/2/1' => 2, '/2/2' => 3}, results)
end
+ def test_comment
+ json = %{{
+ "x"/*one*/:/*two*/true,//three
+ "y":58/*four*/,
+ "z": [1,2/*five*/,
+3 // six
+]
+}
+}
+ results = Oj::Doc.open(json) do |doc|
+ h = {}
+ doc.each_leaf() { |d| h[d.where?] = d.fetch() }
+ h
+ end
+ assert_equal({'/x' => true, '/y' => 58, '/z/1' => 1, '/z/2' => 2, '/z/3' => 3}, results)
+ end
+
end # DocTest
Please sign in to comment.
Something went wrong with that request. Please try again.