use of java.text.AttributedCharacterIterator.Attribute in project es6draft by anba.
the class NumberFormatConstructor method PartitionNumberPattern.
/**
* PartitionNumberPattern(numberFormat, x)
*
* @param numberFormatObj
* the number format object
* @param x
* the number value
* @return the formatted number object
*/
private static List<Map.Entry<String, String>> PartitionNumberPattern(NumberFormatObject numberFormat, double x) {
if (x == -0.0) {
// -0 is not considered to be negative, cf. step 3a
x = +0.0;
}
ArrayList<Map.Entry<String, String>> parts = new ArrayList<>();
NumberFormat numFormat = numberFormat.getNumberFormat();
AttributedCharacterIterator iterator = numFormat.formatToCharacterIterator(x);
StringBuilder sb = new StringBuilder();
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
sb.append(ch);
if (iterator.getIndex() + 1 == iterator.getRunLimit()) {
Iterator<Attribute> keyIterator = iterator.getAttributes().keySet().iterator();
String key;
if (keyIterator.hasNext()) {
key = fieldToString((NumberFormat.Field) keyIterator.next(), x);
} else {
key = "literal";
}
String value = sb.toString();
sb.setLength(0);
parts.add(new AbstractMap.SimpleImmutableEntry<>(key, value));
}
}
return parts;
}
Aggregations