/*
**************************************************************************
- * Copyright (C) 2008-2011, Google, International Business Machines
+ * Copyright (C) 2008-2012, Google, International Business Machines
* Corporation and others. All Rights Reserved.
**************************************************************************
*/
pluralRules = PluralRules.forLocale(locale);
timeUnitToCountToPatterns = new HashMap<TimeUnit, Map<String, Object[]>>();
- setup("units", timeUnitToCountToPatterns, FULL_NAME);
- setup("unitsShort", timeUnitToCountToPatterns, ABBREVIATED_NAME);
+ Set<String> pluralKeywords = pluralRules.getKeywords();
+ setup("units", timeUnitToCountToPatterns, FULL_NAME, pluralKeywords);
+ setup("unitsShort", timeUnitToCountToPatterns, ABBREVIATED_NAME, pluralKeywords);
isReady = true;
}
private void setup(String resourceKey, Map<TimeUnit, Map<String, Object[]>> timeUnitToCountToPatterns,
- int style) {
+ int style, Set<String> pluralKeywords) {
// fill timeUnitToCountToPatterns from resource file
try {
ICUResourceBundle resource = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
}
for ( int pluralIndex = 0; pluralIndex < count; ++pluralIndex) {
String pluralCount = oneUnitRes.get(pluralIndex).getKey();
+ if (!pluralKeywords.contains(pluralCount))
+ continue;
String pattern = oneUnitRes.get(pluralIndex).getString();
final MessageFormat messageFormat = new MessageFormat(pattern, locale);
if (format != null) {
/*
*******************************************************************************
- * Copyright (C) 2008-2010, International Business Machines Corporation and *
+ * Copyright (C) 2008-2012, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
}
}
+ /**
+ * @bug9042
+ * Performs tests for Greek.
+ * This tests that if the plural count listed in time unit format does not
+ * match those in the plural rules for the locale, those plural count in
+ * time unit format will be ingored and subsequently, fall back will kick in
+ * which is tested above.
+ * Without data sanitization, setNumberFormat() would crash.
+ * As of CLDR shiped in ICU4.8, Greek is one such language.
+ */
+ public void TestGreekWithSanitization() {
+ ULocale loc = new ULocale("el");
+ NumberFormat numfmt = NumberFormat.getInstance(loc);
+ TimeUnitFormat tuf = new TimeUnitFormat(loc);
+ tuf.parseObject("", new ParsePosition(0));
+ tuf.setNumberFormat(numfmt);
+ }
+
+
private void formatParsing(TimeUnitFormat format) {
final TimeUnit[] values = TimeUnit.values();
for (int j = 0; j < values.length; ++j) {