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