ICU-701 add offset helper fn & useFallback macros

X-SVN-Rev: 2883
This commit is contained in:
Markus Scherer 2000-11-07 22:37:01 +00:00
parent 0a30744920
commit 36a5f8c725
2 changed files with 48 additions and 0 deletions

View File

@ -168,3 +168,28 @@ ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length
} }
return c; return c;
} }
/* update target offsets after a callback call */
U_CFUNC int32_t *
ucnv_updateCallbackOffsets(int32_t *offsets, int32_t length, int32_t sourceIndex) {
if(offsets!=NULL) {
if(sourceIndex>=0) {
/* add the sourceIndex to the relative offsets that the callback wrote */
while(length>0) {
*offsets+=sourceIndex;
++offsets;
--length;
}
} else {
/* sourceIndex==-1, set -1 offsets */
while(length>0) {
*offsets=-1;
++offsets;
--length;
}
}
return offsets;
} else {
return NULL;
}
}

View File

@ -231,4 +231,27 @@ U_CDECL_END
U_CFUNC UChar32 U_CFUNC UChar32
ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length); ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length);
/**
* This helper function updates the offsets array after a callback function call.
* It adds the sourceIndex to each offsets item, or sets each of them to -1 if
* sourceIndex==-1.
*
* @param offsets The pointer to offsets entry that corresponds to the first target
* unit that the callback wrote.
* @param length The number of output units that the callback wrote.
* @param sourceIndex The sourceIndex of the input sequence that the callback
* function was called for.
* @return offsets+length if offsets!=NULL, otherwise NULL
*/
U_CFUNC int32_t *
ucnv_updateCallbackOffsets(int32_t *offsets, int32_t length, int32_t sourceIndex);
/** Always use fallbacks from codepage to Unicode */
#define TO_U_USE_FALLBACK(useFallback) TRUE
#define UCNV_TO_U_USE_FALLBACK(cnv) TRUE
/** Use fallbacks from Unicode to codepage when cnv->useFallback or for private-use code points */
#define FROM_U_USE_FALLBACK(useFallback, c) ((useFallback) || (uint32_t)((c)-0xe000)<0x1900 || (uint32_t)((c)-0xf0000)<0x20000)
#define UCNV_FROM_U_USE_FALLBACK(cnv, c) FROM_U_USE_FALLBACK((cnv)->useFallback, c)
#endif /* UCNV_CNV */ #endif /* UCNV_CNV */