]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/locdspnm.cpp
ICU-491.11.2.tar.gz
[apple/icu.git] / icuSources / i18n / locdspnm.cpp
1 /*
2 *******************************************************************************
3 * Copyright (C) 2010-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 */
7
8 #include "unicode/utypes.h"
9
10 #if !UCONFIG_NO_FORMATTING
11
12 #include "unicode/locdspnm.h"
13
14 #include "unicode/msgfmt.h"
15
16 #include "cmemory.h"
17 #include "cstring.h"
18 #include "ulocimp.h"
19 #include "ureslocs.h"
20
21 #include <stdarg.h>
22
23 /**
24 * Concatenate a number of null-terminated strings to buffer, leaving a
25 * null-terminated string. The last argument should be the null pointer.
26 * Return the length of the string in the buffer, not counting the trailing
27 * null. Return -1 if there is an error (buffer is null, or buflen < 1).
28 */
29 static int32_t ncat(char *buffer, uint32_t buflen, ...) {
30 va_list args;
31 char *str;
32 char *p = buffer;
33 const char* e = buffer + buflen - 1;
34
35 if (buffer == NULL || buflen < 1) {
36 return -1;
37 }
38
39 va_start(args, buflen);
40 while ((str = va_arg(args, char *))) {
41 char c;
42 while (p != e && (c = *str++)) {
43 *p++ = c;
44 }
45 }
46 *p = 0;
47 va_end(args);
48
49 return p - buffer;
50 }
51
52 U_NAMESPACE_BEGIN
53
54 ////////////////////////////////////////////////////////////////////////////////////////////////////
55
56 // Access resource data for locale components.
57 // Wrap code in uloc.c for now.
58 class ICUDataTable {
59 const char* path;
60 Locale locale;
61
62 public:
63 ICUDataTable(const char* path, const Locale& locale);
64 ~ICUDataTable();
65
66 const Locale& getLocale();
67
68 UnicodeString& get(const char* tableKey, const char* itemKey,
69 UnicodeString& result) const;
70 UnicodeString& get(const char* tableKey, const char* subTableKey, const char* itemKey,
71 UnicodeString& result) const;
72
73 UnicodeString& getNoFallback(const char* tableKey, const char* itemKey,
74 UnicodeString &result) const;
75 UnicodeString& getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey,
76 UnicodeString &result) const;
77 };
78
79 inline UnicodeString &
80 ICUDataTable::get(const char* tableKey, const char* itemKey, UnicodeString& result) const {
81 return get(tableKey, NULL, itemKey, result);
82 }
83
84 inline UnicodeString &
85 ICUDataTable::getNoFallback(const char* tableKey, const char* itemKey, UnicodeString& result) const {
86 return getNoFallback(tableKey, NULL, itemKey, result);
87 }
88
89 ICUDataTable::ICUDataTable(const char* path, const Locale& locale)
90 : path(NULL), locale(Locale::getRoot())
91 {
92 if (path) {
93 int32_t len = uprv_strlen(path);
94 this->path = (const char*) uprv_malloc(len + 1);
95 if (this->path) {
96 uprv_strcpy((char *)this->path, path);
97 this->locale = locale;
98 }
99 }
100 }
101
102 ICUDataTable::~ICUDataTable() {
103 if (path) {
104 uprv_free((void*) path);
105 path = NULL;
106 }
107 }
108
109 const Locale&
110 ICUDataTable::getLocale() {
111 return locale;
112 }
113
114 UnicodeString &
115 ICUDataTable::get(const char* tableKey, const char* subTableKey, const char* itemKey,
116 UnicodeString &result) const {
117 UErrorCode status = U_ZERO_ERROR;
118 int32_t len = 0;
119
120 const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(),
121 tableKey, subTableKey, itemKey,
122 &len, &status);
123 if (U_SUCCESS(status) && len > 0) {
124 return result.setTo(s, len);
125 }
126 return result.setTo(UnicodeString(itemKey, -1, US_INV));
127 }
128
129 UnicodeString &
130 ICUDataTable::getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey,
131 UnicodeString& result) const {
132 UErrorCode status = U_ZERO_ERROR;
133 int32_t len = 0;
134
135 const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(),
136 tableKey, subTableKey, itemKey,
137 &len, &status);
138 if (U_SUCCESS(status)) {
139 return result.setTo(s, len);
140 }
141
142 result.setToBogus();
143 return result;
144 }
145
146 ////////////////////////////////////////////////////////////////////////////////////////////////////
147
148 LocaleDisplayNames::~LocaleDisplayNames() {}
149
150 UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(LocaleDisplayNames)
151
152 ////////////////////////////////////////////////////////////////////////////////////////////////////
153
154 #if 0 // currently unused
155
156 class DefaultLocaleDisplayNames : public LocaleDisplayNames {
157 UDialectHandling dialectHandling;
158
159 public:
160 // constructor
161 DefaultLocaleDisplayNames(UDialectHandling dialectHandling);
162
163 virtual ~DefaultLocaleDisplayNames();
164
165 virtual const Locale& getLocale() const;
166 virtual UDialectHandling getDialectHandling() const;
167 virtual UnicodeString& localeDisplayName(const Locale& locale,
168 UnicodeString& result) const;
169 virtual UnicodeString& localeDisplayName(const char* localeId,
170 UnicodeString& result) const;
171 virtual UnicodeString& languageDisplayName(const char* lang,
172 UnicodeString& result) const;
173 virtual UnicodeString& scriptDisplayName(const char* script,
174 UnicodeString& result) const;
175 virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
176 UnicodeString& result) const;
177 virtual UnicodeString& regionDisplayName(const char* region,
178 UnicodeString& result) const;
179 virtual UnicodeString& variantDisplayName(const char* variant,
180 UnicodeString& result) const;
181 virtual UnicodeString& keyDisplayName(const char* key,
182 UnicodeString& result) const;
183 virtual UnicodeString& keyValueDisplayName(const char* key,
184 const char* value,
185 UnicodeString& result) const;
186 };
187
188 DefaultLocaleDisplayNames::DefaultLocaleDisplayNames(UDialectHandling dialectHandling)
189 : dialectHandling(dialectHandling) {
190 }
191
192 DefaultLocaleDisplayNames::~DefaultLocaleDisplayNames() {
193 }
194
195 const Locale&
196 DefaultLocaleDisplayNames::getLocale() const {
197 return Locale::getRoot();
198 }
199
200 UDialectHandling
201 DefaultLocaleDisplayNames::getDialectHandling() const {
202 return dialectHandling;
203 }
204
205 UnicodeString&
206 DefaultLocaleDisplayNames::localeDisplayName(const Locale& locale,
207 UnicodeString& result) const {
208 return result = UnicodeString(locale.getName(), -1, US_INV);
209 }
210
211 UnicodeString&
212 DefaultLocaleDisplayNames::localeDisplayName(const char* localeId,
213 UnicodeString& result) const {
214 return result = UnicodeString(localeId, -1, US_INV);
215 }
216
217 UnicodeString&
218 DefaultLocaleDisplayNames::languageDisplayName(const char* lang,
219 UnicodeString& result) const {
220 return result = UnicodeString(lang, -1, US_INV);
221 }
222
223 UnicodeString&
224 DefaultLocaleDisplayNames::scriptDisplayName(const char* script,
225 UnicodeString& result) const {
226 return result = UnicodeString(script, -1, US_INV);
227 }
228
229 UnicodeString&
230 DefaultLocaleDisplayNames::scriptDisplayName(UScriptCode scriptCode,
231 UnicodeString& result) const {
232 const char* name = uscript_getName(scriptCode);
233 if (name) {
234 return result = UnicodeString(name, -1, US_INV);
235 }
236 return result.remove();
237 }
238
239 UnicodeString&
240 DefaultLocaleDisplayNames::regionDisplayName(const char* region,
241 UnicodeString& result) const {
242 return result = UnicodeString(region, -1, US_INV);
243 }
244
245 UnicodeString&
246 DefaultLocaleDisplayNames::variantDisplayName(const char* variant,
247 UnicodeString& result) const {
248 return result = UnicodeString(variant, -1, US_INV);
249 }
250
251 UnicodeString&
252 DefaultLocaleDisplayNames::keyDisplayName(const char* key,
253 UnicodeString& result) const {
254 return result = UnicodeString(key, -1, US_INV);
255 }
256
257 UnicodeString&
258 DefaultLocaleDisplayNames::keyValueDisplayName(const char* /* key */,
259 const char* value,
260 UnicodeString& result) const {
261 return result = UnicodeString(value, -1, US_INV);
262 }
263
264 #endif // currently unused class DefaultLocaleDisplayNames
265
266 ////////////////////////////////////////////////////////////////////////////////////////////////////
267
268 class LocaleDisplayNamesImpl : public LocaleDisplayNames {
269 Locale locale;
270 UDialectHandling dialectHandling;
271 ICUDataTable langData;
272 ICUDataTable regionData;
273 UnicodeString sep;
274 MessageFormat *format;
275 MessageFormat *keyTypeFormat;
276
277 public:
278 // constructor
279 LocaleDisplayNamesImpl(const Locale& locale, UDialectHandling dialectHandling);
280 virtual ~LocaleDisplayNamesImpl();
281
282 virtual const Locale& getLocale() const;
283 virtual UDialectHandling getDialectHandling() const;
284
285 virtual UnicodeString& localeDisplayName(const Locale& locale,
286 UnicodeString& result) const;
287 virtual UnicodeString& localeDisplayName(const char* localeId,
288 UnicodeString& result) const;
289 virtual UnicodeString& languageDisplayName(const char* lang,
290 UnicodeString& result) const;
291 virtual UnicodeString& scriptDisplayName(const char* script,
292 UnicodeString& result) const;
293 virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
294 UnicodeString& result) const;
295 virtual UnicodeString& regionDisplayName(const char* region,
296 UnicodeString& result) const;
297 virtual UnicodeString& variantDisplayName(const char* variant,
298 UnicodeString& result) const;
299 virtual UnicodeString& keyDisplayName(const char* key,
300 UnicodeString& result) const;
301 virtual UnicodeString& keyValueDisplayName(const char* key,
302 const char* value,
303 UnicodeString& result) const;
304 private:
305 UnicodeString& localeIdName(const char* localeId,
306 UnicodeString& result) const;
307 UnicodeString& appendWithSep(UnicodeString& buffer, const UnicodeString& src) const;
308 };
309
310 LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
311 UDialectHandling dialectHandling)
312 : dialectHandling(dialectHandling)
313 , langData(U_ICUDATA_LANG, locale)
314 , regionData(U_ICUDATA_REGION, locale)
315 , format(NULL)
316 , keyTypeFormat(NULL)
317 {
318 LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
319 nonConstThis->locale = langData.getLocale() == Locale::getRoot()
320 ? regionData.getLocale()
321 : langData.getLocale();
322
323 langData.getNoFallback("localeDisplayPattern", "separator", sep);
324 if (sep.isBogus()) {
325 sep = UnicodeString(", ", -1, US_INV);
326 }
327
328 UnicodeString pattern;
329 langData.getNoFallback("localeDisplayPattern", "pattern", pattern);
330 if (pattern.isBogus()) {
331 pattern = UnicodeString("{0} ({1})", -1, US_INV);
332 }
333 UErrorCode status = U_ZERO_ERROR;
334 format = new MessageFormat(pattern, status);
335
336 UnicodeString ktPattern;
337 langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
338 if (ktPattern.isBogus()) {
339 ktPattern = UnicodeString("{0}={1}", -1, US_INV);
340 }
341 keyTypeFormat = new MessageFormat(ktPattern, status);
342 }
343
344 LocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() {
345 delete format;
346 delete keyTypeFormat;
347 }
348
349 const Locale&
350 LocaleDisplayNamesImpl::getLocale() const {
351 return locale;
352 }
353
354 UDialectHandling
355 LocaleDisplayNamesImpl::getDialectHandling() const {
356 return dialectHandling;
357 }
358
359 UnicodeString&
360 LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
361 UnicodeString& result) const {
362 UnicodeString resultName;
363
364 const char* lang = locale.getLanguage();
365 if (uprv_strlen(lang) == 0) {
366 lang = "root";
367 }
368 const char* script = locale.getScript();
369 const char* country = locale.getCountry();
370 const char* variant = locale.getVariant();
371
372 UBool hasScript = uprv_strlen(script) > 0;
373 UBool hasCountry = uprv_strlen(country) > 0;
374 UBool hasVariant = uprv_strlen(variant) > 0;
375
376 if (dialectHandling == ULDN_DIALECT_NAMES) {
377 char buffer[ULOC_FULLNAME_CAPACITY];
378 do { // loop construct is so we can break early out of search
379 if (hasScript && hasCountry) {
380 ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
381 localeIdName(buffer, resultName);
382 if (!resultName.isBogus()) {
383 hasScript = FALSE;
384 hasCountry = FALSE;
385 break;
386 }
387 }
388 if (hasScript) {
389 ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
390 localeIdName(buffer, resultName);
391 if (!resultName.isBogus()) {
392 hasScript = FALSE;
393 break;
394 }
395 }
396 if (hasCountry) {
397 ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
398 localeIdName(buffer, resultName);
399 if (!resultName.isBogus()) {
400 hasCountry = FALSE;
401 break;
402 }
403 }
404 } while (FALSE);
405 }
406 if (resultName.isBogus() || resultName.isEmpty()) {
407 localeIdName(lang, resultName);
408 }
409
410 UnicodeString resultRemainder;
411 UnicodeString temp;
412 StringEnumeration *e = NULL;
413 UErrorCode status = U_ZERO_ERROR;
414
415 if (hasScript) {
416 resultRemainder.append(scriptDisplayName(script, temp));
417 }
418 if (hasCountry) {
419 appendWithSep(resultRemainder, regionDisplayName(country, temp));
420 }
421 if (hasVariant) {
422 appendWithSep(resultRemainder, variantDisplayName(variant, temp));
423 }
424
425 e = locale.createKeywords(status);
426 if (e && U_SUCCESS(status)) {
427 UnicodeString temp2;
428 char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
429 const char* key;
430 while ((key = e->next((int32_t *)0, status)) != NULL) {
431 locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
432 keyDisplayName(key, temp);
433 keyValueDisplayName(key, value, temp2);
434 if (temp2 != UnicodeString(value, -1, US_INV)) {
435 appendWithSep(resultRemainder, temp2);
436 } else if (temp != UnicodeString(key, -1, US_INV)) {
437 UnicodeString temp3;
438 Formattable data[] = {
439 temp,
440 temp2
441 };
442 FieldPosition fpos;
443 status = U_ZERO_ERROR;
444 keyTypeFormat->format(data, 2, temp3, fpos, status);
445 appendWithSep(resultRemainder, temp3);
446 } else {
447 appendWithSep(resultRemainder, temp)
448 .append((UChar)0x3d /* = */)
449 .append(temp2);
450 }
451 }
452 delete e;
453 }
454
455 if (!resultRemainder.isEmpty()) {
456 Formattable data[] = {
457 resultName,
458 resultRemainder
459 };
460 FieldPosition fpos;
461 status = U_ZERO_ERROR;
462 format->format(data, 2, result, fpos, status);
463 return result;
464 }
465
466 return result = resultName;
467 }
468
469 UnicodeString&
470 LocaleDisplayNamesImpl::appendWithSep(UnicodeString& buffer, const UnicodeString& src) const {
471 if (!buffer.isEmpty()) {
472 buffer.append(sep);
473 }
474 buffer.append(src);
475 return buffer;
476 }
477
478 UnicodeString&
479 LocaleDisplayNamesImpl::localeDisplayName(const char* localeId,
480 UnicodeString& result) const {
481 return localeDisplayName(Locale(localeId), result);
482 }
483
484 UnicodeString&
485 LocaleDisplayNamesImpl::localeIdName(const char* localeId,
486 UnicodeString& result) const {
487 return langData.getNoFallback("Languages", localeId, result);
488 }
489
490 UnicodeString&
491 LocaleDisplayNamesImpl::languageDisplayName(const char* lang,
492 UnicodeString& result) const {
493 if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) {
494 return result = UnicodeString(lang, -1, US_INV);
495 }
496 return langData.get("Languages", lang, result);
497 }
498
499 UnicodeString&
500 LocaleDisplayNamesImpl::scriptDisplayName(const char* script,
501 UnicodeString& result) const {
502 return langData.get("Scripts", script, result);
503 }
504
505 UnicodeString&
506 LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode,
507 UnicodeString& result) const {
508 const char* name = uscript_getName(scriptCode);
509 return langData.get("Scripts", name, result);
510 }
511
512 UnicodeString&
513 LocaleDisplayNamesImpl::regionDisplayName(const char* region,
514 UnicodeString& result) const {
515 return regionData.get("Countries", region, result);
516 }
517
518 UnicodeString&
519 LocaleDisplayNamesImpl::variantDisplayName(const char* variant,
520 UnicodeString& result) const {
521 return langData.get("Variants", variant, result);
522 }
523
524 UnicodeString&
525 LocaleDisplayNamesImpl::keyDisplayName(const char* key,
526 UnicodeString& result) const {
527 return langData.get("Keys", key, result);
528 }
529
530 UnicodeString&
531 LocaleDisplayNamesImpl::keyValueDisplayName(const char* key,
532 const char* value,
533 UnicodeString& result) const {
534 return langData.get("Types", key, value, result);
535 }
536
537 ////////////////////////////////////////////////////////////////////////////////////////////////////
538
539 LocaleDisplayNames*
540 LocaleDisplayNames::createInstance(const Locale& locale,
541 UDialectHandling dialectHandling) {
542 return new LocaleDisplayNamesImpl(locale, dialectHandling);
543 }
544
545 U_NAMESPACE_END
546
547 ////////////////////////////////////////////////////////////////////////////////////////////////////
548
549 U_NAMESPACE_USE
550
551 U_DRAFT ULocaleDisplayNames * U_EXPORT2
552 uldn_open(const char * locale,
553 UDialectHandling dialectHandling,
554 UErrorCode *pErrorCode) {
555 if (U_FAILURE(*pErrorCode)) {
556 return 0;
557 }
558 if (locale == NULL) {
559 locale = uloc_getDefault();
560 }
561 return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), dialectHandling);
562 }
563
564 U_DRAFT void U_EXPORT2
565 uldn_close(ULocaleDisplayNames *ldn) {
566 delete (LocaleDisplayNames *)ldn;
567 }
568
569 U_DRAFT const char * U_EXPORT2
570 uldn_getLocale(const ULocaleDisplayNames *ldn) {
571 if (ldn) {
572 return ((const LocaleDisplayNames *)ldn)->getLocale().getName();
573 }
574 return NULL;
575 }
576
577 U_DRAFT UDialectHandling U_EXPORT2
578 uldn_getDialectHandling(const ULocaleDisplayNames *ldn) {
579 if (ldn) {
580 return ((const LocaleDisplayNames *)ldn)->getDialectHandling();
581 }
582 return ULDN_STANDARD_NAMES;
583 }
584
585 U_DRAFT int32_t U_EXPORT2
586 uldn_localeDisplayName(const ULocaleDisplayNames *ldn,
587 const char *locale,
588 UChar *result,
589 int32_t maxResultSize,
590 UErrorCode *pErrorCode) {
591 if (U_FAILURE(*pErrorCode)) {
592 return 0;
593 }
594 if (ldn == NULL || locale == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
595 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
596 return 0;
597 }
598 UnicodeString temp(result, 0, maxResultSize);
599 ((const LocaleDisplayNames *)ldn)->localeDisplayName(locale, temp);
600 return temp.extract(result, maxResultSize, *pErrorCode);
601 }
602
603 U_DRAFT int32_t U_EXPORT2
604 uldn_languageDisplayName(const ULocaleDisplayNames *ldn,
605 const char *lang,
606 UChar *result,
607 int32_t maxResultSize,
608 UErrorCode *pErrorCode) {
609 if (U_FAILURE(*pErrorCode)) {
610 return 0;
611 }
612 if (ldn == NULL || lang == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
613 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
614 return 0;
615 }
616 UnicodeString temp(result, 0, maxResultSize);
617 ((const LocaleDisplayNames *)ldn)->languageDisplayName(lang, temp);
618 return temp.extract(result, maxResultSize, *pErrorCode);
619 }
620
621 U_DRAFT int32_t U_EXPORT2
622 uldn_scriptDisplayName(const ULocaleDisplayNames *ldn,
623 const char *script,
624 UChar *result,
625 int32_t maxResultSize,
626 UErrorCode *pErrorCode) {
627 if (U_FAILURE(*pErrorCode)) {
628 return 0;
629 }
630 if (ldn == NULL || script == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
631 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
632 return 0;
633 }
634 UnicodeString temp(result, 0, maxResultSize);
635 ((const LocaleDisplayNames *)ldn)->scriptDisplayName(script, temp);
636 return temp.extract(result, maxResultSize, *pErrorCode);
637 }
638
639 U_DRAFT int32_t U_EXPORT2
640 uldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn,
641 UScriptCode scriptCode,
642 UChar *result,
643 int32_t maxResultSize,
644 UErrorCode *pErrorCode) {
645 return uldn_scriptDisplayName(ldn, uscript_getName(scriptCode), result, maxResultSize, pErrorCode);
646 }
647
648 U_DRAFT int32_t U_EXPORT2
649 uldn_regionDisplayName(const ULocaleDisplayNames *ldn,
650 const char *region,
651 UChar *result,
652 int32_t maxResultSize,
653 UErrorCode *pErrorCode) {
654 if (U_FAILURE(*pErrorCode)) {
655 return 0;
656 }
657 if (ldn == NULL || region == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
658 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
659 return 0;
660 }
661 UnicodeString temp(result, 0, maxResultSize);
662 ((const LocaleDisplayNames *)ldn)->regionDisplayName(region, temp);
663 return temp.extract(result, maxResultSize, *pErrorCode);
664 }
665
666 U_DRAFT int32_t U_EXPORT2
667 uldn_variantDisplayName(const ULocaleDisplayNames *ldn,
668 const char *variant,
669 UChar *result,
670 int32_t maxResultSize,
671 UErrorCode *pErrorCode) {
672 if (U_FAILURE(*pErrorCode)) {
673 return 0;
674 }
675 if (ldn == NULL || variant == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
676 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
677 return 0;
678 }
679 UnicodeString temp(result, 0, maxResultSize);
680 ((const LocaleDisplayNames *)ldn)->variantDisplayName(variant, temp);
681 return temp.extract(result, maxResultSize, *pErrorCode);
682 }
683
684 U_DRAFT int32_t U_EXPORT2
685 uldn_keyDisplayName(const ULocaleDisplayNames *ldn,
686 const char *key,
687 UChar *result,
688 int32_t maxResultSize,
689 UErrorCode *pErrorCode) {
690 if (U_FAILURE(*pErrorCode)) {
691 return 0;
692 }
693 if (ldn == NULL || key == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
694 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
695 return 0;
696 }
697 UnicodeString temp(result, 0, maxResultSize);
698 ((const LocaleDisplayNames *)ldn)->keyDisplayName(key, temp);
699 return temp.extract(result, maxResultSize, *pErrorCode);
700 }
701
702 U_DRAFT int32_t U_EXPORT2
703 uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn,
704 const char *key,
705 const char *value,
706 UChar *result,
707 int32_t maxResultSize,
708 UErrorCode *pErrorCode) {
709 if (U_FAILURE(*pErrorCode)) {
710 return 0;
711 }
712 if (ldn == NULL || key == NULL || value == NULL || (result == NULL && maxResultSize > 0)
713 || maxResultSize < 0) {
714 *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
715 return 0;
716 }
717 UnicodeString temp(result, 0, maxResultSize);
718 ((const LocaleDisplayNames *)ldn)->keyValueDisplayName(key, value, temp);
719 return temp.extract(result, maxResultSize, *pErrorCode);
720 }
721
722 #endif