json
This commit is contained in:
@@ -162,7 +162,7 @@ public class JsonReader extends Reader {
|
|||||||
*/
|
*/
|
||||||
protected char nextChar() {
|
protected char nextChar() {
|
||||||
int p = ++this.position;
|
int p = ++this.position;
|
||||||
if (p >= text.length) {
|
if (p >= limit) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return this.text[p];
|
return this.text[p];
|
||||||
@@ -818,38 +818,38 @@ public class JsonReader extends Reader {
|
|||||||
}
|
}
|
||||||
char ch = nextGoodChar(true); // 需要跳过注释
|
char ch = nextGoodChar(true); // 需要跳过注释
|
||||||
final char[] text0 = this.text;
|
final char[] text0 = this.text;
|
||||||
int currpos = this.position;
|
int curr = this.position;
|
||||||
if (ch == '"' || ch == '\'') {
|
if (ch == '"' || ch == '\'') {
|
||||||
final char quote = ch;
|
final char quote = ch;
|
||||||
final int start = currpos + 1;
|
final int start = curr + 1;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
ch = text0[++currpos];
|
ch = text0[++curr];
|
||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
this.position = currpos - 1;
|
this.position = curr - 1;
|
||||||
return readEscapeValue(quote, start);
|
return readEscapeValue(quote, start);
|
||||||
} else if (ch == quote) {
|
} else if (ch == quote) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
return new String(text0, start, currpos - start);
|
return new String(text0, start, curr - start);
|
||||||
} else {
|
} else {
|
||||||
int start = currpos;
|
int start = curr;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
if (currpos == eof) {
|
if (curr == eof) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ch = text0[++currpos];
|
ch = text0[++curr];
|
||||||
if (ch == ',' || ch == ']' || ch == '}' || ch <= ' ' || ch == ':') {
|
if (ch == ',' || ch == ']' || ch == '}' || ch <= ' ' || ch == ':') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int len = currpos - start;
|
int len = curr - start;
|
||||||
if (len < 1) {
|
if (len < 1) {
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
return String.valueOf(ch);
|
return String.valueOf(ch);
|
||||||
}
|
}
|
||||||
this.position = currpos - 1;
|
this.position = curr - 1;
|
||||||
if (len == 4
|
if (len == 4
|
||||||
&& text0[start] == 'n'
|
&& text0[start] == 'n'
|
||||||
&& text0[start + 1] == 'u'
|
&& text0[start + 1] == 'u'
|
||||||
@@ -878,75 +878,76 @@ public class JsonReader extends Reader {
|
|||||||
protected String readString(boolean flag) {
|
protected String readString(boolean flag) {
|
||||||
final char[] text0 = this.text;
|
final char[] text0 = this.text;
|
||||||
char expected = nextGoodChar(true);
|
char expected = nextGoodChar(true);
|
||||||
int currpos = this.position;
|
int curr = this.position;
|
||||||
if (expected != '"' && expected != '\'') {
|
if (expected != '"' && expected != '\'') {
|
||||||
if (expected == 'n'
|
if (expected == 'n'
|
||||||
&& text0.length > currpos + 3
|
&& text0.length > curr + 3
|
||||||
&& (text0[1 + currpos] == 'u' && text0[2 + currpos] == 'l' && text0[3 + currpos] == 'l')) {
|
&& (text0[1 + curr] == 'u' && text0[2 + curr] == 'l' && text0[3 + curr] == 'l')) {
|
||||||
if (text0[++currpos] == 'u' && text0[++currpos] == 'l' && text0[++currpos] == 'l') {
|
if (text0[++curr] == 'u' && text0[++curr] == 'l' && text0[++curr] == 'l') {
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
if (text0.length > currpos + 4) {
|
if (text0.length > curr + 4) {
|
||||||
char ch = text0[currpos + 1];
|
char ch = text0[curr + 1];
|
||||||
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final int start = currpos - 3;
|
final int start = curr - 3;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
if (currpos >= text0.length) {
|
if (curr >= text0.length) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ch = text0[currpos];
|
ch = text0[curr];
|
||||||
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currpos++;
|
curr++;
|
||||||
}
|
}
|
||||||
if (currpos == start) {
|
if (curr == start) {
|
||||||
throw new ConvertException("expected a string after a key but '" + text0[position]
|
throw new ConvertException("expected a string after a key but '" + text0[position]
|
||||||
+ "' (position = " + position + ") in (" + new String(this.text) + ")");
|
+ "' (position = " + position + ") in " + new String(this.text));
|
||||||
}
|
}
|
||||||
this.position = currpos - 1;
|
this.position = curr - 1;
|
||||||
return new String(text0, start, currpos - start);
|
return new String(text0, start, curr - start);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final int start = currpos;
|
final int start = curr;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
if (currpos >= text0.length) {
|
if (curr >= text0.length) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char ch = text0[currpos];
|
char ch = text0[curr];
|
||||||
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
if (ch == ',' || ch <= ' ' || ch == '}' || ch == ']' || (flag && ch == ':')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currpos++;
|
curr++;
|
||||||
}
|
}
|
||||||
if (currpos == start) {
|
if (curr == start) {
|
||||||
throw new ConvertException("expected a string after a key but '" + text0[position]
|
throw new ConvertException("expected a string after a key but '" + text0[position]
|
||||||
+ "' (position = " + position + ") in (" + new String(this.text) + ")");
|
+ "' (position = " + position + ") in " + new String(this.text));
|
||||||
}
|
}
|
||||||
this.position = currpos - 1;
|
this.position = curr - 1;
|
||||||
return new String(text0, start, currpos - start);
|
return new String(text0, start, curr - start);
|
||||||
}
|
}
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
throw new ConvertException("expected a ':' after a key but '" + text0[position] + "' (position = "
|
throw new ConvertException("expected a ':' after a key but '" + text0[position] + "' (position = "
|
||||||
+ position + ") in (" + new String(this.text) + ")");
|
+ position + ") in " + new String(this.text));
|
||||||
}
|
}
|
||||||
final int start = ++currpos;
|
final int start = ++curr;
|
||||||
|
int end = limit;
|
||||||
CharArray array = null;
|
CharArray array = null;
|
||||||
char c;
|
char c;
|
||||||
for (; ; ) {
|
for (; curr <= end; curr++) {
|
||||||
char ch = text0[currpos];
|
char ch = text0[curr];
|
||||||
if (ch == expected) {
|
if (ch == expected) {
|
||||||
break;
|
break;
|
||||||
} else if (ch == '\\') {
|
} else if (ch == '\\') {
|
||||||
if (array == null) {
|
if (array == null) {
|
||||||
array = array();
|
array = array();
|
||||||
array.append(text0, start, currpos - start);
|
array.append(text0, start, curr - start);
|
||||||
}
|
}
|
||||||
c = text0[++currpos];
|
c = text0[++curr];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
@@ -962,9 +963,7 @@ public class JsonReader extends Reader {
|
|||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
array.append((char) Integer.parseInt(
|
array.append((char) Integer.parseInt(
|
||||||
new String(new char[] {
|
new String(new char[] {text0[++curr], text0[++curr], text0[++curr], text0[++curr]}),
|
||||||
text0[++currpos], text0[++currpos], text0[++currpos], text0[++currpos]
|
|
||||||
}),
|
|
||||||
16));
|
16));
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
@@ -977,32 +976,31 @@ public class JsonReader extends Reader {
|
|||||||
array.append('\f');
|
array.append('\f');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
throw new ConvertException("illegal escape(" + c + ") (position = " + this.position + ") in ("
|
throw new ConvertException("illegal escape(" + c + ") (position = " + this.position + ") in "
|
||||||
+ new String(this.text) + ")");
|
+ new String(this.text));
|
||||||
}
|
}
|
||||||
} else if (array != null) {
|
} else if (array != null) {
|
||||||
array.append(ch);
|
array.append(ch);
|
||||||
}
|
}
|
||||||
currpos++;
|
|
||||||
}
|
}
|
||||||
this.position = currpos;
|
this.position = curr;
|
||||||
return array != null ? array.toStringThenClear() : new String(text0, start, currpos - start);
|
return array != null ? array.toStringThenClear() : new String(text0, start, curr - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readEscapeValue(final char expected, int start) {
|
private String readEscapeValue(final char expected, int start) {
|
||||||
CharArray array = this.array();
|
CharArray array = this.array();
|
||||||
final char[] text0 = this.text;
|
final char[] text0 = this.text;
|
||||||
int pos = this.position;
|
int curr = this.position;
|
||||||
array.append(text0, start, pos + 1 - start);
|
array.append(text0, start, curr + 1 - start);
|
||||||
char c;
|
char c;
|
||||||
for (; ; ) {
|
for (; ; ) {
|
||||||
c = text0[++pos];
|
c = text0[++curr];
|
||||||
if (c == expected) {
|
if (c == expected) {
|
||||||
this.position = pos;
|
this.position = curr;
|
||||||
return array.toStringThenClear();
|
return array.toStringThenClear();
|
||||||
} else if (c == '\\') {
|
} else if (c == '\\') {
|
||||||
c = text0[++pos];
|
c = text0[++curr];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
@@ -1018,7 +1016,8 @@ public class JsonReader extends Reader {
|
|||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
array.append((char) Integer.parseInt(
|
array.append((char) Integer.parseInt(
|
||||||
new String(new char[] {text0[++pos], text0[++pos], text0[++pos], text0[++pos]}), 16));
|
new String(new char[] {text0[++curr], text0[++curr], text0[++curr], text0[++curr]}),
|
||||||
|
16));
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
array.append('\t');
|
array.append('\t');
|
||||||
@@ -1030,9 +1029,9 @@ public class JsonReader extends Reader {
|
|||||||
array.append('\f');
|
array.append('\f');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.position = pos;
|
this.position = curr;
|
||||||
throw new ConvertException("illegal escape(" + c + ") (position = " + this.position + ") in ("
|
throw new ConvertException("illegal escape(" + c + ") (position = " + this.position + ") in "
|
||||||
+ new String(this.text) + ")");
|
+ new String(this.text));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
array.append(c);
|
array.append(c);
|
||||||
|
|||||||
Reference in New Issue
Block a user