blob: 8e0687c5f6302d3ff95ac1cf4c518580aed09c14 [file] [log] [blame]
Andy Heninger242e02c2017-01-20 00:20:31 +00001// © 2016 and later: Unicode, Inc. and others.
Michael Ow61607c22016-06-15 18:58:17 +00002// License & terms of use: http://www.unicode.org/copyright.html
Ram Viswanadha3858d6a2003-11-07 02:39:42 +00003/*
4******************************************************************************
5* *
Yoshito Umaoka00ca13e2016-05-31 21:45:07 +00006* Copyright (C) 2003-2016, International Business Machines *
7* Corporation and others. All Rights Reserved. *
Ram Viswanadha3858d6a2003-11-07 02:39:42 +00008* *
9******************************************************************************
10* file name: ulocdata.c
Andy Heninger04448b02017-02-03 18:57:23 +000011* encoding: UTF-8
Ram Viswanadha3858d6a2003-11-07 02:39:42 +000012* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2003Oct21
John Emmonsdf5fb972005-06-30 16:56:46 +000016* created by: Ram Viswanadha,John Emmons
Ram Viswanadha3858d6a2003-11-07 02:39:42 +000017*/
18
John Emmons5662d6d2005-06-24 20:09:52 +000019#include "cmemory.h"
20#include "unicode/ustring.h"
Peter Edberg9163c9d2013-08-19 22:29:26 +000021#include "unicode/ures.h"
22#include "unicode/uloc.h"
Ram Viswanadha3858d6a2003-11-07 02:39:42 +000023#include "unicode/ulocdata.h"
Steven R. Loomisff0c25c2009-03-16 20:45:02 +000024#include "uresimp.h"
Doug Feltd62a45c2009-11-12 21:53:42 +000025#include "ureslocs.h"
Peter Edberg086ee672016-02-15 17:58:23 +000026#include "ulocimp.h"
Ram Viswanadha3858d6a2003-11-07 02:39:42 +000027
Ram Viswanadha3858d6a2003-11-07 02:39:42 +000028#define MEASUREMENT_SYSTEM "MeasurementSystem"
29#define PAPER_SIZE "PaperSize"
30
George Rhoten9327ff52005-12-01 17:51:20 +000031/** A locale data object.
32 * For usage in C programs.
33 * @draft ICU 3.4
34 */
George Rhotene8fece02005-12-02 00:05:15 +000035struct ULocaleData {
George Rhoten9327ff52005-12-01 17:51:20 +000036 /**
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 Feltd62a45c2009-11-12 21:53:42 +000045
46 /**
47 * Pointer to the lang resource bundle associated with this locale data object
48 */
49 UResourceBundle *langBundle;
George Rhotene8fece02005-12-02 00:05:15 +000050};
George Rhoten9327ff52005-12-01 17:51:20 +000051
John Emmons6fa37a02005-06-24 15:48:23 +000052U_CAPI ULocaleData* U_EXPORT2
53ulocdata_open(const char *localeID, UErrorCode *status)
54{
55 ULocaleData *uld;
Claire Ho5d175552009-02-21 00:31:21 +000056
John Emmons6fa37a02005-06-24 15:48:23 +000057 if (U_FAILURE(*status)) {
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090058 return nullptr;
John Emmons6fa37a02005-06-24 15:48:23 +000059 }
60
61 uld = (ULocaleData *)uprv_malloc(sizeof(ULocaleData));
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090062 if (uld == nullptr) {
John Emmons6fa37a02005-06-24 15:48:23 +000063 *status = U_MEMORY_ALLOCATION_ERROR;
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090064 return(nullptr);
John Emmons6fa37a02005-06-24 15:48:23 +000065 }
66
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090067 uld->langBundle = nullptr;
Claire Ho5d175552009-02-21 00:31:21 +000068
Fredrik Roubert030fa1a2022-09-06 21:18:38 +020069 uld->noSubstitute = false;
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090070 uld->bundle = ures_open(nullptr, localeID, status);
Doug Feltd62a45c2009-11-12 21:53:42 +000071 uld->langBundle = ures_open(U_ICUDATA_LANG, localeID, status);
John Emmons6fa37a02005-06-24 15:48:23 +000072
73 if (U_FAILURE(*status)) {
74 uprv_free(uld);
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090075 return nullptr;
John Emmons6fa37a02005-06-24 15:48:23 +000076 }
77
78 return uld;
79}
80
81U_CAPI void U_EXPORT2
82ulocdata_close(ULocaleData *uld)
83{
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +090084 if ( uld != nullptr ) {
Doug Feltd62a45c2009-11-12 21:53:42 +000085 ures_close(uld->langBundle);
John Emmons6fa37a02005-06-24 15:48:23 +000086 ures_close(uld->bundle);
87 uprv_free(uld);
Claire Ho5d175552009-02-21 00:31:21 +000088 }
John Emmons6fa37a02005-06-24 15:48:23 +000089}
90
John Emmonsdf5fb972005-06-30 16:56:46 +000091U_CAPI void U_EXPORT2
92ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting)
93{
94 uld->noSubstitute = setting;
95}
96
97U_CAPI UBool U_EXPORT2
98ulocdata_getNoSubstitute(ULocaleData *uld)
99{
100 return uld->noSubstitute;
101}
102
John Emmons6fa37a02005-06-24 15:48:23 +0000103U_CAPI USet* U_EXPORT2
Claire Ho5d175552009-02-21 00:31:21 +0000104ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn,
John Emmons6fa37a02005-06-24 15:48:23 +0000105 uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status){
Claire Ho5d175552009-02-21 00:31:21 +0000106
Andy Heninger7b7f48e2011-02-25 22:21:30 +0000107 static const char* const exemplarSetTypes[] = { "ExemplarCharacters",
108 "AuxExemplarCharacters",
Yoshito Umaoka557da152013-01-18 16:29:02 +0000109 "ExemplarCharactersIndex",
110 "ExemplarCharactersPunctuation"};
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900111 const char16_t *exemplarChars = nullptr;
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000112 int32_t len = 0;
George Rhoten83642162004-10-19 05:19:36 +0000113 UErrorCode localStatus = U_ZERO_ERROR;
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000114
John Emmons6fa37a02005-06-24 15:48:23 +0000115 if (U_FAILURE(*status))
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900116 return nullptr;
Claire Ho5d175552009-02-21 00:31:21 +0000117
John Emmons6fa37a02005-06-24 15:48:23 +0000118 exemplarChars = ures_getStringByKey(uld->bundle, exemplarSetTypes[extype], &len, &localStatus);
John Emmonsdf5fb972005-06-30 16:56:46 +0000119 if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
120 localStatus = U_MISSING_RESOURCE_ERROR;
121 }
Claire Ho5d175552009-02-21 00:31:21 +0000122
George Rhoten87b2dc62005-09-14 19:09:13 +0000123 if (localStatus != U_ZERO_ERROR) {
Deborah Goldsmith9cc484f2004-10-18 23:58:03 +0000124 *status = localStatus;
125 }
Claire Ho5d175552009-02-21 00:31:21 +0000126
John Emmonsdf5fb972005-06-30 16:56:46 +0000127 if (U_FAILURE(*status))
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900128 return nullptr;
Claire Ho5d175552009-02-21 00:31:21 +0000129
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900130 if(fillIn != nullptr)
Claire Ho5d175552009-02-21 00:31:21 +0000131 uset_applyPattern(fillIn, exemplarChars, len,
Alan Liu850661f2004-05-17 21:42:43 +0000132 USET_IGNORE_SPACE | options, status);
John Emmons6fa37a02005-06-24 15:48:23 +0000133 else
Alan Liu850661f2004-05-17 21:42:43 +0000134 fillIn = uset_openPatternOptions(exemplarChars, len,
135 USET_IGNORE_SPACE | options, status);
Claire Ho5d175552009-02-21 00:31:21 +0000136
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000137 return fillIn;
138
139}
140
John Emmons6fa37a02005-06-24 15:48:23 +0000141U_CAPI int32_t U_EXPORT2
Claire Ho5d175552009-02-21 00:31:21 +0000142ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type,
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900143 char16_t *result, int32_t resultLength, UErrorCode *status){
John Emmons6fa37a02005-06-24 15:48:23 +0000144
George Rhotencf340142007-06-14 01:30:51 +0000145 static const char* const delimiterKeys[] = {
146 "quotationStart",
147 "quotationEnd",
148 "alternateQuotationStart",
149 "alternateQuotationEnd"
150 };
Claire Ho5d175552009-02-21 00:31:21 +0000151
John Emmonsdf5fb972005-06-30 16:56:46 +0000152 UResourceBundle *delimiterBundle;
John Emmons6fa37a02005-06-24 15:48:23 +0000153 int32_t len = 0;
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900154 const char16_t *delimiter = nullptr;
John Emmons6fa37a02005-06-24 15:48:23 +0000155 UErrorCode localStatus = U_ZERO_ERROR;
156
157 if (U_FAILURE(*status))
George Rhoten83af9f32005-06-24 22:19:45 +0000158 return 0;
John Emmons6fa37a02005-06-24 15:48:23 +0000159
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900160 delimiterBundle = ures_getByKey(uld->bundle, "delimiters", nullptr, &localStatus);
John Emmonsdf5fb972005-06-30 16:56:46 +0000161
162 if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
163 localStatus = U_MISSING_RESOURCE_ERROR;
164 }
165
George Rhoten87b2dc62005-09-14 19:09:13 +0000166 if (localStatus != U_ZERO_ERROR) {
John Emmonsdf5fb972005-06-30 16:56:46 +0000167 *status = localStatus;
168 }
169
Ram Viswanadhabaf31502005-07-14 23:25:48 +0000170 if (U_FAILURE(*status)){
171 ures_close(delimiterBundle);
John Emmonsdf5fb972005-06-30 16:56:46 +0000172 return 0;
Ram Viswanadhabaf31502005-07-14 23:25:48 +0000173 }
John Emmonsdf5fb972005-06-30 16:56:46 +0000174
Frank Tangf1a8a632020-10-08 00:25:34 +0000175 delimiter = ures_getStringByKeyWithFallback(delimiterBundle, delimiterKeys[type], &len, &localStatus);
George Rhotenb11decc2005-07-18 06:05:28 +0000176 ures_close(delimiterBundle);
John Emmonsdf5fb972005-06-30 16:56:46 +0000177
178 if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
179 localStatus = U_MISSING_RESOURCE_ERROR;
180 }
181
George Rhoten87b2dc62005-09-14 19:09:13 +0000182 if (localStatus != U_ZERO_ERROR) {
John Emmons6fa37a02005-06-24 15:48:23 +0000183 *status = localStatus;
184 }
Claire Ho5d175552009-02-21 00:31:21 +0000185
Ram Viswanadhabaf31502005-07-14 23:25:48 +0000186 if (U_FAILURE(*status)){
John Emmonsdf5fb972005-06-30 16:56:46 +0000187 return 0;
Ram Viswanadhabaf31502005-07-14 23:25:48 +0000188 }
Claire Ho5d175552009-02-21 00:31:21 +0000189
190 u_strncpy(result,delimiter, resultLength);
John Emmons6fa37a02005-06-24 15:48:23 +0000191 return len;
192}
193
Peter Edberg9163c9d2013-08-19 22:29:26 +0000194static UResourceBundle * measurementTypeBundleForLocale(const char *localeID, const char *measurementType, UErrorCode *status){
Peter Edberg9163c9d2013-08-19 22:29:26 +0000195 char region[ULOC_COUNTRY_CAPACITY];
196 UResourceBundle *rb;
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900197 UResourceBundle *measTypeBundle = nullptr;
Peter Edberg9163c9d2013-08-19 22:29:26 +0000198
Fredrik Roubert030fa1a2022-09-06 21:18:38 +0200199 ulocimp_getRegionForSupplementalData(localeID, true, region, ULOC_COUNTRY_CAPACITY, status);
Peter Edberg9163c9d2013-08-19 22:29:26 +0000200
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900201 rb = ures_openDirect(nullptr, "supplementalData", status);
Peter Edberg9163c9d2013-08-19 22:29:26 +0000202 ures_getByKey(rb, "measurementData", rb, status);
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900203 if (rb != nullptr) {
204 UResourceBundle *measDataBundle = ures_getByKey(rb, region, nullptr, status);
Peter Edberg9163c9d2013-08-19 22:29:26 +0000205 if (U_SUCCESS(*status)) {
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900206 measTypeBundle = ures_getByKey(measDataBundle, measurementType, nullptr, status);
Peter Edberg9163c9d2013-08-19 22:29:26 +0000207 }
208 if (*status == U_MISSING_RESOURCE_ERROR) {
209 *status = U_ZERO_ERROR;
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900210 if (measDataBundle != nullptr) {
Michael Ow10ae93e2013-08-20 20:19:58 +0000211 ures_close(measDataBundle);
212 }
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900213 measDataBundle = ures_getByKey(rb, "001", nullptr, status);
214 measTypeBundle = ures_getByKey(measDataBundle, measurementType, nullptr, status);
Peter Edberg9163c9d2013-08-19 22:29:26 +0000215 }
216 ures_close(measDataBundle);
217 }
218 ures_close(rb);
219 return measTypeBundle;
220}
221
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000222U_CAPI UMeasurementSystem U_EXPORT2
223ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
Claire Ho5d175552009-02-21 00:31:21 +0000224
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900225 UResourceBundle* measurement=nullptr;
Claire Ho5d175552009-02-21 00:31:21 +0000226 UMeasurementSystem system = UMS_LIMIT;
227
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900228 if(status == nullptr || U_FAILURE(*status)){
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000229 return system;
230 }
Claire Ho5d175552009-02-21 00:31:21 +0000231
Peter Edberg9163c9d2013-08-19 22:29:26 +0000232 measurement = measurementTypeBundleForLocale(localeID, MEASUREMENT_SYSTEM, status);
Frank Tang43f2ae72022-06-24 16:43:55 -0700233 int32_t result = ures_getInt(measurement, status);
234 if (U_SUCCESS(*status)) {
235 system = static_cast<UMeasurementSystem>(result);
236 }
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000237
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000238 ures_close(measurement);
239
240 return system;
241
242}
243
244U_CAPI void U_EXPORT2
245ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UErrorCode *status){
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900246 UResourceBundle* paperSizeBundle = nullptr;
247 const int32_t* paperSize=nullptr;
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000248 int32_t len = 0;
249
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900250 if(status == nullptr || U_FAILURE(*status)){
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000251 return;
252 }
Claire Ho5d175552009-02-21 00:31:21 +0000253
Peter Edberg9163c9d2013-08-19 22:29:26 +0000254 paperSizeBundle = measurementTypeBundleForLocale(localeID, PAPER_SIZE, status);
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000255 paperSize = ures_getIntVector(paperSizeBundle, &len, status);
Claire Ho5d175552009-02-21 00:31:21 +0000256
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000257 if(U_SUCCESS(*status)){
258 if(len < 2){
259 *status = U_INTERNAL_PROGRAM_ERROR;
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000260 }else{
261 *height = paperSize[0];
262 *width = paperSize[1];
263 }
264 }
Claire Ho5d175552009-02-21 00:31:21 +0000265
George Rhotenb56d67b2003-11-18 23:27:49 +0000266 ures_close(paperSizeBundle);
Claire Ho5d175552009-02-21 00:31:21 +0000267
Ram Viswanadha3858d6a2003-11-07 02:39:42 +0000268}
Steven R. Loomisf5a1df12009-01-29 20:31:37 +0000269
Peter Edbergb72359e2012-10-08 05:16:32 +0000270U_CAPI void U_EXPORT2
Steven R. Loomisf5a1df12009-01-29 20:31:37 +0000271ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode *status) {
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900272 UResourceBundle *rb = nullptr;
273 rb = ures_openDirect(nullptr, "supplementalData", status);
Steven R. Loomisff0c25c2009-03-16 20:45:02 +0000274 ures_getVersionByKey(rb, "cldrVersion", versionArray, status);
Steven R. Loomisf5a1df12009-01-29 20:31:37 +0000275 ures_close(rb);
276}
Claire Ho5d175552009-02-21 00:31:21 +0000277
Peter Edbergb72359e2012-10-08 05:16:32 +0000278U_CAPI int32_t U_EXPORT2
Claire Ho5d175552009-02-21 00:31:21 +0000279ulocdata_getLocaleDisplayPattern(ULocaleData *uld,
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900280 char16_t *result,
Claire Ho5d175552009-02-21 00:31:21 +0000281 int32_t resultCapacity,
282 UErrorCode *status) {
283 UResourceBundle *patternBundle;
284 int32_t len = 0;
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900285 const char16_t *pattern = nullptr;
Claire Ho5d175552009-02-21 00:31:21 +0000286 UErrorCode localStatus = U_ZERO_ERROR;
287
288 if (U_FAILURE(*status))
289 return 0;
290
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900291 patternBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", nullptr, &localStatus);
Claire Ho5d175552009-02-21 00:31:21 +0000292
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 Ho5d175552009-02-21 00:31:21 +0000323}
324
325
Peter Edbergb72359e2012-10-08 05:16:32 +0000326U_CAPI int32_t U_EXPORT2
Claire Ho5d175552009-02-21 00:31:21 +0000327ulocdata_getLocaleSeparator(ULocaleData *uld,
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900328 char16_t *result,
Claire Ho5d175552009-02-21 00:31:21 +0000329 int32_t resultCapacity,
330 UErrorCode *status) {
331 UResourceBundle *separatorBundle;
332 int32_t len = 0;
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900333 const char16_t *separator = nullptr;
Claire Ho5d175552009-02-21 00:31:21 +0000334 UErrorCode localStatus = U_ZERO_ERROR;
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900335 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 Edbergf4fd91b2013-07-11 07:00:49 +0000338 static const int32_t subLen = 3;
Claire Ho5d175552009-02-21 00:31:21 +0000339
340 if (U_FAILURE(*status))
341 return 0;
342
Fredrik Roubert2e0d30c2022-12-22 20:22:18 +0900343 separatorBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", nullptr, &localStatus);
Claire Ho5d175552009-02-21 00:31:21 +0000344
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 Edbergf4fd91b2013-07-11 07:00:49 +0000373 /* 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 Roubert2e0d30c2022-12-22 20:22:18 +0900376 if (p0!=nullptr && p1!=nullptr && p0<=p1) {
Fredrik Roubert2de88f92022-12-27 16:54:24 +0900377 separator = (const char16_t *)p0 + subLen;
Daniel Jub13c9512018-08-10 18:05:58 -0700378 len = static_cast<int32_t>(p1 - separator);
Peter Edbergf4fd91b2013-07-11 07:00:49 +0000379 /* 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 Ho5d175552009-02-21 00:31:21 +0000387 u_strncpy(result, separator, resultCapacity);
388 return len;
Claire Ho5d175552009-02-21 00:31:21 +0000389}