2 ******************************************************************************
4 * Copyright (C) 2003-2009, International Business Machines *
5 * Corporation and others. All Rights Reserved. *
7 ******************************************************************************
8 * file name: ulocdata.c
10 * tab size: 8 (not used)
13 * created on: 2003Oct21
14 * created by: Ram Viswanadha,John Emmons
18 #include "unicode/ustring.h"
19 #include "unicode/ulocdata.h"
24 #define MEASUREMENT_SYSTEM "MeasurementSystem"
25 #define PAPER_SIZE "PaperSize"
27 /** A locale data object.
28 * For usage in C programs.
33 * Controls the "No Substitute" behavior of this locale data object
38 * Pointer to the resource bundle associated with this locale data object
40 UResourceBundle
*bundle
;
43 * Pointer to the lang resource bundle associated with this locale data object
45 UResourceBundle
*langBundle
;
48 U_CAPI ULocaleData
* U_EXPORT2
49 ulocdata_open(const char *localeID
, UErrorCode
*status
)
53 if (U_FAILURE(*status
)) {
57 uld
= (ULocaleData
*)uprv_malloc(sizeof(ULocaleData
));
59 *status
= U_MEMORY_ALLOCATION_ERROR
;
63 uld
->langBundle
= NULL
;
65 uld
->noSubstitute
= FALSE
;
66 uld
->bundle
= ures_open(NULL
, localeID
, status
);
67 uld
->langBundle
= ures_open(U_ICUDATA_LANG
, localeID
, status
);
69 if (U_FAILURE(*status
)) {
78 ulocdata_close(ULocaleData
*uld
)
81 ures_close(uld
->langBundle
);
82 ures_close(uld
->bundle
);
88 ulocdata_setNoSubstitute(ULocaleData
*uld
, UBool setting
)
90 uld
->noSubstitute
= setting
;
93 U_CAPI UBool U_EXPORT2
94 ulocdata_getNoSubstitute(ULocaleData
*uld
)
96 return uld
->noSubstitute
;
99 U_CAPI USet
* U_EXPORT2
100 ulocdata_getExemplarSet(ULocaleData
*uld
, USet
*fillIn
,
101 uint32_t options
, ULocaleDataExemplarSetType extype
, UErrorCode
*status
){
103 static const char* const exemplarSetTypes
[] = { "ExemplarCharacters", "AuxExemplarCharacters" };
104 const UChar
*exemplarChars
= NULL
;
106 UErrorCode localStatus
= U_ZERO_ERROR
;
108 if (U_FAILURE(*status
))
111 exemplarChars
= ures_getStringByKey(uld
->bundle
, exemplarSetTypes
[extype
], &len
, &localStatus
);
112 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
113 localStatus
= U_MISSING_RESOURCE_ERROR
;
116 if (localStatus
!= U_ZERO_ERROR
) {
117 *status
= localStatus
;
120 if (U_FAILURE(*status
))
124 uset_applyPattern(fillIn
, exemplarChars
, len
,
125 USET_IGNORE_SPACE
| options
, status
);
127 fillIn
= uset_openPatternOptions(exemplarChars
, len
,
128 USET_IGNORE_SPACE
| options
, status
);
134 U_CAPI
int32_t U_EXPORT2
135 ulocdata_getDelimiter(ULocaleData
*uld
, ULocaleDataDelimiterType type
,
136 UChar
*result
, int32_t resultLength
, UErrorCode
*status
){
138 static const char* const delimiterKeys
[] = {
141 "alternateQuotationStart",
142 "alternateQuotationEnd"
145 UResourceBundle
*delimiterBundle
;
147 const UChar
*delimiter
= NULL
;
148 UErrorCode localStatus
= U_ZERO_ERROR
;
150 if (U_FAILURE(*status
))
153 delimiterBundle
= ures_getByKey(uld
->bundle
, "delimiters", NULL
, &localStatus
);
155 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
156 localStatus
= U_MISSING_RESOURCE_ERROR
;
159 if (localStatus
!= U_ZERO_ERROR
) {
160 *status
= localStatus
;
163 if (U_FAILURE(*status
)){
164 ures_close(delimiterBundle
);
168 delimiter
= ures_getStringByKey(delimiterBundle
, delimiterKeys
[type
], &len
, &localStatus
);
169 ures_close(delimiterBundle
);
171 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
172 localStatus
= U_MISSING_RESOURCE_ERROR
;
175 if (localStatus
!= U_ZERO_ERROR
) {
176 *status
= localStatus
;
179 if (U_FAILURE(*status
)){
183 u_strncpy(result
,delimiter
, resultLength
);
187 U_CAPI UMeasurementSystem U_EXPORT2
188 ulocdata_getMeasurementSystem(const char *localeID
, UErrorCode
*status
){
190 UResourceBundle
* bundle
=NULL
;
191 UResourceBundle
* measurement
=NULL
;
192 UMeasurementSystem system
= UMS_LIMIT
;
194 if(status
== NULL
|| U_FAILURE(*status
)){
198 bundle
= ures_open(NULL
, localeID
, status
);
200 measurement
= ures_getByKeyWithFallback(bundle
, MEASUREMENT_SYSTEM
, NULL
, status
);
202 system
= (UMeasurementSystem
) ures_getInt(measurement
, status
);
205 ures_close(measurement
);
211 U_CAPI
void U_EXPORT2
212 ulocdata_getPaperSize(const char* localeID
, int32_t *height
, int32_t *width
, UErrorCode
*status
){
213 UResourceBundle
* bundle
=NULL
;
214 UResourceBundle
* paperSizeBundle
= NULL
;
215 const int32_t* paperSize
=NULL
;
218 if(status
== NULL
|| U_FAILURE(*status
)){
222 bundle
= ures_open(NULL
, localeID
, status
);
223 paperSizeBundle
= ures_getByKeyWithFallback(bundle
, PAPER_SIZE
, NULL
, status
);
224 paperSize
= ures_getIntVector(paperSizeBundle
, &len
, status
);
226 if(U_SUCCESS(*status
)){
228 *status
= U_INTERNAL_PROGRAM_ERROR
;
230 *height
= paperSize
[0];
231 *width
= paperSize
[1];
236 ures_close(paperSizeBundle
);
240 U_DRAFT
void U_EXPORT2
241 ulocdata_getCLDRVersion(UVersionInfo versionArray
, UErrorCode
*status
) {
242 UResourceBundle
*rb
= NULL
;
243 rb
= ures_openDirect(NULL
, "supplementalData", status
);
244 ures_getVersionByKey(rb
, "cldrVersion", versionArray
, status
);
248 U_DRAFT
int32_t U_EXPORT2
249 ulocdata_getLocaleDisplayPattern(ULocaleData
*uld
,
251 int32_t resultCapacity
,
252 UErrorCode
*status
) {
253 UResourceBundle
*patternBundle
;
255 const UChar
*pattern
= NULL
;
256 UErrorCode localStatus
= U_ZERO_ERROR
;
258 if (U_FAILURE(*status
))
261 patternBundle
= ures_getByKey(uld
->langBundle
, "localeDisplayPattern", NULL
, &localStatus
);
263 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
264 localStatus
= U_MISSING_RESOURCE_ERROR
;
267 if (localStatus
!= U_ZERO_ERROR
) {
268 *status
= localStatus
;
271 if (U_FAILURE(*status
)){
272 ures_close(patternBundle
);
276 pattern
= ures_getStringByKey(patternBundle
, "pattern", &len
, &localStatus
);
277 ures_close(patternBundle
);
279 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
280 localStatus
= U_MISSING_RESOURCE_ERROR
;
283 if (localStatus
!= U_ZERO_ERROR
) {
284 *status
= localStatus
;
287 if (U_FAILURE(*status
)){
291 u_strncpy(result
, pattern
, resultCapacity
);
296 U_DRAFT
int32_t U_EXPORT2
297 ulocdata_getLocaleSeparator(ULocaleData
*uld
,
299 int32_t resultCapacity
,
300 UErrorCode
*status
) {
301 UResourceBundle
*separatorBundle
;
303 const UChar
*separator
= NULL
;
304 UErrorCode localStatus
= U_ZERO_ERROR
;
306 if (U_FAILURE(*status
))
309 separatorBundle
= ures_getByKey(uld
->langBundle
, "localeDisplayPattern", NULL
, &localStatus
);
311 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
312 localStatus
= U_MISSING_RESOURCE_ERROR
;
315 if (localStatus
!= U_ZERO_ERROR
) {
316 *status
= localStatus
;
319 if (U_FAILURE(*status
)){
320 ures_close(separatorBundle
);
324 separator
= ures_getStringByKey(separatorBundle
, "separator", &len
, &localStatus
);
325 ures_close(separatorBundle
);
327 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
328 localStatus
= U_MISSING_RESOURCE_ERROR
;
331 if (localStatus
!= U_ZERO_ERROR
) {
332 *status
= localStatus
;
335 if (U_FAILURE(*status
)){
339 u_strncpy(result
, separator
, resultCapacity
);