ICU-1005 more resource bundle cleanup and greater test coverage, fixed faulty test

X-SVN-Rev: 5362
This commit is contained in:
Vladimir Weinstein 2001-07-27 17:15:30 +00:00
parent d45d3201ba
commit d6693e4b66
6 changed files with 53 additions and 112 deletions

View file

@ -259,9 +259,6 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_openU(const UChar* path,
* <STRONG>taggedArrays</STRONG>: returns the number of strings in the array
* <STRONG>single string</STRONG>: returns 1
*@see ures_get
*@see ures_getArrayItem
*@see ures_getTaggedArrayItem
*@see ures_get2dArrayItem
*@draft
*/
U_CAPI int32_t U_EXPORT2 ures_countArrayItems(const UResourceBundle* resourceBundle,
@ -490,9 +487,5 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resourceB
*/
U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* key, int32_t* len, UErrorCode *status);
U_CFUNC const char* ures_getName(const UResourceBundle* resB);
U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
U_CFUNC const char* ures_getTag(const UResourceBundle* resB);
#endif /*_URES*/
/*eof*/

View file

@ -284,7 +284,7 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
uhash_put(cache, (void *)r, r, status);
} else {
/* somebody have already inserted it while we were working, discard newly opened data */
/* this part is probably obsolete since we check cache in locked state */
/* Also, we could get here IF we opened an alias */
uprv_free(r->fName);
if(r->fPath != NULL) {
uprv_free(r->fPath);
@ -404,7 +404,7 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, const Resour
resB = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
ures_setIsStackObject(resB, FALSE);
} else {
if(ures_isStackObject(resB, status) != FALSE) {
if(ures_isStackObject(resB) != FALSE) {
ures_setIsStackObject(resB, TRUE);
}
}
@ -433,7 +433,7 @@ UResourceBundle *copyResb(UResourceBundle *r, const UResourceBundle *original, U
isStackObject = FALSE;
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
} else {
isStackObject = ures_isStackObject(r, status);
isStackObject = ures_isStackObject(r);
if(U_FAILURE(*status)) {
return r;
}
@ -719,9 +719,9 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB,
/* TODO: do the fallback */
}
return res_getString(&(resB->fResData), r, len);
case RES_INT_VECTOR:
default:
return NULL;
/*case RES_INT_VECTOR:*/
/*default:*/
/*return;*/
}
} else {
*status = U_MISSING_RESOURCE_ERROR;
@ -735,12 +735,10 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
const char *key = inKey;
if (status==NULL || U_FAILURE(*status)) {
/*return NULL;*/
return fillIn;
}
if(resB == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
/*return NULL;*/
return fillIn;
}
@ -762,7 +760,11 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
} else {
return init_resb_result(&(resB->fResData), res, key, resB->fData, fillIn, status);
}
} else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
}
#if 0
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
/* not currently */
else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
/* here should go a first attempt to locate the key using index table */
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
if(U_SUCCESS(*status)) {
@ -770,10 +772,11 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
} else {
*status = U_MISSING_RESOURCE_ERROR;
}
} else {
}
#endif
else {
*status = U_RESOURCE_TYPE_MISMATCH;
}
/*return NULL;*/
return fillIn;
}
@ -808,7 +811,11 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
} else {
return res_getString(&(resB->fResData), res, len);
}
} else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
}
#if 0
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
/* not currently */
else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
/* here should go a first attempt to locate the key using index table */
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
if(U_SUCCESS(*status)) {
@ -816,7 +823,9 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
} else {
*status = U_MISSING_RESOURCE_ERROR;
}
} else {
}
#endif
else {
*status = U_RESOURCE_TYPE_MISMATCH;
}
return NULL;
@ -893,16 +902,19 @@ void entryClose(UResourceDataEntry *resB) {
U_CFUNC const char* ures_getName(const UResourceBundle* resB) {
return resB->fData->fName;
if(resB == NULL) {
return NULL;
}
return resB->fData->fName;
}
U_CFUNC const char* ures_getPath(const UResourceBundle* resB) {
return resB->fData->fPath;
}
U_CFUNC const char* ures_getTag(const UResourceBundle* resB) {
return resB->fKey;
}
U_CFUNC const ResourceData * ures_getResData(const UResourceBundle* resB) {
return &(resB->fData->fData);
if(resB == NULL) {
return NULL;
}
return resB->fData->fPath;
}
/* OLD API implementation */
@ -963,6 +975,8 @@ U_CAPI UResourceBundle* ures_open(const char* path,
while(hasData->fBogus != U_ZERO_ERROR) {
hasData = hasData->fParent;
if(hasData == NULL) {
/* This can happen only if fallback chain gets broken by an act of God */
/* TODO: this unlikely to happen, consider removing it */
entryClose(r->fData);
uprv_free(r);
*status = U_MISSING_RESOURCE_ERROR;
@ -1022,7 +1036,7 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_openU(const UChar* myPath,
return r;
}
U_CAPI void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
U_CFUNC void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
if(state) {
resB->fMagic1 = 0;
resB->fMagic2 = 0;
@ -1032,19 +1046,8 @@ U_CAPI void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
}
}
U_CAPI UBool ures_isStackObject( UResourceBundle* resB, UErrorCode *status) {
if(status == NULL || U_FAILURE(*status)) {
return FALSE;
}
if(resB == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return TRUE;
}
if(resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2) {
return FALSE;
} else {
return TRUE;
}
U_CFUNC UBool ures_isStackObject(UResourceBundle* resB) {
return((resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2)?FALSE:TRUE);
}
/**
@ -1093,7 +1096,7 @@ U_CAPI void ures_close(UResourceBundle* resB)
uprv_free(resB->fVersion);
}
if(ures_isStackObject(resB, &status) == FALSE) {
if(ures_isStackObject(resB) == FALSE) {
uprv_free(resB);
}
}

View file

@ -38,37 +38,6 @@
* the resource is of the expected type.
*/
/*
* Unicode String functions
*
* Note that the type value for strings is 0, therefore
* res itself contains the offset value.
*/
static const UChar nulUChar=0;
static const UChar *
_res_getString(Resource *pRoot, Resource res, int32_t *pLength) {
if(res==0) {
*pLength=0;
return &nulUChar;
} else {
int32_t *p=(int32_t *)RES_GET_POINTER(pRoot, res);
*pLength=*p++;
return (UChar *)p;
}
}
static const uint8_t *
_res_getBinary(Resource *pRoot, Resource res, int32_t *pLength) {
if(res==0) {
*pLength=0;
return NULL;
} else {
int32_t *p=(int32_t *)RES_GET_POINTER(pRoot, res);
*pLength=*p++;
return (uint8_t *)p;
}
}
/*
* Array functions
@ -195,10 +164,6 @@ isAcceptable(void *context,
U_CFUNC UBool
res_load(ResourceData *pResData,
const char *path, const char *name, UErrorCode *errorCode) {
if(errorCode==NULL || U_FAILURE(*errorCode)) {
return FALSE;
}
/* load the ResourceBundle file */
pResData->data=udata_openChoice(path, "res", name, isAcceptable, NULL, errorCode);
if(U_FAILURE(*errorCode)) {
@ -230,7 +195,9 @@ res_unload(ResourceData *pResData) {
U_CFUNC const UChar *
res_getString(const ResourceData *pResData, const Resource res, int32_t *pLength) {
if(res!=RES_BOGUS && RES_GET_TYPE(res)==RES_STRING) {
return _res_getString(pResData->pRoot, res, pLength);
int32_t *p=(int32_t *)RES_GET_POINTER(pResData->pRoot, res);
*pLength=*p++;
return (UChar *)p;
} else {
*pLength=0;
return NULL;
@ -239,12 +206,9 @@ res_getString(const ResourceData *pResData, const Resource res, int32_t *pLength
U_CFUNC const uint8_t *
res_getBinary(const ResourceData *pResData, const Resource res, int32_t *pLength) {
if(res!=RES_BOGUS && RES_GET_TYPE(res)==RES_BINARY) {
return _res_getBinary(pResData->pRoot, res, pLength);
} else {
*pLength=0;
return NULL;
}
int32_t *p=(int32_t *)RES_GET_POINTER(pResData->pRoot, res);
*pLength=*p++;
return (uint8_t *)p;
}
U_CFUNC int32_t
@ -304,21 +268,3 @@ U_CFUNC int32_t res_getTableSize(const ResourceData *pResData, Resource table) {
return *p;
}
U_CFUNC void
res_getNextStringTableItem(const ResourceData *pResData, Resource table, const UChar **value, const char **key, int32_t *len, int16_t *indexS) {
Resource next;
if(*indexS == -1) {
*indexS = 0;
}
next = _res_getTableItem(pResData->pRoot, table, *indexS);
if ((next == RES_BOGUS) || (RES_GET_TYPE(next) != RES_STRING)) {
*key = NULL;
*value = NULL;
len = 0;
return;
}
*key = _res_getTableKey(pResData->pRoot, table, *indexS);
(*indexS)++;
*value = _res_getString(pResData->pRoot, next, len);
}

View file

@ -101,10 +101,6 @@ res_getResource(const ResourceData *pResData, const char *key);
U_CFUNC int32_t
res_countArrayItems(const ResourceData *pResData, const Resource res);
U_CFUNC void
res_getNextStringTableItem(const ResourceData *pResData, Resource table,
const UChar **value, const char **key, int32_t *len,
int16_t *indexS);
U_CFUNC int32_t res_getTableSize(const ResourceData *pResData, Resource table);
U_CFUNC Resource res_getArrayItem(const ResourceData *pResData, const Resource array, const int32_t indexS);

View file

@ -74,14 +74,16 @@ struct UResourceBundle {
};
U_CFUNC const char* ures_getRealLocale(const UResourceBundle* resourceBundle, UErrorCode* status);
U_CAPI void ures_setIsStackObject( UResourceBundle* resB, UBool state);
U_CAPI UBool ures_isStackObject( UResourceBundle* resB, UErrorCode *status);
U_CFUNC void ures_setIsStackObject( UResourceBundle* resB, UBool state);
U_CFUNC UBool ures_isStackObject( UResourceBundle* resB);
U_CFUNC const ResourceData *getFallbackData(const UResourceBundle* resBundle, const char* * resTag, UResourceDataEntry* *realData, Resource *res, UErrorCode *status);
U_CFUNC int32_t hashBundle(const void *parm);
U_CFUNC UBool compareBundles(const void *p1, const void *p2);
/* Some getters used by the copy constructor */
U_CFUNC const char* ures_getName(const UResourceBundle* resB);
U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
/* Candidates for export */
U_CFUNC UResourceBundle *copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
U_CFUNC const ResourceData * ures_getResData(const UResourceBundle* resB);
#endif /*URESIMP_H*/

View file

@ -828,12 +828,13 @@ NewResourceBundleTest::testTag(const char* frag,
UnicodeString value=tagelement.getNextString(&tkey, status);
UnicodeString key(tkey);
logln("tag = " + key + ", value = " + value );
if(key.startsWith("tag") && value.startsWith(base)){
if(value.startsWith(base)){
record_pass();
}else{
record_fail();
}
}
}else{
tag_count=0;
}