Andy Heninger | 242e02c | 2017-01-20 00:20:31 +0000 | [diff] [blame] | 1 | // © 2016 and later: Unicode, Inc. and others. |
Michael Ow | 61607c2 | 2016-06-15 18:58:17 +0000 | [diff] [blame] | 2 | // License & terms of use: http://www.unicode.org/copyright.html |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 3 | /* |
| 4 | ****************************************************************************** |
| 5 | * * |
Yoshito Umaoka | 00ca13e | 2016-05-31 21:45:07 +0000 | [diff] [blame] | 6 | * Copyright (C) 2003-2016, International Business Machines * |
| 7 | * Corporation and others. All Rights Reserved. * |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 8 | * * |
| 9 | ****************************************************************************** |
| 10 | * file name: ulocdata.c |
Andy Heninger | 04448b0 | 2017-02-03 18:57:23 +0000 | [diff] [blame] | 11 | * encoding: UTF-8 |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 12 | * tab size: 8 (not used) |
| 13 | * indentation:4 |
| 14 | * |
| 15 | * created on: 2003Oct21 |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 16 | * created by: Ram Viswanadha,John Emmons |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
John Emmons | 5662d6d | 2005-06-24 20:09:52 +0000 | [diff] [blame] | 19 | #include "cmemory.h" |
| 20 | #include "unicode/ustring.h" |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 21 | #include "unicode/ures.h" |
| 22 | #include "unicode/uloc.h" |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 23 | #include "unicode/ulocdata.h" |
Steven R. Loomis | ff0c25c | 2009-03-16 20:45:02 +0000 | [diff] [blame] | 24 | #include "uresimp.h" |
Doug Felt | d62a45c | 2009-11-12 21:53:42 +0000 | [diff] [blame] | 25 | #include "ureslocs.h" |
Peter Edberg | 086ee67 | 2016-02-15 17:58:23 +0000 | [diff] [blame] | 26 | #include "ulocimp.h" |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 27 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 28 | #define MEASUREMENT_SYSTEM "MeasurementSystem" |
| 29 | #define PAPER_SIZE "PaperSize" |
| 30 | |
George Rhoten | 9327ff5 | 2005-12-01 17:51:20 +0000 | [diff] [blame] | 31 | /** A locale data object. |
| 32 | * For usage in C programs. |
| 33 | * @draft ICU 3.4 |
| 34 | */ |
George Rhoten | e8fece0 | 2005-12-02 00:05:15 +0000 | [diff] [blame] | 35 | struct ULocaleData { |
George Rhoten | 9327ff5 | 2005-12-01 17:51:20 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Controls the "No Substitute" behavior of this locale data object |
| 38 | */ |
| 39 | UBool noSubstitute; |
| 40 | |
| 41 | /** |
| 42 | * Pointer to the resource bundle associated with this locale data object |
| 43 | */ |
| 44 | UResourceBundle *bundle; |
Doug Felt | d62a45c | 2009-11-12 21:53:42 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Pointer to the lang resource bundle associated with this locale data object |
| 48 | */ |
| 49 | UResourceBundle *langBundle; |
George Rhoten | e8fece0 | 2005-12-02 00:05:15 +0000 | [diff] [blame] | 50 | }; |
George Rhoten | 9327ff5 | 2005-12-01 17:51:20 +0000 | [diff] [blame] | 51 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 52 | U_CAPI ULocaleData* U_EXPORT2 |
| 53 | ulocdata_open(const char *localeID, UErrorCode *status) |
| 54 | { |
| 55 | ULocaleData *uld; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 56 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 57 | if (U_FAILURE(*status)) { |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 58 | return nullptr; |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | uld = (ULocaleData *)uprv_malloc(sizeof(ULocaleData)); |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 62 | if (uld == nullptr) { |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 63 | *status = U_MEMORY_ALLOCATION_ERROR; |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 64 | return(nullptr); |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 67 | uld->langBundle = nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 68 | |
Fredrik Roubert | 030fa1a | 2022-09-06 21:18:38 +0200 | [diff] [blame] | 69 | uld->noSubstitute = false; |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 70 | uld->bundle = ures_open(nullptr, localeID, status); |
Doug Felt | d62a45c | 2009-11-12 21:53:42 +0000 | [diff] [blame] | 71 | uld->langBundle = ures_open(U_ICUDATA_LANG, localeID, status); |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 72 | |
| 73 | if (U_FAILURE(*status)) { |
| 74 | uprv_free(uld); |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 75 | return nullptr; |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | return uld; |
| 79 | } |
| 80 | |
| 81 | U_CAPI void U_EXPORT2 |
| 82 | ulocdata_close(ULocaleData *uld) |
| 83 | { |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 84 | if ( uld != nullptr ) { |
Doug Felt | d62a45c | 2009-11-12 21:53:42 +0000 | [diff] [blame] | 85 | ures_close(uld->langBundle); |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 86 | ures_close(uld->bundle); |
| 87 | uprv_free(uld); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 88 | } |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 91 | U_CAPI void U_EXPORT2 |
| 92 | ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting) |
| 93 | { |
| 94 | uld->noSubstitute = setting; |
| 95 | } |
| 96 | |
| 97 | U_CAPI UBool U_EXPORT2 |
| 98 | ulocdata_getNoSubstitute(ULocaleData *uld) |
| 99 | { |
| 100 | return uld->noSubstitute; |
| 101 | } |
| 102 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 103 | U_CAPI USet* U_EXPORT2 |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 104 | ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn, |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 105 | uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status){ |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 106 | |
Andy Heninger | 7b7f48e | 2011-02-25 22:21:30 +0000 | [diff] [blame] | 107 | static const char* const exemplarSetTypes[] = { "ExemplarCharacters", |
| 108 | "AuxExemplarCharacters", |
Yoshito Umaoka | 557da15 | 2013-01-18 16:29:02 +0000 | [diff] [blame] | 109 | "ExemplarCharactersIndex", |
| 110 | "ExemplarCharactersPunctuation"}; |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 111 | const char16_t *exemplarChars = nullptr; |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 112 | int32_t len = 0; |
George Rhoten | 8364216 | 2004-10-19 05:19:36 +0000 | [diff] [blame] | 113 | UErrorCode localStatus = U_ZERO_ERROR; |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 114 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 115 | if (U_FAILURE(*status)) |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 116 | return nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 117 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 118 | exemplarChars = ures_getStringByKey(uld->bundle, exemplarSetTypes[extype], &len, &localStatus); |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 119 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 120 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 121 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 122 | |
George Rhoten | 87b2dc6 | 2005-09-14 19:09:13 +0000 | [diff] [blame] | 123 | if (localStatus != U_ZERO_ERROR) { |
Deborah Goldsmith | 9cc484f | 2004-10-18 23:58:03 +0000 | [diff] [blame] | 124 | *status = localStatus; |
| 125 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 126 | |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 127 | if (U_FAILURE(*status)) |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 128 | return nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 129 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 130 | if(fillIn != nullptr) |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 131 | uset_applyPattern(fillIn, exemplarChars, len, |
Alan Liu | 850661f | 2004-05-17 21:42:43 +0000 | [diff] [blame] | 132 | USET_IGNORE_SPACE | options, status); |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 133 | else |
Alan Liu | 850661f | 2004-05-17 21:42:43 +0000 | [diff] [blame] | 134 | fillIn = uset_openPatternOptions(exemplarChars, len, |
| 135 | USET_IGNORE_SPACE | options, status); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 136 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 137 | return fillIn; |
| 138 | |
| 139 | } |
| 140 | |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 141 | U_CAPI int32_t U_EXPORT2 |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 142 | ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type, |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 143 | char16_t *result, int32_t resultLength, UErrorCode *status){ |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 144 | |
George Rhoten | cf34014 | 2007-06-14 01:30:51 +0000 | [diff] [blame] | 145 | static const char* const delimiterKeys[] = { |
| 146 | "quotationStart", |
| 147 | "quotationEnd", |
| 148 | "alternateQuotationStart", |
| 149 | "alternateQuotationEnd" |
| 150 | }; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 151 | |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 152 | UResourceBundle *delimiterBundle; |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 153 | int32_t len = 0; |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 154 | const char16_t *delimiter = nullptr; |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 155 | UErrorCode localStatus = U_ZERO_ERROR; |
| 156 | |
| 157 | if (U_FAILURE(*status)) |
George Rhoten | 83af9f3 | 2005-06-24 22:19:45 +0000 | [diff] [blame] | 158 | return 0; |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 159 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 160 | delimiterBundle = ures_getByKey(uld->bundle, "delimiters", nullptr, &localStatus); |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 161 | |
| 162 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 163 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 164 | } |
| 165 | |
George Rhoten | 87b2dc6 | 2005-09-14 19:09:13 +0000 | [diff] [blame] | 166 | if (localStatus != U_ZERO_ERROR) { |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 167 | *status = localStatus; |
| 168 | } |
| 169 | |
Ram Viswanadha | baf3150 | 2005-07-14 23:25:48 +0000 | [diff] [blame] | 170 | if (U_FAILURE(*status)){ |
| 171 | ures_close(delimiterBundle); |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 172 | return 0; |
Ram Viswanadha | baf3150 | 2005-07-14 23:25:48 +0000 | [diff] [blame] | 173 | } |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 174 | |
Frank Tang | f1a8a63 | 2020-10-08 00:25:34 +0000 | [diff] [blame] | 175 | delimiter = ures_getStringByKeyWithFallback(delimiterBundle, delimiterKeys[type], &len, &localStatus); |
George Rhoten | b11decc | 2005-07-18 06:05:28 +0000 | [diff] [blame] | 176 | ures_close(delimiterBundle); |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 177 | |
| 178 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 179 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 180 | } |
| 181 | |
George Rhoten | 87b2dc6 | 2005-09-14 19:09:13 +0000 | [diff] [blame] | 182 | if (localStatus != U_ZERO_ERROR) { |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 183 | *status = localStatus; |
| 184 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 185 | |
Ram Viswanadha | baf3150 | 2005-07-14 23:25:48 +0000 | [diff] [blame] | 186 | if (U_FAILURE(*status)){ |
John Emmons | df5fb97 | 2005-06-30 16:56:46 +0000 | [diff] [blame] | 187 | return 0; |
Ram Viswanadha | baf3150 | 2005-07-14 23:25:48 +0000 | [diff] [blame] | 188 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 189 | |
| 190 | u_strncpy(result,delimiter, resultLength); |
John Emmons | 6fa37a0 | 2005-06-24 15:48:23 +0000 | [diff] [blame] | 191 | return len; |
| 192 | } |
| 193 | |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 194 | static UResourceBundle * measurementTypeBundleForLocale(const char *localeID, const char *measurementType, UErrorCode *status){ |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 195 | char region[ULOC_COUNTRY_CAPACITY]; |
| 196 | UResourceBundle *rb; |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 197 | UResourceBundle *measTypeBundle = nullptr; |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 198 | |
Fredrik Roubert | 030fa1a | 2022-09-06 21:18:38 +0200 | [diff] [blame] | 199 | ulocimp_getRegionForSupplementalData(localeID, true, region, ULOC_COUNTRY_CAPACITY, status); |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 200 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 201 | rb = ures_openDirect(nullptr, "supplementalData", status); |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 202 | ures_getByKey(rb, "measurementData", rb, status); |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 203 | if (rb != nullptr) { |
| 204 | UResourceBundle *measDataBundle = ures_getByKey(rb, region, nullptr, status); |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 205 | if (U_SUCCESS(*status)) { |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 206 | measTypeBundle = ures_getByKey(measDataBundle, measurementType, nullptr, status); |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 207 | } |
| 208 | if (*status == U_MISSING_RESOURCE_ERROR) { |
| 209 | *status = U_ZERO_ERROR; |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 210 | if (measDataBundle != nullptr) { |
Michael Ow | 10ae93e | 2013-08-20 20:19:58 +0000 | [diff] [blame] | 211 | ures_close(measDataBundle); |
| 212 | } |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 213 | measDataBundle = ures_getByKey(rb, "001", nullptr, status); |
| 214 | measTypeBundle = ures_getByKey(measDataBundle, measurementType, nullptr, status); |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 215 | } |
| 216 | ures_close(measDataBundle); |
| 217 | } |
| 218 | ures_close(rb); |
| 219 | return measTypeBundle; |
| 220 | } |
| 221 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 222 | U_CAPI UMeasurementSystem U_EXPORT2 |
| 223 | ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){ |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 224 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 225 | UResourceBundle* measurement=nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 226 | UMeasurementSystem system = UMS_LIMIT; |
| 227 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 228 | if(status == nullptr || U_FAILURE(*status)){ |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 229 | return system; |
| 230 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 231 | |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 232 | measurement = measurementTypeBundleForLocale(localeID, MEASUREMENT_SYSTEM, status); |
Frank Tang | 43f2ae7 | 2022-06-24 16:43:55 -0700 | [diff] [blame] | 233 | int32_t result = ures_getInt(measurement, status); |
| 234 | if (U_SUCCESS(*status)) { |
| 235 | system = static_cast<UMeasurementSystem>(result); |
| 236 | } |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 237 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 238 | ures_close(measurement); |
| 239 | |
| 240 | return system; |
| 241 | |
| 242 | } |
| 243 | |
| 244 | U_CAPI void U_EXPORT2 |
| 245 | ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UErrorCode *status){ |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 246 | UResourceBundle* paperSizeBundle = nullptr; |
| 247 | const int32_t* paperSize=nullptr; |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 248 | int32_t len = 0; |
| 249 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 250 | if(status == nullptr || U_FAILURE(*status)){ |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 251 | return; |
| 252 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 253 | |
Peter Edberg | 9163c9d | 2013-08-19 22:29:26 +0000 | [diff] [blame] | 254 | paperSizeBundle = measurementTypeBundleForLocale(localeID, PAPER_SIZE, status); |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 255 | paperSize = ures_getIntVector(paperSizeBundle, &len, status); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 256 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 257 | if(U_SUCCESS(*status)){ |
| 258 | if(len < 2){ |
| 259 | *status = U_INTERNAL_PROGRAM_ERROR; |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 260 | }else{ |
| 261 | *height = paperSize[0]; |
| 262 | *width = paperSize[1]; |
| 263 | } |
| 264 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 265 | |
George Rhoten | b56d67b | 2003-11-18 23:27:49 +0000 | [diff] [blame] | 266 | ures_close(paperSizeBundle); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 267 | |
Ram Viswanadha | 3858d6a | 2003-11-07 02:39:42 +0000 | [diff] [blame] | 268 | } |
Steven R. Loomis | f5a1df1 | 2009-01-29 20:31:37 +0000 | [diff] [blame] | 269 | |
Peter Edberg | b72359e | 2012-10-08 05:16:32 +0000 | [diff] [blame] | 270 | U_CAPI void U_EXPORT2 |
Steven R. Loomis | f5a1df1 | 2009-01-29 20:31:37 +0000 | [diff] [blame] | 271 | ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode *status) { |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 272 | UResourceBundle *rb = nullptr; |
| 273 | rb = ures_openDirect(nullptr, "supplementalData", status); |
Steven R. Loomis | ff0c25c | 2009-03-16 20:45:02 +0000 | [diff] [blame] | 274 | ures_getVersionByKey(rb, "cldrVersion", versionArray, status); |
Steven R. Loomis | f5a1df1 | 2009-01-29 20:31:37 +0000 | [diff] [blame] | 275 | ures_close(rb); |
| 276 | } |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 277 | |
Peter Edberg | b72359e | 2012-10-08 05:16:32 +0000 | [diff] [blame] | 278 | U_CAPI int32_t U_EXPORT2 |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 279 | ulocdata_getLocaleDisplayPattern(ULocaleData *uld, |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 280 | char16_t *result, |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 281 | int32_t resultCapacity, |
| 282 | UErrorCode *status) { |
| 283 | UResourceBundle *patternBundle; |
| 284 | int32_t len = 0; |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 285 | const char16_t *pattern = nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 286 | UErrorCode localStatus = U_ZERO_ERROR; |
| 287 | |
| 288 | if (U_FAILURE(*status)) |
| 289 | return 0; |
| 290 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 291 | patternBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", nullptr, &localStatus); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 292 | |
| 293 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 294 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 295 | } |
| 296 | |
| 297 | if (localStatus != U_ZERO_ERROR) { |
| 298 | *status = localStatus; |
| 299 | } |
| 300 | |
| 301 | if (U_FAILURE(*status)){ |
| 302 | ures_close(patternBundle); |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | pattern = ures_getStringByKey(patternBundle, "pattern", &len, &localStatus); |
| 307 | ures_close(patternBundle); |
| 308 | |
| 309 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 310 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 311 | } |
| 312 | |
| 313 | if (localStatus != U_ZERO_ERROR) { |
| 314 | *status = localStatus; |
| 315 | } |
| 316 | |
| 317 | if (U_FAILURE(*status)){ |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | u_strncpy(result, pattern, resultCapacity); |
| 322 | return len; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
Peter Edberg | b72359e | 2012-10-08 05:16:32 +0000 | [diff] [blame] | 326 | U_CAPI int32_t U_EXPORT2 |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 327 | ulocdata_getLocaleSeparator(ULocaleData *uld, |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 328 | char16_t *result, |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 329 | int32_t resultCapacity, |
| 330 | UErrorCode *status) { |
| 331 | UResourceBundle *separatorBundle; |
| 332 | int32_t len = 0; |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 333 | const char16_t *separator = nullptr; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 334 | UErrorCode localStatus = U_ZERO_ERROR; |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 335 | char16_t *p0, *p1; |
| 336 | static const char16_t sub0[4] = { 0x007b, 0x0030, 0x007d , 0x0000 }; /* {0} */ |
| 337 | static const char16_t sub1[4] = { 0x007b, 0x0031, 0x007d , 0x0000 }; /* {1} */ |
Peter Edberg | f4fd91b | 2013-07-11 07:00:49 +0000 | [diff] [blame] | 338 | static const int32_t subLen = 3; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 339 | |
| 340 | if (U_FAILURE(*status)) |
| 341 | return 0; |
| 342 | |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 343 | separatorBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", nullptr, &localStatus); |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 344 | |
| 345 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 346 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 347 | } |
| 348 | |
| 349 | if (localStatus != U_ZERO_ERROR) { |
| 350 | *status = localStatus; |
| 351 | } |
| 352 | |
| 353 | if (U_FAILURE(*status)){ |
| 354 | ures_close(separatorBundle); |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | separator = ures_getStringByKey(separatorBundle, "separator", &len, &localStatus); |
| 359 | ures_close(separatorBundle); |
| 360 | |
| 361 | if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { |
| 362 | localStatus = U_MISSING_RESOURCE_ERROR; |
| 363 | } |
| 364 | |
| 365 | if (localStatus != U_ZERO_ERROR) { |
| 366 | *status = localStatus; |
| 367 | } |
| 368 | |
| 369 | if (U_FAILURE(*status)){ |
| 370 | return 0; |
| 371 | } |
| 372 | |
Peter Edberg | f4fd91b | 2013-07-11 07:00:49 +0000 | [diff] [blame] | 373 | /* For backwards compatibility, if we have a pattern, return the portion between {0} and {1} */ |
| 374 | p0=u_strstr(separator, sub0); |
| 375 | p1=u_strstr(separator, sub1); |
Fredrik Roubert | 2e0d30c | 2022-12-22 20:22:18 +0900 | [diff] [blame] | 376 | if (p0!=nullptr && p1!=nullptr && p0<=p1) { |
Fredrik Roubert | 2de88f9 | 2022-12-27 16:54:24 +0900 | [diff] [blame] | 377 | separator = (const char16_t *)p0 + subLen; |
Daniel Ju | b13c951 | 2018-08-10 18:05:58 -0700 | [diff] [blame] | 378 | len = static_cast<int32_t>(p1 - separator); |
Peter Edberg | f4fd91b | 2013-07-11 07:00:49 +0000 | [diff] [blame] | 379 | /* Desired separator is no longer zero-terminated; handle that if necessary */ |
| 380 | if (len < resultCapacity) { |
| 381 | u_strncpy(result, separator, len); |
| 382 | result[len] = 0; |
| 383 | return len; |
| 384 | } |
| 385 | } |
| 386 | |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 387 | u_strncpy(result, separator, resultCapacity); |
| 388 | return len; |
Claire Ho | 5d17555 | 2009-02-21 00:31:21 +0000 | [diff] [blame] | 389 | } |