This commit is contained in:
redkale
2024-10-23 08:32:56 +08:00
parent f8b8429044
commit 3a7a462f65
2 changed files with 29 additions and 77 deletions

View File

@@ -76,7 +76,7 @@ public class JsonByteBufferReader extends JsonReader {
this.cacheChar = 0;
return ch;
}
byte b = nextByte();
if (b >= 0) { // 1 byte, 7 bits: 0xxxxxxx
return (char) b;

View File

@@ -180,13 +180,13 @@ public class JsonReader extends Reader {
* @return 有效字符
*/
protected char nextGoodChar(boolean allowComment) {
char[] text0 = this.text;
int end = this.limit;
int curr = ++this.position;
char c = text0[curr];
char c = this.text[++this.position];
if (c > ' ' && c != '/') {
return c;
}
char[] text0 = this.text;
int end = this.limit;
int curr = this.position;
for (; curr <= end; curr++) {
c = text0[curr];
if (c > ' ') {
@@ -419,52 +419,28 @@ public class JsonReader extends Reader {
if (negative) {
throw new ConvertException("illegal escape(" + firstchar + ") (position = " + position + ")");
}
char c = nextChar();
if (c != 'a') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'N') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
if (nextChar() != 'a' || nextChar() != 'N') {
throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")");
}
if (quote) {
c = nextChar();
char c = nextChar();
if (c != '"' && c != '\'') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
}
return 0; // NaN 返回0;
} else if (firstchar == 'I') { // Infinity
char c = nextChar();
if (c != 'n') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'f') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'i') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'n') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'i') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 't') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'y') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
if (nextChar() != 'n'
|| nextChar() != 'f'
|| nextChar() != 'i'
|| nextChar() != 'n'
|| nextChar() != 'i'
|| nextChar() != 't'
|| nextChar() != 'y') {
throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")");
}
if (quote) {
c = nextChar();
char c = nextChar();
if (c != '"' && c != '\'') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
@@ -582,52 +558,28 @@ public class JsonReader extends Reader {
if (negative) {
throw new ConvertException("illegal escape(" + firstchar + ") (position = " + position + ")");
}
char c = nextChar();
if (c != 'a') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'N') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
if (nextChar() != 'a' || nextChar() != 'N') {
throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")");
}
if (quote) {
c = nextChar();
char c = nextChar();
if (c != '"' && c != '\'') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
}
return 0L; // NaN 返回0;
} else if (firstchar == 'I') { // Infinity
char c = nextChar();
if (c != 'n') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'f') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'i') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'n') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'i') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 't') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}
c = nextChar();
if (c != 'y') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
if (nextChar() != 'n'
|| nextChar() != 'f'
|| nextChar() != 'i'
|| nextChar() != 'n'
|| nextChar() != 'i'
|| nextChar() != 't'
|| nextChar() != 'y') {
throw new ConvertException("illegal escape(" + text[position] + ") (position = " + position + ")");
}
if (quote) {
c = nextChar();
char c = nextChar();
if (c != '"' && c != '\'') {
throw new ConvertException("illegal escape(" + c + ") (position = " + position + ")");
}