PlotSquared/src/main/java/com/intellectualcrafters/json/HTTPTokener.java

55 lines
1.3 KiB
Java
Raw Normal View History

2014-11-08 20:27:09 +01:00
package com.intellectualcrafters.json;
/**
2014-12-18 03:15:11 +01:00
* The HTTPTokener extends the JSONTokener to provide additional methods for the parsing of HTTP headers.
2014-11-05 04:42:08 +01:00
*
* @author JSON.org
* @version 2014-05-03
*/
public class HTTPTokener extends JSONTokener {
/**
* Construct an HTTPTokener from a string.
2014-11-05 04:42:08 +01:00
*
2014-12-18 03:15:11 +01:00
* @param string A source string.
*/
2014-11-05 04:42:08 +01:00
public HTTPTokener(final String string) {
super(string);
}
2015-02-23 02:32:27 +01:00
/**
* Get the next token or string. This is used in parsing HTTP headers.
2014-11-05 04:42:08 +01:00
*
* @return A String.
2014-12-18 03:15:11 +01:00
*
2014-11-08 20:27:09 +01:00
* @throws JSONException
*/
public String nextToken() throws JSONException {
char c;
char q;
2014-11-05 04:42:08 +01:00
final StringBuilder sb = new StringBuilder();
do {
c = next();
2014-12-18 03:15:11 +01:00
} while (Character.isWhitespace(c));
2014-11-05 04:42:08 +01:00
if ((c == '"') || (c == '\'')) {
q = c;
2015-02-20 07:34:19 +01:00
for (;;) {
c = next();
if (c < ' ') {
throw syntaxError("Unterminated string.");
}
if (c == q) {
return sb.toString();
}
sb.append(c);
}
}
2015-02-20 07:34:19 +01:00
for (;;) {
2014-11-05 04:42:08 +01:00
if ((c == 0) || Character.isWhitespace(c)) {
return sb.toString();
}
sb.append(c);
c = next();
}
}
}