Esempio n. 1
0
 @Test
 public void ensureEquals() {
   CharacterSource source = new CharSeqCharacterSource("ahuhub");
   source.next();
   KeyReference key = new KeyReference(0, "huhu".length(), "huhu".hashCode(), source);
   assertEquals(key, new KeyReference("huhu"));
 }
Esempio n. 2
0
 protected char consumeAfterValue(final ElementKey currentKey) {
   char c = json.nextConsumingWhitespace();
   if (c == ',') {
     currentKey.next();
     c = json.next();
     if (c <= ' ') {
       c = json.nextConsumingWhitespace();
     }
     return c;
   }
   return c;
 }
Esempio n. 3
0
 protected KeyReference parseUnquotedJSONKey(final char firstChar) {
   int start = json.getPrevPosition();
   int hash = firstChar;
   int length = 1;
   while (json.hasNext()) {
     char c = json.next();
     // if (c == '"') {
     if (':' == c) { // FIXME: handle"\:"
       // cursor = i + 1;
       return new KeyReference(start, length, hash, json);
     }
     ++length;
     hash = (31 * hash) + c;
   }
   throw new UnexpectedEOF(json.getPosition());
 }
Esempio n. 4
0
 protected void expectMoreData() {
   if (!json.hasNext()) {
     throw new UnexpectedEOF(json.getPosition());
   }
 }
Esempio n. 5
0
 protected void expect(final char c, final String expectedChars) {
   if (-1 == expectedChars.indexOf(c)) {
     throw new ParseErrorException(json.getPosition(), c, expectedChars); // FIXME
   }
 }
Esempio n. 6
0
  protected Reference parseUnquotedJSONString(char c) {
    int start = json.getPosition();
    int tc = 4, tf = 4, tn = 4;
    int length = 0;
    //		for (int i = 0; (i < 4) && json.hasNext(); ++i) {
    int i = 0;
    do {
      //			char c = json.getNext();
      //			if (isStringEnd(c)) {
      //				return new StringValueReference(start, json.getPosition() - start, json);
      //			}
      if (TRUE[i] == c) {
        --tc;
      } else if (FALS[i] == c) {
        --tf;
        if (i == 2) {
          --tn;
        }
      } else if (NULL[i] == c) {
        --tn;
      } else {
        if (isStringEnd(c)) {
          currentChar = c;
          return new StringValueReference(start, length, json);
        }
        break;
      }
      expectMoreData();
      c = json.next();
      ++length;
      ++i;
    } while (i < 4);

    if ((i == 4)) {
      if (isStringEnd(c)) {
        currentChar = c;
        if (tc == 0) {
          return Reference.TRUE;
        }
        if (tn == 0) {
          return Reference.NULL;
        }
      }
      if ((tf == 0) && (c == 'e')) {
        c = json.next();
        if (isStringEnd(c)) {
          currentChar = c;
          return Reference.FALSE;
        }
        ++length;
      }
    }

    while (json.hasNext()) {
      c = json.next();
      ++length;
      if (isStringEnd(c)) {
        currentChar = c;
        return new StringValueReference(start, length, json);
      }

      //			if (c == '\\') {
      //				StringBuilder builder = new StringBuilder();
      //				builder.append(array, start, i - start);
      //				for (int j = i; j < max; ++j) {
      //					c = array.charAt(j);
      //					if (isStringEnd(c)) {
      //						//cursor = j + 1;
      //						return new StringCopyReference(builder);
      //					}
      //					if (c == '\\') {
      //						switch (c = array.charAt(++j)) {
      //						case '"':
      //						case '\\':
      //						case ',':
      //						case ']':
      //						case '}':
      //						case '/':
      //							builder.append(c);
      //							continue;
      //						case 'n':
      //							builder.append('\n');
      //							continue;
      //						case 'r':
      //							builder.append('\r');
      //							continue;
      //						case 't':
      //							builder.append('\t');
      //							continue;
      //						case 'b':
      //							builder.append('\b');
      //							continue;
      //						case 'f':
      //							builder.append('\f');
      //							continue;
      //						case 'u':
      //							builder.append(Character.toChars(Integer.valueOf(new
      // StringBuilder(array.subSequence(i, i + 4)).toString(), 16)));
      //							j += 4;
      //							continue;
      //
      //						default:
      //						}
      //						continue;
      //					}
      //					builder.append(c);
      //				}
      //			}
    }
    throw new UnexpectedEOF(json.getPosition());
  }
Esempio n. 7
0
 protected Reference parseJSONString() {
   int start = json.getPosition();
   int length = json.skipToQuote();
   return new StringValueReference(start, length, json);
 }