jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1213221 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/json/JsopStream.java test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
Date Mon, 12 Dec 2011 13:05:43 GMT
Author: thomasm
Date: Mon Dec 12 13:05:42 2011
New Revision: 1213221

URL: http://svn.apache.org/viewvc?rev=1213221&view=rev
Log:
JsopStream: support newline.

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

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=1213221&r1=1213220&r2=1213221&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
Mon Dec 12 13:05:42 2011
@@ -22,9 +22,9 @@ package org.apache.jackrabbit.mk.json;
 public class JsopStream implements JsopReader, JsopWriter {
 
     private boolean needComma;
-    private int len, pos, valuesLen;
-    private int[] tokens = new int[10];
-    private Object[] values = new Object[10];
+    private int len, pos, lastPos, valuesLen;
+    private int[] tokens = new int[4];
+    private Object[] values = new Object[4];
 
     // write
 
@@ -115,6 +115,7 @@ public class JsopStream implements JsopR
     }
 
     public JsopStream newline() {
+        addToken('\n');
         return this;
     }
 
@@ -168,7 +169,7 @@ public class JsopStream implements JsopR
     // read
 
     public String getToken() {
-        int x = tokens[pos - 1];
+        int x = tokens[lastPos];
         switch (x & 255) {
         case JsopTokenizer.STRING:
         case JsopTokenizer.NUMBER:
@@ -186,18 +187,20 @@ public class JsopStream implements JsopR
     }
 
     public int getTokenType() {
-        return getType(pos - 1);
+        return tokens[lastPos] & 255;
     }
 
     public boolean matches(int type) {
-        if (getType(pos) == type) {
+        if (getType() == type) {
+            lastPos = pos;
             pos++;
             return true;
         }
         return false;
     }
 
-    private int getType(int pos) {
+    private int getType() {
+        skipNewline();
         return tokens[pos] & 255;
     }
 
@@ -209,11 +212,25 @@ public class JsopStream implements JsopR
     }
 
     public int read() {
-        return getType(pos++);
+        int t = getType();
+        lastPos = pos++;
+        return t;
+    }
+
+    private void skipNewline() {
+        while (true) {
+            int x = tokens[pos];
+            if (x != '\n') {
+                return;
+            }
+            pos++;
+        }
     }
 
     public String readRawValue() {
-        int x = tokens[pos++];
+        skipNewline();
+        int x = tokens[pos];
+        lastPos = pos++;
         switch (x & 255) {
         case JsopTokenizer.COMMENT:
         case JsopTokenizer.NUMBER:

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=1213221&r1=1213220&r2=1213221&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
Mon Dec 12 13:05:42 2011
@@ -201,14 +201,14 @@ public class JsopStreamTest extends Test
                 object().key("y").value("2").endObject().newline().
                 endArray();
         json = buff.toString();
-        assertEquals("[{\"x\":\"1\"},{\"y\":\"2\"}]", json);
+        assertEquals("[{\"x\":\"1\"}\n,{\"y\":\"2\"}\n]", json);
 
         buff = new JsopStream();
         buff.tag('+').key("x").value("1").newline();
         buff.tag('+').key("y").value("2").newline();
         buff.tag('+').key("z").value(false).newline();
         json = buff.toString();
-        assertEquals("+\"x\":\"1\"+\"y\":\"2\"+\"z\":false", json);
+        assertEquals("+\"x\":\"1\"\n+\"y\":\"2\"\n+\"z\":false\n", json);
 
     }
 



Mime
View raw message