2004-08-26 22:51:40 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2006-03-16 22:47:23 +00:00
|
|
|
* Copyright (C) 1997-2006, International Business Machines
|
2004-08-26 22:51:40 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: ures_cnv.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2004aug25
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Character conversion functions moved here from uresbund.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2004-10-18 03:03:13 +00:00
|
|
|
#include "unicode/putil.h"
|
2004-08-26 22:51:40 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "unicode/ures.h"
|
2004-09-14 16:58:51 +00:00
|
|
|
#include "uinvchar.h"
|
2004-08-27 17:56:01 +00:00
|
|
|
#include "ustr_cnv.h"
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
U_CAPI UResourceBundle * U_EXPORT2
|
|
|
|
ures_openU(const UChar *myPath,
|
|
|
|
const char *localeID,
|
2004-12-15 02:49:04 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
char pathBuffer[1024];
|
2004-08-26 22:51:40 +00:00
|
|
|
int32_t length;
|
2004-12-15 02:49:04 +00:00
|
|
|
char *path = pathBuffer;
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
if(status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(myPath==NULL) {
|
2004-12-15 02:49:04 +00:00
|
|
|
path = NULL;
|
2004-08-26 22:51:40 +00:00
|
|
|
}
|
2004-12-15 02:49:04 +00:00
|
|
|
else {
|
|
|
|
length=u_strlen(myPath);
|
|
|
|
if(length>=sizeof(pathBuffer)) {
|
2004-08-26 22:51:40 +00:00
|
|
|
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
2004-12-15 02:49:04 +00:00
|
|
|
} else if(uprv_isInvariantUString(myPath, length)) {
|
|
|
|
/*
|
|
|
|
* the invariant converter is sufficient for package and tree names
|
|
|
|
* and is more efficient
|
|
|
|
*/
|
|
|
|
u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */
|
|
|
|
} else {
|
|
|
|
#if !UCONFIG_NO_CONVERSION
|
|
|
|
/* use the default converter to support variant-character paths */
|
|
|
|
UConverter *cnv=u_getDefaultConverter(status);
|
|
|
|
length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status);
|
|
|
|
u_releaseDefaultConverter(cnv);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(length>=sizeof(pathBuffer)) {
|
|
|
|
/* not NUL-terminated - path too long */
|
|
|
|
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-26 22:51:40 +00:00
|
|
|
#else
|
2004-12-15 02:49:04 +00:00
|
|
|
/* the default converter is not available */
|
|
|
|
*status=U_UNSUPPORTED_ERROR;
|
|
|
|
return NULL;
|
2004-08-26 22:51:40 +00:00
|
|
|
#endif
|
2004-12-15 02:49:04 +00:00
|
|
|
}
|
2004-08-26 22:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ures_open(path, localeID, status);
|
|
|
|
}
|