jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1232857 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/json/ test/java/org/apache/jackrabbit/mk/json/
Date Wed, 18 Jan 2012 12:37:00 GMT
Author: thomasm
Date: Wed Jan 18 12:36:59 2012
New Revision: 1232857

URL: http://svn.apache.org/viewvc?rev=1232857&view=rev
Log:
Jsop parser / generator: faster and lenient array parsing, no space after newline.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1232857&r1=1232856&r2=1232857&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Wed Jan 18 12:36:59 2012
@@ -207,7 +207,7 @@ public class JsopBuilder implements Jsop
         if (lineLength > 0) {
             int len = buff.length();
             if (len > lineLength / 4 && len + add - previous > lineLength)
{
-                buff.append("\n ");
+                buff.append('\n');
                 previous = len;
             }
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java?rev=1232857&r1=1232856&r2=1232857&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
Wed Jan 18 12:36:59 2012
@@ -244,6 +244,17 @@ public class JsopStream implements JsopR
             return "false";
         case JsopTokenizer.NULL:
             return "null";
+        case '[':
+            StringBuilder buff = new StringBuilder();
+            buff.append('[');
+            while (true) {
+                String s = readRawValue();
+                buff.append(s);
+                if ("]".equals(s)) {
+                    break;
+                }
+            }
+            return buff.toString();
         }
         return Character.toString((char) (x & 255));
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java?rev=1232857&r1=1232856&r2=1232857&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
Wed Jan 18 12:36:59 2012
@@ -71,6 +71,9 @@ public class JsopTokenizer implements Js
      * @return the token
      */
     public String getToken() {
+        if (lastType > COMMENT) {
+            return String.valueOf((char) lastType);
+        }
         return lastEscaped ? decode(lastToken) : lastToken;
     }
 
@@ -393,15 +396,20 @@ public class JsopTokenizer implements Js
 
     private void skipRawValue() {
         switch (currentType) {
-            case '[':
+            case '[': {
                 read();
-                if (!matches(']')) {
-                    do {
-                        skipRawValue();
-                    } while (matches(','));
-                    read(']');
+                int level = 0;
+                while (true) {
+                    if (matches(']') && level-- == 0) {
+                        break;
+                    } else if (matches('[')) {
+                        level++;
+                    } else {
+                        read();
+                    }
                 }
                 break;
+            }
             case '{':
                 read();
                 if (!matches('}')) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java?rev=1232857&r1=1232856&r2=1232857&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
Wed Jan 18 12:36:59 2012
@@ -47,6 +47,27 @@ public class JsopStreamTest extends Test
         assertEquals("\"x\":[1,null,true,false,\"Hello\"]", s.toString());
     }
 
+    public void testRawValue() {
+        JsopStream s = new JsopStream().tag('+').
+        key("x").object().
+            key("y").array().value(1).array().endArray().value(2).endArray().endObject();
+        assertEquals("+\"x\":{\"y\":[1,[],2]}", s.toString());
+        testRawValue(s);
+        testRawValue(new JsopTokenizer(s.toString()));
+    }
+
+    private void testRawValue(JsopReader s) {
+        assertFalse(s.matches('-'));
+        assertTrue(s.matches('+'));
+        assertEquals("x", s.read(JsopTokenizer.STRING));
+        s.read(':');
+        assertEquals("{", s.read('{'));
+        assertEquals("y", s.readString());
+        s.read(':');
+        assertEquals("[1,[],2]", s.readRawValue());
+        s.read('}');
+    }
+
     public void testJsopReader() {
         JsopStream s = new JsopStream().tag('+').
             key("x").object().

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java?rev=1232857&r1=1232856&r2=1232857&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
Wed Jan 18 12:36:59 2012
@@ -76,8 +76,8 @@ public class JsopTest extends TestCase {
 
         buff.setLineLength(10);
         buff.key("hello").value("world");
-        assertEquals("\"hello\":\n \"world\"", buff.toString());
-        assertEquals(17, buff.length());
+        assertEquals("\"hello\":\n\"world\"", buff.toString());
+        assertEquals(16, buff.length());
     }
 
     public void testNumber() {



Mime
View raw message