From 3b048dbe57033b7c3ec4da9643cb8220fd8aa47c Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Mon, 17 Jul 2000 21:30:13 +0000 Subject: [PATCH] ICU-103 add getNextUChar() helper ucnv_getUChar32KeepOverflow() X-SVN-Rev: 1914 --- icu4c/source/common/ucnv_cnv.c | 53 ++++++++++++++++++++++++++++++++++ icu4c/source/common/ucnv_cnv.h | 19 ++++++++++++ 2 files changed, 72 insertions(+) diff --git a/icu4c/source/common/ucnv_cnv.c b/icu4c/source/common/ucnv_cnv.c index 8c6ebe3365d..985c7531d94 100644 --- a/icu4c/source/common/ucnv_cnv.c +++ b/icu4c/source/common/ucnv_cnv.c @@ -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(iUCharErrorBuffer; + 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(i0. + * @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 */