• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *******************************************************************************
3 *
4 *   Copyright (C) 1997-2006, 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
ures_openU(const UChar * myPath,const char * localeID,UErrorCode * status)28 ures_openU(const UChar *myPath,
29            const char *localeID,
30            UErrorCode *status)
31 {
32     char pathBuffer[1024];
33     int32_t length;
34     char *path = pathBuffer;
35 
36     if(status==NULL || U_FAILURE(*status)) {
37         return NULL;
38     }
39     if(myPath==NULL) {
40         path = NULL;
41     }
42     else {
43         length=u_strlen(myPath);
44         if(length>=sizeof(pathBuffer)) {
45             *status=U_ILLEGAL_ARGUMENT_ERROR;
46             return NULL;
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             }
67 #else
68             /* the default converter is not available */
69             *status=U_UNSUPPORTED_ERROR;
70             return NULL;
71 #endif
72         }
73     }
74 
75     return ures_open(path, localeID, status);
76 }
77