]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/LocaleData.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / util / LocaleData.java
similarity index 79%
rename from jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/util/LocaleData.java
rename to jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/LocaleData.java
index ebbdb8b02e7d152a3368521b9f28f1db8c677bde..d3de18a716aebbfed0d9f9c2e454ce413dc7f751 100644 (file)
@@ -1,6 +1,6 @@
 /*
  **************************************************************************************
- * Copyright (C) 2009-2011, Google, Inc.; International Business Machines Corporation *
+ * Copyright (C) 2009-2013, Google, Inc.; International Business Machines Corporation *
  * and others. All Rights Reserved.                                                   *
  **************************************************************************************
  */
@@ -13,7 +13,7 @@ import com.ibm.icu.text.UnicodeSet;
 import com.ibm.icu.util.ULocale.Category;
 
 /**
- * A class for accessing miscelleneous data in the locale bundles
+ * A class for accessing miscellaneous data in the locale bundles
  * @author ram
  * @stable ICU 2.8
  */
@@ -43,21 +43,28 @@ public final class LocaleData {
 
     /**
      * EXType for {@link #getExemplarSet(int, int)}.
-     * @stable ICU 3.4
+     * @stable ICU 4.4
      */
    public static final int ES_INDEX = 2;
 
    /**
     * EXType for {@link #getExemplarSet(int, int)}.
-    * @stable ICU 3.4
+    * Note: This type is no longer supported.
+    * @deprecated ICU 51
     */
     public static final int ES_CURRENCY = 3;
 
+    /**
+     * EXType for {@link #getExemplarSet(int, int)}.
+     * @stable ICU 49
+     */
+     public static final int ES_PUNCTUATION = 4;
+
     /**
      * Count of EXTypes for {@link #getExemplarSet(int, int)}.
      * @stable ICU 3.4
      */
-    public static final int ES_COUNT = 4;
+    public static final int ES_COUNT = 5;
     
     /**
      * Delimiter type for {@link #getDelimiter(int)}.
@@ -147,23 +154,37 @@ public final class LocaleData {
      *                  IGNORE_SPACE bit is always set, regardless of the
      *                  value of 'options'.
      * @param extype    The type of exemplar set to be retrieved,
-     *                  ES_STANDARD, ES_INDEX, ES_CURRENCY,  or ES_AUXILIARY
+     *                  ES_STANDARD, ES_INDEX, ES_AUXILIARY, or ES_PUNCTUATION
      * @return          The set of exemplar characters for the given locale.
      * @stable ICU 3.4
      */
     public UnicodeSet getExemplarSet(int options, int extype) {
         String [] exemplarSetTypes = { 
             "ExemplarCharacters", "AuxExemplarCharacters",
-            "ExemplarCharactersIndex", "ExemplarCharactersCurrency"
+            "ExemplarCharactersIndex", "ExemplarCharactersCurrency",
+            "ExemplarCharactersPunctuation"
         };
 
+        if (extype == ES_CURRENCY) {
+            // currency symbol exemplar is no longer available
+            return new UnicodeSet();
+        }
+
         try{
             ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get(exemplarSetTypes[extype]);
     
             if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) )
                return null;
     
-            return new UnicodeSet(stringBundle.getString(), UnicodeSet.IGNORE_SPACE | options);
+            String unicodeSetPattern = stringBundle.getString();
+            if (extype == ES_PUNCTUATION) {
+                try {
+                    return new UnicodeSet(unicodeSetPattern, UnicodeSet.IGNORE_SPACE | options);
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalArgumentException("Can't create exemplars for " + exemplarSetTypes[extype] + " in " + bundle.getLocale(), e);
+                }
+            }
+            return new UnicodeSet(unicodeSetPattern, UnicodeSet.IGNORE_SPACE | options);
         }catch(MissingResourceException ex){
             if(extype==LocaleData.ES_AUXILIARY){
                 return new UnicodeSet();
@@ -226,6 +247,13 @@ public final class LocaleData {
        return noSubstitute;
     }
 
+    private static final String [] DELIMITER_TYPES = {
+                                 "quotationStart", 
+                                 "quotationEnd", 
+                                 "alternateQuotationStart", 
+                                 "alternateQuotationEnd"
+    };
+
     /**
      * Retrieves a delimiter string from the locale data.
      *
@@ -236,19 +264,46 @@ public final class LocaleData {
      * @stable ICU 3.4
      */
     public String getDelimiter(int type) {
-        String [] delimiterTypes = { "quotationStart", 
-                                     "quotationEnd", 
-                                     "alternateQuotationStart", 
-                                     "alternateQuotationEnd" };
-
-        ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get("delimiters").get(delimiterTypes[type]);
+        ICUResourceBundle delimitersBundle = (ICUResourceBundle) bundle.get("delimiters");
+        // Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback.
+        ICUResourceBundle stringBundle = delimitersBundle.getWithFallback(DELIMITER_TYPES[type]);
 
         if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) )
            return null;
 
-        return new String (stringBundle.getString());
+        return stringBundle.getString();
     }
 
+    /**
+     * Utility for getMeasurementSystem and getPaperSize
+     */
+    private static UResourceBundle measurementTypeBundleForLocale(ULocale locale, String measurementType){
+        // Much of this is taken from getCalendarType in impl/CalendarUtil.java
+        UResourceBundle measTypeBundle = null;
+       ULocale fullLoc = ULocale.addLikelySubtags(locale);
+       String region = fullLoc.getCountry();
+               try {
+                       UResourceBundle rb = UResourceBundle.getBundleInstance(
+                                                                       ICUResourceBundle.ICU_BASE_NAME,
+                                                                       "supplementalData",
+                                                                       ICUResourceBundle.ICU_DATA_CLASS_LOADER);
+                       UResourceBundle measurementData = rb.get("measurementData");
+                       UResourceBundle measDataBundle = null;
+                       try {
+                               measDataBundle = measurementData.get(region);
+                               measTypeBundle = measDataBundle.get(measurementType);
+                       } catch (MissingResourceException mre) {
+                               // use "001" as fallback
+                               measDataBundle = measurementData.get("001");
+                               measTypeBundle = measDataBundle.get(measurementType);
+                       }
+               } catch (MissingResourceException mre) {
+                       // fall through
+               }
+               return measTypeBundle;
+    }
+
+
     /**
      * Enumeration for representing the measurement systems.
      * @stable ICU 2.8
@@ -285,8 +340,7 @@ public final class LocaleData {
      * @stable ICU 3.0
      */
     public static final MeasurementSystem getMeasurementSystem(ULocale locale){
-        UResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
-        UResourceBundle sysBundle = bundle.get(MEASUREMENT_SYSTEM);
+        UResourceBundle sysBundle = measurementTypeBundleForLocale(locale, MEASUREMENT_SYSTEM);
         
         int system = sysBundle.getInt();
         if(MeasurementSystem.US.equals(system)){
@@ -339,8 +393,7 @@ public final class LocaleData {
      * @stable ICU 3.0
      */
     public static final PaperSize getPaperSize(ULocale locale){
-        UResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
-        UResourceBundle obj = bundle.get(PAPER_SIZE);
+        UResourceBundle obj = measurementTypeBundleForLocale(locale, PAPER_SIZE);
         int[] size = obj.getIntVector();
         return new PaperSize(size[0], size[1]);
     }
@@ -362,8 +415,15 @@ public final class LocaleData {
      * @stable ICU 4.2
      */ 
     public String getLocaleSeparator() {
+      String sub0 = "{0}";
+      String sub1 = "{1}";
       ICUResourceBundle locDispBundle = (ICUResourceBundle) langBundle.get(LOCALE_DISPLAY_PATTERN);
       String  localeSeparator = locDispBundle.getStringWithFallback(SEPARATOR);
+      int index0 = localeSeparator.indexOf(sub0);
+      int index1 = localeSeparator.indexOf(sub1);
+      if (index0 >= 0 && index1 >= 0 && index0 <= index1) {
+          return localeSeparator.substring(index0 + sub0.length(), index1);
+      }
       return localeSeparator;
     }