]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
73c04bcf | 4 | * Copyright (C) 1997-2006, International Business Machines |
374ca955 A |
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, | |
73c04bcf A |
30 | UErrorCode *status) |
31 | { | |
32 | char pathBuffer[1024]; | |
374ca955 | 33 | int32_t length; |
73c04bcf | 34 | char *path = pathBuffer; |
374ca955 A |
35 | |
36 | if(status==NULL || U_FAILURE(*status)) { | |
37 | return NULL; | |
38 | } | |
39 | if(myPath==NULL) { | |
73c04bcf | 40 | path = NULL; |
374ca955 | 41 | } |
73c04bcf A |
42 | else { |
43 | length=u_strlen(myPath); | |
44 | if(length>=sizeof(pathBuffer)) { | |
374ca955 A |
45 | *status=U_ILLEGAL_ARGUMENT_ERROR; |
46 | return NULL; | |
73c04bcf A |
47 | } else if(uprv_isInvariantUString(myPath, length)) { |
48 | /* | |
49 | * the invariant converter is sufficient for package and tree names | |
50 | * and is more efficient | |
51 | */ | |
52 | u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */ | |
53 | } else { | |
54 | #if !UCONFIG_NO_CONVERSION | |
55 | /* use the default converter to support variant-character paths */ | |
56 | UConverter *cnv=u_getDefaultConverter(status); | |
57 | length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status); | |
58 | u_releaseDefaultConverter(cnv); | |
59 | if(U_FAILURE(*status)) { | |
60 | return NULL; | |
61 | } | |
62 | if(length>=sizeof(pathBuffer)) { | |
63 | /* not NUL-terminated - path too long */ | |
64 | *status=U_ILLEGAL_ARGUMENT_ERROR; | |
65 | return NULL; | |
66 | } | |
374ca955 | 67 | #else |
73c04bcf A |
68 | /* the default converter is not available */ |
69 | *status=U_UNSUPPORTED_ERROR; | |
70 | return NULL; | |
374ca955 | 71 | #endif |
73c04bcf | 72 | } |
374ca955 A |
73 | } |
74 | ||
75 | return ures_open(path, localeID, status); | |
76 | } |