in core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java [5101:5232]
private boolean readBoolValue0(byte type) {
final byte[] bytes = this.bytes;
switch (type) {
case BC_INT32_NUM_1:
return true;
case BC_INT32_NUM_0:
return false;
case BC_NULL:
if ((context.features & Feature.ErrorOnNullForPrimitives.mask) != 0) {
throw new JSONException(info("long value not support input null"));
}
wasNull = true;
return false;
case BC_STR_ASCII_FIX_1:
if (bytes[offset] == '1' || bytes[offset] == 'Y') {
offset++;
return true;
}
if (bytes[offset] == '0' || bytes[offset] == 'N') {
offset++;
return false;
}
case BC_STR_ASCII_FIX_4:
if (bytes[offset] == 't'
&& bytes[offset + 1] == 'r'
&& bytes[offset + 2] == 'u'
&& bytes[offset + 3] == 'e'
) {
offset += 4;
return true;
}
if (bytes[offset] == 'T'
&& bytes[offset + 1] == 'R'
&& bytes[offset + 2] == 'U'
&& bytes[offset + 3] == 'E'
) {
offset += 4;
return true;
}
case BC_STR_ASCII_FIX_5:
if (bytes[offset] == 'f'
&& bytes[offset + 1] == 'a'
&& bytes[offset + 2] == 'l'
&& bytes[offset + 3] == 's'
&& bytes[offset + 4] == 'e'
) {
offset += 5;
return false;
}
if (bytes[offset] == 'F'
&& bytes[offset + 1] == 'A'
&& bytes[offset + 2] == 'L'
&& bytes[offset + 3] == 'S'
&& bytes[offset + 4] == 'E'
) {
offset += 5;
return false;
}
case BC_STR_UTF8:
case BC_STR_ASCII: {
strlen = readLength();
if (strlen == 1) {
if (bytes[offset] == 'Y') {
offset++;
return true;
}
if (bytes[offset] == 'N') {
offset++;
return true;
}
} else if (strlen == 4
&& bytes[offset] == 't'
&& bytes[offset + 1] == 'r'
&& bytes[offset + 2] == 'u'
&& bytes[offset + 3] == 'e'
) {
offset += 4;
return true;
} else if (strlen == 5) {
if (bytes[offset] == 'f'
&& bytes[offset + 1] == 'a'
&& bytes[offset + 2] == 'l'
&& bytes[offset + 3] == 's'
&& bytes[offset + 4] == 'e') {
offset += 5;
return false;
} else if (bytes[offset] == 'F'
&& bytes[offset + 1] == 'A'
&& bytes[offset + 2] == 'L'
&& bytes[offset + 3] == 'S'
&& bytes[offset + 4] == 'E') {
offset += 5;
return false;
}
}
String str = new String(bytes, offset, strlen, ISO_8859_1);
offset += strlen;
throw new JSONException("not support input " + str);
}
case BC_STR_UTF16:
case BC_STR_UTF16BE:
case BC_STR_UTF16LE: {
strlen = readLength();
byte[] chars = new byte[strlen];
System.arraycopy(bytes, offset, chars, 0, strlen);
Charset charset = type == BC_STR_UTF16BE
? StandardCharsets.UTF_16BE
: type == BC_STR_UTF16LE ? StandardCharsets.UTF_16LE : StandardCharsets.UTF_16;
String str = new String(chars, charset);
offset += strlen;
switch (str) {
case "0":
case "N":
case "false":
case "FALSE":
return false;
case "1":
case "Y":
case "true":
case "TRUE":
return true;
default:
throw new JSONException("not support input " + str);
}
}
default:
throw notSupportType(type);
}
}