X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..73c04bcfe1096173b00431f0cdc742894b15eef0:/icuSources/common/ucnv_cb.c diff --git a/icuSources/common/ucnv_cb.c b/icuSources/common/ucnv_cb.c index 5038ab57..fa34b658 100644 --- a/icuSources/common/ucnv_cb.c +++ b/icuSources/common/ucnv_cb.c @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2000-2004, International Business Machines +* Copyright (C) 2000-2006, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * ucnv_cb.c: @@ -104,7 +104,7 @@ ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, /* && (*source < sourceLimit && args->target >= args->targetLimit) -- S. Hrcek */ { - /* Overflowed the target. Now, we'll write into the charErrorBuffer. + /* Overflowed the target. Now, we'll write into the charErrorBuffer. It's a fixed size. If we overflow it... Hmm */ char *newTarget; const char *newTargetLimit; @@ -126,49 +126,48 @@ ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, return; } - /* We're going to tell the converter that the errbuff len is empty. - This prevents the existing errbuff from being 'flushed' out onto - itself. If the errbuff is needed by the converter this time, - we're hosed - we're out of space! */ - - args->converter->charErrorBufferLength = 0; - - ucnv_fromUnicode(args->converter, - &newTarget, - newTargetLimit, - source, - sourceLimit, - NULL, - FALSE, - &err2); - - /* We can go ahead and overwrite the length here. We know just how - to recalculate it. */ - - args->converter->charErrorBufferLength = (int8_t)( - newTarget - (char*)args->converter->charErrorBuffer); - - if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR)) - { - /* now we're REALLY in trouble. - Internal program error - callback shouldn't have written this much - data! - */ - *err = U_INTERNAL_PROGRAM_ERROR; - return; - } - else - { - /* sub errs could be invalid/truncated/illegal chars or w/e. - These might want to be passed on up.. But the problem is, we already - need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these - other errs.. */ - - /* - if(U_FAILURE(err2)) - ?? - */ - } + /* We're going to tell the converter that the errbuff len is empty. + This prevents the existing errbuff from being 'flushed' out onto + itself. If the errbuff is needed by the converter this time, + we're hosed - we're out of space! */ + + args->converter->charErrorBufferLength = 0; + + ucnv_fromUnicode(args->converter, + &newTarget, + newTargetLimit, + source, + sourceLimit, + NULL, + FALSE, + &err2); + + /* We can go ahead and overwrite the length here. We know just how + to recalculate it. */ + + args->converter->charErrorBufferLength = (int8_t)( + newTarget - (char*)args->converter->charErrorBuffer); + + if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR)) + { + /* now we're REALLY in trouble. + Internal program error - callback shouldn't have written this much + data! + */ + *err = U_INTERNAL_PROGRAM_ERROR; + return; + } + /*else {*/ + /* sub errs could be invalid/truncated/illegal chars or w/e. + These might want to be passed on up.. But the problem is, we already + need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these + other errs.. */ + + /* + if(U_FAILURE(err2)) + ?? + */ + /*}*/ } } @@ -177,19 +176,48 @@ ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err) { + UConverter *converter; + int32_t length; + if(U_FAILURE(*err)) { return; } + converter = args->converter; + length = converter->subCharLen; - if(args->converter->sharedData->impl->writeSub!=NULL) { - args->converter->sharedData->impl->writeSub(args, offsetIndex, err); - } else if(args->converter->subChar1!=0 && args->converter->invalidUCharBuffer[0]<=0xff) { + if(length == 0) { + return; + } + + if(length < 0) { + /* + * Write/convert the substitution string. Its real length is -length. + * Unlike the escape callback, we need not change the converter's + * callback function because ucnv_setSubstString() verified that + * the string can be converted, so we will not get a conversion error + * and will not recurse. + * At worst we should get a U_BUFFER_OVERFLOW_ERROR. + */ + const UChar *source = (const UChar *)converter->subChars; + ucnv_cbFromUWriteUChars(args, &source, source - length, offsetIndex, err); + return; + } + + if(converter->sharedData->impl->writeSub!=NULL) { + converter->sharedData->impl->writeSub(args, offsetIndex, err); + } + else if(converter->subChar1!=0 && (uint16_t)converter->invalidUCharBuffer[0]<=(uint16_t)0xffu) { + /* + TODO: Is this untestable because the MBCS converter has a writeSub function to call + and the other converters don't use subChar1? + */ ucnv_cbFromUWriteBytes(args, - (const char *)&args->converter->subChar1, 1, + (const char *)&converter->subChar1, 1, offsetIndex, err); - } else { + } + else { ucnv_cbFromUWriteBytes(args, - (const char *)args->converter->subChar, args->converter->subCharLen, + (const char *)converter->subChars, length, offsetIndex, err); } }