extend syntax error information

This commit is contained in:
Simulant 2024-03-22 12:02:09 +01:00
parent 45dede448c
commit 30dc22790c

View File

@ -299,7 +299,8 @@ public class JSONTokener {
case 0: case 0:
case '\n': case '\n':
case '\r': case '\r':
throw this.syntaxError("Unterminated string"); throw this.syntaxError("Unterminated string. " +
"Character with int code " + (int) c + " is not allowed within a quoted string.");
case '\\': case '\\':
c = this.next(); c = this.next();
switch (c) { switch (c) {
@ -322,7 +323,7 @@ public class JSONTokener {
try { try {
sb.append((char)Integer.parseInt(this.next(4), 16)); sb.append((char)Integer.parseInt(this.next(4), 16));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw this.syntaxError("Illegal escape.", e); throw this.syntaxError("Illegal escape. \\u must be followed by a 4 digit number.", e);
} }
break; break;
case '"': case '"':
@ -332,7 +333,7 @@ public class JSONTokener {
sb.append(c); sb.append(c);
break; break;
default: default:
throw this.syntaxError("Illegal escape."); throw this.syntaxError("Illegal escape. Escape sequence \\" + c + " is not valid.");
} }
break; break;
default: default:
@ -521,7 +522,7 @@ public class JSONTokener {
*/ */
@Override @Override
public String toString() { public String toString() {
return " at " + this.index + " [character " + this.character + " line " + return " at index: " + this.index + " [character number " + this.character + " in line " +
this.line + "]"; this.line + "]";
} }