in core/src/main/java/com/alibaba/fastjson2/JSONPathSegmentName.java [447:697]
public void accept(JSONReader jsonReader, JSONPath.Context context) {
if (context.parent != null
&& (context.parent.eval
|| context.parent.current instanceof JSONPathFilter
|| context.parent.current instanceof MultiIndexSegment)
) {
eval(context);
return;
}
if (jsonReader.jsonb) {
if (jsonReader.nextIfObjectStart()) {
for (int i = 0; ; ++i) {
if (jsonReader.nextIfObjectEnd()) {
break;
}
long nameHashCode = jsonReader.readFieldNameHashCode();
if (nameHashCode == 0) {
continue;
}
boolean match = nameHashCode == this.nameHashCode;
if (!match) {
jsonReader.skipValue();
continue;
}
if (jsonReader.isArray() || jsonReader.isObject()) {
if (context.next != null) {
break;
}
}
context.value = jsonReader.readAny();
context.eval = true;
break;
}
return;
} else if (jsonReader.isArray()
&& context.parent != null
&& context.parent.current instanceof AllSegment) {
List values = new JSONArray();
int itemCnt = jsonReader.startArray();
for (int i = 0; i < itemCnt; i++) {
if (jsonReader.nextIfMatch(BC_OBJECT)) {
for (int j = 0; ; j++) {
if (jsonReader.nextIfMatch(BC_OBJECT_END)) {
break;
}
long nameHashCode = jsonReader.readFieldNameHashCode();
boolean match = nameHashCode == this.nameHashCode;
if (!match) {
jsonReader.skipValue();
continue;
}
if (jsonReader.isArray() || jsonReader.isObject()) {
if (context.next != null) {
break;
}
}
values.add(jsonReader.readAny());
}
} else {
jsonReader.skipValue();
}
}
context.value = values;
context.eval = true;
return;
}
throw new JSONException("TODO");
}
if (jsonReader.nextIfObjectStart()) {
if (jsonReader.ch == '}') {
jsonReader.next();
if (jsonReader.isEnd()) {
return;
}
jsonReader.nextIfComma();
// return object;
}
_for:
for (; ; ) {
if (jsonReader.nextIfObjectEnd()) {
jsonReader.next();
break;
}
long nameHashCode = jsonReader.readFieldNameHashCode();
boolean match = nameHashCode == this.nameHashCode;
if (!match) {
jsonReader.skipValue();
if (jsonReader.ch == ',') {
jsonReader.next();
}
continue;
}
Object val;
switch (jsonReader.ch) {
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
jsonReader.readNumber0();
val = jsonReader.getNumber();
break;
case '[':
if (context.next != null && !(context.next instanceof EvalSegment)
&& !(context.next instanceof JSONPathSegmentName)
&& !(context.next instanceof AllSegment)) {
break _for;
}
val = jsonReader.readArray();
context.eval = true;
break;
case '{':
if (context.next != null
&& !(context.next instanceof EvalSegment)
&& !(context.next instanceof AllSegment)) {
break _for;
}
val = jsonReader.readObject();
context.eval = true;
break;
case '"':
case '\'':
val = jsonReader.readString();
break;
case 't':
case 'f':
val = jsonReader.readBoolValue();
break;
case 'n':
jsonReader.readNull();
val = null;
break;
default:
throw new JSONException("TODO : " + jsonReader.ch);
}
context.value = val;
break;
}
} else if (jsonReader.ch == '[' && context.parent != null && context.parent.current instanceof AllSegment) {
jsonReader.next();
List values = new JSONArray();
while (jsonReader.ch != EOI) {
if (jsonReader.ch == ']') {
jsonReader.next();
break;
}
if (jsonReader.ch == '{') {
jsonReader.next();
_for:
for (; ; ) {
if (jsonReader.ch == '}') {
jsonReader.next();
break;
}
long nameHashCode = jsonReader.readFieldNameHashCode();
boolean match = nameHashCode == this.nameHashCode;
if (!match) {
jsonReader.skipValue();
if (jsonReader.ch == ',') {
jsonReader.next();
}
continue;
}
Object val;
switch (jsonReader.ch) {
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
jsonReader.readNumber0();
val = jsonReader.getNumber();
break;
case '[':
if (context.next != null) {
break _for;
}
val = jsonReader.readArray();
break;
case '{':
if (context.next != null) {
break _for;
}
val = jsonReader.readObject();
break;
case '"':
case '\'':
val = jsonReader.readString();
break;
case 't':
case 'f':
val = jsonReader.readBoolValue();
break;
case 'n':
jsonReader.readNull();
val = null;
break;
default:
throw new JSONException("TODO : " + jsonReader.ch);
}
values.add(val);
}
} else {
jsonReader.skipValue();
}
if (jsonReader.ch == ',') {
jsonReader.next();
}
}
context.value = values;
}/* else if (jsonReader.ch == JSONReader.EOI) {
return;
}*/
}