intl/icu/source/common/ures_cnv.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/ures_cnv.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1997-2006, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  ures_cnv.c
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 2004aug25
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   Character conversion functions moved here from uresbund.c
    1.20 +*/
    1.21 +
    1.22 +#include "unicode/utypes.h"
    1.23 +#include "unicode/putil.h"
    1.24 +#include "unicode/ustring.h"
    1.25 +#include "unicode/ucnv.h"
    1.26 +#include "unicode/ures.h"
    1.27 +#include "uinvchar.h"
    1.28 +#include "ustr_cnv.h"
    1.29 +
    1.30 +U_CAPI UResourceBundle * U_EXPORT2
    1.31 +ures_openU(const UChar *myPath, 
    1.32 +           const char *localeID, 
    1.33 +           UErrorCode *status)
    1.34 +{
    1.35 +    char pathBuffer[1024];
    1.36 +    int32_t length;
    1.37 +    char *path = pathBuffer;
    1.38 +
    1.39 +    if(status==NULL || U_FAILURE(*status)) {
    1.40 +        return NULL;
    1.41 +    }
    1.42 +    if(myPath==NULL) {
    1.43 +        path = NULL;
    1.44 +    }
    1.45 +    else {
    1.46 +        length=u_strlen(myPath);
    1.47 +        if(length>=sizeof(pathBuffer)) {
    1.48 +            *status=U_ILLEGAL_ARGUMENT_ERROR;
    1.49 +            return NULL;
    1.50 +        } else if(uprv_isInvariantUString(myPath, length)) {
    1.51 +            /*
    1.52 +             * the invariant converter is sufficient for package and tree names
    1.53 +             * and is more efficient
    1.54 +             */
    1.55 +            u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */
    1.56 +        } else {
    1.57 +#if !UCONFIG_NO_CONVERSION
    1.58 +            /* use the default converter to support variant-character paths */
    1.59 +            UConverter *cnv=u_getDefaultConverter(status);
    1.60 +            length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status);
    1.61 +            u_releaseDefaultConverter(cnv);
    1.62 +            if(U_FAILURE(*status)) {
    1.63 +                return NULL;
    1.64 +            }
    1.65 +            if(length>=sizeof(pathBuffer)) {
    1.66 +                /* not NUL-terminated - path too long */
    1.67 +                *status=U_ILLEGAL_ARGUMENT_ERROR;
    1.68 +                return NULL;
    1.69 +            }
    1.70 +#else
    1.71 +            /* the default converter is not available */
    1.72 +            *status=U_UNSUPPORTED_ERROR;
    1.73 +            return NULL;
    1.74 +#endif
    1.75 +        }
    1.76 +    }
    1.77 +
    1.78 +    return ures_open(path, localeID, status);
    1.79 +}

mercurial