json
This commit is contained in:
@@ -476,50 +476,76 @@ public class JsonReader extends Reader {
|
|||||||
int end = this.limit;
|
int end = this.limit;
|
||||||
char[] text0 = this.text;
|
char[] text0 = this.text;
|
||||||
char ch;
|
char ch;
|
||||||
boolean hex = false;
|
|
||||||
boolean dot = false;
|
boolean dot = false;
|
||||||
for (; curr <= end; curr++) {
|
if (value > 0) { // 十进制
|
||||||
ch = text0[curr];
|
for (; curr <= end; curr++) {
|
||||||
if (ch >= '0' && ch <= '9') {
|
ch = text0[curr];
|
||||||
if (dot) {
|
if (ch >= '0' && ch <= '9') {
|
||||||
continue;
|
if (dot) {
|
||||||
}
|
continue;
|
||||||
value = (hex ? (value << 4) : ((value << 3) + (value << 1))) + digits[ch];
|
}
|
||||||
} else if (ch == '"' || ch == '\'') {
|
value = (value << 3) + (value << 1) + digits[ch];
|
||||||
if (quote) {
|
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
||||||
|
curr--;
|
||||||
break;
|
break;
|
||||||
}
|
} else if (ch == '"' || ch == '\'') {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
if (quote) {
|
||||||
} else if (ch == 'x' || ch == 'X') {
|
break;
|
||||||
if (value != 0) {
|
}
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
} else if (quote && ch <= ' ') {
|
||||||
|
// do nothing
|
||||||
|
} else if (ch == '.') {
|
||||||
|
dot = true;
|
||||||
|
} else {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
}
|
}
|
||||||
hex = true;
|
}
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else {
|
||||||
if (!hex) {
|
boolean hex = false;
|
||||||
|
for (; curr <= end; curr++) {
|
||||||
|
ch = text0[curr];
|
||||||
|
if (ch >= '0' && ch <= '9') {
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (hex ? (value << 4) : ((value << 3) + (value << 1))) + digits[ch];
|
||||||
|
} else if (ch == '"' || ch == '\'') {
|
||||||
|
if (quote) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
} else if (ch == 'x' || ch == 'X') {
|
||||||
|
if (value != 0) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
hex = true;
|
||||||
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
|
if (!hex) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (value << 4) + digits[ch];
|
||||||
|
} else if (ch >= 'A' && ch <= 'F') {
|
||||||
|
if (!hex) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (value << 4) + digits[ch];
|
||||||
|
} else if (quote && ch <= ' ') {
|
||||||
|
// do nothing
|
||||||
|
} else if (ch == '.') {
|
||||||
|
dot = true;
|
||||||
|
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
||||||
|
curr--;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
}
|
}
|
||||||
if (dot) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
value = (value << 4) + digits[ch];
|
|
||||||
} else if (ch >= 'A' && ch <= 'F') {
|
|
||||||
if (!hex) {
|
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
|
||||||
}
|
|
||||||
if (dot) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
value = (value << 4) + digits[ch];
|
|
||||||
} else if (quote && ch <= ' ') {
|
|
||||||
// do nothing
|
|
||||||
} else if (ch == '.') {
|
|
||||||
dot = true;
|
|
||||||
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
|
||||||
curr--;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
@@ -613,50 +639,76 @@ public class JsonReader extends Reader {
|
|||||||
int end = this.limit;
|
int end = this.limit;
|
||||||
char[] text0 = this.text;
|
char[] text0 = this.text;
|
||||||
char ch;
|
char ch;
|
||||||
boolean hex = false;
|
|
||||||
boolean dot = false;
|
boolean dot = false;
|
||||||
for (; curr <= end; curr++) {
|
if (value > 0) { // 十进制
|
||||||
ch = text0[curr];
|
for (; curr <= end; curr++) {
|
||||||
if (ch >= '0' && ch <= '9') {
|
ch = text0[curr];
|
||||||
if (dot) {
|
if (ch >= '0' && ch <= '9') {
|
||||||
continue;
|
if (dot) {
|
||||||
}
|
continue;
|
||||||
value = (hex ? (value << 4) : ((value << 3) + (value << 1))) + digits[ch];
|
}
|
||||||
} else if (ch == '"' || ch == '\'') {
|
value = (value << 3) + (value << 1) + digits[ch];
|
||||||
if (quote) {
|
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
||||||
|
curr--;
|
||||||
break;
|
break;
|
||||||
}
|
} else if (ch == '"' || ch == '\'') {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
if (quote) {
|
||||||
} else if (ch == 'x' || ch == 'X') {
|
break;
|
||||||
if (value != 0) {
|
}
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
} else if (quote && ch <= ' ') {
|
||||||
|
// do nothing
|
||||||
|
} else if (ch == '.') {
|
||||||
|
dot = true;
|
||||||
|
} else {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
}
|
}
|
||||||
hex = true;
|
}
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else {
|
||||||
if (!hex) {
|
boolean hex = false;
|
||||||
|
for (; curr <= end; curr++) {
|
||||||
|
ch = text0[curr];
|
||||||
|
if (ch >= '0' && ch <= '9') {
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (hex ? (value << 4) : ((value << 3) + (value << 1))) + digits[ch];
|
||||||
|
} else if (ch == '"' || ch == '\'') {
|
||||||
|
if (quote) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
} else if (ch == 'x' || ch == 'X') {
|
||||||
|
if (value != 0) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
hex = true;
|
||||||
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
|
if (!hex) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (value << 4) + digits[ch];
|
||||||
|
} else if (ch >= 'A' && ch <= 'F') {
|
||||||
|
if (!hex) {
|
||||||
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
|
}
|
||||||
|
if (dot) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value = (value << 4) + digits[ch];
|
||||||
|
} else if (quote && ch <= ' ') {
|
||||||
|
// do nothing
|
||||||
|
} else if (ch == '.') {
|
||||||
|
dot = true;
|
||||||
|
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
||||||
|
curr--;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
||||||
}
|
}
|
||||||
if (dot) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
value = (value << 4) + digits[ch];
|
|
||||||
} else if (ch >= 'A' && ch <= 'F') {
|
|
||||||
if (!hex) {
|
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
|
||||||
}
|
|
||||||
if (dot) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
value = (value << 4) + digits[ch];
|
|
||||||
} else if (quote && ch <= ' ') {
|
|
||||||
// do nothing
|
|
||||||
} else if (ch == '.') {
|
|
||||||
dot = true;
|
|
||||||
} else if (ch == ',' || ch == '}' || ch == ']' || ch <= ' ' || ch == ':') {
|
|
||||||
curr--;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
throw new ConvertException("illegal escape(" + ch + ") (position = " + position + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
@@ -679,17 +731,17 @@ public class JsonReader extends Reader {
|
|||||||
int curr = this.position;
|
int curr = this.position;
|
||||||
if (ch == '"' || ch == '\'') {
|
if (ch == '"' || ch == '\'') {
|
||||||
final char quote = ch;
|
final char quote = ch;
|
||||||
for (; ; ) {
|
while ((ch = text0[++curr]) != quote) {
|
||||||
ch = text0[++curr];
|
if (node != null) {
|
||||||
if (ch == quote) {
|
node = node.getNode(ch);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
node = node == null ? null : node.getNode(ch);
|
|
||||||
}
|
}
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
return node == null ? null : node.getValue();
|
return node == null ? null : node.getValue();
|
||||||
} else {
|
} else {
|
||||||
node = node == null ? null : node.getNode(ch);
|
if (node != null) {
|
||||||
|
node = node.getNode(ch);
|
||||||
|
}
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
if (curr == eof) {
|
if (curr == eof) {
|
||||||
break;
|
break;
|
||||||
@@ -699,7 +751,9 @@ public class JsonReader extends Reader {
|
|||||||
curr--;
|
curr--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
node = node == null ? null : node.getNode(ch);
|
if (node != null) {
|
||||||
|
node = node.getNode(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
return node == null ? null : node.getValue();
|
return node == null ? null : node.getValue();
|
||||||
@@ -973,16 +1027,16 @@ public class JsonReader extends Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String readEscapeValue(final char expected, int start) {
|
private String readEscapeValue(final char expected, int start) {
|
||||||
CharArray array = this.array();
|
CharArray tmp = this.array();
|
||||||
final char[] text0 = this.text;
|
final char[] text0 = this.text;
|
||||||
int curr = this.position;
|
int curr = this.position;
|
||||||
array.append(text0, start, curr + 1 - start);
|
tmp.append(text0, start, curr + 1 - start);
|
||||||
char c;
|
char c;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
c = text0[++curr];
|
c = text0[++curr];
|
||||||
if (c == expected) {
|
if (c == expected) {
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
return array.toStringThenClear();
|
return tmp.toStringThenClear();
|
||||||
} else if (c == '\\') {
|
} else if (c == '\\') {
|
||||||
c = text0[++curr];
|
c = text0[++curr];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -990,27 +1044,29 @@ public class JsonReader extends Reader {
|
|||||||
case '\'':
|
case '\'':
|
||||||
case '\\':
|
case '\\':
|
||||||
case '/':
|
case '/':
|
||||||
array.append(c);
|
tmp.append(c);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
array.append('\n');
|
tmp.append('\n');
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
array.append('\r');
|
tmp.append('\r');
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
array.append((char) Integer.parseInt(
|
int hex = (Character.digit(text0[++curr], 16) << 12)
|
||||||
new String(new char[] {text0[++curr], text0[++curr], text0[++curr], text0[++curr]}),
|
+ (Character.digit(text0[++curr], 16) << 8)
|
||||||
16));
|
+ (Character.digit(text0[++curr], 16) << 4)
|
||||||
|
+ Character.digit(text0[++curr], 16);
|
||||||
|
tmp.append((char) hex);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
array.append('\t');
|
tmp.append('\t');
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
array.append('\b');
|
tmp.append('\b');
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
array.append('\f');
|
tmp.append('\f');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.position = curr;
|
this.position = curr;
|
||||||
@@ -1018,7 +1074,7 @@ public class JsonReader extends Reader {
|
|||||||
+ new String(this.text));
|
+ new String(this.text));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
array.append(c);
|
tmp.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1039,7 +1095,7 @@ public class JsonReader extends Reader {
|
|||||||
digits[i] = i - 'A' + 10;
|
digits[i] = i - 'A' + 10;
|
||||||
}
|
}
|
||||||
digits['"'] = digits['\''] = -2; // -2 跳过
|
digits['"'] = digits['\''] = -2; // -2 跳过
|
||||||
digits[' '] = digits['\t'] = digits['\r'] = digits['\n'] = -3; // -3可能跳过
|
digits[' '] = digits['\t'] = digits['\b'] = digits['\f'] = digits['\r'] = digits['\n'] = -3; // -3可能跳过
|
||||||
digits[','] = digits['}'] = digits[']'] = digits[':'] = -4; // -4退出
|
digits[','] = digits['}'] = digits[']'] = digits[':'] = -4; // -4退出
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user