michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2004, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * ucnvdisp.c: michael@0: * Implements APIs for the ICU's codeset conversion library display names. michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 04/04/99 helena Fixed internal header inclusion. michael@0: * 05/09/00 helena Added implementation to handle fallback mappings. michael@0: * 06/20/2000 helena OS/400 port changes; mostly typecast. michael@0: * 09/08/2004 grhoten split from ucnv.c michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/ures.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "cstring.h" michael@0: #include "ustr_imp.h" michael@0: #include "ucnv_imp.h" michael@0: #include "putilimp.h" michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ucnv_getDisplayName(const UConverter *cnv, michael@0: const char *displayLocale, michael@0: UChar *displayName, int32_t displayNameCapacity, michael@0: UErrorCode *pErrorCode) { michael@0: UResourceBundle *rb; michael@0: const UChar *name; michael@0: int32_t length; michael@0: UErrorCode localStatus = U_ZERO_ERROR; michael@0: michael@0: /* check arguments */ michael@0: if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { michael@0: return 0; michael@0: } michael@0: michael@0: if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) { michael@0: *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: /* open the resource bundle and get the display name string */ michael@0: rb=ures_open(NULL, displayLocale, pErrorCode); michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return 0; michael@0: } michael@0: michael@0: /* use the internal name as the key */ michael@0: name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, &localStatus); michael@0: ures_close(rb); michael@0: michael@0: if(U_SUCCESS(localStatus)) { michael@0: /* copy the string */ michael@0: if (*pErrorCode == U_ZERO_ERROR) { michael@0: *pErrorCode = localStatus; michael@0: } michael@0: u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR); michael@0: } else { michael@0: /* convert the internal name into a Unicode string */ michael@0: length=(int32_t)uprv_strlen(cnv->sharedData->staticData->name); michael@0: u_charsToUChars(cnv->sharedData->staticData->name, displayName, uprv_min(length, displayNameCapacity)); michael@0: } michael@0: return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode); michael@0: } michael@0: michael@0: #endif michael@0: michael@0: /* michael@0: * Hey, Emacs, please set the following: michael@0: * michael@0: * Local Variables: michael@0: * indent-tabs-mode: nil michael@0: * End: michael@0: * michael@0: */