* if {@code level} is non-null, or a {@link String} otherwise.
*/
private static Object doFormatUnparsable(String text, final int index, int errorIndex,
final Locale locale, final Level level)
{
final Errors resources = Errors.getResources(locale);
final int length = text.length();
if (errorIndex < index) {
errorIndex = index;
}
if (errorIndex == length) {
if (level != null) {
return resources.getLogRecord(level, ErrorKeys.UNEXPECTED_END_OF_STRING);
}
return resources.getString(ErrorKeys.UNEXPECTED_END_OF_STRING);
}
int upper = errorIndex;
if (upper < length) {
final int type = Character.getType(text.charAt(upper));
while (++upper < length) {
if (Character.getType(text.charAt(upper)) != type) {
break;
}
}
}
final String error = text.substring(errorIndex, upper);
text = text.substring(index);
if (level != null) {
return resources.getLogRecord(level, ErrorKeys.UNPARSABLE_STRING_$2, text, error);
}
return resources.getString(ErrorKeys.UNPARSABLE_STRING_$2, text, error);
}