mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-103 add getNextUChar() helper ucnv_getUChar32KeepOverflow()
X-SVN-Rev: 1914
This commit is contained in:
parent
072f942e56
commit
3b048dbe57
2 changed files with 72 additions and 0 deletions
icu4c/source/common
|
@ -115,3 +115,56 @@ void flushInternalCharBuffer (UConverter * _this,
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is useful for implementations of getNextUChar().
|
||||
* After a call to a callback function or to toUnicode(), an output buffer
|
||||
* begins with a Unicode code point that needs to be returned as UChar32,
|
||||
* and all following code units must be prepended to the - potentially
|
||||
* prefilled - overflow buffer in the UConverter.
|
||||
* The buffer should be at least of capacity UTF_MAX_CHAR_LENGTH so that a
|
||||
* complete UChar32's UChars fit into it.
|
||||
*
|
||||
* @param cnv The converter that will get remaining UChars copied to its overflow area.
|
||||
* @param buffer An array of UChars that was passed into a callback function
|
||||
* or a toUnicode() function.
|
||||
* @param length The number of code units (UChars) that are actually in the buffer.
|
||||
* This must be >0.
|
||||
* @return The code point from the first UChars in the buffer.
|
||||
*/
|
||||
U_CFUNC UChar32
|
||||
ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length) {
|
||||
UChar32 c;
|
||||
int32_t i;
|
||||
|
||||
if(length<=0) {
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
/* get the first code point in the buffer */
|
||||
i=0;
|
||||
UTF_NEXT_CHAR_SAFE(buffer, i, length, c, FALSE);
|
||||
if(i<length) {
|
||||
/* there are UChars left in the buffer that need to go into the overflow buffer */
|
||||
UChar *overflow=cnv->UCharErrorBuffer;
|
||||
int32_t j=cnv->UCharErrorBufferLength;
|
||||
|
||||
if(j>0) {
|
||||
/* move the overflow buffer contents to make room for the extra UChars */
|
||||
int32_t k;
|
||||
|
||||
cnv->UCharErrorBufferLength=(int8_t)(k=(length-i)+j);
|
||||
do {
|
||||
overflow[--k]=overflow[--j];
|
||||
} while(j>0);
|
||||
} else {
|
||||
cnv->UCharErrorBufferLength=(int8_t)(length-i);
|
||||
}
|
||||
|
||||
/* copy the remaining UChars to the beginning of the overflow buffer */
|
||||
do {
|
||||
overflow[j++]=buffer[i++];
|
||||
} while(i<length);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -220,4 +220,23 @@ extern const UConverterSharedData
|
|||
|
||||
U_CDECL_END
|
||||
|
||||
/**
|
||||
* This function is useful for implementations of getNextUChar().
|
||||
* After a call to a callback function or to toUnicode(), an output buffer
|
||||
* begins with a Unicode code point that needs to be returned as UChar32,
|
||||
* and all following code units must be prepended to the - potentially
|
||||
* prefilled - overflow buffer in the UConverter.
|
||||
* The buffer should be at least of capacity UTF_MAX_CHAR_LENGTH so that a
|
||||
* complete UChar32's UChars fit into it.
|
||||
*
|
||||
* @param cnv The converter that will get remaining UChars copied to its overflow area.
|
||||
* @param buffer An array of UChars that was passed into a callback function
|
||||
* or a toUnicode() function.
|
||||
* @param length The number of code units (UChars) that are actually in the buffer.
|
||||
* This must be >0.
|
||||
* @return The code point from the first UChars in the buffer.
|
||||
*/
|
||||
U_CFUNC UChar32
|
||||
ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length);
|
||||
|
||||
#endif /* UCNV_CNV */
|
||||
|
|
Loading…
Add table
Reference in a new issue