diff options
author | Andrew John Hughes <gandalf@gcc.gnu.org> | 2012-03-23 15:19:26 +0000 |
---|---|---|
committer | Andrew John Hughes <gandalf@gcc.gnu.org> | 2012-03-23 15:19:26 +0000 |
commit | 0563022a206294757effa44686727bffc4f7c2bd (patch) | |
tree | febe3d4d4c0c994db223fee8e819bde6582494c9 /libjava/classpath/java/text/DateFormatSymbols.java | |
parent | 21669dfe20db0246ece395db5558a081a5c7088f (diff) | |
download | gcc-0563022a206294757effa44686727bffc4f7c2bd.zip gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.gz gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.bz2 |
Merge GNU Classpath 0.99 into libjava.
From-SVN: r185741
Diffstat (limited to 'libjava/classpath/java/text/DateFormatSymbols.java')
-rw-r--r-- | libjava/classpath/java/text/DateFormatSymbols.java | 81 |
1 files changed, 70 insertions, 11 deletions
diff --git a/libjava/classpath/java/text/DateFormatSymbols.java b/libjava/classpath/java/text/DateFormatSymbols.java index c22dd38..53e7ba0 100644 --- a/libjava/classpath/java/text/DateFormatSymbols.java +++ b/libjava/classpath/java/text/DateFormatSymbols.java @@ -45,6 +45,7 @@ import java.io.IOException; import java.text.spi.DateFormatSymbolsProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -125,9 +126,58 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable transient String[] dateFormats; transient String[] timeFormats; - private static String[] getStringArray(ResourceBundle res, String name) + /** + * Compiles a string array for a property using data from each of the locales in the + * hierarchy as necessary. + * + * @param bundles the locale hierarchy, starting with the most specific. + * @param name the name of the property. + * @param size the size the array should be when complete. + * @return a completed string array. + */ + private static String[] getStringArray(List<ResourceBundle> bundles, String name, int size) + { + return getStringArray(bundles, name, size, null); + } + + /** + * Compiles a string array for a property using data from each of the locales in the + * hierarchy as necessary. If non-null, the fallback array is also used for "sideways" + * inheritance (e.g. if there is no short name for a month, the long name is used rather + * than the empty string). + * + * @param bundles the locale hierarchy, starting with the most specific. + * @param name the name of the property. + * @param size the size the array should be when complete. + * @param fallback an array of long name fallback strings for data with both long and short names. + * @return a completed string array. + */ + private static String[] getStringArray(List<ResourceBundle> bundles, String name, int size, + String[] fallback) { - return res.getString(name).split("\u00ae"); + String[] data = new String[size]; + Arrays.fill(data, ""); + // Populate array with data from each locale back to the root, starting with the most specific + for (int a = 0; a < bundles.size(); ++a) + { + String localeData = bundles.get(a).getString(name); + String[] array = localeData.split("\u00ae", size); + for (int b = 0; b < data.length; ++b) + { + if (array.length > b && array[b] != null && data[b].isEmpty() && !array[b].isEmpty()) + data[b] = array[b]; + } + } + // Replace any remaining empty strings with data from the fallback array, if non-null + if (fallback != null && fallback.length == size) + { + for (int a = 0; a < data.length; ++a) + { + if (data[a].isEmpty() && fallback[a] != null && !fallback[a].isEmpty()) + data[a] = fallback[a]; + } + } + return data; } private String[][] getZoneStrings(ResourceBundle res, Locale locale) @@ -264,17 +314,26 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable public DateFormatSymbols (Locale locale) throws MissingResourceException { + ClassLoader ldr = ClassLoader.getSystemClassLoader(); + List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); ResourceBundle res - = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, - ClassLoader.getSystemClassLoader()); - - ampms = getStringArray(res, "ampms"); - eras = getStringArray(res, "eras"); + = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, ldr); + bundles.add(res); + Locale resLocale = res.getLocale(); + while (resLocale != Locale.ROOT) + { + res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + LocaleHelper.getFallbackLocale(resLocale), ldr); + bundles.add(res); + resLocale = res.getLocale(); + } + ampms = getStringArray(bundles, "ampms", 2); + eras = getStringArray(bundles, "eras", 2); localPatternChars = res.getString("localPatternChars"); - months = getStringArray(res, "months"); - shortMonths = getStringArray(res, "shortMonths"); - shortWeekdays = getStringArray(res, "shortWeekdays"); - weekdays = getStringArray(res, "weekdays"); + months = getStringArray(bundles, "months", 13); + shortMonths = getStringArray(bundles, "shortMonths", 13, months); + weekdays = getStringArray(bundles, "weekdays", 8); + shortWeekdays = getStringArray(bundles, "shortWeekdays", 8, weekdays); dateFormats = formatsForKey(res, "DateFormat"); timeFormats = formatsForKey(res, "TimeFormat"); runtimeZoneStrings = getZoneStrings(res, locale); |