ICU-1078 support for IntVector type in resource bundles

X-SVN-Rev: 5410
This commit is contained in:
Vladimir Weinstein 2001-08-01 17:08:07 +00:00
parent a0801c85b9
commit 749a62ae93
5 changed files with 57 additions and 1 deletions

View File

@ -346,6 +346,21 @@ U_CAPI const UChar* U_EXPORT2 ures_getString(const UResourceBundle* resourceBund
U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resourceBundle, int32_t* len,
UErrorCode* status);
/**
* returns a 32 bit integer array from a resource.
*
* @param resourceBundle: an int vector resource
* @param len: fills in the length of resulting byte chunk
* @param status: fills in the outgoing error code
* could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
* could be a non-failing error
* e.g.: <TT>U_USING_FALLBACK_ERROR</TT>,<TT>U_USING_DEFAULT_ERROR </TT>
* @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
* @draft
*/
U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resourceBundle, int32_t* len,
UErrorCode* status);
/**
* returns an integer from a resource.
*

View File

@ -507,6 +507,30 @@ U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resB, int3
return NULL;
}
U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, int32_t* len,
UErrorCode* status) {
if (status==NULL || U_FAILURE(*status)) {
return NULL;
}
if(resB == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
switch(RES_GET_TYPE(resB->fRes)) {
case RES_INT_VECTOR:
return res_getIntVector(&(resB->fResData), resB->fRes, len);
case RES_INT:
case RES_STRING:
case RES_ARRAY:
case RES_BINARY:
case RES_TABLE:
default:
*status = U_RESOURCE_TYPE_MISMATCH;
}
return NULL;
}
U_CAPI uint32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
if (status==NULL || U_FAILURE(*status)) {

View File

@ -211,6 +211,14 @@ res_getBinary(const ResourceData *pResData, const Resource res, int32_t *pLength
return (uint8_t *)p;
}
U_CFUNC const int32_t *
res_getIntVector(const ResourceData *pResData, const Resource res, int32_t *pLength) {
int32_t *p=(int32_t *)RES_GET_POINTER(pResData->pRoot, res);
*pLength=*p++;
return (const int32_t *)p;
}
U_CFUNC int32_t
res_countArrayItems(const ResourceData *pResData, const Resource res) {
if(res!=RES_BOGUS) {

View File

@ -95,6 +95,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);
U_CFUNC const int32_t *
res_getIntVector(const ResourceData *pResData, const Resource res, int32_t *pLength);
U_CFUNC Resource
res_getResource(const ResourceData *pResData, const char *key);

View File

@ -112,6 +112,12 @@ static uint32_t array_write(UNewDataMemory *mem, struct SResource *res,
static uint32_t intvector_write(UNewDataMemory *mem, struct SResource *res,
uint32_t usedOffset, UErrorCode *status) {
uint32_t i = 0;
udata_write32(mem, res->u.fIntVector.fCount);
for(i = 0; i<res->u.fIntVector.fCount; i++) {
udata_write32(mem, res->u.fIntVector.fArray[i]);
}
return usedOffset;
}
@ -394,7 +400,7 @@ struct SResource* intvector_open(struct SRBRoot *bundle, char *tag, UErrorCode *
return NULL;
}
res->fType = RES_ARRAY;
res->fType = RES_INT_VECTOR;
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {