ICU-1198 added different functions for getting signed and unsigned integers. Test to follow

X-SVN-Rev: 5762
This commit is contained in:
Vladimir Weinstein 2001-09-17 23:05:08 +00:00
parent 4801157384
commit e9fe410e8d
5 changed files with 72 additions and 4 deletions

View File

@ -294,6 +294,14 @@ const int32_t *ResourceBundle::getIntVector(int32_t& len, UErrorCode& status) co
return ures_getIntVector(resource, &len, &status);
}
uint32_t ResourceBundle::getUInt(UErrorCode& status) const {
return ures_getUInt(resource, &status);
}
int32_t ResourceBundle::getInt(UErrorCode& status) const {
return ures_getInt(resource, &status);
}
const char *ResourceBundle::getName(void) {
return ures_getName(resource);
}

View File

@ -252,6 +252,32 @@ public:
*/
const int32_t *getIntVector(int32_t& len, UErrorCode& status) const;
/**
* returns an unsigned integer from a resource.
* This integer is originally 28 bits.
*
* @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 an unsigned integer value
* @draft
*/
uint32_t getUInt(UErrorCode& status) const;
/**
* returns a signed integer from a resource.
* This integer is originally 28 bit and the sign gets propagated.
*
* @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 signed integer value
* @draft
*/
int32_t getInt(UErrorCode& status) const;
/**
* Checks whether the resource has another element to iterate over.
*

View File

@ -362,7 +362,8 @@ U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resourc
UErrorCode* status);
/**
* returns an integer from a resource.
* returns an unsigned integer from a resource.
* This integer is originally 28 bits.
*
* @param resourceBundle: a string resource
* @param status: fills in the outgoing error code
@ -372,7 +373,21 @@ U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resourc
* @return an integer value
* @draft
*/
U_CAPI uint32_t U_EXPORT2 ures_getInt(const UResourceBundle* resourceBundle, UErrorCode *status);
U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resourceBundle, UErrorCode *status);
/**
* returns a signed integer from a resource.
* This integer is originally 28 bit and the sign gets propagated.
*
* @param resourceBundle: a string resource
* @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 an integer value
* @draft
*/
U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resourceBundle, UErrorCode *status);
/**
* Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is

View File

@ -592,7 +592,25 @@ U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, i
return NULL;
}
U_CAPI uint32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
/* this function returns a signed integer */
/* it performs sign extension */
U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
uint32_t uintValue = 0;
int32_t returnValue = 0;
if (status==NULL || U_FAILURE(*status)) {
return 0xffffffff;
}
if(resB == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0xffffffff;
}
uintValue = RES_GET_UINT(resB->fRes);
returnValue = (int32_t)(uintValue<<4)>>4;
return returnValue;
}
U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resB, UErrorCode *status) {
if (status==NULL || U_FAILURE(*status)) {
return 0xffffffff;

View File

@ -17,7 +17,8 @@ testtypes
importtest:import { "importtest.bin" }
integerarray:intvector { 1, 2, 3, -3, 4, 5, 6, 7 } // an array of 32-bit integers
minusone:int {-1} // number -1
plusone:int {1} // number 1
// Empties
emptyexplicitstring:string { "" }
emptystring { "" }