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