in src/main/java/org/apache/commons/beanutils2/converters/ArrayConverter.java [377:433]
private List<String> parseElements(String value) {
if (log().isDebugEnabled()) {
log().debug("Parsing elements, delimiter=[" + delimiter + "], value=[" + value + "]");
}
// Trim any matching '{' and '}' delimiters
value = toTrim(value);
if (value.startsWith("{") && value.endsWith("}")) {
value = value.substring(1, value.length() - 1);
}
final String typeName = toString(String.class);
try {
// Set up a StreamTokenizer on the characters in this String
final StreamTokenizer st = new StreamTokenizer(new StringReader(value));
st.whitespaceChars(delimiter , delimiter); // Set the delimiters
st.ordinaryChars('0', '9'); // Needed to turn off numeric flag
st.wordChars('0', '9'); // Needed to make part of tokens
for (final char allowedChar : allowedChars) {
st.ordinaryChars(allowedChar, allowedChar);
st.wordChars(allowedChar, allowedChar);
}
// Split comma-delimited tokens into a List
List<String> list = null;
while (true) {
final int ttype = st.nextToken();
if (ttype == StreamTokenizer.TT_WORD || ttype > 0) {
if (st.sval != null) {
if (list == null) {
list = new ArrayList<>();
}
list.add(st.sval);
}
} else if (ttype == StreamTokenizer.TT_EOF) {
break;
} else {
throw ConversionException.format("Encountered token of type %s parsing elements to '%s'.", ttype, typeName);
}
}
if (list == null) {
list = Collections.emptyList();
}
if (log().isDebugEnabled()) {
log().debug(list.size() + " elements parsed");
}
// Return the completed list
return list;
} catch (final IOException e) {
throw new ConversionException("Error converting from String to '"
+ typeName + "': " + e.getMessage(), e);
}
}