summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/common/ucnv_cb.c
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2007-11-21 12:29:46 +0000
committerJonathan Kew <jfkthame@googlemail.com>2007-11-21 12:29:46 +0000
commit952d69f85d43b087ce9fa79d3fc6f1c076000bc7 (patch)
treedd6937a6486e80e1638618308481075efab000ae /Build/source/libs/icu-xetex/common/ucnv_cb.c
parent888236cb9df7b7d7b5a3e2d784037a9a59511c53 (diff)
updated icu-xetex library for XeTeX 0.997
git-svn-id: svn://tug.org/texlive/trunk@5536 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/icu-xetex/common/ucnv_cb.c')
-rw-r--r--Build/source/libs/icu-xetex/common/ucnv_cb.c130
1 files changed, 79 insertions, 51 deletions
diff --git a/Build/source/libs/icu-xetex/common/ucnv_cb.c b/Build/source/libs/icu-xetex/common/ucnv_cb.c
index 5038ab574f3..fa34b658327 100644
--- a/Build/source/libs/icu-xetex/common/ucnv_cb.c
+++ b/Build/source/libs/icu-xetex/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);
}
}