From afbd051d769008ff81095e1bc334a61f5b398873 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 2 Aug 2000 19:35:17 +0000 Subject: [PATCH] ICU-311 more cbWrite updates and changes to the included callbacks X-SVN-Rev: 2098 --- icu4c/source/common/ucnv_cb.c | 12 ++-- icu4c/source/common/ucnv_err.c | 87 +++++++++------------------ icu4c/source/common/unicode/ucnv_cb.h | 8 +-- 3 files changed, 36 insertions(+), 71 deletions(-) diff --git a/icu4c/source/common/ucnv_cb.c b/icu4c/source/common/ucnv_cb.c index fa621c45b3..f82f02775c 100644 --- a/icu4c/source/common/ucnv_cb.c +++ b/icu4c/source/common/ucnv_cb.c @@ -79,8 +79,8 @@ void ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, } void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, - const UChar* source, - int32_t length, + const UChar** source, + const UChar* sourceLimit, int32_t offsetIndex, UErrorCode * err) { @@ -97,8 +97,6 @@ void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, */ char *oldTarget; - const UChar* mySource = source; - const UChar* sourceLimit = source + length; if(U_FAILURE(*err)) { @@ -110,7 +108,7 @@ void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, ucnv_fromUnicode(args->converter, &args->target, args->targetLimit, - &mySource, + source, sourceLimit, NULL, /* no offsets */ FALSE, /* no flush */ @@ -129,7 +127,7 @@ void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, In fact, here's where we want to return the partially consumed in-source! */ if(*err == U_INDEX_OUTOFBOUNDS_ERROR) - /* && (mySource < source+length && args->target >= args->targetLimit) + /* && (*source < sourceLimit && args->target >= args->targetLimit) -- S. Hrcek */ { /* Overflowed the target. Now, we'll write into the charErrorBuffer. @@ -164,7 +162,7 @@ void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, ucnv_fromUnicode(args->converter, &newTarget, newTargetLimit, - &mySource, + source, sourceLimit, NULL, FALSE, diff --git a/icu4c/source/common/ucnv_err.c b/icu4c/source/common/ucnv_err.c index 53a34f37f2..f783188fcb 100644 --- a/icu4c/source/common/ucnv_err.c +++ b/icu4c/source/common/ucnv_err.c @@ -126,17 +126,14 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE ( UConverterCallbackReason reason, UErrorCode * err) { - char togo[5]; - int32_t togoLen; - - if (reason > UCNV_IRREGULAR) - { - return; - } - - *err = U_ZERO_ERROR; - - ucnv_cbFromUWriteSub(fromArgs, 0, err); + if (reason > UCNV_IRREGULAR) + { + return; + } + + *err = U_ZERO_ERROR; + + ucnv_cbFromUWriteSub(fromArgs, 0, err); } /*uses itou to get a unicode escape sequence of the offensive sequence, @@ -156,7 +153,7 @@ void UCNV_FROM_U_CALLBACK_ESCAPE ( UChar valueString[VALUE_STRING_LENGTH]; int32_t valueStringLength = 0; - uint32_t i = 0; + int32_t i = 0; const UChar *myValueSource = NULL; UErrorCode err2 = U_ZERO_ERROR; @@ -178,11 +175,11 @@ void UCNV_FROM_U_CALLBACK_ESCAPE ( &originalContext, &err2); if (U_FAILURE (err2)) - { - *err = err2; - return; - } - + { + *err = err2; + return; + } + /* * ### TODO: * This should actually really work with the codePoint, not with the codeUnits; @@ -190,19 +187,19 @@ void UCNV_FROM_U_CALLBACK_ESCAPE ( * two for a surrogate pair! */ while (i < length) - { - valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ - valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ - itou (valueString + valueStringLength, codeUnits[i++], 16, 4); - valueStringLength += 4; - } + { + valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ + valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ + itou (valueString + valueStringLength, codeUnits[i++], 16, 4); + valueStringLength += 4; + } myValueSource = valueString; /* reset the error */ *err = U_ZERO_ERROR; - ucnv_cbFromUWriteUChars(fromArgs, myValueSource, valueStringLength, 0, err); + ucnv_cbFromUWriteUChars(fromArgs, &myValueSource, myValueSource+valueStringLength, 0, err); ucnv_setFromUCallBack (fromArgs->converter, original, @@ -268,7 +265,7 @@ void UCNV_TO_U_CALLBACK_ESCAPE ( UChar uniValueString[VALUE_STRING_LENGTH]; int32_t valueStringLength = 0; int32_t i = 0; - + if (reason > UCNV_IRREGULAR) { return; @@ -288,41 +285,11 @@ void UCNV_TO_U_CALLBACK_ESCAPE ( valueStringLength += 2; } - if ((toArgs->targetLimit - toArgs->target) >= valueStringLength) - { - /*if we have enough space on the output buffer we just copy - * the subchar there and update the pointer - */ - uprv_memcpy (toArgs->target, uniValueString, (sizeof (UChar)) * (valueStringLength)); - if (toArgs->offsets) - { - for (i = 0; i < valueStringLength; i++) toArgs->offsets[i] = 0; - } - toArgs->target += valueStringLength; - - *err = U_ZERO_ERROR; - } - else - { - /*if we don't have enough space on the output buffer - *we copy as much as we can to it, update that pointer. - *copy the rest in the internal buffer, and increase the - *length marker - */ - uprv_memcpy (toArgs->target, uniValueString, (sizeof (UChar)) * (toArgs->targetLimit - toArgs->target)); - if (toArgs->offsets) - { - for (i = 0; i < (toArgs->targetLimit - toArgs->target); i++) toArgs->offsets[i] = 0; - } - - - uprv_memcpy (toArgs->converter->UCharErrorBuffer, - uniValueString + (toArgs->targetLimit - toArgs->target), - (sizeof (UChar)) * (valueStringLength - (toArgs->targetLimit - toArgs->target))); - toArgs->converter->UCharErrorBufferLength += valueStringLength - (toArgs->targetLimit - toArgs->target); - toArgs->target += (toArgs->targetLimit - toArgs->target); - *err = U_INDEX_OUTOFBOUNDS_ERROR; - } + + /* reset the error */ + *err = U_ZERO_ERROR; + + ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err); return; } diff --git a/icu4c/source/common/unicode/ucnv_cb.h b/icu4c/source/common/unicode/ucnv_cb.h index 47fed255c5..68314338d6 100644 --- a/icu4c/source/common/unicode/ucnv_cb.h +++ b/icu4c/source/common/unicode/ucnv_cb.h @@ -67,16 +67,16 @@ U_CAPI void U_EXPORT2 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, * character(s) to the target UChar buffer. * * @param args : callback fromUnicode arguments - * @param target : output target buffer of the callback result. - * @param length : the length of target buffer + * @param source : pointer to pointer to first UChar to write [on exit: 1 after last UChar processed] + * @param sourceLimit : pointer after last UChar to write * @param offsetIndex : the relative offset index from callback. * @param err error status U_BUFFER_OVERFLOW * @see ucnv_cbToUWriteSub * @draft */ U_CAPI void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, - const UChar* source, - int32_t length, + const UChar** source, + const UChar* sourceLimit, int32_t offsetIndex, UErrorCode * err);