*/
private Appendable decodeString(final boolean quoted, final Appendable sb) {
int index = _index;
int c1 = _bytes[index++] & 0xFF;
if (c1 != TYPE_STRING) {
throw new ConversionException("Invalid String lead-in byte (" + c1 + ") at position " + (index - 1)
+ " in key");
}
while ((c1 = _bytes[index++] & 0xFF) != 0 && index <= _size) {
char c = 0;
// Handle encoded NUL and SOH bytes
if (c1 == 0x01) {
final int c2 = _bytes[index++] & 0xFF;
if (c2 >= 0x0020 && c2 <= 0x0021) {
c = (char) (c2 - 0x0020);
} else {
throw new ConversionException("String decoding exception at position " + (index - 1));
}
}
// 7-bit ASCII
else if (c1 <= 0x7F) {
c = (char) c1;
}
else if (c1 > 0xC0 && c1 <= 0xDF) {
final int c2 = _bytes[index++] & 0xFF;
if (c2 >= 0x80 && c2 <= 0xBF) {
c = (char) (((c1 & 0x1F) << 6) | ((c2 & 0x3F) << 0));
} else {
throw new ConversionException("String decoding exception at position " + (index - 1));
}
} else if (c1 >= 0xE0 && c1 <= 0xEF) {
final int c2 = _bytes[index++] & 0xFF;
final int c3 = _bytes[index++] & 0xFF;
if (c2 >= 0x80 && c2 <= 0xBF && c3 >= 0x80 && c3 <= 0xBF) {
c = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | ((c3 & 0x3F) << 0));
}
} else {
throw new ConversionException("String decoding exception at position " + (index - 1));
}
if (quoted) {
Util.appendQuotedChar(sb, c);
} else {
Util.append(sb, c);