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 33U_CAPI int32_t U_EXPORT2 34ucnv_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 UErrorCode localStatus = U_ZERO_ERROR; 42 43 /* check arguments */ 44 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { 45 return 0; 46 } 47 48 if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) { 49 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 50 return 0; 51 } 52 53 /* open the resource bundle and get the display name string */ 54 rb=ures_open(NULL, displayLocale, pErrorCode); 55 if(U_FAILURE(*pErrorCode)) { 56 return 0; 57 } 58 59 /* use the internal name as the key */ 60 name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, &localStatus); 61 ures_close(rb); 62 63 if(U_SUCCESS(localStatus)) { 64 /* copy the string */ 65 if (*pErrorCode == U_ZERO_ERROR) { 66 *pErrorCode = localStatus; 67 } 68 u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR); 69 } else { 70 /* convert the internal name into a Unicode string */ 71 length=(int32_t)uprv_strlen(cnv->sharedData->staticData->name); 72 u_charsToUChars(cnv->sharedData->staticData->name, displayName, uprv_min(length, displayNameCapacity)); 73 } 74 return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode); 75} 76 77#endif 78 79/* 80 * Hey, Emacs, please set the following: 81 * 82 * Local Variables: 83 * indent-tabs-mode: nil 84 * End: 85 * 86 */ 87