2 ******************************************************************************
4 * Copyright (C) 2003-2007, 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"
21 #define MEASUREMENT_SYSTEM "MeasurementSystem"
22 #define PAPER_SIZE "PaperSize"
24 /** A locale data object.
25 * For usage in C programs.
30 * Controls the "No Substitute" behavior of this locale data object
35 * Pointer to the resource bundle associated with this locale data object
37 UResourceBundle
*bundle
;
40 U_CAPI ULocaleData
* U_EXPORT2
41 ulocdata_open(const char *localeID
, UErrorCode
*status
)
45 if (U_FAILURE(*status
)) {
49 uld
= (ULocaleData
*)uprv_malloc(sizeof(ULocaleData
));
51 *status
= U_MEMORY_ALLOCATION_ERROR
;
56 uld
->noSubstitute
= FALSE
;
57 uld
->bundle
= ures_open(NULL
, localeID
, status
);
59 if (U_FAILURE(*status
)) {
68 ulocdata_close(ULocaleData
*uld
)
71 ures_close(uld
->bundle
);
77 ulocdata_setNoSubstitute(ULocaleData
*uld
, UBool setting
)
79 uld
->noSubstitute
= setting
;
82 U_CAPI UBool U_EXPORT2
83 ulocdata_getNoSubstitute(ULocaleData
*uld
)
85 return uld
->noSubstitute
;
88 U_CAPI USet
* U_EXPORT2
89 ulocdata_getExemplarSet(ULocaleData
*uld
, USet
*fillIn
,
90 uint32_t options
, ULocaleDataExemplarSetType extype
, UErrorCode
*status
){
92 static const char* const exemplarSetTypes
[] = { "ExemplarCharacters", "AuxExemplarCharacters" };
93 const UChar
*exemplarChars
= NULL
;
95 UErrorCode localStatus
= U_ZERO_ERROR
;
97 if (U_FAILURE(*status
))
100 exemplarChars
= ures_getStringByKey(uld
->bundle
, exemplarSetTypes
[extype
], &len
, &localStatus
);
101 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
102 localStatus
= U_MISSING_RESOURCE_ERROR
;
105 if (localStatus
!= U_ZERO_ERROR
) {
106 *status
= localStatus
;
109 if (U_FAILURE(*status
))
113 uset_applyPattern(fillIn
, exemplarChars
, len
,
114 USET_IGNORE_SPACE
| options
, status
);
116 fillIn
= uset_openPatternOptions(exemplarChars
, len
,
117 USET_IGNORE_SPACE
| options
, status
);
123 U_CAPI
int32_t U_EXPORT2
124 ulocdata_getDelimiter(ULocaleData
*uld
, ULocaleDataDelimiterType type
,
125 UChar
*result
, int32_t resultLength
, UErrorCode
*status
){
127 static const char* const delimiterKeys
[] = {
130 "alternateQuotationStart",
131 "alternateQuotationEnd"
134 UResourceBundle
*delimiterBundle
;
136 const UChar
*delimiter
= NULL
;
137 UErrorCode localStatus
= U_ZERO_ERROR
;
139 if (U_FAILURE(*status
))
142 delimiterBundle
= ures_getByKey(uld
->bundle
, "delimiters", NULL
, &localStatus
);
144 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
145 localStatus
= U_MISSING_RESOURCE_ERROR
;
148 if (localStatus
!= U_ZERO_ERROR
) {
149 *status
= localStatus
;
152 if (U_FAILURE(*status
)){
153 ures_close(delimiterBundle
);
157 delimiter
= ures_getStringByKey(delimiterBundle
, delimiterKeys
[type
], &len
, &localStatus
);
158 ures_close(delimiterBundle
);
160 if ( (localStatus
== U_USING_DEFAULT_WARNING
) && uld
->noSubstitute
) {
161 localStatus
= U_MISSING_RESOURCE_ERROR
;
164 if (localStatus
!= U_ZERO_ERROR
) {
165 *status
= localStatus
;
168 if (U_FAILURE(*status
)){
172 u_strncpy(result
,delimiter
,resultLength
);
176 U_CAPI UMeasurementSystem U_EXPORT2
177 ulocdata_getMeasurementSystem(const char *localeID
, UErrorCode
*status
){
179 UResourceBundle
* bundle
=NULL
;
180 UResourceBundle
* measurement
=NULL
;
181 UMeasurementSystem system
= UMS_LIMIT
;
183 if(status
== NULL
|| U_FAILURE(*status
)){
187 bundle
= ures_open(NULL
, localeID
, status
);
189 measurement
= ures_getByKey(bundle
, MEASUREMENT_SYSTEM
, NULL
, status
);
191 system
= (UMeasurementSystem
) ures_getInt(measurement
, status
);
194 ures_close(measurement
);
200 U_CAPI
void U_EXPORT2
201 ulocdata_getPaperSize(const char* localeID
, int32_t *height
, int32_t *width
, UErrorCode
*status
){
202 UResourceBundle
* bundle
=NULL
;
203 UResourceBundle
* paperSizeBundle
= NULL
;
204 const int32_t* paperSize
=NULL
;
207 if(status
== NULL
|| U_FAILURE(*status
)){
211 bundle
= ures_open(NULL
, localeID
, status
);
212 paperSizeBundle
= ures_getByKey(bundle
, PAPER_SIZE
, NULL
, status
);
213 paperSize
= ures_getIntVector(paperSizeBundle
, &len
, status
);
215 if(U_SUCCESS(*status
)){
217 *status
= U_INTERNAL_PROGRAM_ERROR
;
219 *height
= paperSize
[0];
220 *width
= paperSize
[1];
225 ures_close(paperSizeBundle
);