]> granicus.if.org Git - icu/commitdiff
ICU-10243 C, ulocdata_getMeasurementSystem/getPaperSize should get data from suppleme...
authorPeter Edberg <pedberg@unicode.org>
Mon, 19 Aug 2013 22:29:26 +0000 (22:29 +0000)
committerPeter Edberg <pedberg@unicode.org>
Mon, 19 Aug 2013 22:29:26 +0000 (22:29 +0000)
X-SVN-Rev: 34065

icu4c/source/i18n/ulocdata.c
icu4c/source/test/cintltst/cldrtest.c

index 80e782ceeb90c8cf20b107d24c75383b05d022cb..5d2461e91b029f5c3c5d9cbe9deab62b039ce60c 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "cmemory.h"
 #include "unicode/ustring.h"
+#include "unicode/ures.h"
+#include "unicode/uloc.h"
 #include "unicode/ulocdata.h"
 #include "uresimp.h"
 #include "ureslocs.h"
@@ -186,10 +188,39 @@ ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type,
     return len;
 }
 
+static UResourceBundle * measurementTypeBundleForLocale(const char *localeID, const char *measurementType, UErrorCode *status){
+    char fullLoc[ULOC_FULLNAME_CAPACITY];
+    char region[ULOC_COUNTRY_CAPACITY];
+    UResourceBundle *rb;
+    UResourceBundle *measTypeBundle = NULL;
+    
+    /* The following code is basically copied from Calendar::setWeekData and
+     * Calendar::getCalendarTypeForLocale with adjustments for resource name
+     */
+    uloc_addLikelySubtags(localeID, fullLoc, ULOC_FULLNAME_CAPACITY, status);
+    uloc_getCountry(fullLoc, region, ULOC_COUNTRY_CAPACITY, status);
+    
+    rb = ures_openDirect(NULL, "supplementalData", status);
+    ures_getByKey(rb, "measurementData", rb, status);
+    if (rb != NULL) {
+        UResourceBundle *measDataBundle = ures_getByKey(rb, region, NULL, status);
+        if (U_SUCCESS(*status)) {
+               measTypeBundle = ures_getByKey(measDataBundle, measurementType, NULL, status);
+        }
+        if (*status == U_MISSING_RESOURCE_ERROR) {
+            *status = U_ZERO_ERROR;
+            measDataBundle = ures_getByKey(rb, "001", NULL, status);
+            measTypeBundle = ures_getByKey(measDataBundle, measurementType, NULL, status);
+        }
+        ures_close(measDataBundle);
+    }
+    ures_close(rb);
+    return measTypeBundle;
+}
+
 U_CAPI UMeasurementSystem U_EXPORT2
 ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
 
-    UResourceBundle* bundle=NULL;
     UResourceBundle* measurement=NULL;
     UMeasurementSystem system = UMS_LIMIT;
 
@@ -197,13 +228,9 @@ ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
         return system;
     }
 
-    bundle = ures_open(NULL, localeID, status);
-
-    measurement = ures_getByKeyWithFallback(bundle, MEASUREMENT_SYSTEM, NULL, status);
-
+    measurement = measurementTypeBundleForLocale(localeID, MEASUREMENT_SYSTEM, status);
     system = (UMeasurementSystem) ures_getInt(measurement, status);
 
-    ures_close(bundle);
     ures_close(measurement);
 
     return system;
@@ -212,7 +239,6 @@ ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
 
 U_CAPI void U_EXPORT2
 ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UErrorCode *status){
-    UResourceBundle* bundle=NULL;
     UResourceBundle* paperSizeBundle = NULL;
     const int32_t* paperSize=NULL;
     int32_t len = 0;
@@ -221,8 +247,7 @@ ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UEr
         return;
     }
 
-    bundle = ures_open(NULL, localeID, status);
-    paperSizeBundle = ures_getByKeyWithFallback(bundle, PAPER_SIZE, NULL, status);
+    paperSizeBundle = measurementTypeBundleForLocale(localeID, PAPER_SIZE, status);
     paperSize = ures_getIntVector(paperSizeBundle, &len,  status);
 
     if(U_SUCCESS(*status)){
@@ -234,7 +259,6 @@ ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UEr
         }
     }
 
-    ures_close(bundle);
     ures_close(paperSizeBundle);
 
 }
index 0b05bacbc32d73419b01cf547953ce8fa145ea17..a94d4f8d3d3f3a914e9aa63d3818c1d4e40697ed 100644 (file)
@@ -1078,18 +1078,43 @@ static void VerifyTranslation(void) {
                    log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
                }
            }
-            /* test that the MeasurementSystem works API works */
+            /* test that the MeasurementSystem API works */
            {
-               UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
-               if(U_FAILURE(errorCode)){
+               char fullLoc[ULOC_FULLNAME_CAPACITY];
+               UMeasurementSystem measurementSystem;
+               int32_t height = 0, width = 0;
+
+               uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
+
+               errorCode = U_ZERO_ERROR;
+               measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
+               if (U_FAILURE(errorCode)) {
                    log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
+               } else {
+                   if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_MM")!=NULL || strstr(fullLoc, "_LR")!=NULL ) {
+                       if(measurementSystem != UMS_US){
+                            log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
+                       }
+                   } else if (measurementSystem != UMS_SI) {
+                       log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
+                   }
                }
-               if(strstr(currLoc, "_US")!=NULL || strstr(currLoc, "_MM")!=NULL || strstr(currLoc, "_LR")!=NULL){
-                   if(measurementSystem != UMS_US){
-                        log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
+               
+               errorCode = U_ZERO_ERROR;
+               ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
+               if (U_FAILURE(errorCode)) {
+                   log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
+               } else {
+                   if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_BZ")!=NULL || strstr(fullLoc, "_CA")!=NULL || strstr(fullLoc, "_CL")!=NULL ||
+                        strstr(fullLoc, "_CO")!=NULL || strstr(fullLoc, "_CR")!=NULL || strstr(fullLoc, "_GT")!=NULL || strstr(fullLoc, "_MX")!=NULL ||
+                        strstr(fullLoc, "_NI")!=NULL || strstr(fullLoc, "_PA")!=NULL || strstr(fullLoc, "_PH")!=NULL || strstr(fullLoc, "_PR")!=NULL ||
+                        strstr(fullLoc, "_SV")!=NULL || strstr(fullLoc, "_VE")!=NULL ) {
+                       if (height != 279 || width != 216) {
+                            log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
+                       }
+                   } else if (height != 297 || width != 210) {
+                       log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
                    }
-               }else if(measurementSystem != UMS_SI){
-                   log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
                }
            }
         }