You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by rm...@apache.org on 2015/01/04 21:57:41 UTC

incubator-johnzon git commit: supporting /**/ comments

Repository: incubator-johnzon
Updated Branches:
  refs/heads/master ed1e7d6ff -> 4d4ac2ee6


supporting /**/ comments


Project: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/commit/4d4ac2ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/tree/4d4ac2ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/diff/4d4ac2ee

Branch: refs/heads/master
Commit: 4d4ac2ee64646e053e09d46c7fdbb3280bf3205b
Parents: ed1e7d6
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sun Jan 4 21:57:00 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sun Jan 4 21:57:00 2015 +0100

----------------------------------------------------------------------
 .../core/CommentsJsonStreamParserImpl.java      | 22 +++++++++++++-------
 .../johnzon/core/JsonStreamParserImpl.java      |  7 +++----
 .../src/test/resources/json/comments.json       |  8 ++++++-
 3 files changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/4d4ac2ee/johnzon-core/src/main/java/org/apache/johnzon/core/CommentsJsonStreamParserImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/CommentsJsonStreamParserImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/CommentsJsonStreamParserImpl.java
index f89b4d8..e28c03a 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/CommentsJsonStreamParserImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/CommentsJsonStreamParserImpl.java
@@ -48,15 +48,23 @@ public class CommentsJsonStreamParserImpl extends JsonStreamParserImpl {
     @Override
     protected Event defaultHandling(final char c) {
         if (c == '/') {
-            char next = super.readNextChar();
-            if (next != '/') { // fail
+            char next = readNextChar();
+            if (next == '/') { // fail
+                do {
+                    next = readNextChar();
+                } while (next != '\n');
+            } else if (next == '*') {
+                next = 0;
+                char previous;
+                do {
+                    previous = next;
+                    next = readNextChar();
+                } while (next != '/' && previous != '*');
+                readNextNonWhitespaceChar(next);
+            } else {
                 return super.defaultHandling(c);
             }
-
-            do {
-                next = super.readNextChar();
-            } while (next != '\n');
         }
-        return super.next();
+        return next();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/4d4ac2ee/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
index 99cd677..d1d5968 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
@@ -187,7 +187,7 @@ public class JsonStreamParserImpl implements JsonChars, JsonParser{
         //detect garbage at the end of the file after last object or array is closed
         if (bufferPos < availableCharsInBuffer - 2) {
 
-            final char c = readNextNonWhitespaceChar();
+            final char c = readNextNonWhitespaceChar(readNextChar());
 
             if (c == EOF) {
                 return false;
@@ -293,10 +293,9 @@ public class JsonStreamParserImpl implements JsonChars, JsonParser{
     //skip whitespaces
     //tracks location informations (line, column)
     //returns the first non whitespace character
-    private char readNextNonWhitespaceChar() {
+    protected final char readNextNonWhitespaceChar(char c) {
 
         int dosCount = 0;
-        char c = readNextChar();
 
         while (c == SPACE || c == TAB || c == CR || c == EOL) {
 
@@ -331,7 +330,7 @@ public class JsonStreamParserImpl implements JsonChars, JsonParser{
             throw uexc("Unexpected end of structure");
         }
 
-        final char c = readNextNonWhitespaceChar();
+        final char c = readNextNonWhitespaceChar(readNextChar());
 
         if (c == COMMA_CHAR) {
 

http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/4d4ac2ee/johnzon-core/src/test/resources/json/comments.json
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/resources/json/comments.json b/johnzon-core/src/test/resources/json/comments.json
index 14a497b..27dc495 100644
--- a/johnzon-core/src/test/resources/json/comments.json
+++ b/johnzon-core/src/test/resources/json/comments.json
@@ -1,11 +1,17 @@
-{
+/* super header comment
+dont put the brace on another line
+it is part of the test */{
   "foo": "//bar//but//not//a/comment",
   // a comment
   // on multiple lines
   //even without space at the beginning;
+  /* a long comment */
   "another": 5,
   "//object": {
     // another comment
     "sub": "fdmcd"
+    /*
+    super long comment
+    */
   }
 }
\ No newline at end of file