StandardPlural.fromString(keywordLow),
StandardPlural.fromString(keywordHigh));
- SimplePatternFormatter rangeFormatter = getRangeFormat(getLocale(), formatWidth);
- String formattedNumber = rangeFormatter.format(lowFormatted, highFormatted);
+ String rangeFormatter = getRangeFormat(getLocale(), formatWidth);
+ String formattedNumber = SimplePatternFormatter.formatCompiledPattern(rangeFormatter, lowFormatted, highFormatted);
if (isCurrency) {
// Nasty hack
return values[ordinal];
}
- static final Map<ULocale, SimplePatternFormatter> localeIdToRangeFormat
- = new ConcurrentHashMap<ULocale, SimplePatternFormatter>();
+ private static final Map<ULocale, String> localeIdToRangeFormat =
+ new ConcurrentHashMap<ULocale, String>();
/**
- * Return a simple pattern formatter for a range, such as "{0}–{1}".
+ * Return a formatter (compiled SimplePatternFormatter pattern) for a range, such as "{0}–{1}".
* @param forLocale locale to get the format for
* @param width the format width
* @return range formatter, such as "{0}–{1}"
* @deprecated This API is ICU internal only.
*/
@Deprecated
-
- public static SimplePatternFormatter getRangeFormat(ULocale forLocale, FormatWidth width) {
+ public static String getRangeFormat(ULocale forLocale, FormatWidth width) {
// TODO fix Hack for French
if (forLocale.getLanguage().equals("fr")) {
return getRangeFormat(ULocale.ROOT, width);
}
- SimplePatternFormatter result = localeIdToRangeFormat.get(forLocale);
+ String result = localeIdToRangeFormat.get(forLocale);
if (result == null) {
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
getBundleInstance(ICUData.ICU_BASE_NAME, forLocale);
} catch ( MissingResourceException ex ) {
resultString = rb.getStringWithFallback("NumberElements/latn/patterns/range");
}
- result = SimplePatternFormatter.compileMinMaxPlaceholders(resultString, 2, 2);
+ result = SimplePatternFormatter.compileToStringMinMaxPlaceholders(resultString, new StringBuilder(), 2, 2);
localeIdToRangeFormat.put(forLocale, result);
if (!forLocale.equals(realLocale)) {
localeIdToRangeFormat.put(realLocale, result);
}
return result;
}
-
- /**
- * Return a simple pattern pattern for a range, such as "{0}–{1}" or "{0}~{1}".
- * @param forLocale locale to get the range pattern for
- * @param width the format width.
- * @return range pattern
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- public static String getRangePattern(ULocale forLocale, FormatWidth width) {
- return getRangeFormat(forLocale, width).toString();
- }
}
/*
*******************************************************************************
- * Copyright (C) 2008-2015, International Business Machines Corporation and
+ * Copyright (C) 2008-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
import java.util.Arrays;
import com.ibm.icu.dev.test.TestFmwk;
+import com.ibm.icu.impl.SimplePatternFormatter;
import com.ibm.icu.impl.StandardPlural;
import com.ibm.icu.text.MeasureFormat;
import com.ibm.icu.text.MeasureFormat.FormatWidth;
ULocale ulocale = new ULocale(test[0]);
FormatWidth width = FormatWidth.valueOf(test[1]);
String expected = test[2];
- String actual = MeasureFormat.getRangePattern(ulocale, width);
+ String formatter = MeasureFormat.getRangeFormat(ulocale, width);
+ String actual = SimplePatternFormatter.formatCompiledPattern(formatter, "{0}", "{1}");
assertEquals("range pattern " + Arrays.asList(test), expected, actual);
}
}
-
+
public void TestFormatting() {
Object[][] tests = {
{0.0, 1.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "0–1 degré Fahrenheit"},
/*
*******************************************************************************
- * Copyright (c) 2004-2014, International Business Machines
+ * Copyright (c) 2004-2016, International Business Machines
* Corporation and others. All Rights Reserved.
* Copyright (C) 2010 , Yahoo! Inc.
*******************************************************************************
"IntlTestDecimalFormatAPIC",
"IntlTestDecimalFormatSymbols",
"IntlTestDecimalFormatSymbolsC",
- "PluralRangesTest",
});
}
}