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