jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1084853 - in /jackrabbit/sandbox/jackrabbit-j3/src: main/java/org/apache/jackrabbit/j3/json/ main/java/org/apache/jackrabbit/j3/mc/ test/java/org/apache/jackrabbit/j3/json/
Date Thu, 24 Mar 2011 06:26:40 GMT
Author: thomasm
Date: Thu Mar 24 06:26:40 2011
New Revision: 1084853

URL: http://svn.apache.org/viewvc?rev=1084853&view=rev
Log:
Json/Jsop Tokenizer

Modified:
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/JsopTokenizer.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Val.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestNode.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestTokenizer.java

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/JsopTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/JsopTokenizer.java?rev=1084853&r1=1084852&r2=1084853&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/JsopTokenizer.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/JsopTokenizer.java
Thu Mar 24 06:26:40 2011
@@ -25,7 +25,7 @@ public class JsopTokenizer {
     // please note .0 and -.1 are not valid numbers
 
     final static int STRING = 0, NUMBER = 1, TRUE = 2, FALSE = 3, NULL = 4;
-    final static int ERROR = 5, END = 6;
+    final static int COMMENT = 5, ERROR = 6, END = 7;
 
     private static final String[] TYPE = {
         "string", "number", "true", "false", "null", "error", "end"
@@ -44,6 +44,11 @@ public class JsopTokenizer {
     }
 
     public String toString() {
+        int todo;
+//      version as comment
+//      newlines in strings -> error
+//      project source code format
+
         return jsop;
     }
 
@@ -167,6 +172,22 @@ public class JsopTokenizer {
         case '>':
         case '^':
             return ch;
+        case '/': {
+            ch = jsop.charAt(pos);
+            if (ch != '*') {
+                return '/';
+            }
+            pos++;
+            while (true) {
+                ch = jsop.charAt(pos++);
+                if (ch == '*' && jsop.charAt(pos) == '/') {
+                    break;
+                }
+            }
+            currentToken = jsop.substring(start + 2, pos - 1);
+            pos += 2;
+            return COMMENT;
+        }
         case '-':
             ch = jsop.charAt(pos);
             if (ch < '0' || ch > '9') {

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/NodeImpl.java?rev=1084853&r1=1084852&r2=1084853&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/json/NodeImpl.java
Thu Mar 24 06:26:40 2011
@@ -134,6 +134,10 @@ public class NodeImpl {
             return Val.TRUE;
         } else if (t.matches(JsopTokenizer.FALSE)) {
             return Val.FALSE;
+        } else if (t.matches(JsopTokenizer.COMMENT)) {
+            String typeName = t.getToken().trim();
+            int type = PropertyType.valueFromName(typeName);
+            return Val.get(type, t.readString());
         }
         return Val.get(t.readString());
     }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Val.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Val.java?rev=1084853&r1=1084852&r2=1084853&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Val.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Val.java Thu
Mar 24 06:26:40 2011
@@ -242,6 +242,8 @@ public class Val implements Comparable<V
             return get(Boolean.parseBoolean(x));
         case PropertyType.LONG:
             return get(Long.decode(x));
+        case PropertyType.DOUBLE:
+            return get(Double.parseDouble(x));
         case PropertyType.DECIMAL:
         case PropertyType.DATE:
         case PropertyType.NAME:
@@ -310,8 +312,13 @@ public class Val implements Comparable<V
         case PropertyType.LONG:
             return value.toString();
         case PropertyType.DECIMAL:
-        case PropertyType.DOUBLE:
             return "/* " + PropertyType.nameFromValue(type) + " */ " + value.toString();
+        case PropertyType.DOUBLE:
+            String s = value.toString();
+            if (s.equals("NaN") || s.endsWith("Infinity")) {
+                s = "\"" + s + "\"";
+            }
+            return "/* " + PropertyType.nameFromValue(type) + " */ " + s;
         case PropertyType.STRING:
             return JsopTokenizer.encode(value.toString());
         default:

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestNode.java?rev=1084853&r1=1084852&r2=1084853&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestNode.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestNode.java
Thu Mar 24 06:26:40 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.j3.json;
 
+import org.apache.jackrabbit.j3.mc.Val;
 import junit.framework.TestCase;
 
 /**
@@ -52,6 +53,16 @@ public class TestNode extends TestCase {
         node = NodeImpl.fromString("{\"long\": -230, \"decimal\": 230.0, \"double\": 230.0e1}");
         assertEquals("{\"double\": /* Double */ 2300.0,\n\"long\": -230,\n\"decimal\": /*
Decimal */ 230.0\n}", node.toString());
 
+        node = new NodeImpl();
+        node.setProperty("NaN", Val.get(Math.sqrt(-1)));
+        node.setProperty("Inf", Val.get(Math.pow(0, -1)));
+        node.setProperty("negInf", Val.get(-Math.pow(0, -1)));
+        String s = node.toString();
+        assertEquals("{\"Inf\": /* Double */ \"Infinity\",\n\"NaN\": /* Double */ \"NaN\",\n\"negInf\":
/* Double */ \"-Infinity\"\n}", s);
+        node = NodeImpl.fromString(s);
+        s = node.toString();
+        assertEquals("{\"Inf\": /* Double */ \"Infinity\",\n\"NaN\": /* Double */ \"NaN\",\n\"negInf\":
/* Double */ \"-Infinity\"\n}", s);
+
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestTokenizer.java?rev=1084853&r1=1084852&r2=1084853&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestTokenizer.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/json/TestTokenizer.java
Thu Mar 24 06:26:40 2011
@@ -66,6 +66,8 @@ public class TestTokenizer extends TestC
         test("\"Hello\"", "\"Hello\"");
         test(" [\n\n]\n", "[]");
         test(" {\n\n}\n", "{}");
+        test(" {\n\"a\": /* test */ 10\n}\n", "{ \"a\": /* test */ 10}");
+        test("+ - / ^ ", "+ - / ^");
 
         JsopTokenizer t = new JsopTokenizer("{}123");
         assertFalse(t.matches('+'));
@@ -126,6 +128,9 @@ public class TestTokenizer extends TestC
             case JsopTokenizer.ERROR:
                 buff.append("/error/");
                 break;
+            case JsopTokenizer.COMMENT:
+                buff.append("/*").append(t.getToken()).append("*/ ");
+                break;
             case '{':
                 buff.append(" {\n");
                 break;
@@ -153,6 +158,9 @@ public class TestTokenizer extends TestC
             case '^':
                 buff.append("^ ");
                 break;
+            case '/':
+                buff.append("/ ");
+                break;
             default:
                 throw new AssertionError("token type: " + t.getTokenType());
             }



Mime
View raw message