intl/icu/source/common/ucnvdisp.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/ucnvdisp.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1998-2004, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*
    1.12 +*  ucnvdisp.c:
    1.13 +*  Implements APIs for the ICU's codeset conversion library display names.
    1.14 +*
    1.15 +* Modification History:
    1.16 +*
    1.17 +*   Date        Name        Description
    1.18 +*   04/04/99    helena      Fixed internal header inclusion.
    1.19 +*   05/09/00    helena      Added implementation to handle fallback mappings.
    1.20 +*   06/20/2000  helena      OS/400 port changes; mostly typecast.
    1.21 +*   09/08/2004  grhoten     split from ucnv.c
    1.22 +*/
    1.23 +
    1.24 +#include "unicode/utypes.h"
    1.25 +
    1.26 +#if !UCONFIG_NO_CONVERSION
    1.27 +
    1.28 +#include "unicode/ustring.h"
    1.29 +#include "unicode/ures.h"
    1.30 +#include "unicode/ucnv.h"
    1.31 +#include "cstring.h"
    1.32 +#include "ustr_imp.h"
    1.33 +#include "ucnv_imp.h"
    1.34 +#include "putilimp.h"
    1.35 +
    1.36 +U_CAPI int32_t U_EXPORT2
    1.37 +ucnv_getDisplayName(const UConverter *cnv,
    1.38 +                    const char *displayLocale,
    1.39 +                    UChar *displayName, int32_t displayNameCapacity,
    1.40 +                    UErrorCode *pErrorCode) {
    1.41 +    UResourceBundle *rb;
    1.42 +    const UChar *name;
    1.43 +    int32_t length;
    1.44 +    UErrorCode localStatus = U_ZERO_ERROR;
    1.45 +
    1.46 +    /* check arguments */
    1.47 +    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
    1.48 +        return 0;
    1.49 +    }
    1.50 +
    1.51 +    if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) {
    1.52 +        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
    1.53 +        return 0;
    1.54 +    }
    1.55 +
    1.56 +    /* open the resource bundle and get the display name string */
    1.57 +    rb=ures_open(NULL, displayLocale, pErrorCode);
    1.58 +    if(U_FAILURE(*pErrorCode)) {
    1.59 +        return 0;
    1.60 +    }
    1.61 +
    1.62 +    /* use the internal name as the key */
    1.63 +    name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, &localStatus);
    1.64 +    ures_close(rb);
    1.65 +
    1.66 +    if(U_SUCCESS(localStatus)) {
    1.67 +        /* copy the string */
    1.68 +        if (*pErrorCode == U_ZERO_ERROR) {
    1.69 +            *pErrorCode = localStatus;
    1.70 +        }
    1.71 +        u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR);
    1.72 +    } else {
    1.73 +        /* convert the internal name into a Unicode string */
    1.74 +        length=(int32_t)uprv_strlen(cnv->sharedData->staticData->name);
    1.75 +        u_charsToUChars(cnv->sharedData->staticData->name, displayName, uprv_min(length, displayNameCapacity));
    1.76 +    }
    1.77 +    return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode);
    1.78 +}
    1.79 +
    1.80 +#endif
    1.81 +
    1.82 +/*
    1.83 + * Hey, Emacs, please set the following:
    1.84 + *
    1.85 + * Local Variables:
    1.86 + * indent-tabs-mode: nil
    1.87 + * End:
    1.88 + *
    1.89 + */

mercurial