public void setMonetaryGroupingSeparator(char sep) {
monetaryGroupingSeparator = sep;
}
+
+ /**
+ * Returns the multiplication sign
+ * @draft ICU 54
+ * @provisional
+ */
+ public String getExponentMultiplicationSign() {
+ return exponentMultiplicationSign;
+ }
+
+ /**
+ * Sets the multiplication sign
+ * @draft ICU 54
+ * @provisional
+ */
+ public void setExponentMultiplicationSign(String exponentMultiplicationSign) {
+ this.exponentMultiplicationSign = exponentMultiplicationSign;
+ }
/**
* {@icu} Returns the string used to separate the mantissa from the exponent.
plusString.equals(other.plusString) &&
exponentSeparator.equals(other.exponentSeparator) &&
monetarySeparator == other.monetarySeparator &&
- monetaryGroupingSeparator == other.monetaryGroupingSeparator);
+ monetaryGroupingSeparator == other.monetaryGroupingSeparator &&
+ exponentMultiplicationSign.equals(other.exponentMultiplicationSign));
}
/**
boolean isLatn = nsName.equals("latn");
String baseKey = "NumberElements/" + nsName + "/symbols/";
String latnKey = "NumberElements/latn/symbols/";
- String[] symbolKeys = { "decimal", "group", "list", "percentSign", "minusSign", "plusSign", "exponential", "perMille", "infinity", "nan", "currencyDecimal", "currencyGroup" };
+ String[] symbolKeys = { "decimal", "group", "list", "percentSign", "minusSign", "plusSign", "exponential", "perMille", "infinity", "nan", "currencyDecimal", "currencyGroup", "superscriptingExponent" };
String[] fallbackElements = { ".", ",", ";", "%", "-", "+", "E", "\u2030", "\u221e", "NaN", null, null };
String[] symbolsArray = new String[symbolKeys.length];
for ( int i = 0 ; i < symbolKeys.length; i++ ) {
monetaryGroupingSeparator = groupingSeparator;
}
+ if ( numberElements[12] != null) {
+ exponentMultiplicationSign = numberElements[12];
+ } else {
+ exponentMultiplicationSign = "\u00D7";
+ }
+
digit = DecimalFormat.PATTERN_DIGIT; // Localized pattern character no longer in CLDR
padEscape = DecimalFormat.PATTERN_PAD_ESCAPE;
sigDigit = DecimalFormat.PATTERN_SIGNIFICANT_DIGIT;
plusString = new String(plusArray);
}
}
+ if (serialVersionOnStream < 8) {
+ if (exponentMultiplicationSign == null) {
+ exponentMultiplicationSign = "\u00D7";
+ }
+ }
serialVersionOnStream = currentSerialVersion;
// recreate
*/
private String minusString = null;
private String plusString = null;
+
+ /**
+ * Exponent multiplication sign. e.g "x"
+ * @serial
+ * @since ICU 54
+ */
+ private String exponentMultiplicationSign = null;
// Proclaim JDK 1.1 FCS compatibility
private static final long serialVersionUID = 5772796243397350300L;
// - 5 for ICU 3.6, which includes the monetaryGroupingSeparator field
// - 6 for ICU 4.2, which includes the currencySpc* fields
// - 7 for ICU 52, which includes the minusString and plusString fields
- private static final int currentSerialVersion = 7;
+ // - 8 for ICU 54, which includes exponentMultiplicationSign field.
+ private static final int currentSerialVersion = 8;
/**
* Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
}
private static String getMultiplicationSymbol(DecimalFormatSymbols dfs) {
- //TODO: revisit this
- return "\u00d7";
+ return dfs.getExponentMultiplicationSign();
}
/**
CharSequence endMarkup) {
int copyFromOffset = 0;
StringBuilder result = new StringBuilder();
+ boolean exponentSymbolFieldPresent = false;
+ boolean exponentFieldPresent = false;
for (
iterator.first();
iterator.current() != CharacterIterator.DONE;
) {
Map<Attribute, Object> attributeSet = iterator.getAttributes();
if (attributeSet.containsKey(NumberFormat.Field.EXPONENT_SYMBOL)) {
+ exponentSymbolFieldPresent = true;
append(
iterator,
copyFromOffset,
result.append(preExponent);
result.append(beginMarkup);
} else if (attributeSet.containsKey(NumberFormat.Field.EXPONENT)) {
+ exponentFieldPresent = true;
int limit = iterator.getRunLimit(NumberFormat.Field.EXPONENT);
append(
iterator,
} else {
iterator.next();
}
- }
+ }
+ if (!exponentSymbolFieldPresent || !exponentFieldPresent) {
+ throw new IllegalArgumentException("Must start with standard e notation.");
+ }
append(iterator, copyFromOffset, iterator.getEndIndex(), result);
return result.toString();
}
public String toSuperscriptExponentDigits(AttributedCharacterIterator iterator) {
int copyFromOffset = 0;
StringBuilder result = new StringBuilder();
+ boolean exponentSymbolFieldPresent = false;
+ boolean exponentFieldPresent = false;
for (
iterator.first();
iterator.current() != CharacterIterator.DONE;
) {
Map<Attribute, Object> attributeSet = iterator.getAttributes();
if (attributeSet.containsKey(NumberFormat.Field.EXPONENT_SYMBOL)) {
+ exponentSymbolFieldPresent = true;
append(
iterator,
copyFromOffset,
copyFromOffset = limit;
iterator.setIndex(copyFromOffset);
} else if (attributeSet.containsKey(NumberFormat.Field.EXPONENT)) {
+ exponentFieldPresent = true;
int start = iterator.getRunStart(NumberFormat.Field.EXPONENT);
int limit = iterator.getRunLimit(NumberFormat.Field.EXPONENT);
append(
iterator.next();
}
}
+ if (!exponentSymbolFieldPresent || !exponentFieldPresent) {
+ throw new IllegalArgumentException("Must start with standard e notation.");
+ }
append(iterator, copyFromOffset, iterator.getEndIndex(), result);
return result.toString();
}
"1.23456\u00d710\u207b\u2077\u2078",
helper.toSuperscriptExponentDigits(iterator));
}
+
+ public void TestPlusSignInExponentMarkup() {
+ ULocale en = new ULocale("en");
+ DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(en);
+ decfmt.applyPattern("0.00E+0");
+ AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(6.02e23);
+ ScientificFormatHelper helper = ScientificFormatHelper.getInstance(
+ decfmt.getDecimalFormatSymbols());
+ assertEquals(
+ "",
+ "6.02\u00d710<sup>+23</sup>",
+ helper.insertMarkup(iterator, "<sup>", "</sup>"));
+ }
+
- public void TestPlusSignInExponent() {
+ public void TestPlusSignInExponentSuperscript() {
ULocale en = new ULocale("en");
DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(en);
decfmt.applyPattern("0.00E+0");
"6.02\u00d710\u207a\u00b2\u00b3",
helper.toSuperscriptExponentDigits(iterator));
}
+
+ public void TestFixedDecimalMarkup() {
+ ULocale en = new ULocale("en");
+ DecimalFormat decfmt = (DecimalFormat) NumberFormat.getInstance(en);
+ AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(123456.0);
+ ScientificFormatHelper helper = ScientificFormatHelper.getInstance(
+ decfmt.getDecimalFormatSymbols());
+ try {
+ helper.insertMarkup(iterator, "<sup>", "</sup>");
+ fail("expected illegal argument exception");
+ } catch (IllegalArgumentException expected) {
+ // do nothing
+ }
+ }
+
+ public void TestFixedDecimalSuperscript() {
+ ULocale en = new ULocale("en");
+ DecimalFormat decfmt = (DecimalFormat) NumberFormat.getInstance(en);
+ AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(123456.0);
+ ScientificFormatHelper helper = ScientificFormatHelper.getInstance(
+ decfmt.getDecimalFormatSymbols());
+ try {
+ helper.toSuperscriptExponentDigits(iterator);
+ fail("expected illegal argument exception");
+ } catch (IllegalArgumentException expected) {
+ // do nothing
+ }
+ }
}
/*
*******************************************************************************
- * Copyright (C) 2008-2012, International Business Machines Corporation and *
+ * Copyright (C) 2008-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
decfs.setPercent(decfsEnUS.getPercent());
decfs.setPerMill(decfsEnUS.getPerMill());
decfs.setZeroDigit(decfsEnUS.getZeroDigit());
+ decfs.setExponentMultiplicationSign(decfsEnUS.getExponentMultiplicationSign());
// Check
Currency cur = decfs.getCurrency();
checkEquivalence(decfs.getPercent(), decfsEnUS.getPercent(), loc, "getPercent");
checkEquivalence(decfs.getPerMill(), decfsEnUS.getPerMill(), loc, "getPerMill");
checkEquivalence(decfs.getZeroDigit(), decfsEnUS.getZeroDigit(), loc, "getZeroDigit");
+ checkEquivalence(decfs.getExponentMultiplicationSign(), decfsEnUS.getExponentMultiplicationSign(), loc, "getExponentMultiplicationSign");
}
public void TestKeywords() {