}
// We do not support parsing Plural formats. (No REPLACE_NUMBER here.)
assert type==Part.Type.ARG_START : "Unexpected Part "+part+" in parsed message.";
int argLimit=msgPattern.getLimitPartIndex(i);
ArgType argType=part.getArgType();
part=msgPattern.getPart(++i);
// Compute the argId, so we can use it as a key.
Object argId=null;
int argNumber = 0;
String key = null;
if(args!=null) {
argNumber=part.getValue(); // ARG_NUMBER
argId = Integer.valueOf(argNumber);
} else {
if(part.getType()==MessagePattern.Part.Type.ARG_NAME) {
key=msgPattern.getSubstring(part);
} else /* ARG_NUMBER */ {
key=Integer.toString(part.getValue());
}
argId = key;
}
++i;
Format formatter = null;
boolean haveArgResult = false;
Object argResult = null;
if(cachedFormatters!=null && (formatter=cachedFormatters.get(i - 2))!=null) {
// Just parse using the formatter.
tempStatus.setIndex(sourceOffset);
argResult = formatter.parseObject(source, tempStatus);
if (tempStatus.getIndex() == sourceOffset) {
pos.setErrorIndex(sourceOffset);
return; // leave index as is to signal error
}
haveArgResult = true;
sourceOffset = tempStatus.getIndex();
} else if(
argType==ArgType.NONE ||
(cachedFormatters!=null && cachedFormatters.containsKey(i - 2))) {
// Match as a string.
// if at end, use longest possible match
// otherwise uses first match to intervening string
// does NOT recursively try all possibilities
String stringAfterArgument = getLiteralStringUntilNextArgument(argLimit);
int next;
if (stringAfterArgument.length() != 0) {
next = source.indexOf(stringAfterArgument, sourceOffset);
} else {
next = source.length();
}
if (next < 0) {
pos.setErrorIndex(sourceOffset);
return; // leave index as is to signal error
} else {
String strValue = source.substring(sourceOffset, next);
if (!strValue.equals("{" + argId.toString() + "}")) {
haveArgResult = true;
argResult = strValue;
}
sourceOffset = next;
}
} else if(argType==ArgType.CHOICE) {
tempStatus.setIndex(sourceOffset);
double choiceResult = parseChoiceArgument(msgPattern, i, source, tempStatus);
if (tempStatus.getIndex() == sourceOffset) {
pos.setErrorIndex(sourceOffset);
return; // leave index as is to signal error
}
argResult = choiceResult;
haveArgResult = true;
sourceOffset = tempStatus.getIndex();
} else if(argType.hasPluralStyle() || argType==ArgType.SELECT) {
// No can do!
throw new UnsupportedOperationException(
"Parsing of plural/select/selectordinal argument is not supported.");
} else {
// This should never happen.