intl/icu/source/common/ures_cnv.c

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1997-2006, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: ures_cnv.c
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 2004aug25
michael@0 14 * created by: Markus W. Scherer
michael@0 15 *
michael@0 16 * Character conversion functions moved here from uresbund.c
michael@0 17 */
michael@0 18
michael@0 19 #include "unicode/utypes.h"
michael@0 20 #include "unicode/putil.h"
michael@0 21 #include "unicode/ustring.h"
michael@0 22 #include "unicode/ucnv.h"
michael@0 23 #include "unicode/ures.h"
michael@0 24 #include "uinvchar.h"
michael@0 25 #include "ustr_cnv.h"
michael@0 26
michael@0 27 U_CAPI UResourceBundle * U_EXPORT2
michael@0 28 ures_openU(const UChar *myPath,
michael@0 29 const char *localeID,
michael@0 30 UErrorCode *status)
michael@0 31 {
michael@0 32 char pathBuffer[1024];
michael@0 33 int32_t length;
michael@0 34 char *path = pathBuffer;
michael@0 35
michael@0 36 if(status==NULL || U_FAILURE(*status)) {
michael@0 37 return NULL;
michael@0 38 }
michael@0 39 if(myPath==NULL) {
michael@0 40 path = NULL;
michael@0 41 }
michael@0 42 else {
michael@0 43 length=u_strlen(myPath);
michael@0 44 if(length>=sizeof(pathBuffer)) {
michael@0 45 *status=U_ILLEGAL_ARGUMENT_ERROR;
michael@0 46 return NULL;
michael@0 47 } else if(uprv_isInvariantUString(myPath, length)) {
michael@0 48 /*
michael@0 49 * the invariant converter is sufficient for package and tree names
michael@0 50 * and is more efficient
michael@0 51 */
michael@0 52 u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */
michael@0 53 } else {
michael@0 54 #if !UCONFIG_NO_CONVERSION
michael@0 55 /* use the default converter to support variant-character paths */
michael@0 56 UConverter *cnv=u_getDefaultConverter(status);
michael@0 57 length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status);
michael@0 58 u_releaseDefaultConverter(cnv);
michael@0 59 if(U_FAILURE(*status)) {
michael@0 60 return NULL;
michael@0 61 }
michael@0 62 if(length>=sizeof(pathBuffer)) {
michael@0 63 /* not NUL-terminated - path too long */
michael@0 64 *status=U_ILLEGAL_ARGUMENT_ERROR;
michael@0 65 return NULL;
michael@0 66 }
michael@0 67 #else
michael@0 68 /* the default converter is not available */
michael@0 69 *status=U_UNSUPPORTED_ERROR;
michael@0 70 return NULL;
michael@0 71 #endif
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 return ures_open(path, localeID, status);
michael@0 76 }

mercurial