2000-05-15 18:39:17 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2010-03-11 18:38:24 +00:00
|
|
|
* Copyright (C) 1997-2010, International Business Machines Corporation and *
|
2001-03-21 20:44:20 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
******************************************************************************
|
2000-05-15 18:39:17 +00:00
|
|
|
*
|
2000-06-20 23:42:20 +00:00
|
|
|
* File URESBUND.C
|
2000-05-15 18:39:17 +00:00
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/01/97 aliu Creation.
|
|
|
|
* 06/14/99 stephen Removed functions taking a filename suffix.
|
|
|
|
* 07/20/99 stephen Changed for UResourceBundle typedef'd to void*
|
2000-06-07 19:52:08 +00:00
|
|
|
* 11/09/99 weiv Added ures_getLocale()
|
2000-05-15 18:39:17 +00:00
|
|
|
* March 2000 weiv Total overhaul - using data in DLLs
|
2000-06-20 23:42:20 +00:00
|
|
|
* 06/20/2000 helena OS/400 port changes; mostly typecast.
|
2002-06-24 20:58:17 +00:00
|
|
|
* 06/24/02 weiv Added support for resource sharing
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-05-15 18:39:17 +00:00
|
|
|
*/
|
|
|
|
|
2001-10-10 18:05:10 +00:00
|
|
|
#include "unicode/ustring.h"
|
2003-07-02 17:24:45 +00:00
|
|
|
#include "unicode/ucnv.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "uresimp.h"
|
2003-07-02 17:24:45 +00:00
|
|
|
#include "ustr_imp.h"
|
2001-05-25 17:57:14 +00:00
|
|
|
#include "cwchar.h"
|
2001-08-11 00:29:58 +00:00
|
|
|
#include "ucln_cmn.h"
|
2001-10-10 18:05:10 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "uhash.h"
|
2004-04-13 17:39:55 +00:00
|
|
|
#include "unicode/uenum.h"
|
|
|
|
#include "uenumimp.h"
|
2004-04-16 20:29:09 +00:00
|
|
|
#include "ulocimp.h"
|
2001-10-10 18:05:10 +00:00
|
|
|
#include "umutex.h"
|
2004-10-18 02:43:33 +00:00
|
|
|
#include "putilimp.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
|
2001-03-22 01:13:46 +00:00
|
|
|
/*
|
|
|
|
Static cache for already opened resource bundles - mostly for keeping fallback info
|
|
|
|
TODO: This cache should probably be removed when the deprecated code is
|
|
|
|
completely removed.
|
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
static UHashtable *cache = NULL;
|
2001-03-22 01:13:46 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
static UMTX resbMutex = NULL;
|
|
|
|
|
|
|
|
/* INTERNAL: hashes an entry */
|
2005-07-07 17:50:37 +00:00
|
|
|
static int32_t U_CALLCONV hashEntry(const UHashTok parm) {
|
2001-07-06 19:53:12 +00:00
|
|
|
UResourceDataEntry *b = (UResourceDataEntry *)parm.pointer;
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok namekey, pathkey;
|
2001-07-06 19:53:12 +00:00
|
|
|
namekey.pointer = b->fName;
|
|
|
|
pathkey.pointer = b->fPath;
|
|
|
|
return uhash_hashChars(namekey)+37*uhash_hashChars(pathkey);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: compares two entries */
|
2005-07-07 17:50:37 +00:00
|
|
|
static UBool U_CALLCONV compareEntries(const UHashTok p1, const UHashTok p2) {
|
2001-07-06 19:53:12 +00:00
|
|
|
UResourceDataEntry *b1 = (UResourceDataEntry *)p1.pointer;
|
|
|
|
UResourceDataEntry *b2 = (UResourceDataEntry *)p2.pointer;
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok name1, name2, path1, path2;
|
2001-07-06 19:53:12 +00:00
|
|
|
name1.pointer = b1->fName;
|
|
|
|
name2.pointer = b2->fName;
|
|
|
|
path1.pointer = b1->fPath;
|
|
|
|
path2.pointer = b2->fPath;
|
|
|
|
return (UBool)(uhash_compareChars(name1, name2) &
|
|
|
|
uhash_compareChars(path1, path2));
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function, gets parts of locale name according
|
|
|
|
* to the position of '_' character
|
|
|
|
*/
|
2000-11-28 19:59:22 +00:00
|
|
|
static UBool chopLocale(char *name) {
|
2000-05-15 18:39:17 +00:00
|
|
|
char *i = uprv_strrchr(name, '_');
|
|
|
|
|
|
|
|
if(i != NULL) {
|
|
|
|
*i = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
/**
|
|
|
|
* Internal function
|
|
|
|
*/
|
|
|
|
static void entryIncrease(UResourceDataEntry *entry) {
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
entry->fCountExisting++;
|
|
|
|
while(entry->fParent != NULL) {
|
|
|
|
entry = entry->fParent;
|
|
|
|
entry->fCountExisting++;
|
|
|
|
}
|
|
|
|
umtx_unlock(&resbMutex);
|
2000-05-24 19:58:40 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/**
|
|
|
|
* Internal function. Tries to find a resource in given Resource
|
|
|
|
* Bundle, as well as in its parents
|
|
|
|
*/
|
2001-10-04 00:12:19 +00:00
|
|
|
static const ResourceData *getFallbackData(const UResourceBundle* resBundle, const char* * resTag, UResourceDataEntry* *realData, Resource *res, UErrorCode *status) {
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *resB = resBundle->fData;
|
2000-05-30 17:02:26 +00:00
|
|
|
int32_t indexR = -1;
|
2000-05-15 18:39:17 +00:00
|
|
|
int32_t i = 0;
|
|
|
|
*res = RES_BOGUS;
|
|
|
|
if(resB != NULL) {
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) { /* if this resource is real, */
|
2000-05-30 17:02:26 +00:00
|
|
|
*res = res_getTableItemByKey(&(resB->fData), resB->fData.rootRes, &indexR, resTag); /* try to get data from there */
|
2000-05-15 18:39:17 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(resBundle->fHasFallback == TRUE) {
|
|
|
|
while(*res == RES_BOGUS && resB->fParent != NULL) { /* Otherwise, we'll look in parents */
|
|
|
|
resB = resB->fParent;
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) {
|
|
|
|
i++;
|
2000-05-30 17:02:26 +00:00
|
|
|
*res = res_getTableItemByKey(&(resB->fData), resB->fData.rootRes, &indexR, resTag);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*res != RES_BOGUS) { /* If the resource is found in parents, we need to adjust the error */
|
|
|
|
if(i>1) {
|
|
|
|
if(uprv_strcmp(resB->fName, uloc_getDefault())==0 || uprv_strcmp(resB->fName, kRootLocaleName)==0) {
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_DEFAULT_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
*realData = resB;
|
2000-05-15 18:39:17 +00:00
|
|
|
return (&(resB->fData));
|
|
|
|
} else { /* If resource is not found, we need to give an error */
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 07:04:16 +00:00
|
|
|
static void
|
|
|
|
free_entry(UResourceDataEntry *entry) {
|
2009-07-17 22:57:26 +00:00
|
|
|
UResourceDataEntry *alias;
|
|
|
|
res_unload(&(entry->fData));
|
2008-02-19 07:09:38 +00:00
|
|
|
if(entry->fName != NULL && entry->fName != entry->fNameBuffer) {
|
2008-02-08 07:04:16 +00:00
|
|
|
uprv_free(entry->fName);
|
|
|
|
}
|
|
|
|
if(entry->fPath != NULL) {
|
|
|
|
uprv_free(entry->fPath);
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
if(entry->fPool != NULL) {
|
|
|
|
--entry->fPool->fCountExisting;
|
|
|
|
}
|
|
|
|
alias = entry->fAlias;
|
|
|
|
if(alias != NULL) {
|
|
|
|
while(alias->fAlias != NULL) {
|
|
|
|
alias = alias->fAlias;
|
|
|
|
}
|
|
|
|
--alias->fCountExisting;
|
|
|
|
}
|
2008-02-08 07:04:16 +00:00
|
|
|
uprv_free(entry);
|
|
|
|
}
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* Works just like ucnv_flushCache() */
|
|
|
|
static int32_t ures_flushCache()
|
|
|
|
{
|
2009-07-17 22:57:26 +00:00
|
|
|
UResourceDataEntry *resB;
|
|
|
|
int32_t pos;
|
2001-08-11 00:29:58 +00:00
|
|
|
int32_t rbDeletedNum = 0;
|
|
|
|
const UHashElement *e;
|
2009-07-17 22:57:26 +00:00
|
|
|
UBool deletedMore;
|
2001-08-11 00:29:58 +00:00
|
|
|
|
|
|
|
/*if shared data hasn't even been lazy evaluated yet
|
|
|
|
* return 0
|
|
|
|
*/
|
2003-06-05 18:15:20 +00:00
|
|
|
umtx_lock(&resbMutex);
|
2003-06-05 20:30:55 +00:00
|
|
|
if (cache == NULL) {
|
2003-06-05 18:15:20 +00:00
|
|
|
umtx_unlock(&resbMutex);
|
2001-08-11 00:29:58 +00:00
|
|
|
return 0;
|
2003-06-05 20:30:55 +00:00
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
do {
|
|
|
|
deletedMore = FALSE;
|
|
|
|
/*creates an enumeration to iterate through every element in the table */
|
|
|
|
pos = -1;
|
|
|
|
while ((e = uhash_nextElement(cache, &pos)) != NULL)
|
|
|
|
{
|
|
|
|
resB = (UResourceDataEntry *) e->value.pointer;
|
|
|
|
/* Deletes only if reference counter == 0
|
|
|
|
* Don't worry about the children of this node.
|
|
|
|
* Those will eventually get deleted too, if not already.
|
|
|
|
* Don't worry about the parents of this node.
|
|
|
|
* Those will eventually get deleted too, if not already.
|
|
|
|
*/
|
|
|
|
/* 04/05/2002 [weiv] fCountExisting should now be accurate. If it's not zero, that means that */
|
|
|
|
/* some resource bundles are still open somewhere. */
|
|
|
|
|
|
|
|
if (resB->fCountExisting == 0) {
|
|
|
|
rbDeletedNum++;
|
|
|
|
deletedMore = TRUE;
|
|
|
|
uhash_removeElement(cache, e);
|
|
|
|
free_entry(resB);
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
/*
|
|
|
|
* Do it again to catch bundles (aliases, pool bundle) whose fCountExisting
|
|
|
|
* got decremented by free_entry().
|
|
|
|
*/
|
|
|
|
} while(deletedMore);
|
2001-08-11 00:29:58 +00:00
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
|
|
|
|
return rbDeletedNum;
|
|
|
|
}
|
|
|
|
|
2010-03-11 20:05:42 +00:00
|
|
|
#ifdef URES_DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void) {
|
|
|
|
UBool cacheNotEmpty = FALSE;
|
|
|
|
int32_t pos = -1;
|
|
|
|
const UHashElement *e;
|
|
|
|
UResourceDataEntry *resB;
|
|
|
|
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
if (cache == NULL) {
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
fprintf(stderr,"%s:%d: RB Cache is NULL.\n", __FILE__, __LINE__);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((e = uhash_nextElement(cache, &pos)) != NULL) {
|
|
|
|
cacheNotEmpty=TRUE;
|
|
|
|
resB = (UResourceDataEntry *) e->value.pointer;
|
|
|
|
fprintf(stderr,"%s:%d: RB Cache: Entry @0x%p, refcount %d, name %s:%s. Pool 0x%p, alias 0x%p, parent 0x%p\n",
|
|
|
|
__FILE__, __LINE__,
|
|
|
|
(void*)resB, resB->fCountExisting,
|
|
|
|
resB->fName?resB->fName:"NULL",
|
|
|
|
resB->fPath?resB->fPath:"NULL",
|
|
|
|
(void*)resB->fPool,
|
|
|
|
(void*)resB->fAlias,
|
|
|
|
(void*)resB->fParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,"%s:%d: RB Cache still contains %d items.\n", __FILE__, __LINE__, uhash_count(cache));
|
|
|
|
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
|
|
|
|
return cacheNotEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
static UBool U_CALLCONV ures_cleanup(void)
|
2001-08-11 00:29:58 +00:00
|
|
|
{
|
|
|
|
if (cache != NULL) {
|
|
|
|
ures_flushCache();
|
|
|
|
if (cache != NULL && uhash_count(cache) == 0) {
|
|
|
|
uhash_close(cache);
|
|
|
|
cache = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-07-22 15:07:18 +00:00
|
|
|
if (cache == NULL && resbMutex != NULL) {
|
|
|
|
umtx_destroy(&resbMutex);
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
return (cache == NULL);
|
|
|
|
}
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
/** INTERNAL: Initializes the cache for resources */
|
|
|
|
static void initCache(UErrorCode *status) {
|
|
|
|
UBool makeCache = FALSE;
|
2006-08-29 04:57:05 +00:00
|
|
|
UMTX_CHECK(&resbMutex, (cache == NULL), makeCache);
|
2004-10-06 23:10:53 +00:00
|
|
|
if(makeCache) {
|
2005-11-11 19:23:09 +00:00
|
|
|
UHashtable *newCache = uhash_open(hashEntry, compareEntries, NULL, status);
|
2004-10-06 23:10:53 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
if(cache == NULL) {
|
|
|
|
cache = newCache;
|
|
|
|
newCache = NULL;
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_URES, ures_cleanup);
|
|
|
|
}
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
if(newCache != NULL) {
|
|
|
|
uhash_close(newCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/** INTERNAL: sets the name (locale) of the resource bundle to given name */
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
static void setEntryName(UResourceDataEntry *res, char *name, UErrorCode *status) {
|
2009-11-11 15:47:22 +00:00
|
|
|
int32_t len = (int32_t)uprv_strlen(name);
|
2008-02-19 07:09:38 +00:00
|
|
|
if(res->fName != NULL && res->fName != res->fNameBuffer) {
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_free(res->fName);
|
|
|
|
}
|
2008-02-19 07:09:38 +00:00
|
|
|
if (len < (int32_t)sizeof(res->fNameBuffer)) {
|
|
|
|
res->fName = res->fNameBuffer;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res->fName = (char *)uprv_malloc(len+1);
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if(res->fName == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(res->fName, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
static UResourceDataEntry *
|
|
|
|
getPoolEntry(const char *path, UErrorCode *status);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/**
|
|
|
|
* INTERNAL: Inits and opens an entry from a data DLL.
|
2004-02-23 04:36:02 +00:00
|
|
|
* CAUTION: resbMutex must be locked when calling this function.
|
2000-05-15 18:39:17 +00:00
|
|
|
*/
|
2000-11-28 19:59:22 +00:00
|
|
|
static UResourceDataEntry *init_entry(const char *localeID, const char *path, UErrorCode *status) {
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UResourceDataEntry find;
|
2008-02-19 05:59:10 +00:00
|
|
|
/*int32_t hashValue;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
char name[96];
|
2001-04-17 19:09:23 +00:00
|
|
|
char aliasName[100] = { 0 };
|
|
|
|
int32_t aliasLen = 0;
|
2006-03-16 06:07:07 +00:00
|
|
|
/*UBool isAlias = FALSE;*/
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok hashkey;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we try to deduce the right locale name */
|
|
|
|
if(localeID == NULL) { /* if localeID is NULL, we're trying to open default locale */
|
|
|
|
uprv_strcpy(name, uloc_getDefault());
|
2005-03-15 00:03:58 +00:00
|
|
|
} else if(*localeID == 0) { /* if localeID is "" then we try to open root locale */
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_strcpy(name, kRootLocaleName);
|
|
|
|
} else { /* otherwise, we'll open what we're given */
|
|
|
|
uprv_strcpy(name, localeID);
|
|
|
|
}
|
|
|
|
|
|
|
|
find.fName = name;
|
2009-07-17 22:57:26 +00:00
|
|
|
find.fPath = (char *)path;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* calculate the hash value of the entry */
|
2001-07-06 19:53:12 +00:00
|
|
|
hashkey.pointer = (void *)&find;
|
2008-02-19 05:59:10 +00:00
|
|
|
/*hashValue = hashEntry(hashkey);*/
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* check to see if we already have this entry */
|
|
|
|
r = (UResourceDataEntry *)uhash_get(cache, &find);
|
2009-07-17 22:57:26 +00:00
|
|
|
if(r == NULL) {
|
|
|
|
/* if the entry is not yet in the hash table, we'll try to construct a new one */
|
2000-05-15 18:39:17 +00:00
|
|
|
r = (UResourceDataEntry *) uprv_malloc(sizeof(UResourceDataEntry));
|
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-19 05:59:10 +00:00
|
|
|
|
|
|
|
uprv_memset(r, 0, sizeof(UResourceDataEntry));
|
|
|
|
/*r->fHashKey = hashValue;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
setEntryName(r, name, status);
|
2008-02-19 05:59:10 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
if(path != NULL) {
|
|
|
|
r->fPath = (char *)uprv_strdup(path);
|
2000-05-15 18:39:17 +00:00
|
|
|
if(r->fPath == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2008-02-19 05:59:10 +00:00
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
/* this is the actual loading */
|
|
|
|
res_load(&(r->fData), r->fPath, r->fName, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 18:39:17 +00:00
|
|
|
/* we have no such entry in dll, so it will always use fallback */
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
|
|
|
r->fBogus = U_USING_FALLBACK_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else { /* if we have a regular entry */
|
2009-07-17 22:57:26 +00:00
|
|
|
Resource aliasres;
|
|
|
|
if (r->fData.usesPoolBundle) {
|
|
|
|
r->fPool = getPoolEntry(r->fPath, status);
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
const int32_t *poolIndexes = r->fPool->fData.pRoot + 1;
|
|
|
|
if(r->fData.pRoot[1 + URES_INDEX_POOL_CHECKSUM] == poolIndexes[URES_INDEX_POOL_CHECKSUM]) {
|
|
|
|
r->fData.poolBundleKeys = (const char *)(poolIndexes + (poolIndexes[URES_INDEX_LENGTH] & 0xff));
|
|
|
|
} else {
|
|
|
|
r->fBogus = *status = U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r->fBogus = *status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
/* handle the alias by trying to get out the %%Alias tag.*/
|
|
|
|
/* We'll try to get alias string from the bundle */
|
|
|
|
aliasres = res_getResource(&(r->fData), "%%ALIAS");
|
|
|
|
if (aliasres != RES_BOGUS) {
|
|
|
|
const UChar *alias = res_getString(&(r->fData), aliasres, &aliasLen);
|
|
|
|
if(alias != NULL && aliasLen > 0) { /* if there is actual alias - unload and load new data */
|
|
|
|
u_UCharsToChars(alias, aliasName, aliasLen+1);
|
|
|
|
r->fAlias = init_entry(aliasName, path, status);
|
2005-03-15 00:03:58 +00:00
|
|
|
}
|
2000-10-02 19:58:36 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
UResourceDataEntry *oldR = NULL;
|
|
|
|
if((oldR = (UResourceDataEntry *)uhash_get(cache, r)) == NULL) { /* if the data is not cached */
|
2008-02-08 07:04:16 +00:00
|
|
|
/* just insert it in the cache */
|
2009-07-17 22:57:26 +00:00
|
|
|
UErrorCode cacheStatus = U_ZERO_ERROR;
|
|
|
|
uhash_put(cache, (void *)r, r, &cacheStatus);
|
|
|
|
if (U_FAILURE(cacheStatus)) {
|
|
|
|
*status = cacheStatus;
|
2008-02-08 07:04:16 +00:00
|
|
|
free_entry(r);
|
|
|
|
r = NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2008-02-08 07:04:16 +00:00
|
|
|
/* somebody have already inserted it while we were working, discard newly opened data */
|
|
|
|
/* Also, we could get here IF we opened an alias */
|
2008-02-19 07:09:38 +00:00
|
|
|
free_entry(r);
|
2000-05-15 18:39:17 +00:00
|
|
|
r = oldR;
|
|
|
|
}
|
|
|
|
}
|
2001-04-17 19:09:23 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
if(r != NULL) {
|
|
|
|
/* return the real bundle */
|
|
|
|
while(r->fAlias != NULL) {
|
|
|
|
r = r->fAlias;
|
|
|
|
}
|
|
|
|
r->fCountExisting++; /* we increase its reference count */
|
|
|
|
/* if the resource has a warning */
|
|
|
|
/* we don't want to overwrite a status with no error */
|
|
|
|
if(r->fBogus != U_ZERO_ERROR && U_SUCCESS(*status)) {
|
|
|
|
*status = r->fBogus; /* set the returning status */
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
static UResourceDataEntry *
|
|
|
|
getPoolEntry(const char *path, UErrorCode *status) {
|
|
|
|
UResourceDataEntry *poolBundle = init_entry(kPoolBundleName, path, status);
|
|
|
|
if( U_SUCCESS(*status) &&
|
|
|
|
(poolBundle == NULL || poolBundle->fBogus != U_ZERO_ERROR || !poolBundle->fData.isPoolBundle)
|
|
|
|
) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
|
|
|
return poolBundle;
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
/* INTERNAL: */
|
2004-02-23 04:36:02 +00:00
|
|
|
/* CAUTION: resbMutex must be locked when calling this function! */
|
2001-10-11 18:46:18 +00:00
|
|
|
static UResourceDataEntry *findFirstExisting(const char* path, char* name, UBool *isRoot, UBool *hasChopped, UBool *isDefault, UErrorCode* status) {
|
2008-02-08 03:42:40 +00:00
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UBool hasRealData = FALSE;
|
|
|
|
const char *defaultLoc = uloc_getDefault();
|
|
|
|
*hasChopped = TRUE; /* we're starting with a fresh name */
|
|
|
|
|
|
|
|
while(*hasChopped && !hasRealData) {
|
|
|
|
r = init_entry(name, path, status);
|
|
|
|
/* Null pointer test */
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*isDefault = (UBool)(uprv_strncmp(name, defaultLoc, uprv_strlen(name)) == 0);
|
|
|
|
hasRealData = (UBool)(r->fBogus == U_ZERO_ERROR);
|
|
|
|
if(!hasRealData) {
|
|
|
|
/* this entry is not real. We will discard it. */
|
|
|
|
/* However, the parent line for this entry is */
|
|
|
|
/* not to be used - as there might be parent */
|
|
|
|
/* lines in cache from previous openings that */
|
|
|
|
/* are not updated yet. */
|
|
|
|
r->fCountExisting--;
|
|
|
|
/*entryCloseInt(r);*/
|
|
|
|
r = NULL;
|
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(name, r->fName); /* this is needed for supporting aliases */
|
|
|
|
}
|
2001-10-11 18:46:18 +00:00
|
|
|
|
2008-02-08 03:42:40 +00:00
|
|
|
*isRoot = (UBool)(uprv_strcmp(name, kRootLocaleName) == 0);
|
2001-10-11 18:46:18 +00:00
|
|
|
|
2008-02-08 03:42:40 +00:00
|
|
|
/*Fallback data stuff*/
|
|
|
|
*hasChopped = chopLocale(name);
|
|
|
|
}
|
|
|
|
return r;
|
2001-10-11 18:46:18 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 04:00:12 +00:00
|
|
|
static void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
|
|
|
|
if(state) {
|
|
|
|
resB->fMagic1 = 0;
|
|
|
|
resB->fMagic2 = 0;
|
|
|
|
} else {
|
|
|
|
resB->fMagic1 = MAGIC1;
|
|
|
|
resB->fMagic2 = MAGIC2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static UBool ures_isStackObject(const UResourceBundle* resB) {
|
|
|
|
return((resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2)?FALSE:TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CFUNC void ures_initStackObject(UResourceBundle* resB) {
|
|
|
|
uprv_memset(resB, 0, sizeof(UResourceBundle));
|
|
|
|
ures_setIsStackObject(resB, TRUE);
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
static UResourceDataEntry *entryOpen(const char* path, const char* localeID, UErrorCode* status) {
|
2001-10-11 18:46:18 +00:00
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
2002-12-11 22:35:01 +00:00
|
|
|
UErrorCode parentStatus = U_ZERO_ERROR;
|
2009-12-03 18:06:37 +00:00
|
|
|
UErrorCode usrStatus = U_ZERO_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UResourceDataEntry *t1 = NULL;
|
|
|
|
UResourceDataEntry *t2 = NULL;
|
2009-12-03 18:06:37 +00:00
|
|
|
UResourceDataEntry *u1 = NULL;
|
|
|
|
UResourceDataEntry *u2 = NULL;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isDefault = FALSE;
|
2000-08-10 01:59:18 +00:00
|
|
|
UBool isRoot = FALSE;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool hasRealData = FALSE;
|
2001-10-11 18:46:18 +00:00
|
|
|
UBool hasChopped = TRUE;
|
2009-12-03 18:06:37 +00:00
|
|
|
UBool usingUSRData = U_USE_USRDATA && ( path == NULL || uprv_strncmp(path,U_ICUDATA_NAME,8) == 0);
|
2009-09-21 22:51:00 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
char name[96];
|
2009-12-03 18:06:37 +00:00
|
|
|
char usrDataPath[96];
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2008-02-16 22:58:32 +00:00
|
|
|
initCache(status);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2008-02-08 03:42:40 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
uprv_strcpy(name, localeID);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2009-12-03 18:06:37 +00:00
|
|
|
if ( usingUSRData ) {
|
|
|
|
if ( path == NULL ) {
|
|
|
|
uprv_strcpy(usrDataPath,U_USRDATA_NAME);
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(usrDataPath,path);
|
|
|
|
usrDataPath[0] = 'u';
|
|
|
|
usrDataPath[1] = 's';
|
|
|
|
usrDataPath[2] = 'r';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
{ /* umtx_lock */
|
2008-02-08 03:42:40 +00:00
|
|
|
/* We're going to skip all the locales that do not have any data */
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
|
|
|
|
|
|
|
if(r != NULL) { /* if there is one real locale, we can look for parents. */
|
2001-10-11 18:46:18 +00:00
|
|
|
t1 = r;
|
|
|
|
hasRealData = TRUE;
|
2009-12-03 22:41:48 +00:00
|
|
|
if ( usingUSRData ) { /* This code inserts user override data into the inheritance chain */
|
2009-12-03 18:06:37 +00:00
|
|
|
u1 = init_entry(t1->fName, usrDataPath, &usrStatus);
|
2010-03-11 20:05:42 +00:00
|
|
|
if ( u1 != NULL ) {
|
|
|
|
if(u1->fBogus == U_ZERO_ERROR) {
|
2009-12-03 18:06:37 +00:00
|
|
|
u1->fParent = t1;
|
|
|
|
r = u1;
|
2010-03-11 20:05:42 +00:00
|
|
|
} else {
|
|
|
|
/* the USR override data wasn't found, delete it */
|
|
|
|
uhash_remove(cache, u1);
|
|
|
|
free_entry(u1);
|
|
|
|
}
|
2009-12-03 18:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-08 03:42:40 +00:00
|
|
|
while (hasChopped && !isRoot && t1->fParent == NULL && !t1->fData.noFallback) {
|
|
|
|
/* insert regular parents */
|
2009-12-03 18:06:37 +00:00
|
|
|
t2 = init_entry(name, t1->fPath, &parentStatus);
|
2009-12-03 22:41:48 +00:00
|
|
|
if ( usingUSRData ) { /* This code inserts user override data into the inheritance chain */
|
2009-12-03 18:06:37 +00:00
|
|
|
usrStatus = U_ZERO_ERROR;
|
|
|
|
u2 = init_entry(name, usrDataPath, &usrStatus);
|
|
|
|
}
|
2008-01-16 23:16:41 +00:00
|
|
|
/* Check for null pointer. */
|
2009-12-03 18:06:37 +00:00
|
|
|
if (t2 == NULL || ( usingUSRData && u2 == NULL)) {
|
2008-02-08 03:42:40 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finishUnlock;
|
2008-01-16 23:16:41 +00:00
|
|
|
}
|
2009-09-21 22:51:00 +00:00
|
|
|
|
2009-09-22 16:05:30 +00:00
|
|
|
if ( res_getResource(&t1->fData,"%%ParentIsRoot") == RES_BOGUS) {
|
2009-12-03 18:06:37 +00:00
|
|
|
if ( usingUSRData && u2->fBogus == U_ZERO_ERROR ) {
|
|
|
|
t1->fParent = u2;
|
|
|
|
u2->fParent = t2;
|
|
|
|
} else {
|
|
|
|
t1->fParent = t2;
|
2010-03-11 20:05:42 +00:00
|
|
|
if(usingUSRData) {
|
|
|
|
/* the USR override data wasn't found, delete it */
|
|
|
|
uhash_remove(cache, u2);
|
|
|
|
free_entry(u2);
|
|
|
|
}
|
2009-12-03 18:06:37 +00:00
|
|
|
}
|
2009-09-21 22:51:00 +00:00
|
|
|
t1 = t2;
|
2010-03-11 18:38:24 +00:00
|
|
|
} else {
|
2010-03-12 08:06:33 +00:00
|
|
|
if (usingUSRData) {
|
|
|
|
/* the USR override data wasn't found, delete it */
|
|
|
|
uhash_remove(cache, u2);
|
|
|
|
free_entry(u2);
|
|
|
|
}
|
2010-03-11 18:38:24 +00:00
|
|
|
/* t2->fCountExisting have to be decremented since the call to init_entry increments
|
|
|
|
* it and if we hit this code, that means it is not set as the parent.
|
|
|
|
*/
|
|
|
|
t2->fCountExisting--;
|
2009-09-21 22:51:00 +00:00
|
|
|
}
|
2001-10-11 18:46:18 +00:00
|
|
|
hasChopped = chopLocale(name);
|
|
|
|
}
|
2008-02-08 03:42:40 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2008-02-08 03:42:40 +00:00
|
|
|
/* we could have reached this point without having any real data */
|
|
|
|
/* if that is the case, we need to chain in the default locale */
|
|
|
|
if(r==NULL && !isDefault && !isRoot /*&& t1->fParent == NULL*/) {
|
|
|
|
/* insert default locale */
|
|
|
|
uprv_strcpy(name, uloc_getDefault());
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
|
|
|
intStatus = U_USING_DEFAULT_WARNING;
|
|
|
|
if(r != NULL) { /* the default locale exists */
|
|
|
|
t1 = r;
|
|
|
|
hasRealData = TRUE;
|
|
|
|
isDefault = TRUE;
|
|
|
|
while (hasChopped && t1->fParent == NULL) {
|
|
|
|
/* insert chopped defaults */
|
2009-12-03 18:06:37 +00:00
|
|
|
t2 = init_entry(name, t1->fPath, &parentStatus);
|
2008-02-08 03:42:40 +00:00
|
|
|
/* Check for null pointer. */
|
|
|
|
if (t2 == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finishUnlock;
|
|
|
|
}
|
2009-09-21 22:51:00 +00:00
|
|
|
|
2009-09-22 16:05:30 +00:00
|
|
|
if ( res_getResource(&t1->fData,"%%ParentIsRoot") == RES_BOGUS) {
|
2009-09-21 22:51:00 +00:00
|
|
|
t1->fParent = t2;
|
|
|
|
t1 = t2;
|
|
|
|
}
|
2008-02-08 03:42:40 +00:00
|
|
|
hasChopped = chopLocale(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we could still have r == NULL at this point - maybe even default locale is not */
|
|
|
|
/* present */
|
|
|
|
if(r == NULL) {
|
|
|
|
uprv_strcpy(name, kRootLocaleName);
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
|
|
|
if(r != NULL) {
|
|
|
|
t1 = r;
|
|
|
|
intStatus = U_USING_DEFAULT_WARNING;
|
|
|
|
hasRealData = TRUE;
|
|
|
|
} else { /* we don't even have the root locale */
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
goto finishUnlock;
|
|
|
|
}
|
|
|
|
} else if(!isRoot && uprv_strcmp(t1->fName, kRootLocaleName) != 0 && t1->fParent == NULL && !r->fData.noFallback) {
|
|
|
|
/* insert root locale */
|
2009-12-03 18:06:37 +00:00
|
|
|
t2 = init_entry(kRootLocaleName, t1->fPath, &parentStatus);
|
2008-02-08 03:42:40 +00:00
|
|
|
/* Check for null pointer. */
|
|
|
|
if (t2 == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finishUnlock;
|
|
|
|
}
|
|
|
|
if(!hasRealData) {
|
|
|
|
r->fBogus = U_USING_DEFAULT_WARNING;
|
|
|
|
}
|
|
|
|
hasRealData = (UBool)((t2->fBogus == U_ZERO_ERROR) | hasRealData);
|
|
|
|
t1->fParent = t2;
|
|
|
|
t1 = t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(r != NULL && !isRoot && t1->fParent != NULL) {
|
|
|
|
t1->fParent->fCountExisting++;
|
|
|
|
t1 = t1->fParent;
|
|
|
|
hasRealData = (UBool)((t1->fBogus == U_ZERO_ERROR) | hasRealData);
|
2001-10-11 18:46:18 +00:00
|
|
|
}
|
|
|
|
} /* umtx_lock */
|
2008-02-08 03:42:40 +00:00
|
|
|
finishUnlock:
|
2000-05-15 18:39:17 +00:00
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
2008-02-08 03:42:40 +00:00
|
|
|
if(U_SUCCESS(parentStatus)) {
|
|
|
|
if(intStatus != U_ZERO_ERROR) {
|
|
|
|
*status = intStatus;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
*status = parentStatus;
|
|
|
|
return NULL;
|
2002-12-11 22:35:01 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2008-02-08 03:42:40 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to create and destroy resource bundles.
|
2004-02-23 04:36:02 +00:00
|
|
|
* CAUTION: resbMutex must be locked when calling this function.
|
2000-05-15 18:39:17 +00:00
|
|
|
*/
|
2000-11-28 19:59:22 +00:00
|
|
|
/* INTERNAL: */
|
2003-05-19 20:44:08 +00:00
|
|
|
static void entryCloseInt(UResourceDataEntry *resB) {
|
|
|
|
UResourceDataEntry *p = resB;
|
|
|
|
|
|
|
|
while(resB != NULL) {
|
|
|
|
p = resB->fParent;
|
|
|
|
resB->fCountExisting--;
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
/* Entries are left in the cache. TODO: add ures_flushCache() to force a flush
|
2003-05-19 20:44:08 +00:00
|
|
|
of the cache. */
|
|
|
|
/*
|
|
|
|
if(resB->fCountExisting <= 0) {
|
|
|
|
uhash_remove(cache, resB);
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) {
|
|
|
|
res_unload(&(resB->fData));
|
|
|
|
}
|
|
|
|
if(resB->fName != NULL) {
|
|
|
|
uprv_free(resB->fName);
|
|
|
|
}
|
|
|
|
if(resB->fPath != NULL) {
|
|
|
|
uprv_free(resB->fPath);
|
|
|
|
}
|
|
|
|
uprv_free(resB);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
resB = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API: closes a resource bundle and cleans up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void entryClose(UResourceDataEntry *resB) {
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
entryCloseInt(resB);
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
}
|
|
|
|
|
2006-04-25 19:32:35 +00:00
|
|
|
/*
|
|
|
|
U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
|
|
|
|
if(resB->fResPath == NULL) {
|
|
|
|
resB->fResPath = resB->fResBuf;
|
|
|
|
*(resB->fResPath) = 0;
|
|
|
|
}
|
|
|
|
resB->fResPathLen = uprv_strlen(toAdd);
|
|
|
|
if(RES_BUFSIZE <= resB->fResPathLen+1) {
|
|
|
|
if(resB->fResPath == resB->fResBuf) {
|
|
|
|
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
|
|
|
|
} else {
|
|
|
|
resB->fResPath = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_strcpy(resB->fResPath, toAdd);
|
|
|
|
}
|
|
|
|
*/
|
2008-02-23 19:15:18 +00:00
|
|
|
static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd, UErrorCode *status) {
|
|
|
|
int32_t resPathLenOrig = resB->fResPathLen;
|
|
|
|
if(resB->fResPath == NULL) {
|
|
|
|
resB->fResPath = resB->fResBuf;
|
|
|
|
*(resB->fResPath) = 0;
|
|
|
|
resB->fResPathLen = 0;
|
|
|
|
}
|
|
|
|
resB->fResPathLen += lenToAdd;
|
|
|
|
if(RES_BUFSIZE <= resB->fResPathLen+1) {
|
|
|
|
if(resB->fResPath == resB->fResBuf) {
|
|
|
|
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
|
|
|
|
/* Check that memory was allocated correctly. */
|
|
|
|
if (resB->fResPath == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uprv_strcpy(resB->fResPath, resB->fResBuf);
|
|
|
|
} else {
|
|
|
|
char *temp = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
|
|
|
|
/* Check that memory was reallocated correctly. */
|
|
|
|
if (temp == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resB->fResPath = temp;
|
|
|
|
}
|
2006-04-25 19:32:35 +00:00
|
|
|
}
|
2008-02-23 19:15:18 +00:00
|
|
|
uprv_strcpy(resB->fResPath + resPathLenOrig, toAdd);
|
2006-04-25 19:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ures_freeResPath(UResourceBundle *resB) {
|
|
|
|
if (resB->fResPath && resB->fResPath != resB->fResBuf) {
|
|
|
|
uprv_free(resB->fResPath);
|
|
|
|
}
|
|
|
|
resB->fResPath = NULL;
|
|
|
|
resB->fResPathLen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ures_closeBundle(UResourceBundle* resB, UBool freeBundleObj)
|
|
|
|
{
|
|
|
|
if(resB != NULL) {
|
|
|
|
if(resB->fData != NULL) {
|
|
|
|
entryClose(resB->fData);
|
|
|
|
}
|
|
|
|
if(resB->fVersion != NULL) {
|
|
|
|
uprv_free(resB->fVersion);
|
|
|
|
}
|
|
|
|
ures_freeResPath(resB);
|
|
|
|
|
|
|
|
if(ures_isStackObject(resB) == FALSE && freeBundleObj) {
|
|
|
|
uprv_free(resB);
|
|
|
|
}
|
|
|
|
#if 0 /*U_DEBUG*/
|
|
|
|
else {
|
|
|
|
/* poison the data */
|
|
|
|
uprv_memset(resB, -1, sizeof(UResourceBundle));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ures_close(UResourceBundle* resB)
|
|
|
|
{
|
|
|
|
ures_closeBundle(resB, TRUE);
|
|
|
|
}
|
|
|
|
|
2002-06-14 06:35:09 +00:00
|
|
|
static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
|
2009-04-15 01:57:02 +00:00
|
|
|
const char *key, int32_t idx, UResourceDataEntry *realData,
|
2002-06-24 20:58:17 +00:00
|
|
|
const UResourceBundle *parent, int32_t noAlias,
|
|
|
|
UResourceBundle *resB, UErrorCode *status)
|
|
|
|
{
|
2000-07-12 22:59:57 +00:00
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return resB;
|
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
if (parent == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-04-16 23:52:32 +00:00
|
|
|
if(RES_GET_TYPE(r) == URES_ALIAS) { /* This is an alias, need to exchange with real data */
|
2008-02-13 09:35:50 +00:00
|
|
|
if(noAlias < URES_MAX_ALIAS_LEVEL) {
|
|
|
|
int32_t len = 0;
|
|
|
|
const UChar *alias = res_getAlias(rdata, r, &len);
|
|
|
|
if(len > 0) {
|
|
|
|
/* we have an alias, now let's cut it up */
|
|
|
|
char stackAlias[200];
|
|
|
|
char *chAlias = NULL, *path = NULL, *locale = NULL, *keyPath = NULL;
|
|
|
|
int32_t capacity;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate enough space for both the char * version
|
|
|
|
* of the alias and parent->fResPath.
|
|
|
|
*
|
|
|
|
* We do this so that res_findResource() can modify the path,
|
|
|
|
* which allows us to remove redundant _res_findResource() variants
|
|
|
|
* in uresdata.c.
|
|
|
|
* res_findResource() now NUL-terminates each segment so that table keys
|
|
|
|
* can always be compared with strcmp() instead of strncmp().
|
|
|
|
* Saves code there and simplifies testing and code coverage.
|
|
|
|
*
|
|
|
|
* markus 2003oct17
|
|
|
|
*/
|
|
|
|
++len; /* count the terminating NUL */
|
|
|
|
if(parent->fResPath != NULL) {
|
|
|
|
capacity = (int32_t)uprv_strlen(parent->fResPath) + 1;
|
|
|
|
} else {
|
|
|
|
capacity = 0;
|
2005-03-09 00:00:34 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
if(capacity < len) {
|
|
|
|
capacity = len;
|
2005-03-09 00:00:34 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
if(capacity <= sizeof(stackAlias)) {
|
|
|
|
capacity = sizeof(stackAlias);
|
|
|
|
chAlias = stackAlias;
|
2002-09-18 06:04:31 +00:00
|
|
|
} else {
|
2008-02-13 09:35:50 +00:00
|
|
|
chAlias = (char *)uprv_malloc(capacity);
|
|
|
|
/* test for NULL */
|
|
|
|
if(chAlias == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
u_UCharsToChars(alias, chAlias, len);
|
|
|
|
|
|
|
|
if(*chAlias == RES_PATH_SEPARATOR) {
|
|
|
|
/* there is a path included */
|
|
|
|
locale = uprv_strchr(chAlias+1, RES_PATH_SEPARATOR);
|
|
|
|
if(locale == NULL) {
|
|
|
|
locale = uprv_strchr(chAlias, 0); /* avoid locale == NULL to make code below work */
|
2003-10-17 23:58:52 +00:00
|
|
|
} else {
|
2008-02-13 09:35:50 +00:00
|
|
|
*locale = 0;
|
|
|
|
locale++;
|
2003-10-17 23:58:52 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
path = chAlias+1;
|
|
|
|
if(uprv_strcmp(path, "LOCALE") == 0) {
|
|
|
|
/* this is an XPath alias, starting with "/LOCALE/" */
|
|
|
|
/* it contains the path to a resource which should be looked up */
|
|
|
|
/* starting in the requested locale */
|
|
|
|
keyPath = locale;
|
|
|
|
locale = parent->fTopLevelData->fName; /* this is the requested locale's name */
|
|
|
|
path = realData->fPath; /* we will be looking in the same package */
|
|
|
|
} else {
|
|
|
|
if(uprv_strcmp(path, "ICUDATA") == 0) { /* want ICU data */
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
keyPath = uprv_strchr(locale, RES_PATH_SEPARATOR);
|
|
|
|
if(keyPath) {
|
|
|
|
*keyPath = 0;
|
|
|
|
keyPath++;
|
|
|
|
}
|
2003-10-17 23:58:52 +00:00
|
|
|
}
|
2002-09-18 06:04:31 +00:00
|
|
|
} else {
|
2008-02-13 09:35:50 +00:00
|
|
|
/* no path, start with a locale */
|
|
|
|
locale = chAlias;
|
|
|
|
keyPath = uprv_strchr(locale, RES_PATH_SEPARATOR);
|
|
|
|
if(keyPath) {
|
|
|
|
*keyPath = 0;
|
|
|
|
keyPath++;
|
2005-04-01 07:57:40 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
path = realData->fPath;
|
2002-09-18 06:04:31 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
/* got almost everything, let's try to open */
|
|
|
|
/* first, open the bundle with real data */
|
|
|
|
UResourceBundle *result = resB;
|
|
|
|
const char* temp = NULL;
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
UResourceBundle *mainRes = ures_openDirect(path, locale, &intStatus);
|
|
|
|
if(U_SUCCESS(intStatus)) {
|
|
|
|
if(keyPath == NULL) {
|
|
|
|
/* no key path. This means that we are going to
|
|
|
|
* to use the corresponding resource from
|
|
|
|
* another bundle
|
|
|
|
*/
|
|
|
|
/* first, we are going to get a corresponding parent
|
|
|
|
* resource to the one we are searching.
|
|
|
|
*/
|
|
|
|
char *aKey = parent->fResPath;
|
|
|
|
if(aKey) {
|
|
|
|
uprv_strcpy(chAlias, aKey); /* allocated large enough above */
|
|
|
|
aKey = chAlias;
|
|
|
|
r = res_findResource(&(mainRes->fResData), mainRes->fRes, &aKey, &temp);
|
|
|
|
} else {
|
|
|
|
r = mainRes->fRes;
|
|
|
|
}
|
|
|
|
if(key) {
|
|
|
|
/* we need to make keyPath from parent's fResPath and
|
|
|
|
* current key, if there is a key associated
|
|
|
|
*/
|
|
|
|
len = (int32_t)(uprv_strlen(key) + 1);
|
|
|
|
if(len > capacity) {
|
|
|
|
capacity = len;
|
|
|
|
if(chAlias == stackAlias) {
|
|
|
|
chAlias = (char *)uprv_malloc(capacity);
|
|
|
|
} else {
|
|
|
|
chAlias = (char *)uprv_realloc(chAlias, capacity);
|
|
|
|
}
|
|
|
|
if(chAlias == NULL) {
|
|
|
|
ures_close(mainRes);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_memcpy(chAlias, key, len);
|
|
|
|
aKey = chAlias;
|
|
|
|
r = res_findResource(&(mainRes->fResData), r, &aKey, &temp);
|
2009-04-15 01:57:02 +00:00
|
|
|
} else if(idx != -1) {
|
2008-02-13 09:35:50 +00:00
|
|
|
/* if there is no key, but there is an index, try to get by the index */
|
|
|
|
/* here we have either a table or an array, so get the element */
|
2009-07-17 22:57:26 +00:00
|
|
|
UResType type = RES_GET_TYPE(r);
|
|
|
|
if(URES_IS_TABLE(type)) {
|
2009-04-15 01:57:02 +00:00
|
|
|
r = res_getTableItemByIndex(&(mainRes->fResData), r, idx, (const char **)&aKey);
|
2008-02-13 09:35:50 +00:00
|
|
|
} else { /* array */
|
2009-04-15 01:57:02 +00:00
|
|
|
r = res_getArrayItem(&(mainRes->fResData), r, idx);
|
2008-02-13 09:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(r != RES_BOGUS) {
|
|
|
|
result = init_resb_result(&(mainRes->fResData), r, temp, -1, mainRes->fData, mainRes, noAlias+1, resB, status);
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
result = resB;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* this one is a bit trickier.
|
|
|
|
* we start finding keys, but after we resolve one alias, the path might continue.
|
|
|
|
* Consider:
|
|
|
|
* aliastest:alias { "testtypes/anotheralias/Sequence" }
|
|
|
|
* anotheralias:alias { "/ICUDATA/sh/CollationElements" }
|
|
|
|
* aliastest resource should finally have the sequence, not collation elements.
|
|
|
|
*/
|
|
|
|
UResourceDataEntry *dataEntry = mainRes->fData;
|
|
|
|
char stackPath[URES_MAX_BUFFER_SIZE];
|
|
|
|
char *pathBuf = stackPath, *myPath = pathBuf;
|
|
|
|
if(uprv_strlen(keyPath) > URES_MAX_BUFFER_SIZE) {
|
|
|
|
pathBuf = (char *)uprv_malloc((uprv_strlen(keyPath)+1)*sizeof(char));
|
|
|
|
if(pathBuf == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_strcpy(pathBuf, keyPath);
|
|
|
|
result = mainRes;
|
|
|
|
/* now we have fallback following here */
|
|
|
|
do {
|
|
|
|
r = dataEntry->fData.rootRes;
|
|
|
|
/* this loop handles 'found' resources over several levels */
|
|
|
|
while(*myPath && U_SUCCESS(*status)) {
|
|
|
|
r = res_findResource(&(dataEntry->fData), r, &myPath, &temp);
|
|
|
|
if(r != RES_BOGUS) { /* found a resource, but it might be an indirection */
|
|
|
|
resB = init_resb_result(&(dataEntry->fData), r, temp, -1, dataEntry, result, noAlias+1, resB, status);
|
|
|
|
result = resB;
|
|
|
|
if(result) {
|
|
|
|
r = result->fRes; /* switch to a new resource, possibly a new tree */
|
|
|
|
dataEntry = result->fData;
|
|
|
|
}
|
|
|
|
} else { /* no resource found, we don't really want to look anymore on this level */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataEntry = dataEntry->fParent;
|
|
|
|
uprv_strcpy(pathBuf, keyPath);
|
|
|
|
myPath = pathBuf;
|
|
|
|
} while(r == RES_BOGUS && dataEntry != NULL);
|
|
|
|
if(r == RES_BOGUS) {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
result = resB;
|
|
|
|
}
|
|
|
|
if(pathBuf != stackPath) {
|
|
|
|
uprv_free(pathBuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* we failed to open the resource we're aliasing to */
|
|
|
|
*status = intStatus;
|
|
|
|
}
|
|
|
|
if(chAlias != stackAlias) {
|
|
|
|
uprv_free(chAlias);
|
|
|
|
}
|
|
|
|
if(mainRes != result) {
|
|
|
|
ures_close(mainRes);
|
|
|
|
}
|
|
|
|
return result;
|
2005-04-01 07:57:40 +00:00
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
} else {
|
|
|
|
/* bad alias, should be an error */
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return resB;
|
2003-10-17 23:58:52 +00:00
|
|
|
}
|
2002-06-14 06:03:08 +00:00
|
|
|
} else {
|
2008-02-13 09:35:50 +00:00
|
|
|
*status = U_TOO_MANY_ALIASES_ERROR;
|
|
|
|
return resB;
|
2002-06-14 06:03:08 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if(resB == NULL) {
|
2000-06-20 23:42:20 +00:00
|
|
|
resB = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if (resB == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(resB, FALSE);
|
2002-06-24 20:58:17 +00:00
|
|
|
resB->fResPath = NULL;
|
2003-11-07 09:00:24 +00:00
|
|
|
resB->fResPathLen = 0;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-04-17 21:19:38 +00:00
|
|
|
if(resB->fData != NULL) {
|
|
|
|
entryClose(resB->fData);
|
|
|
|
}
|
|
|
|
if(resB->fVersion != NULL) {
|
|
|
|
uprv_free(resB->fVersion);
|
|
|
|
}
|
2005-08-10 06:13:04 +00:00
|
|
|
/*
|
2008-02-13 09:35:50 +00:00
|
|
|
weiv: if stack object was passed in, it doesn't really need to be reinited,
|
|
|
|
since the purpose of initing is to remove stack junk. However, at this point
|
|
|
|
we would not do anything to an allocated object, so stack object should be
|
|
|
|
treated the same
|
2005-08-10 06:13:04 +00:00
|
|
|
*/
|
|
|
|
/*
|
2001-07-27 17:15:30 +00:00
|
|
|
if(ures_isStackObject(resB) != FALSE) {
|
2008-02-13 09:35:50 +00:00
|
|
|
ures_initStackObject(resB);
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
2005-08-10 06:13:04 +00:00
|
|
|
*/
|
2004-10-23 00:19:39 +00:00
|
|
|
if(parent != resB) {
|
|
|
|
ures_freeResPath(resB);
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2000-05-24 19:58:40 +00:00
|
|
|
resB->fData = realData;
|
|
|
|
entryIncrease(resB->fData);
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fHasFallback = FALSE;
|
|
|
|
resB->fIsTopLevel = FALSE;
|
|
|
|
resB->fIndex = -1;
|
2005-05-17 00:09:28 +00:00
|
|
|
resB->fKey = key;
|
2008-02-19 17:27:59 +00:00
|
|
|
/*resB->fParentRes = parent;*/
|
2003-11-08 08:30:31 +00:00
|
|
|
resB->fTopLevelData = parent->fTopLevelData;
|
2004-10-23 00:19:39 +00:00
|
|
|
if(parent->fResPath && parent != resB) {
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen, status);
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
|
|
|
if(key != NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key), status);
|
2005-06-01 01:23:19 +00:00
|
|
|
if(resB->fResPath[resB->fResPathLen-1] != RES_PATH_SEPARATOR) {
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1, status);
|
2005-06-01 01:23:19 +00:00
|
|
|
}
|
2009-04-15 01:57:02 +00:00
|
|
|
} else if(idx >= 0) {
|
2005-03-15 00:03:58 +00:00
|
|
|
char buf[256];
|
2009-04-15 01:57:02 +00:00
|
|
|
int32_t len = T_CString_integerToString(buf, idx, 10);
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(resB, buf, len, status);
|
2005-06-01 01:23:19 +00:00
|
|
|
if(resB->fResPath[resB->fResPathLen-1] != RES_PATH_SEPARATOR) {
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1, status);
|
2005-06-01 01:23:19 +00:00
|
|
|
}
|
2005-03-15 00:03:58 +00:00
|
|
|
}
|
|
|
|
/* Make sure that Purify doesn't complain about uninitialized memory copies. */
|
|
|
|
{
|
2005-03-25 19:38:41 +00:00
|
|
|
int32_t usedLen = ((resB->fResBuf == resB->fResPath) ? resB->fResPathLen : 0);
|
|
|
|
uprv_memset(resB->fResBuf + usedLen, 0, sizeof(resB->fResBuf) - usedLen);
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fVersion = NULL;
|
|
|
|
resB->fRes = r;
|
2002-06-24 20:58:17 +00:00
|
|
|
/*resB->fParent = parent->fRes;*/
|
2008-02-08 06:19:48 +00:00
|
|
|
uprv_memmove(&resB->fResData, rdata, sizeof(ResourceData));
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fSize = res_countArrayItems(&(resB->fResData), resB->fRes);
|
|
|
|
return resB;
|
|
|
|
}
|
|
|
|
|
2001-10-04 00:12:19 +00:00
|
|
|
UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status) {
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isStackObject;
|
2000-07-10 20:43:34 +00:00
|
|
|
if(U_FAILURE(*status) || r == original) {
|
2000-05-15 18:39:17 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
if(original != NULL) {
|
|
|
|
if(r == NULL) {
|
|
|
|
isStackObject = FALSE;
|
2000-06-20 23:42:20 +00:00
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if (r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2001-07-27 17:15:30 +00:00
|
|
|
isStackObject = ures_isStackObject(r);
|
2006-04-25 19:32:35 +00:00
|
|
|
ures_closeBundle(r, FALSE);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
uprv_memcpy(r, original, sizeof(UResourceBundle));
|
2002-06-24 20:58:17 +00:00
|
|
|
r->fResPath = NULL;
|
2003-11-12 06:10:59 +00:00
|
|
|
r->fResPathLen = 0;
|
2002-06-24 20:58:17 +00:00
|
|
|
if(original->fResPath) {
|
2008-02-23 19:15:18 +00:00
|
|
|
ures_appendResPath(r, original->fResPath, original->fResPathLen, status);
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(r, isStackObject);
|
2000-05-15 18:39:17 +00:00
|
|
|
if(r->fData != NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
entryIncrease(r->fData);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-25 19:32:35 +00:00
|
|
|
return r;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to retrieve data from resource bundles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getString(const UResourceBundle* resB, int32_t* len, UErrorCode* status) {
|
2009-07-17 22:57:26 +00:00
|
|
|
const UChar *s;
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
s = res_getString(&(resB->fResData), resB->fRes, len);
|
|
|
|
if (s == NULL) {
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
return s;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2006-07-03 21:05:30 +00:00
|
|
|
static const char *
|
|
|
|
ures_toUTF8String(const UChar *s16, int32_t length16,
|
|
|
|
char *dest, int32_t *pLength,
|
|
|
|
UBool forceCopy,
|
|
|
|
UErrorCode *status) {
|
|
|
|
int32_t capacity;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (pLength != NULL) {
|
|
|
|
capacity = *pLength;
|
|
|
|
} else {
|
|
|
|
capacity = 0;
|
|
|
|
}
|
|
|
|
if (capacity < 0 || (capacity > 0 && dest == NULL)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length16 == 0) {
|
|
|
|
/* empty string, return as read-only pointer */
|
|
|
|
if (pLength != NULL) {
|
|
|
|
*pLength = 0;
|
|
|
|
}
|
|
|
|
if (forceCopy) {
|
2007-08-31 19:39:14 +00:00
|
|
|
u_terminateChars(dest, capacity, 0, status);
|
2006-07-03 21:05:30 +00:00
|
|
|
return dest;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We need to transform the string to the destination buffer. */
|
|
|
|
if (capacity < length16) {
|
|
|
|
/* No chance for the string to fit. Pure preflighting. */
|
|
|
|
return u_strToUTF8(NULL, 0, pLength, s16, length16, status);
|
|
|
|
}
|
|
|
|
if (!forceCopy && (length16 <= 0x2aaaaaaa)) {
|
|
|
|
/*
|
|
|
|
* We know the string will fit into dest because each UChar turns
|
|
|
|
* into at most three UTF-8 bytes. Fill the latter part of dest
|
|
|
|
* so that callers do not expect to use dest as a string pointer,
|
|
|
|
* hopefully leading to more robust code for when resource bundles
|
|
|
|
* may store UTF-8 natively.
|
|
|
|
* (In which case dest would not be used at all.)
|
|
|
|
*
|
|
|
|
* We do not do this if forceCopy=TRUE because then the caller
|
|
|
|
* expects the string to start exactly at dest.
|
|
|
|
*
|
|
|
|
* The test above for <= 0x2aaaaaaa prevents overflows.
|
|
|
|
* The +1 is for the NUL terminator.
|
|
|
|
*/
|
|
|
|
int32_t maxLength = 3 * length16 + 1;
|
|
|
|
if (capacity > maxLength) {
|
|
|
|
dest += capacity - maxLength;
|
|
|
|
capacity = maxLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return u_strToUTF8(dest, capacity, pLength, s16, length16, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
2006-07-03 21:05:30 +00:00
|
|
|
ures_getUTF8String(const UResourceBundle *resB,
|
|
|
|
char *dest, int32_t *pLength,
|
|
|
|
UBool forceCopy,
|
|
|
|
UErrorCode *status) {
|
|
|
|
int32_t length16;
|
|
|
|
const UChar *s16 = ures_getString(resB, &length16, status);
|
|
|
|
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
|
|
|
|
}
|
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resB, int32_t* len,
|
2000-06-07 19:52:08 +00:00
|
|
|
UErrorCode* status) {
|
2009-07-17 22:57:26 +00:00
|
|
|
const uint8_t *p;
|
2000-06-07 19:52:08 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
p = res_getBinary(&(resB->fResData), resB->fRes, len);
|
|
|
|
if (p == NULL) {
|
2000-06-07 19:52:08 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
return p;
|
2000-05-18 21:25:51 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 17:08:07 +00:00
|
|
|
U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, int32_t* len,
|
|
|
|
UErrorCode* status) {
|
2009-07-17 22:57:26 +00:00
|
|
|
const int32_t *p;
|
2001-08-01 17:08:07 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
p = res_getIntVector(&(resB->fResData), resB->fRes, len);
|
|
|
|
if (p == NULL) {
|
2001-08-01 17:08:07 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
return p;
|
2001-08-01 17:08:07 +00:00
|
|
|
}
|
|
|
|
|
2001-09-17 23:05:08 +00:00
|
|
|
/* this function returns a signed integer */
|
|
|
|
/* it performs sign extension */
|
|
|
|
U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2003-04-16 23:52:32 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) != URES_INT) {
|
2001-09-21 00:02:24 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
return RES_GET_INT(resB->fRes);
|
2001-09-17 23:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resB, UErrorCode *status) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2003-04-16 23:52:32 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) != URES_INT) {
|
2001-09-21 00:02:24 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
return RES_GET_UINT(resB->fRes);
|
2000-05-18 21:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
U_CAPI UResType U_EXPORT2 ures_getType(const UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
2003-04-16 23:52:32 +00:00
|
|
|
return URES_NONE;
|
2000-06-07 19:52:08 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
return res_getPublicType(resB->fRes);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
U_CAPI const char * U_EXPORT2 ures_getKey(const UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(resB->fKey);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2 ures_getSize(const UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fSize;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2003-05-12 18:24:56 +00:00
|
|
|
static const UChar* ures_getStringWithAlias(const UResourceBundle *resB, Resource r, int32_t sIndex, int32_t *len, UErrorCode *status) {
|
|
|
|
if(RES_GET_TYPE(r) == URES_ALIAS) {
|
|
|
|
const UChar* result = 0;
|
|
|
|
UResourceBundle *tempRes = ures_getByIndex(resB, sIndex, NULL, status);
|
|
|
|
result = ures_getString(tempRes, len, status);
|
|
|
|
ures_close(tempRes);
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return res_getString(&(resB->fResData), r, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 21:13:33 +00:00
|
|
|
U_CAPI void U_EXPORT2 ures_resetIterator(UResourceBundle *resB){
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resB->fIndex = -1;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
U_CAPI UBool U_EXPORT2 ures_hasNext(const UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-08-10 01:59:18 +00:00
|
|
|
return (UBool)(resB->fIndex < resB->fSize-1);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getNextString(UResourceBundle *resB, int32_t* len, const char ** key, UErrorCode *status) {
|
2000-06-07 19:52:08 +00:00
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(resB->fIndex == resB->fSize-1) {
|
|
|
|
*status = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
} else {
|
|
|
|
resB->fIndex++;
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
2000-06-07 19:52:08 +00:00
|
|
|
return res_getString(&(resB->fResData), resB->fRes, len);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_TABLE:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_TABLE16:
|
2003-09-24 17:44:43 +00:00
|
|
|
case URES_TABLE32:
|
2000-06-07 19:52:08 +00:00
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, resB->fIndex, key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2003-05-12 18:24:56 +00:00
|
|
|
return ures_getStringWithAlias(resB, r, resB->fIndex, len, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_ARRAY16:
|
2000-08-24 21:20:10 +00:00
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, resB->fIndex);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2003-05-12 18:24:56 +00:00
|
|
|
return ures_getStringWithAlias(resB, r, resB->fIndex, len, status);
|
2003-04-23 06:59:29 +00:00
|
|
|
case URES_ALIAS:
|
2003-05-12 18:24:56 +00:00
|
|
|
return ures_getStringWithAlias(resB, resB->fRes, resB->fIndex, len, status);
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_INT:
|
|
|
|
case URES_BINARY:
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT_VECTOR:
|
2009-07-17 22:57:26 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
2000-06-07 19:52:08 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
|
2000-06-20 23:42:20 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getNextResource(UResourceBundle *resB, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
const char *key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(resB->fIndex == resB->fSize-1) {
|
|
|
|
*status = U_INDEX_OUTOFBOUNDS_ERROR;
|
2000-08-24 21:20:10 +00:00
|
|
|
/*return NULL;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
resB->fIndex++;
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT:
|
|
|
|
case URES_BINARY:
|
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
|
|
|
case URES_INT_VECTOR:
|
2001-10-04 00:12:19 +00:00
|
|
|
return ures_copyResb(fillIn, resB, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_TABLE:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_TABLE16:
|
2003-09-24 17:44:43 +00:00
|
|
|
case URES_TABLE32:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, resB->fIndex, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, resB->fIndex, resB->fData, resB, 0, fillIn, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_ARRAY16:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, resB->fIndex);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, resB->fIndex, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
default:
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getByIndex(const UResourceBundle *resB, int32_t indexR, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
const char* key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(indexR >= 0 && resB->fSize > indexR) {
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT:
|
|
|
|
case URES_BINARY:
|
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
|
|
|
case URES_INT_VECTOR:
|
2001-10-04 00:12:19 +00:00
|
|
|
return ures_copyResb(fillIn, resB, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_TABLE:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_TABLE16:
|
2003-09-24 17:44:43 +00:00
|
|
|
case URES_TABLE32:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, indexR, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, indexR, resB->fData, resB, 0, fillIn, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_ARRAY16:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, indexR);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, indexR, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
default:
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB, int32_t indexS, int32_t* len, UErrorCode *status) {
|
|
|
|
const char* key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(indexS >= 0 && resB->fSize > indexS) {
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
2000-05-15 18:39:17 +00:00
|
|
|
return res_getString(&(resB->fResData), resB->fRes, len);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_TABLE:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_TABLE16:
|
2003-09-24 17:44:43 +00:00
|
|
|
case URES_TABLE32:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, indexS, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2003-05-12 18:24:56 +00:00
|
|
|
return ures_getStringWithAlias(resB, r, indexS, len, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_ARRAY16:
|
2000-05-15 18:39:17 +00:00
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, indexS);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2003-05-12 18:24:56 +00:00
|
|
|
return ures_getStringWithAlias(resB, r, indexS, len, status);
|
2003-04-23 06:59:29 +00:00
|
|
|
case URES_ALIAS:
|
2006-11-16 17:39:09 +00:00
|
|
|
return ures_getStringWithAlias(resB, resB->fRes, indexS, len, status);
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_INT:
|
|
|
|
case URES_BINARY:
|
|
|
|
case URES_INT_VECTOR:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
break;
|
2006-11-16 17:39:09 +00:00
|
|
|
default:
|
2007-06-11 18:42:07 +00:00
|
|
|
/* must not occur */
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
break;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
2006-07-03 21:05:30 +00:00
|
|
|
ures_getUTF8StringByIndex(const UResourceBundle *resB,
|
2009-04-15 01:57:02 +00:00
|
|
|
int32_t idx,
|
2006-07-03 21:05:30 +00:00
|
|
|
char *dest, int32_t *pLength,
|
|
|
|
UBool forceCopy,
|
|
|
|
UErrorCode *status) {
|
|
|
|
int32_t length16;
|
2009-04-15 01:57:02 +00:00
|
|
|
const UChar *s16 = ures_getStringByIndex(resB, idx, &length16, status);
|
2006-07-03 21:05:30 +00:00
|
|
|
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
|
|
|
|
}
|
|
|
|
|
2002-07-16 18:22:36 +00:00
|
|
|
/*U_CAPI const char *ures_getResPath(UResourceBundle *resB) {
|
2002-06-24 20:58:17 +00:00
|
|
|
return resB->fResPath;
|
2002-07-16 18:22:36 +00:00
|
|
|
}*/
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_findResource(const char* path, UResourceBundle *fillIn, UErrorCode *status)
|
|
|
|
{
|
|
|
|
UResourceBundle *first = NULL;
|
|
|
|
UResourceBundle *result = fillIn;
|
|
|
|
char *packageName = NULL;
|
2005-08-26 21:50:51 +00:00
|
|
|
char *pathToResource = NULL, *save = NULL;
|
2002-06-24 20:58:17 +00:00
|
|
|
char *locale = NULL, *localeEnd = NULL;
|
2003-10-17 23:58:52 +00:00
|
|
|
int32_t length;
|
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return result;
|
|
|
|
}
|
2003-10-17 23:58:52 +00:00
|
|
|
|
2004-12-08 01:05:40 +00:00
|
|
|
length = (int32_t)(uprv_strlen(path)+1);
|
2005-08-26 21:50:51 +00:00
|
|
|
save = pathToResource = (char *)uprv_malloc(length*sizeof(char));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if(pathToResource == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return result;
|
2003-10-17 23:58:52 +00:00
|
|
|
}
|
|
|
|
uprv_memcpy(pathToResource, path, length);
|
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
locale = pathToResource;
|
|
|
|
if(*pathToResource == RES_PATH_SEPARATOR) { /* there is a path specification */
|
|
|
|
pathToResource++;
|
|
|
|
packageName = pathToResource;
|
|
|
|
pathToResource = uprv_strchr(pathToResource, RES_PATH_SEPARATOR);
|
|
|
|
if(pathToResource == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
} else {
|
|
|
|
*pathToResource = 0;
|
|
|
|
locale = pathToResource+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-14 23:01:06 +00:00
|
|
|
localeEnd = uprv_strchr(locale, RES_PATH_SEPARATOR);
|
2002-06-24 20:58:17 +00:00
|
|
|
if(localeEnd != NULL) {
|
|
|
|
*localeEnd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = ures_open(packageName, locale, status);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
if(localeEnd) {
|
|
|
|
result = ures_findSubResource(first, localeEnd+1, fillIn, status);
|
|
|
|
} else {
|
|
|
|
result = ures_copyResb(fillIn, first, status);
|
|
|
|
}
|
|
|
|
ures_close(first);
|
|
|
|
}
|
2005-08-26 21:50:51 +00:00
|
|
|
uprv_free(save);
|
2002-06-24 20:58:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
2003-10-17 23:58:52 +00:00
|
|
|
ures_findSubResource(const UResourceBundle *resB, char* path, UResourceBundle *fillIn, UErrorCode *status)
|
2002-06-24 20:58:17 +00:00
|
|
|
{
|
|
|
|
Resource res = RES_BOGUS;
|
|
|
|
UResourceBundle *result = fillIn;
|
2002-07-30 20:49:30 +00:00
|
|
|
const char *key;
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we do looping and circular alias checking */
|
2004-09-14 23:35:32 +00:00
|
|
|
/* this loop is here because aliasing is resolved on this level, not on res level */
|
|
|
|
/* so, when we encounter an alias, it is not an aggregate resource, so we return */
|
|
|
|
do {
|
|
|
|
res = res_findResource(&(resB->fResData), resB->fRes, &path, &key);
|
|
|
|
if(res != RES_BOGUS) {
|
|
|
|
result = init_resb_result(&(resB->fResData), res, key, -1, resB->fData, resB, 0, fillIn, status);
|
|
|
|
resB = result;
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-15 00:03:58 +00:00
|
|
|
} while(*path); /* there is more stuff in the path */
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2005-08-12 22:01:55 +00:00
|
|
|
U_INTERNAL const UChar* U_EXPORT2
|
|
|
|
ures_getStringByKeyWithFallback(const UResourceBundle *resB,
|
|
|
|
const char* inKey,
|
|
|
|
int32_t* len,
|
|
|
|
UErrorCode *status) {
|
|
|
|
|
|
|
|
UResourceBundle stack;
|
|
|
|
const UChar* retVal = NULL;
|
|
|
|
ures_initStackObject(&stack);
|
|
|
|
ures_getByKeyWithFallback(resB, inKey, &stack, status);
|
|
|
|
retVal = ures_getString(&stack, len, status);
|
|
|
|
ures_close(&stack);
|
|
|
|
return retVal;
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
|
2003-11-08 08:30:31 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_getByKeyWithFallback(const UResourceBundle *resB,
|
|
|
|
const char* inKey,
|
|
|
|
UResourceBundle *fillIn,
|
|
|
|
UErrorCode *status) {
|
2005-05-17 00:09:28 +00:00
|
|
|
Resource res = RES_BOGUS, rootRes = RES_BOGUS;
|
2003-11-27 01:14:37 +00:00
|
|
|
/*UResourceDataEntry *realData = NULL;*/
|
2003-11-08 08:30:31 +00:00
|
|
|
const char *key = inKey;
|
2004-10-22 23:13:12 +00:00
|
|
|
UResourceBundle *helper = NULL;
|
2009-07-17 22:57:26 +00:00
|
|
|
UResType type;
|
2003-11-08 08:30:31 +00:00
|
|
|
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
type = RES_GET_TYPE(resB->fRes);
|
|
|
|
if(URES_IS_TABLE(type)) {
|
2003-11-08 08:30:31 +00:00
|
|
|
int32_t t;
|
|
|
|
res = res_getTableItemByKey(&(resB->fResData), resB->fRes, &t, &key);
|
|
|
|
if(res == RES_BOGUS) {
|
|
|
|
UResourceDataEntry *dataEntry = resB->fData;
|
|
|
|
char path[256];
|
|
|
|
char* myPath = path;
|
2005-06-01 01:23:19 +00:00
|
|
|
const char* resPath = resB->fResPath;
|
|
|
|
int32_t len = resB->fResPathLen;
|
2003-11-08 08:30:31 +00:00
|
|
|
|
|
|
|
while(res == RES_BOGUS && dataEntry->fParent != NULL) { /* Otherwise, we'll look in parents */
|
|
|
|
dataEntry = dataEntry->fParent;
|
2005-05-17 00:09:28 +00:00
|
|
|
rootRes = dataEntry->fData.rootRes;
|
2009-12-03 18:06:37 +00:00
|
|
|
|
2003-11-08 08:30:31 +00:00
|
|
|
if(dataEntry->fBogus == U_ZERO_ERROR) {
|
2005-06-01 01:23:19 +00:00
|
|
|
uprv_strncpy(path, resPath, len);
|
|
|
|
uprv_strcpy(path+len, inKey);
|
2004-10-17 05:16:23 +00:00
|
|
|
myPath = path;
|
|
|
|
key = inKey;
|
2004-10-22 23:13:12 +00:00
|
|
|
do {
|
2005-05-17 00:09:28 +00:00
|
|
|
res = res_findResource(&(dataEntry->fData), rootRes, &myPath, &key);
|
2004-10-22 23:13:12 +00:00
|
|
|
if (RES_GET_TYPE(res) == URES_ALIAS && *myPath) {
|
|
|
|
/* We hit an alias, but we didn't finish following the path. */
|
2005-05-17 00:09:28 +00:00
|
|
|
helper = init_resb_result(&(dataEntry->fData), res, NULL, -1, dataEntry, resB, 0, helper, status);
|
2005-05-17 06:07:40 +00:00
|
|
|
/*helper = init_resb_result(&(dataEntry->fData), res, inKey, -1, dataEntry, resB, 0, helper, status);*/
|
2005-05-17 00:09:28 +00:00
|
|
|
if(helper) {
|
|
|
|
dataEntry = helper->fData;
|
|
|
|
rootRes = helper->fRes;
|
2005-06-01 01:23:19 +00:00
|
|
|
resPath = helper->fResPath;
|
|
|
|
len = helper->fResPathLen;
|
|
|
|
|
2005-05-17 00:09:28 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2004-10-22 23:13:12 +00:00
|
|
|
}
|
2004-12-02 07:27:34 +00:00
|
|
|
} while(*myPath); /* Continue until the whole path is consumed */
|
2003-11-08 08:30:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);*/
|
|
|
|
if(res != RES_BOGUS) {
|
|
|
|
/* check if resB->fResPath gives the right name here */
|
2005-07-11 22:38:59 +00:00
|
|
|
if(uprv_strcmp(dataEntry->fName, uloc_getDefault())==0 || uprv_strcmp(dataEntry->fName, kRootLocaleName)==0) {
|
|
|
|
*status = U_USING_DEFAULT_WARNING;
|
|
|
|
} else {
|
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
|
|
|
}
|
|
|
|
|
2004-10-22 23:13:12 +00:00
|
|
|
fillIn = init_resb_result(&(dataEntry->fData), res, inKey, -1, dataEntry, resB, 0, fillIn, status);
|
2003-11-08 08:30:31 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
2004-10-22 23:13:12 +00:00
|
|
|
fillIn = init_resb_result(&(resB->fResData), res, key, -1, resB->fData, resB, 0, fillIn, status);
|
2003-11-08 08:30:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2004-10-22 23:13:12 +00:00
|
|
|
ures_close(helper);
|
2003-11-08 08:30:31 +00:00
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, const char* inKey, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
Resource res = RES_BOGUS;
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *realData = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
const char *key = inKey;
|
2009-07-17 22:57:26 +00:00
|
|
|
UResType type;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
type = RES_GET_TYPE(resB->fRes);
|
|
|
|
if(URES_IS_TABLE(type)) {
|
2000-05-15 18:39:17 +00:00
|
|
|
int32_t t;
|
|
|
|
res = res_getTableItemByKey(&(resB->fResData), resB->fRes, &t, &key);
|
|
|
|
if(res == RES_BOGUS) {
|
2000-08-24 21:20:10 +00:00
|
|
|
key = inKey;
|
|
|
|
if(resB->fHasFallback == TRUE) {
|
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
2002-06-24 20:58:17 +00:00
|
|
|
/* check if resB->fResPath gives the right name here */
|
|
|
|
return init_resb_result(rd, res, key, -1, realData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), res, key, -1, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
|
|
|
|
/* not currently */
|
2003-04-16 23:52:32 +00:00
|
|
|
else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == TRUE) {
|
2000-05-15 18:39:17 +00:00
|
|
|
/* here should go a first attempt to locate the key using index table */
|
2000-05-24 19:58:40 +00:00
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(rd, res, key, realData, resB, fillIn, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* inKey, int32_t* len, UErrorCode *status) {
|
|
|
|
Resource res = RES_BOGUS;
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *realData = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* key = inKey;
|
2009-07-17 22:57:26 +00:00
|
|
|
UResType type;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
type = RES_GET_TYPE(resB->fRes);
|
|
|
|
if(URES_IS_TABLE(type)) {
|
2000-05-15 18:39:17 +00:00
|
|
|
int32_t t=0;
|
2002-02-08 00:52:08 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
res = res_getTableItemByKey(&(resB->fResData), resB->fRes, &t, &key);
|
2002-02-08 00:52:08 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(res == RES_BOGUS) {
|
2000-08-24 21:20:10 +00:00
|
|
|
key = inKey;
|
|
|
|
if(resB->fHasFallback == TRUE) {
|
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
2002-02-08 00:52:08 +00:00
|
|
|
switch (RES_GET_TYPE(res)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
2002-02-08 00:52:08 +00:00
|
|
|
return res_getString(rd, res, len);
|
2003-04-23 06:59:29 +00:00
|
|
|
case URES_ALIAS:
|
|
|
|
{
|
|
|
|
const UChar* result = 0;
|
|
|
|
UResourceBundle *tempRes = ures_getByKey(resB, inKey, NULL, status);
|
|
|
|
result = ures_getString(tempRes, len, status);
|
|
|
|
ures_close(tempRes);
|
|
|
|
return result;
|
|
|
|
}
|
2002-02-08 00:52:08 +00:00
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-02-08 00:52:08 +00:00
|
|
|
switch (RES_GET_TYPE(res)) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2009-07-17 22:57:26 +00:00
|
|
|
case URES_STRING_V2:
|
2002-02-08 00:52:08 +00:00
|
|
|
return res_getString(&(resB->fResData), res, len);
|
2003-04-23 06:59:29 +00:00
|
|
|
case URES_ALIAS:
|
|
|
|
{
|
|
|
|
const UChar* result = 0;
|
|
|
|
UResourceBundle *tempRes = ures_getByKey(resB, inKey, NULL, status);
|
|
|
|
result = ures_getString(tempRes, len, status);
|
|
|
|
ures_close(tempRes);
|
|
|
|
return result;
|
|
|
|
}
|
2002-02-08 00:52:08 +00:00
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
|
|
|
|
/* not currently */
|
2003-04-16 23:52:32 +00:00
|
|
|
else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == TRUE) {
|
2000-05-15 18:39:17 +00:00
|
|
|
/* here should go a first attempt to locate the key using index table */
|
2000-05-24 19:58:40 +00:00
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2000-05-15 18:39:17 +00:00
|
|
|
return res_getString(rd, res, len);
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
2006-07-03 21:05:30 +00:00
|
|
|
ures_getUTF8StringByKey(const UResourceBundle *resB,
|
|
|
|
const char *key,
|
|
|
|
char *dest, int32_t *pLength,
|
|
|
|
UBool forceCopy,
|
|
|
|
UErrorCode *status) {
|
|
|
|
int32_t length16;
|
|
|
|
const UChar *s16 = ures_getStringByKey(resB, key, &length16, status);
|
|
|
|
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* TODO: clean from here down */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INTERNAL: Get the name of the first real locale (not placeholder)
|
|
|
|
* that has resource bundle data.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status)
|
2000-05-15 18:39:17 +00:00
|
|
|
{
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if (!resourceBundle) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2001-10-11 18:46:18 +00:00
|
|
|
return resourceBundle->fData->fName;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-07 09:00:24 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ures_getLocaleByType(const UResourceBundle* resourceBundle,
|
|
|
|
ULocDataLocaleType type,
|
|
|
|
UErrorCode* status) {
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!resourceBundle) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2003-11-27 01:14:37 +00:00
|
|
|
switch(type) {
|
|
|
|
case ULOC_ACTUAL_LOCALE:
|
|
|
|
return resourceBundle->fData->fName;
|
|
|
|
case ULOC_VALID_LOCALE:
|
|
|
|
return resourceBundle->fTopLevelData->fName;
|
|
|
|
case ULOC_REQUESTED_LOCALE:
|
|
|
|
return NULL;
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-11-07 09:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CFUNC const char* ures_getName(const UResourceBundle* resB) {
|
2001-07-27 17:15:30 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fData->fName;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
|
2006-11-15 00:38:04 +00:00
|
|
|
#ifdef URES_DEBUG
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CFUNC const char* ures_getPath(const UResourceBundle* resB) {
|
2001-07-27 17:15:30 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fData->fPath;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2006-11-15 00:38:04 +00:00
|
|
|
#endif
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* OLD API implementation */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API: This function is used to open a resource bundle
|
|
|
|
* proper fallback chaining is executed while initialization.
|
|
|
|
* The result is stored in cache for later fallback search.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ures_openFillIn(UResourceBundle *r, const char* path,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* localeID, UErrorCode* status) {
|
|
|
|
if(r == NULL) {
|
2006-04-25 19:32:35 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
UResourceDataEntry *firstData;
|
2006-04-25 19:49:32 +00:00
|
|
|
UBool isStackObject = ures_isStackObject(r);
|
|
|
|
|
2006-04-25 19:32:35 +00:00
|
|
|
ures_closeBundle(r, FALSE);
|
|
|
|
uprv_memset(r, 0, sizeof(UResourceBundle));
|
2006-04-25 19:49:32 +00:00
|
|
|
ures_setIsStackObject(r, isStackObject);
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fHasFallback = TRUE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
|
|
|
r->fIndex = -1;
|
|
|
|
r->fData = entryOpen(path, localeID, status);
|
2006-04-25 19:32:35 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
/* this is a quick fix to get regular data in bundle - until construction is cleaned up */
|
|
|
|
firstData = r->fData;
|
|
|
|
while(firstData->fBogus != U_ZERO_ERROR && firstData->fParent != NULL) {
|
|
|
|
firstData = firstData->fParent;
|
|
|
|
}
|
2005-11-28 23:59:33 +00:00
|
|
|
uprv_memcpy(&r->fResData, &firstData->fData, sizeof(ResourceData));
|
|
|
|
r->fHasFallback=(UBool)!r->fResData.noFallback;
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fRes = r->fResData.rootRes;
|
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2003-11-08 08:30:31 +00:00
|
|
|
r->fTopLevelData = r->fData;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-07 09:00:24 +00:00
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_open(const char* path,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* localeID,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-11 00:51:18 +00:00
|
|
|
char canonLocaleID[100];
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *hasData = NULL;
|
2001-10-11 00:51:18 +00:00
|
|
|
UResourceBundle *r;
|
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first "canonicalize" the locale ID */
|
2006-03-16 06:07:07 +00:00
|
|
|
uloc_getBaseName(localeID, canonLocaleID, sizeof(canonLocaleID), status);
|
2001-10-11 00:51:18 +00:00
|
|
|
if(U_FAILURE(*status) || *status == U_STRING_NOT_TERMINATED_WARNING) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2000-05-15 18:39:17 +00:00
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-25 19:32:35 +00:00
|
|
|
uprv_memset(r, 0, sizeof(UResourceBundle));
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fHasFallback = TRUE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(r, FALSE);
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fIndex = -1;
|
2001-10-11 00:51:18 +00:00
|
|
|
r->fData = entryOpen(path, canonLocaleID, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-11-08 08:30:31 +00:00
|
|
|
r->fTopLevelData = r->fData;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
hasData = r->fData;
|
|
|
|
while(hasData->fBogus != U_ZERO_ERROR) {
|
|
|
|
hasData = hasData->fParent;
|
|
|
|
if(hasData == NULL) {
|
2001-07-27 17:15:30 +00:00
|
|
|
/* This can happen only if fallback chain gets broken by an act of God */
|
|
|
|
/* TODO: this unlikely to happen, consider removing it */
|
2000-05-15 18:39:17 +00:00
|
|
|
entryClose(r->fData);
|
|
|
|
uprv_free(r);
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-28 23:59:33 +00:00
|
|
|
uprv_memcpy(&r->fResData, &hasData->fData, sizeof(ResourceData));
|
|
|
|
r->fHasFallback=(UBool)!r->fResData.noFallback;
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fRes = r->fResData.rootRes;
|
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
/*
|
|
|
|
if(r->fData->fPath != NULL) {
|
|
|
|
ures_setResPath(r, r->fData->fPath);
|
|
|
|
ures_appendResPath(r, RES_PATH_PACKAGE_S);
|
|
|
|
ures_appendResPath(r, r->fData->fName);
|
|
|
|
} else {
|
|
|
|
ures_setResPath(r, r->fData->fName);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-10-10 01:13:01 +00:00
|
|
|
/**
|
|
|
|
* Opens a resource bundle without "canonicalizing" the locale name. No fallback will be performed
|
2001-10-11 18:46:18 +00:00
|
|
|
* or sought. However, alias substitution will happen!
|
2001-10-10 01:13:01 +00:00
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_openDirect(const char* path, const char* localeID, UErrorCode* status) {
|
2001-10-11 00:51:18 +00:00
|
|
|
UResourceBundle *r;
|
2004-05-25 05:41:20 +00:00
|
|
|
UErrorCode subStatus = U_ZERO_ERROR;
|
2001-10-11 00:51:18 +00:00
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2001-10-10 01:13:01 +00:00
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fHasFallback = FALSE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
|
|
|
ures_setIsStackObject(r, FALSE);
|
|
|
|
r->fIndex = -1;
|
2004-05-25 05:41:20 +00:00
|
|
|
r->fData = entryOpen(path, localeID, &subStatus);
|
|
|
|
if(U_FAILURE(subStatus)) {
|
|
|
|
*status = subStatus;
|
2001-10-10 01:13:01 +00:00
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-05-25 05:41:20 +00:00
|
|
|
if(subStatus != U_ZERO_ERROR /*r->fData->fBogus != U_ZERO_ERROR*/) {
|
2001-10-11 18:46:18 +00:00
|
|
|
/* we didn't find one we were looking for - so openDirect */
|
|
|
|
/* should fail */
|
2001-10-10 01:13:01 +00:00
|
|
|
entryClose(r->fData);
|
|
|
|
uprv_free(r);
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fKey = NULL;
|
|
|
|
r->fVersion = NULL;
|
2005-11-28 23:59:33 +00:00
|
|
|
uprv_memcpy(&r->fResData, &r->fData->fData, sizeof(ResourceData));
|
|
|
|
/* r->fHasFallback remains FALSE here in ures_openDirect() */
|
2001-10-10 01:13:01 +00:00
|
|
|
r->fRes = r->fResData.rootRes;
|
2002-06-24 20:58:17 +00:00
|
|
|
/*r->fParent = RES_BOGUS;*/
|
2001-10-10 01:13:01 +00:00
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
r->fResPath = NULL;
|
2004-06-03 17:44:02 +00:00
|
|
|
r->fResPathLen = 0;
|
2008-02-19 17:27:59 +00:00
|
|
|
/*r->fParentRes = NULL;*/
|
2003-11-08 08:30:31 +00:00
|
|
|
r->fTopLevelData = r->fData;
|
2003-11-07 09:00:24 +00:00
|
|
|
|
2001-10-10 01:13:01 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/**
|
|
|
|
* API: Counts members. For arrays and tables, returns number of resources.
|
|
|
|
* For strings, returns 1.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ures_countArrayItems(const UResourceBundle* resourceBundle,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* resourceKey,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
UResourceBundle resData;
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(&resData);
|
2004-04-23 18:02:55 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(resourceBundle == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
ures_getByKey(resourceBundle, resourceKey, &resData, status);
|
2004-04-23 18:02:55 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(resData.fResData.data != NULL) {
|
2004-04-23 18:02:55 +00:00
|
|
|
int32_t result = res_countArrayItems(&resData.fResData, resData.fRes);
|
|
|
|
ures_close(&resData);
|
|
|
|
return result;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2004-04-23 18:02:55 +00:00
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
ures_close(&resData);
|
|
|
|
return 0;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ures_getVersionNumber(const UResourceBundle* resourceBundle)
|
2000-05-15 18:39:17 +00:00
|
|
|
{
|
|
|
|
if (!resourceBundle) return NULL;
|
|
|
|
|
|
|
|
if(resourceBundle->fVersion == NULL) {
|
|
|
|
|
|
|
|
/* If the version ID has not been built yet, then do so. Retrieve */
|
|
|
|
/* the minor version from the file. */
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t minor_len = 0;
|
2000-10-14 01:53:59 +00:00
|
|
|
int32_t len;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
const UChar* minor_version = ures_getStringByKey(resourceBundle, kVersionTag, &minor_len, &status);
|
2004-08-13 20:32:07 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* Determine the length of of the final version string. This is */
|
|
|
|
/* the length of the major part + the length of the separator */
|
|
|
|
/* (==1) + the length of the minor part (+ 1 for the zero byte at */
|
|
|
|
/* the end). */
|
2000-10-14 01:53:59 +00:00
|
|
|
|
|
|
|
len = (minor_len > 0) ? minor_len : 1;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* Allocate the string, and build it up. */
|
|
|
|
/* + 1 for zero byte */
|
|
|
|
|
|
|
|
|
|
|
|
((UResourceBundle *)resourceBundle)->fVersion = (char *)uprv_malloc(1 + len);
|
2008-01-16 23:16:41 +00:00
|
|
|
/* Check for null pointer. */
|
|
|
|
if (((UResourceBundle *)resourceBundle)->fVersion == NULL) {
|
2008-02-19 17:27:59 +00:00
|
|
|
return NULL;
|
2008-01-16 23:16:41 +00:00
|
|
|
}
|
2004-08-13 20:32:07 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(minor_len > 0) {
|
2000-10-14 01:53:59 +00:00
|
|
|
u_UCharsToChars(minor_version, resourceBundle->fVersion , minor_len);
|
2000-05-15 18:39:17 +00:00
|
|
|
resourceBundle->fVersion[len] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
2006-04-25 19:32:35 +00:00
|
|
|
uprv_strcpy(resourceBundle->fVersion, kDefaultMinorVersion);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resourceBundle->fVersion;
|
|
|
|
}
|
|
|
|
|
2000-06-30 20:24:59 +00:00
|
|
|
U_CAPI void U_EXPORT2 ures_getVersion(const UResourceBundle* resB, UVersionInfo versionInfo) {
|
|
|
|
if (!resB) return;
|
2000-08-10 19:10:12 +00:00
|
|
|
|
|
|
|
u_versionFromString(versionInfo, ures_getVersionNumber(resB));
|
2000-06-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
/** Tree support functions *******************************/
|
|
|
|
#define INDEX_LOCALE_NAME "res_index"
|
|
|
|
#define INDEX_TAG "InstalledLocales"
|
|
|
|
#define DEFAULT_TAG "default"
|
|
|
|
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct ULocalesContext {
|
2004-04-23 18:02:55 +00:00
|
|
|
UResourceBundle installed;
|
|
|
|
UResourceBundle curr;
|
2004-04-13 17:39:55 +00:00
|
|
|
} ULocalesContext;
|
|
|
|
|
|
|
|
static void U_CALLCONV
|
|
|
|
ures_loc_closeLocales(UEnumeration *enumerator) {
|
2004-04-23 18:02:55 +00:00
|
|
|
ULocalesContext *ctx = (ULocalesContext *)enumerator->context;
|
|
|
|
ures_close(&ctx->curr);
|
|
|
|
ures_close(&ctx->installed);
|
|
|
|
uprv_free(ctx);
|
|
|
|
uprv_free(enumerator);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t U_CALLCONV
|
|
|
|
ures_loc_countLocales(UEnumeration *en, UErrorCode *status) {
|
2004-04-23 18:02:55 +00:00
|
|
|
ULocalesContext *ctx = (ULocalesContext *)en->context;
|
|
|
|
return ures_getSize(&ctx->installed);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* U_CALLCONV
|
|
|
|
ures_loc_nextLocale(UEnumeration* en,
|
|
|
|
int32_t* resultLength,
|
|
|
|
UErrorCode* status) {
|
2004-04-23 18:02:55 +00:00
|
|
|
ULocalesContext *ctx = (ULocalesContext *)en->context;
|
|
|
|
UResourceBundle *res = &(ctx->installed);
|
|
|
|
UResourceBundle *k = NULL;
|
|
|
|
const char *result = NULL;
|
2004-04-24 02:53:25 +00:00
|
|
|
int32_t len = 0;
|
2004-04-23 18:02:55 +00:00
|
|
|
if(ures_hasNext(res) && (k = ures_getNextResource(res, &ctx->curr, status))) {
|
|
|
|
result = ures_getKey(k);
|
2004-12-08 01:05:40 +00:00
|
|
|
len = (int32_t)uprv_strlen(result);
|
2004-04-24 02:53:25 +00:00
|
|
|
}
|
|
|
|
if (resultLength) {
|
2004-04-24 03:45:25 +00:00
|
|
|
*resultLength = len;
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
|
|
|
return result;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void U_CALLCONV
|
|
|
|
ures_loc_resetLocales(UEnumeration* en,
|
|
|
|
UErrorCode* status) {
|
2004-04-23 18:02:55 +00:00
|
|
|
UResourceBundle *res = &((ULocalesContext *)en->context)->installed;
|
|
|
|
ures_resetIterator(res);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const UEnumeration gLocalesEnum = {
|
|
|
|
NULL,
|
2004-04-23 18:02:55 +00:00
|
|
|
NULL,
|
|
|
|
ures_loc_closeLocales,
|
|
|
|
ures_loc_countLocales,
|
|
|
|
uenum_unextDefault,
|
|
|
|
ures_loc_nextLocale,
|
|
|
|
ures_loc_resetLocales
|
2004-04-13 17:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
|
|
|
ures_openAvailableLocales(const char *path, UErrorCode *status)
|
|
|
|
{
|
2009-04-15 01:57:02 +00:00
|
|
|
UResourceBundle *idx = NULL;
|
2004-04-23 18:02:55 +00:00
|
|
|
UEnumeration *en = NULL;
|
|
|
|
ULocalesContext *myContext = NULL;
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
myContext = uprv_malloc(sizeof(ULocalesContext));
|
|
|
|
en = (UEnumeration *)uprv_malloc(sizeof(UEnumeration));
|
|
|
|
if(!en || !myContext) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(en);
|
|
|
|
uprv_free(myContext);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memcpy(en, &gLocalesEnum, sizeof(UEnumeration));
|
|
|
|
|
|
|
|
ures_initStackObject(&myContext->installed);
|
|
|
|
ures_initStackObject(&myContext->curr);
|
2009-04-15 01:57:02 +00:00
|
|
|
idx = ures_openDirect(path, INDEX_LOCALE_NAME, status);
|
|
|
|
ures_getByKey(idx, INDEX_TAG, &myContext->installed, status);
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "Got %s::%s::[%s] : %s\n",
|
2004-04-14 17:59:00 +00:00
|
|
|
path, INDEX_LOCALE_NAME, INDEX_TAG, ures_getKey(&myContext->installed));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
en->context = myContext;
|
|
|
|
} else {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s open failed - %s\n", path, u_errorName(*status));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
ures_close(&myContext->installed);
|
|
|
|
uprv_free(myContext);
|
|
|
|
uprv_free(en);
|
|
|
|
en = NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-15 01:57:02 +00:00
|
|
|
ures_close(idx);
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
return en;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 01:21:24 +00:00
|
|
|
static UBool isLocaleInList(UEnumeration *locEnum, const char *locToSearch, UErrorCode *status) {
|
|
|
|
const char *loc;
|
|
|
|
while ((loc = uenum_next(locEnum, NULL, status)) != NULL) {
|
|
|
|
if (uprv_strcmp(loc, locToSearch) == 0) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
|
2004-04-23 18:02:55 +00:00
|
|
|
const char *path, const char *resName, const char *keyword, const char *locid,
|
2004-05-18 02:01:17 +00:00
|
|
|
UBool *isAvailable, UBool omitDefault, UErrorCode *status)
|
2004-04-13 17:39:55 +00:00
|
|
|
{
|
2004-04-23 18:02:55 +00:00
|
|
|
char kwVal[1024] = ""; /* value of keyword 'keyword' */
|
|
|
|
char defVal[1024] = ""; /* default value for given locale */
|
|
|
|
char defLoc[1024] = ""; /* default value for given locale */
|
|
|
|
char base[1024] = ""; /* base locale */
|
|
|
|
char found[1024];
|
|
|
|
char parent[1024];
|
|
|
|
char full[1024] = "";
|
|
|
|
UResourceBundle bund1, bund2;
|
|
|
|
UResourceBundle *res = NULL;
|
|
|
|
UErrorCode subStatus = U_ZERO_ERROR;
|
|
|
|
int32_t length = 0;
|
|
|
|
if(U_FAILURE(*status)) return 0;
|
|
|
|
uloc_getKeywordValue(locid, keyword, kwVal, 1024-1,&subStatus);
|
|
|
|
if(!uprv_strcmp(kwVal, DEFAULT_TAG)) {
|
|
|
|
kwVal[0]=0;
|
|
|
|
}
|
|
|
|
uloc_getBaseName(locid, base, 1024-1,&subStatus);
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-05-18 02:01:17 +00:00
|
|
|
fprintf(stderr, "getFunctionalEquivalent: \"%s\" [%s=%s] in %s - %s\n",
|
|
|
|
locid, keyword, kwVal, base, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
ures_initStackObject(&bund1);
|
|
|
|
ures_initStackObject(&bund2);
|
|
|
|
|
|
|
|
|
|
|
|
uprv_strcpy(parent, base);
|
|
|
|
uprv_strcpy(found, base);
|
2007-03-09 01:21:24 +00:00
|
|
|
|
|
|
|
if(isAvailable) {
|
|
|
|
UEnumeration *locEnum = ures_openAvailableLocales(path, &subStatus);
|
|
|
|
*isAvailable = TRUE;
|
|
|
|
if (U_SUCCESS(subStatus)) {
|
|
|
|
*isAvailable = isLocaleInList(locEnum, parent, &subStatus);
|
|
|
|
}
|
|
|
|
uenum_close(locEnum);
|
|
|
|
}
|
|
|
|
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_FAILURE(subStatus)) {
|
|
|
|
*status = subStatus;
|
|
|
|
return 0;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
subStatus = U_ZERO_ERROR;
|
|
|
|
res = ures_open(path, parent, &subStatus);
|
|
|
|
if(((subStatus == U_USING_FALLBACK_WARNING) ||
|
2007-03-09 01:21:24 +00:00
|
|
|
(subStatus == U_USING_DEFAULT_WARNING)) && isAvailable)
|
|
|
|
{
|
2004-04-23 18:02:55 +00:00
|
|
|
*isAvailable = FALSE;
|
|
|
|
}
|
|
|
|
isAvailable = NULL; /* only want to set this the first time around */
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-05-18 02:01:17 +00:00
|
|
|
fprintf(stderr, "%s;%s -> %s [%s]\n", path?path:"ICUDATA", parent, u_errorName(subStatus), ures_getLocale(res, &subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_FAILURE(subStatus)) {
|
|
|
|
*status = subStatus;
|
|
|
|
} else if(subStatus == U_ZERO_ERROR) {
|
|
|
|
ures_getByKey(res,resName,&bund1, &subStatus);
|
|
|
|
if(subStatus == U_ZERO_ERROR) {
|
|
|
|
const UChar *defUstr;
|
|
|
|
int32_t defLen;
|
|
|
|
/* look for default item */
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s;%s : loaded default -> %s\n",
|
|
|
|
path?path:"ICUDATA", parent, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus);
|
|
|
|
if(U_SUCCESS(subStatus) && defLen) {
|
2004-04-26 19:13:07 +00:00
|
|
|
u_UCharsToChars(defUstr, defVal, u_strlen(defUstr));
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s;%s -> default %s=%s, %s\n",
|
|
|
|
path?path:"ICUDATA", parent, keyword, defVal, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
uprv_strcpy(defLoc, parent);
|
|
|
|
if(kwVal[0]==0) {
|
|
|
|
uprv_strcpy(kwVal, defVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s;%s -> kwVal = %s\n",
|
|
|
|
path?path:"ICUDATA", parent, keyword, kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
subStatus = U_ZERO_ERROR;
|
2007-08-23 01:19:39 +00:00
|
|
|
|
|
|
|
if (res != NULL) {
|
|
|
|
uprv_strcpy(found, ures_getLocaleByType(res, ULOC_VALID_LOCALE, &subStatus));
|
|
|
|
}
|
|
|
|
|
2007-03-09 01:21:24 +00:00
|
|
|
uloc_getParent(found,parent,sizeof(parent),&subStatus);
|
2004-04-23 18:02:55 +00:00
|
|
|
ures_close(res);
|
2007-03-09 01:21:24 +00:00
|
|
|
} while(!defVal[0] && *found && uprv_strcmp(found, "root") != 0 && U_SUCCESS(*status));
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
/* Now, see if we can find the kwVal collator.. start the search over.. */
|
|
|
|
uprv_strcpy(parent, base);
|
|
|
|
uprv_strcpy(found, base);
|
|
|
|
|
|
|
|
do {
|
|
|
|
subStatus = U_ZERO_ERROR;
|
|
|
|
res = ures_open(path, parent, &subStatus);
|
|
|
|
if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) {
|
|
|
|
*isAvailable = FALSE;
|
|
|
|
}
|
|
|
|
isAvailable = NULL; /* only want to set this the first time around */
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s;%s -> %s (looking for %s)\n",
|
2004-04-14 17:59:00 +00:00
|
|
|
path?path:"ICUDATA", parent, u_errorName(subStatus), kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_FAILURE(subStatus)) {
|
|
|
|
*status = subStatus;
|
|
|
|
} else if(subStatus == U_ZERO_ERROR) {
|
|
|
|
ures_getByKey(res,resName,&bund1, &subStatus);
|
2004-05-18 02:01:17 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
/**/ fprintf(stderr,"@%d [%s] %s\n", __LINE__, resName, u_errorName(subStatus));
|
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
if(subStatus == U_ZERO_ERROR) {
|
|
|
|
ures_getByKey(&bund1, kwVal, &bund2, &subStatus);
|
2004-05-18 02:01:17 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
/**/ fprintf(stderr,"@%d [%s] %s\n", __LINE__, kwVal, u_errorName(subStatus));
|
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
if(subStatus == U_ZERO_ERROR) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-10-19 22:53:58 +00:00
|
|
|
fprintf(stderr, "%s;%s -> full0 %s=%s, %s\n",
|
2004-04-23 18:02:55 +00:00
|
|
|
path?path:"ICUDATA", parent, keyword, kwVal, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
uprv_strcpy(full, parent);
|
|
|
|
if(*full == 0) {
|
|
|
|
uprv_strcpy(full, "root");
|
|
|
|
}
|
2004-10-19 22:53:58 +00:00
|
|
|
/* now, recalculate default kw if need be */
|
|
|
|
if(uprv_strlen(defLoc) > uprv_strlen(full)) {
|
|
|
|
const UChar *defUstr;
|
|
|
|
int32_t defLen;
|
|
|
|
/* look for default item */
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr, "%s;%s -> recalculating Default0\n",
|
|
|
|
path?path:"ICUDATA", full);
|
|
|
|
#endif
|
|
|
|
defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus);
|
|
|
|
if(U_SUCCESS(subStatus) && defLen) {
|
|
|
|
u_UCharsToChars(defUstr, defVal, u_strlen(defUstr));
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr, "%s;%s -> default0 %s=%s, %s\n",
|
|
|
|
path?path:"ICUDATA", full, keyword, defVal, u_errorName(subStatus));
|
|
|
|
#endif
|
|
|
|
uprv_strcpy(defLoc, full);
|
|
|
|
}
|
|
|
|
} /* end of recalculate default KW */
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "No trim0, %s <= %s\n", defLoc, full);
|
|
|
|
}
|
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
} else {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "err=%s in %s looking for %s\n",
|
|
|
|
u_errorName(subStatus), parent, kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
subStatus = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
uprv_strcpy(found, parent);
|
|
|
|
uloc_getParent(found,parent,1023,&subStatus);
|
|
|
|
ures_close(res);
|
|
|
|
} while(!full[0] && *found && U_SUCCESS(*status));
|
|
|
|
|
|
|
|
if((full[0]==0) && uprv_strcmp(kwVal, defVal)) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "Failed to locate kw %s - try default %s\n", kwVal, defVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
uprv_strcpy(kwVal, defVal);
|
|
|
|
uprv_strcpy(parent, base);
|
|
|
|
uprv_strcpy(found, base);
|
|
|
|
|
|
|
|
do { /* search for 'default' named item */
|
|
|
|
subStatus = U_ZERO_ERROR;
|
|
|
|
res = ures_open(path, parent, &subStatus);
|
|
|
|
if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) {
|
|
|
|
*isAvailable = FALSE;
|
|
|
|
}
|
|
|
|
isAvailable = NULL; /* only want to set this the first time around */
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s;%s -> %s (looking for default %s)\n",
|
|
|
|
path?path:"ICUDATA", parent, u_errorName(subStatus), kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_FAILURE(subStatus)) {
|
|
|
|
*status = subStatus;
|
|
|
|
} else if(subStatus == U_ZERO_ERROR) {
|
|
|
|
ures_getByKey(res,resName,&bund1, &subStatus);
|
|
|
|
if(subStatus == U_ZERO_ERROR) {
|
|
|
|
ures_getByKey(&bund1, kwVal, &bund2, &subStatus);
|
|
|
|
if(subStatus == U_ZERO_ERROR) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-10-19 22:53:58 +00:00
|
|
|
fprintf(stderr, "%s;%s -> full1 %s=%s, %s\n", path?path:"ICUDATA",
|
2004-04-23 18:02:55 +00:00
|
|
|
parent, keyword, kwVal, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
uprv_strcpy(full, parent);
|
|
|
|
if(*full == 0) {
|
|
|
|
uprv_strcpy(full, "root");
|
|
|
|
}
|
2004-10-19 22:53:58 +00:00
|
|
|
|
|
|
|
/* now, recalculate default kw if need be */
|
|
|
|
if(uprv_strlen(defLoc) > uprv_strlen(full)) {
|
|
|
|
const UChar *defUstr;
|
|
|
|
int32_t defLen;
|
|
|
|
/* look for default item */
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr, "%s;%s -> recalculating Default1\n",
|
|
|
|
path?path:"ICUDATA", full);
|
|
|
|
#endif
|
|
|
|
defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus);
|
|
|
|
if(U_SUCCESS(subStatus) && defLen) {
|
|
|
|
u_UCharsToChars(defUstr, defVal, u_strlen(defUstr));
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr, "%s;%s -> default %s=%s, %s\n",
|
|
|
|
path?path:"ICUDATA", full, keyword, defVal, u_errorName(subStatus));
|
|
|
|
#endif
|
|
|
|
uprv_strcpy(defLoc, full);
|
|
|
|
}
|
|
|
|
} /* end of recalculate default KW */
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "No trim1, %s <= %s\n", defLoc, full);
|
|
|
|
}
|
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
subStatus = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
uprv_strcpy(found, parent);
|
|
|
|
uloc_getParent(found,parent,1023,&subStatus);
|
|
|
|
ures_close(res);
|
|
|
|
} while(!full[0] && *found && U_SUCCESS(*status));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
if(!full[0]) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-05-18 02:01:17 +00:00
|
|
|
fprintf(stderr, "Still could not load keyword %s=%s\n", keyword, kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-05-18 02:01:17 +00:00
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
2004-10-19 22:53:58 +00:00
|
|
|
} else if(omitDefault) {
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr,"Trim? full=%s, defLoc=%s, found=%s\n", full, defLoc, found);
|
|
|
|
#endif
|
|
|
|
if(uprv_strlen(defLoc) <= uprv_strlen(full)) {
|
|
|
|
/* found the keyword in a *child* of where the default tag was present. */
|
|
|
|
if(!uprv_strcmp(kwVal, defVal)) { /* if the requested kw is default, */
|
|
|
|
/* and the default is in or in an ancestor of the current locale */
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-10-19 22:53:58 +00:00
|
|
|
fprintf(stderr, "Removing unneeded var %s=%s\n", keyword, kwVal);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-10-19 22:53:58 +00:00
|
|
|
kwVal[0]=0;
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
|
|
|
uprv_strcpy(found, full);
|
|
|
|
if(kwVal[0]) {
|
|
|
|
uprv_strcat(found, "@");
|
|
|
|
uprv_strcat(found, keyword);
|
|
|
|
uprv_strcat(found, "=");
|
|
|
|
uprv_strcat(found, kwVal);
|
2004-05-18 02:01:17 +00:00
|
|
|
} else if(!omitDefault) {
|
|
|
|
uprv_strcat(found, "@");
|
|
|
|
uprv_strcat(found, keyword);
|
|
|
|
uprv_strcat(found, "=");
|
|
|
|
uprv_strcat(found, defVal);
|
2004-04-23 18:02:55 +00:00
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
/* we found the default locale - no need to repeat it.*/
|
|
|
|
|
|
|
|
ures_close(&bund1);
|
|
|
|
ures_close(&bund2);
|
|
|
|
|
2004-12-08 01:05:40 +00:00
|
|
|
length = (int32_t)uprv_strlen(found);
|
2004-05-11 20:23:16 +00:00
|
|
|
|
2004-04-23 18:02:55 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
int32_t copyLength = uprv_min(length, resultCapacity);
|
|
|
|
if(copyLength>0) {
|
|
|
|
uprv_strncpy(result, found, copyLength);
|
|
|
|
}
|
2004-05-11 20:23:16 +00:00
|
|
|
if(length == 0) {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
} else {
|
|
|
|
length = 0;
|
|
|
|
result[0]=0;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2007-08-31 19:39:14 +00:00
|
|
|
return u_terminateChars(result, resultCapacity, length, status);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
|
|
|
ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
|
|
|
|
{
|
2004-05-25 05:41:20 +00:00
|
|
|
#define VALUES_BUF_SIZE 2048
|
|
|
|
#define VALUES_LIST_SIZE 512
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
char valuesBuf[VALUES_BUF_SIZE];
|
|
|
|
int32_t valuesIndex = 0;
|
|
|
|
const char *valuesList[VALUES_LIST_SIZE];
|
|
|
|
int32_t valuesCount = 0;
|
|
|
|
|
|
|
|
const char *locale;
|
|
|
|
int32_t locLen;
|
|
|
|
|
|
|
|
UEnumeration *locs = NULL;
|
|
|
|
|
|
|
|
UResourceBundle item;
|
|
|
|
UResourceBundle subItem;
|
|
|
|
|
|
|
|
ures_initStackObject(&item);
|
|
|
|
ures_initStackObject(&subItem);
|
|
|
|
locs = ures_openAvailableLocales(path, status);
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
2006-04-25 19:32:35 +00:00
|
|
|
ures_close(&item);
|
|
|
|
ures_close(&subItem);
|
2004-04-23 18:02:55 +00:00
|
|
|
return NULL;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 18:02:55 +00:00
|
|
|
valuesBuf[0]=0;
|
|
|
|
valuesBuf[1]=0;
|
|
|
|
|
|
|
|
while((locale = uenum_next(locs, &locLen, status))) {
|
|
|
|
UResourceBundle *bund = NULL;
|
2004-05-11 20:23:16 +00:00
|
|
|
UResourceBundle *subPtr = NULL;
|
2004-04-23 18:02:55 +00:00
|
|
|
UErrorCode subStatus = U_ZERO_ERROR; /* don't fail if a bundle is unopenable */
|
|
|
|
bund = ures_openDirect(path, locale, &subStatus);
|
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
if(!bund || U_FAILURE(subStatus)) {
|
|
|
|
fprintf(stderr, "%s-%s values: Can't open %s locale - skipping. (%s)\n",
|
|
|
|
path?path:"<ICUDATA>", keyword, locale, u_errorName(subStatus));
|
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
ures_getByKey(bund, keyword, &item, &subStatus);
|
|
|
|
|
|
|
|
if(!bund || U_FAILURE(subStatus)) {
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s-%s values: Can't find in %s - skipping. (%s)\n",
|
|
|
|
path?path:"<ICUDATA>", keyword, locale, u_errorName(subStatus));
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-05-11 20:23:16 +00:00
|
|
|
ures_close(bund);
|
|
|
|
bund = NULL;
|
|
|
|
continue;
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
|
|
|
|
while((subPtr = ures_getNextResource(&item,&subItem,&subStatus))
|
|
|
|
&& U_SUCCESS(subStatus)) {
|
|
|
|
const char *k;
|
|
|
|
int32_t i;
|
2006-03-16 06:07:07 +00:00
|
|
|
k = ures_getKey(subPtr);
|
2004-04-23 18:02:55 +00:00
|
|
|
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
/* fprintf(stderr, "%s | %s | %s | %s\n", path?path:"<ICUDATA>", keyword, locale, k); */
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
for(i=0;k&&i<valuesCount;i++) {
|
|
|
|
if(!uprv_strcmp(valuesList[i],k)) {
|
|
|
|
k = NULL; /* found duplicate */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(k && *k) {
|
2004-12-08 01:05:40 +00:00
|
|
|
int32_t kLen = (int32_t)uprv_strlen(k);
|
2004-04-23 18:02:55 +00:00
|
|
|
if(!uprv_strcmp(k,DEFAULT_TAG)) {
|
|
|
|
continue; /* don't need 'default'. */
|
|
|
|
}
|
|
|
|
if((valuesCount >= (VALUES_LIST_SIZE-1)) || /* no more space in list .. */
|
|
|
|
((valuesIndex+kLen+1+1) >= VALUES_BUF_SIZE)) { /* no more space in buffer (string + 2 nulls) */
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR; /* out of space.. */
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(valuesBuf+valuesIndex, k);
|
|
|
|
valuesList[valuesCount++] = valuesBuf+valuesIndex;
|
|
|
|
valuesIndex += kLen;
|
|
|
|
#if defined(URES_TREE_DEBUG)
|
|
|
|
fprintf(stderr, "%s | %s | %s | [%s] (UNIQUE)\n",
|
|
|
|
path?path:"<ICUDATA>", keyword, locale, k);
|
|
|
|
#endif
|
|
|
|
valuesBuf[valuesIndex++] = 0; /* terminate */
|
|
|
|
}
|
|
|
|
}
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-05-11 20:23:16 +00:00
|
|
|
ures_close(bund);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2004-04-23 18:02:55 +00:00
|
|
|
valuesBuf[valuesIndex++] = 0; /* terminate */
|
|
|
|
|
|
|
|
ures_close(&item);
|
|
|
|
ures_close(&subItem);
|
2004-05-11 20:23:16 +00:00
|
|
|
uenum_close(locs);
|
2004-04-13 17:39:55 +00:00
|
|
|
#if defined(URES_TREE_DEBUG)
|
2004-04-23 18:02:55 +00:00
|
|
|
fprintf(stderr, "%s: size %d, #%d\n", u_errorName(*status),
|
|
|
|
valuesIndex, valuesCount);
|
2004-04-13 17:39:55 +00:00
|
|
|
#endif
|
2004-04-23 18:02:55 +00:00
|
|
|
return uloc_openKeywordList(valuesBuf, valuesIndex, status);
|
2004-04-13 17:39:55 +00:00
|
|
|
}
|
2008-02-07 22:24:27 +00:00
|
|
|
#if 0
|
|
|
|
/* This code isn't needed, and given the documentation warnings the implementation is suspect */
|
2005-08-26 21:50:51 +00:00
|
|
|
U_INTERNAL UBool U_EXPORT2
|
|
|
|
ures_equal(const UResourceBundle* res1, const UResourceBundle* res2){
|
|
|
|
if(res1==NULL || res2==NULL){
|
|
|
|
return res1==res2; /* pointer comparision */
|
|
|
|
}
|
2005-09-01 22:27:16 +00:00
|
|
|
if(res1->fKey==NULL|| res2->fKey==NULL){
|
|
|
|
return (res1->fKey==res2->fKey);
|
|
|
|
}else{
|
|
|
|
if(uprv_strcmp(res1->fKey, res2->fKey)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-08-26 21:50:51 +00:00
|
|
|
}
|
|
|
|
if(uprv_strcmp(res1->fData->fName, res2->fData->fName)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(res1->fData->fPath == NULL|| res2->fData->fPath==NULL){
|
|
|
|
return (res1->fData->fPath == res2->fData->fPath);
|
|
|
|
}else{
|
|
|
|
if(uprv_strcmp(res1->fData->fPath, res2->fData->fPath)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(uprv_strcmp(res1->fData->fParent->fName, res2->fData->fParent->fName)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(uprv_strcmp(res1->fData->fParent->fPath, res2->fData->fParent->fPath)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(uprv_strncmp(res1->fResPath, res2->fResPath, res1->fResPathLen)!=0){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(res1->fRes != res2->fRes){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
U_INTERNAL UResourceBundle* U_EXPORT2
|
|
|
|
ures_clone(const UResourceBundle* res, UErrorCode* status){
|
|
|
|
UResourceBundle* bundle = NULL;
|
|
|
|
UResourceBundle* ret = NULL;
|
|
|
|
if(U_FAILURE(*status) || res == NULL){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bundle = ures_open(res->fData->fPath, res->fData->fName, status);
|
2005-09-01 22:27:16 +00:00
|
|
|
if(res->fResPath!=NULL){
|
|
|
|
ret = ures_findSubResource(bundle, res->fResPath, NULL, status);
|
|
|
|
ures_close(bundle);
|
|
|
|
}else{
|
|
|
|
ret = bundle;
|
|
|
|
}
|
2005-08-26 21:50:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2005-09-01 22:27:16 +00:00
|
|
|
U_INTERNAL const UResourceBundle* U_EXPORT2
|
|
|
|
ures_getParentBundle(const UResourceBundle* res){
|
|
|
|
if(res==NULL){
|
|
|
|
return NULL;
|
2006-04-25 19:32:35 +00:00
|
|
|
}
|
2005-09-01 22:27:16 +00:00
|
|
|
return res->fParentRes;
|
|
|
|
}
|
2008-02-07 22:24:27 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-29 00:17:44 +00:00
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
ures_getVersionByKey(const UResourceBundle* res, const char *key, UVersionInfo ver, UErrorCode *status) {
|
|
|
|
const UChar *str;
|
|
|
|
int32_t len;
|
|
|
|
str = ures_getStringByKey(res, key, &len, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
u_versionFromUString(ver, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* eof */
|