}
}
private Object _parse(Context ctx, Object collection, boolean map) throws IOException {
char c;
StringAppender appender;
while ((c = read()) != 0) {
switch (c) {
case '[':
ctx.addValue(_parse(new Context(), new ArrayList(), false));
break;
case '{':
ctx.addValue(_parse(new Context(), new UHashMap(), true));
break;
case ']':
case '}':
if (map && ctx.encodedType) {
ctx.encodedType = false;
try {
return demarshallAll(ctx.record(collection, decodingContext), decodingContext);
}
catch (Exception e) {
throw new RuntimeException("Could not demarshall object", e);
}
} else {
return ctx.record(collection, decodingContext);
}
case ',':
ctx.record(collection, decodingContext);
break;
case '"':
case '\'':
char term = c;
appender = new StringAppender();
StrCapture:
while ((c = read()) != 0) {
switch (c) {
case '\\':
appender.append(handleEscapeSequence());
break;
case '"':
case '\'':
if (c == term) {
ctx.addValue(appender.toString());
term = 0;
break StrCapture;
}
break;
default:
appender.append(c);
}
}
if (term != 0) {
throw new RuntimeException("unterminated string literal");
}
break;
case ':':
continue;
default:
if (isValidNumberPart(c)) {
ctx.addValue(parseNumber(c));
break;
} else if (Character.isJavaIdentifierPart(c)) {
appender = new StringAppender().append(c);
while (((c = read()) != 0) && Character.isJavaIdentifierPart(c)) {
appender.append(c);
}
String s = appender.toString();
if (s.length() > 4) ctx.addValue(s);
else if ("null".equals(s)) {
ctx.addValue(null);
} else if ("true".equals(s)) {