1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1998-2004, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
12 * Implements APIs for the ICU's codeset conversion library display names.
14 * Modification History:
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
23 #include "unicode/utypes.h"
25 #if !UCONFIG_NO_CONVERSION
27 #include "unicode/ustring.h"
28 #include "unicode/ures.h"
29 #include "unicode/ucnv.h"
35 U_CAPI int32_t U_EXPORT2
36 ucnv_getDisplayName(const UConverter *cnv,
37 const char *displayLocale,
38 UChar *displayName, int32_t displayNameCapacity,
39 UErrorCode *pErrorCode) {
43 UErrorCode localStatus = U_ZERO_ERROR;
46 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
50 if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) {
51 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
55 /* open the resource bundle and get the display name string */
56 rb=ures_open(NULL, displayLocale, pErrorCode);
57 if(U_FAILURE(*pErrorCode)) {
61 /* use the internal name as the key */
62 name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, &localStatus);
65 if(U_SUCCESS(localStatus)) {
67 if (*pErrorCode == U_ZERO_ERROR) {
68 *pErrorCode = localStatus;
70 u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR);
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));
76 return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode);
82 * Hey, Emacs, please set the following:
85 * indent-tabs-mode: nil