/* * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package jdk.test.lib.json;
if (current() == 'f') {
expect('a');
expect('l');
expect('s');
expect('e');
advance(); returnnew JSONString("false");
} throw failure("a boolean can only be 'true' or 'false'");
}
private JSONValue parseNumber() { var isInteger = true; var builder = new StringBuilder();
if (current() == '-') {
builder.append(current());
advance();
expectMoreInput("a number cannot consist of only '-'");
}
if (current() == '0') {
builder.append(current());
advance();
if (!isDigit(current())) { throw failure("a digit must follow {'e','E'}{'+','-'}");
}
while (hasInput() && isDigit(current())) {
builder.append(current());
advance();
}
}
var value = builder.toString(); if (isInteger) { new BigInteger(value); returnnew JSONString(value);
} else { Double.parseDouble(value); returnnew JSONString(value);
}
}
private JSONString parseString() { var missingEndChar = "string is not terminated with '\"'"; var builder = new StringBuilder(); for (var c = next(missingEndChar); c != '"'; c = next(missingEndChar)) { if (c == '\\') { var n = next(missingEndChar); switch (n) { case'"':
builder.append("\""); break; case'\\':
builder.append("\\"); break; case'/':
builder.append("/"); break; case'b':
builder.append("\b"); break; case'f':
builder.append("\f"); break; case'n':
builder.append("\n"); break; case'r':
builder.append("\r"); break; case't':
builder.append("\t"); break; case'u': var u1 = next(missingEndChar); var u2 = next(missingEndChar); var u3 = next(missingEndChar); var u4 = next(missingEndChar); var cp = Integer.parseInt(String.format("%c%c%c%c", u1, u2, u3, u4), 16);
builder.append(new String(newint[]{cp}, 0, 1)); break; default: throw failure(String.format("Unexpected escaped character '%c'", n));
}
} else {
builder.append(c);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.