#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"
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;
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;
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;
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)){
}
}
- ures_close(bundle);
ures_close(paperSizeBundle);
}
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);
}
}
}