]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/ucnvdisp.c
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / common / ucnvdisp.c
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1998-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 *
9 * ucnvdisp.c:
10 * Implements APIs for the ICU's codeset conversion library display names.
11 *
12 * Modification History:
13 *
14 * Date Name Description
15 * 04/04/99 helena Fixed internal header inclusion.
16 * 05/09/00 helena Added implementation to handle fallback mappings.
17 * 06/20/2000 helena OS/400 port changes; mostly typecast.
18 * 09/08/2004 grhoten split from ucnv.c
19 */
20
21 #include "unicode/utypes.h"
22
23 #if !UCONFIG_NO_CONVERSION
24
25 #include "unicode/ustring.h"
26 #include "unicode/ures.h"
27 #include "unicode/ucnv.h"
28 #include "cstring.h"
29 #include "ustr_imp.h"
30 #include "ucnv_imp.h"
31 #include "putilimp.h"
32
33 U_CAPI int32_t U_EXPORT2
34 ucnv_getDisplayName(const UConverter *cnv,
35 const char *displayLocale,
36 UChar *displayName, int32_t displayNameCapacity,
37 UErrorCode *pErrorCode) {
38 UResourceBundle *rb;
39 const UChar *name;
40 int32_t length;
41
42 /* check arguments */
43 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
44 return 0;
45 }
46
47 if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) {
48 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
49 return 0;
50 }
51
52 /* open the resource bundle and get the display name string */
53 rb=ures_open(NULL, displayLocale, pErrorCode);
54 if(U_FAILURE(*pErrorCode)) {
55 return 0;
56 }
57
58 /* use the internal name as the key */
59 name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, pErrorCode);
60 ures_close(rb);
61
62 if(U_SUCCESS(*pErrorCode)) {
63 /* copy the string */
64 u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR);
65 } else {
66 /* convert the internal name into a Unicode string */
67 *pErrorCode=U_ZERO_ERROR;
68 length=(int32_t)uprv_strlen(cnv->sharedData->staticData->name);
69 u_charsToUChars(cnv->sharedData->staticData->name, displayName, uprv_min(length, displayNameCapacity));
70 }
71 return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode);
72 }
73
74 #endif
75
76 /*
77 * Hey, Emacs, please set the following:
78 *
79 * Local Variables:
80 * indent-tabs-mode: nil
81 * End:
82 *
83 */