ICU-311 Another major update with Callback API changes.

X-SVN-Rev: 1720
This commit is contained in:
Helena Chapman 2000-06-30 17:38:47 +00:00
parent 95cf2bc54e
commit 0ad634011e
14 changed files with 559 additions and 385 deletions

View file

@ -724,8 +724,8 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const char *mySource = *source, *srcTemp;
UChar *myTarget = *target, *tgtTemp;
const char *mySource = *source;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -738,7 +738,6 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this,
myToUnicode = &_this->sharedData->table->dbcs.toUnicode;
args.sourceStart = *source;
while (mySourceIndex < sourceLength)
{
if (myTargetIndex < targetLength)
@ -790,27 +789,23 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this,
}
_this->mode = myMode;
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
ToU_CALLBACK_MACRO(_this->toUContext,
args,
srcTemp,
args.source,
1,
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
}
@ -851,8 +846,8 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const char *mySource = *source, *srcTemp;
UChar *myTarget = *target, *tgtTemp;
const char *mySource = *source;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -865,7 +860,6 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
UConverterToUnicodeArgs args;
myToUnicode = &_this->sharedData->table->dbcs.toUnicode;
args.sourceStart = *source;
while (mySourceIndex < sourceLength)
{
@ -911,6 +905,7 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
else
{
int32_t currentOffset = offsets[myTargetIndex-1] + 2;/* Because mySourceIndex was already incremented */
int32_t My_i = myTargetIndex;
*err = U_INVALID_CHAR_FOUND;
if (mySourceChar > 0xFF)
@ -927,27 +922,23 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
_this->mode = myMode;
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* call back handles the offset array */
ToU_CALLBACK_MACRO(_this->toUContext,
ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this->toUContext,
args,
srcTemp,
args.source,
1,
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
}
@ -989,8 +980,8 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
char *myTarget = *target, *tgtTemp;
const UChar *mySource = *source;
char *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -1004,7 +995,6 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this,
UConverterFromUnicodeArgs args;
myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode;
args.sourceStart = *source;
/*writing the char to the output stream */
while (mySourceIndex < sourceLength)
{
@ -1069,28 +1059,24 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this,
_this->invalidUCharLength = 1;
_this->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
/* HSYS: to do: more smarts */
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
args.source,
1,
(UChar32) (*srcTemp),
(UChar32) (*args.source),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
else
@ -1120,8 +1106,8 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
char *myTarget = *target, *tgtTemp;
const UChar *mySource = *source;
char *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -1136,7 +1122,6 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
UConverterFromUnicodeArgs args;
myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode;
args.sourceStart = *source;
/*writing the char to the output stream */
while (mySourceIndex < sourceLength)
{
@ -1199,35 +1184,31 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this,
else
{
int32_t currentOffset = offsets[myTargetIndex-1]+1;
int32_t My_i = myTargetIndex;
*err = U_INVALID_CHAR_FOUND;
_this->invalidUCharBuffer[0] = (UChar) mySourceChar;
_this->invalidUCharLength = 1;
/* Breaks out of the loop since behaviour was set to stop */
_this->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* HSYS: to do: more smarts, including offsets */
FromU_CALLBACK_MACRO(args.converter->fromUContext,
FromU_CALLBACK_OFFSETS_LOGIC_MACRO(args.converter->fromUContext,
args,
srcTemp,
args.source,
1,
(UChar32) (*srcTemp),
(UChar32) (*args.source),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
else
@ -1264,7 +1245,6 @@ UChar32 T_UConverter_getNextUChar_EBCDIC_STATEFUL(UConverter* converter,
return 0xFFFD;
}
args.sourceStart = *source;
/*Checks to see if with have SI/SO shifters
if we do we change the mode appropriately and we consume the byte*/
if ((**source == UCNV_SI) || (**source == UCNV_SO))
@ -1316,9 +1296,9 @@ UChar32 T_UConverter_getNextUChar_EBCDIC_STATEFUL(UConverter* converter,
/*It's is very likely that the ErrorFunctor will write to the
*internal buffers */
args.converter = converter;
args.pTarget = &myUCharPtr;
args.target = myUCharPtr;
args.targetLimit = myUCharPtr + 1;
args.pSource = &sourceFinal;
args.source = sourceFinal;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;

View file

@ -136,6 +136,7 @@ typedef struct {
struct UConverter {
uint32_t toUnicodeStatus; /* Used to internalize stream status information */
uint32_t fromUnicodeStatus;
UChar fromUSurrogateLead;
int32_t mode;
UBool useFallback;

View file

@ -19,28 +19,42 @@
#include "unicode/ucnv_cb.h"
/* need to update the offsets when the target moves. */
/* Note: Recursion may occur in the cb functions, be sure to update the offsets correctly
if you don't use ucnv_cbXXX functions. Make sure you don't use the same callback within
the same call stack if the complexity arises. */
void ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args,
const char* target,
const char* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err)
{
}
void ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args,
const UChar* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err)
{
}
void ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args,
int32_t offsetIndex,
UErrorCode * err)
{
}
void ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args,
UChar* target,
UChar* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err)
{
}
void ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args,
int32_t offsetIndex,
UErrorCode * err)
{
}

View file

@ -79,6 +79,8 @@ U_CDECL_BEGIN
codePoint, \
reason, \
err); \
myTargetIndex = args.target - (char*)myTarget; \
mySourceIndex = args.source - mySource; \
}
#define ToU_CALLBACK_MACRO(context, args, codePoints, length, reason, err) \
@ -93,6 +95,46 @@ U_CDECL_BEGIN
length, \
reason, \
err); \
myTargetIndex = args.target - myTarget; \
mySourceIndex = args.source - (const char*)mySource; \
}
#define FromU_CALLBACK_OFFSETS_LOGIC_MACRO(context, args, codeUnits, length, codePoint, reason, err) \
if (args.converter->fromUCharErrorBehaviour == (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_STOP) break;\
else \
{ \
int32_t My_i = myTargetIndex; \
/*copies current values for the ErrorFunctor to update */ \
/*Calls the ErrorFunctor */ \
args.converter->fromUCharErrorBehaviour ( \
context, \
&args, \
codeUnits, \
length, \
codePoint, \
reason, \
err); \
/*Update the local Indexes so that the conversion can restart at the right points */ \
myTargetIndex = args.target - (char*)myTarget; \
mySourceIndex = args.source - mySource; \
for (;My_i < myTargetIndex;My_i++) offsets[My_i] += currentOffset ; \
}
#define ToU_CALLBACK_OFFSETS_LOGIC_MACRO(context, args, codePoints, length, reason, err) \
if (args.converter->fromCharErrorBehaviour == (UConverterToUCallback) UCNV_TO_U_CALLBACK_STOP) break; \
else \
{ \
args.converter->fromCharErrorBehaviour ( \
context, \
&args, \
codePoints, \
length, \
reason, \
err); \
/*Update the local Indexes so that the conversion can restart at the right points */ \
myTargetIndex = args.target - myTarget; \
mySourceIndex = args.source - (const char*)mySource; \
for (;My_i < myTargetIndex;My_i++) {offsets[My_i] += currentOffset ; } \
}

View file

@ -124,73 +124,71 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (
UConverterCallbackReason reason,
UErrorCode * err)
{
char togo[5];
int32_t togoLen;
char togo[5];
int32_t togoLen;
if (CONVERSION_U_SUCCESS (*err)) return;
/*In case we're dealing with a modal converter a la UCNV_EBCDIC_STATEFUL,
if (CONVERSION_U_SUCCESS (*err)) return;
/*In case we're dealing with a modal converter a la UCNV_EBCDIC_STATEFUL,
we need to make sure that the emitting of the substitution charater in the right mode*/
uprv_memcpy(togo, fromArgs->converter->subChar, togoLen = fromArgs->converter->subCharLen);
if (ucnv_getType(fromArgs->converter) == UCNV_EBCDIC_STATEFUL)
uprv_memcpy(togo, fromArgs->converter->subChar, togoLen = fromArgs->converter->subCharLen);
if (ucnv_getType(fromArgs->converter) == UCNV_EBCDIC_STATEFUL)
{
if ((fromArgs->converter->fromUnicodeStatus)&&(togoLen != 2))
{
togo[0] = UCNV_SI;
togo[1] = fromArgs->converter->subChar[0];
togo[2] = UCNV_SO;
togoLen = 3;
}
else if (!(fromArgs->converter->fromUnicodeStatus)&&(togoLen != 1))
{
togo[0] = UCNV_SO;
togo[1] = fromArgs->converter->subChar[0];
togo[2] = fromArgs->converter->subChar[1];
togo[3] = UCNV_SI;
togoLen = 4;
}
if ((fromArgs->converter->fromUnicodeStatus)&&(togoLen != 2))
{
togo[0] = UCNV_SI;
togo[1] = fromArgs->converter->subChar[0];
togo[2] = UCNV_SO;
togoLen = 3;
}
else if (!(fromArgs->converter->fromUnicodeStatus)&&(togoLen != 1))
{
togo[0] = UCNV_SO;
togo[1] = fromArgs->converter->subChar[0];
togo[2] = fromArgs->converter->subChar[1];
togo[3] = UCNV_SI;
togoLen = 4;
}
}
/*if we have enough space on the output buffer we just copy
/*if we have enough space on the output buffer we just copy
the subchar there and update the pointer */
if ((fromArgs->targetLimit - *(fromArgs->pTarget)) >= togoLen)
if ((fromArgs->targetLimit - fromArgs->target) >= togoLen)
{
uprv_memcpy (*(fromArgs->pTarget), togo, togoLen);
*(fromArgs->pTarget) += togoLen;
*err = U_ZERO_ERROR;
if (fromArgs->offsets)
{
int i=0;
for (i=0;i<togoLen;i++) fromArgs->offsets[i]=0;
fromArgs->offsets += togoLen;
}
uprv_memcpy (fromArgs->target, togo, togoLen);
fromArgs->target += togoLen;
*err = U_ZERO_ERROR;
if (fromArgs->offsets)
{
int i=0;
for (i=0;i<togoLen;i++) fromArgs->offsets[i]=0;
fromArgs->offsets += togoLen;
}
}
else
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 (*(fromArgs->pTarget), togo, (fromArgs->targetLimit - *(fromArgs->pTarget)));
if (fromArgs->offsets)
{
int i=0;
for (i=0;i<(fromArgs->targetLimit - *(fromArgs->pTarget));i++) fromArgs->offsets[i]=0;
fromArgs->offsets += (fromArgs->targetLimit - *(fromArgs->pTarget));
}
uprv_memcpy (fromArgs->converter->charErrorBuffer + fromArgs->converter->charErrorBufferLength,
togo + (fromArgs->targetLimit - *(fromArgs->pTarget)),
togoLen - (fromArgs->targetLimit - *(fromArgs->pTarget)));
fromArgs->converter->charErrorBufferLength += togoLen - (fromArgs->targetLimit - *(fromArgs->pTarget));
*(fromArgs->pTarget) += (fromArgs->targetLimit - *(fromArgs->pTarget));
*err = U_INDEX_OUTOFBOUNDS_ERROR;
/*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 (fromArgs->target, togo, (fromArgs->targetLimit - fromArgs->target));
if (fromArgs->offsets)
{
int i=0;
for (i=0;i<(fromArgs->targetLimit - fromArgs->target);i++) fromArgs->offsets[i]=0;
fromArgs->offsets += (fromArgs->targetLimit - fromArgs->target);
}
uprv_memcpy (fromArgs->converter->charErrorBuffer + fromArgs->converter->charErrorBufferLength,
togo + (fromArgs->targetLimit - fromArgs->target),
togoLen - (fromArgs->targetLimit - fromArgs->target));
fromArgs->converter->charErrorBufferLength += togoLen - (fromArgs->targetLimit - fromArgs->target);
fromArgs->target += (fromArgs->targetLimit - fromArgs->target);
*err = U_INDEX_OUTOFBOUNDS_ERROR;
}
return;
return;
}
/*uses itou to get a unicode escape sequence of the offensive sequence,
@ -280,10 +278,10 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
/*if we have enough space on the output buffer we just copy
* the subchar there and update the pointer
*/
if ((fromArgs->targetLimit - *(fromArgs->pTarget)) >= valueStringLength)
if ((fromArgs->targetLimit - fromArgs->target) >= valueStringLength)
{
uprv_memcpy (*(fromArgs->pTarget), myTarget, valueStringLength);
*(fromArgs->pTarget) += valueStringLength;
uprv_memcpy (fromArgs->target, myTarget, valueStringLength);
fromArgs->target += valueStringLength;
*err = U_ZERO_ERROR;
if (fromArgs->offsets)
@ -304,15 +302,15 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
if (fromArgs->offsets)
{
int j=0;
for (j=0;j<(fromArgs->targetLimit - *(fromArgs->pTarget));j++) fromArgs->offsets[j]=0;
fromArgs->offsets += (fromArgs->targetLimit - *(fromArgs->pTarget));
for (j=0;j<(fromArgs->targetLimit - fromArgs->target);j++) fromArgs->offsets[j]=0;
fromArgs->offsets += (fromArgs->targetLimit - fromArgs->target);
}
uprv_memcpy (*(fromArgs->pTarget), myTarget, (fromArgs->targetLimit - *(fromArgs->pTarget)));
uprv_memcpy (fromArgs->target, myTarget, (fromArgs->targetLimit - fromArgs->target));
uprv_memcpy (fromArgs->converter->charErrorBuffer + fromArgs->converter->charErrorBufferLength,
myTarget + (fromArgs->targetLimit - *(fromArgs->pTarget)),
valueStringLength - (fromArgs->targetLimit - *(fromArgs->pTarget)));
fromArgs->converter->charErrorBufferLength += valueStringLength - (fromArgs->targetLimit - *(fromArgs->pTarget));
*(fromArgs->pTarget) += (fromArgs->targetLimit - *(fromArgs->pTarget));
myTarget + (fromArgs->targetLimit - fromArgs->target),
valueStringLength - (fromArgs->targetLimit - fromArgs->target));
fromArgs->converter->charErrorBufferLength += valueStringLength - (fromArgs->targetLimit - fromArgs->target);
fromArgs->target += (fromArgs->targetLimit - fromArgs->target);
*err = U_INDEX_OUTOFBOUNDS_ERROR;
}
@ -344,10 +342,10 @@ void UCNV_TO_U_CALLBACK_SUBSTITUTE (
if (CONVERSION_U_SUCCESS (*err)) return;
if ((toArgs->targetLimit - *(toArgs->pTarget)) >= 1)
if ((toArgs->targetLimit - toArgs->target) >= 1)
{
**(toArgs->pTarget) = 0xFFFD;
(*(toArgs->pTarget))++;
*toArgs->target = 0xFFFD;
(toArgs->target)++;
if (toArgs->offsets) *(toArgs->offsets) = 0;
*err = U_ZERO_ERROR;
}
@ -390,17 +388,17 @@ void UCNV_TO_U_CALLBACK_ESCAPE (
valueStringLength += 4;
}
if ((toArgs->targetLimit - *(toArgs->pTarget)) >= valueStringLength)
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->pTarget), uniValueString, (sizeof (UChar)) * (valueStringLength));
uprv_memcpy (toArgs->target, uniValueString, (sizeof (UChar)) * (valueStringLength));
if (toArgs->offsets)
{
for (i = 0; i < valueStringLength; i++) toArgs->offsets[i] = 0;
}
*(toArgs->pTarget) += valueStringLength;
toArgs->target += valueStringLength;
*err = U_ZERO_ERROR;
}
@ -411,18 +409,18 @@ void UCNV_TO_U_CALLBACK_ESCAPE (
*copy the rest in the internal buffer, and increase the
*length marker
*/
uprv_memcpy (*(toArgs->pTarget), uniValueString, (sizeof (UChar)) * (toArgs->targetLimit - *(toArgs->pTarget)));
uprv_memcpy (toArgs->target, uniValueString, (sizeof (UChar)) * (toArgs->targetLimit - toArgs->target));
if (toArgs->offsets)
{
for (i = 0; i < (toArgs->targetLimit - *(toArgs->pTarget)); i++) toArgs->offsets[i] = 0;
for (i = 0; i < (toArgs->targetLimit - toArgs->target); i++) toArgs->offsets[i] = 0;
}
uprv_memcpy (toArgs->converter->UCharErrorBuffer,
uniValueString + (toArgs->targetLimit - *(toArgs->pTarget)),
(sizeof (UChar)) * (valueStringLength - (toArgs->targetLimit - *(toArgs->pTarget))));
toArgs->converter->UCharErrorBufferLength += valueStringLength - (toArgs->targetLimit - *(toArgs->pTarget));
*(toArgs->pTarget) += (toArgs->targetLimit - *(toArgs->pTarget));
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;
}

View file

@ -1015,7 +1015,6 @@ _LMBCSGetNextUCharWorker(UConverter* _this,
*err = U_ILLEGAL_ARGUMENT_ERROR;
return missingUCharMarker;
}
args.sourceStart = *source;
/* Grab first byte & save address for error recovery */
CurByte = *((ulmbcs_byte_t *) (saveSource = (*source)++));
@ -1157,9 +1156,9 @@ _LMBCSGetNextUCharWorker(UConverter* _this,
UChar * pUniChar = (UChar *)&uniChar;
args.converter = _this;
args.pTarget = &pUniChar;
args.target = pUniChar;
args.targetLimit = pUniChar + 1;
args.pSource = &saveSource;
args.source = saveSource;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;
@ -1167,7 +1166,7 @@ _LMBCSGetNextUCharWorker(UConverter* _this,
_this->fromCharErrorBehaviour(_this->toUContext,
&args,
saveSource,
1,
sourceLimit - saveSource,
UCNV_UNASSIGNED,
err);
*source = saveSource;

View file

@ -71,8 +71,7 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this,
UErrorCode * err)
{
const unsigned char *mySource = (unsigned char *) *source;
const char *srcTemp; /* to match the Args definition */
UChar *myTarget = *target, *tgtTemp;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -83,7 +82,6 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this,
uint32_t inBytes = 0; /* Total number of bytes in the current UTF8 sequence */
UConverterToUnicodeArgs args;
args.sourceStart = *source;
if (_this->toUnicodeStatus)
{
i = _this->invalidCharLength; /* restore # of bytes consumed */
@ -179,25 +177,21 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this,
#endif
/* Needed explicit cast for mySource on MVS to make compiler happy - JJD */
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = (const char*) mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
ToU_CALLBACK_MACRO(_this->toUContext,
args,
srcTemp,
1,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - (const char *)mySource;
}
}
}
@ -225,8 +219,7 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this,
UErrorCode * err)
{
const unsigned char *mySource = (unsigned char *) *source;
const char *srcTemp;
UChar *myTarget = *target, *tgtTemp;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -235,7 +228,6 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this,
uint32_t inBytes = 0;
UConverterToUnicodeArgs args;
args.sourceStart = *source;
if (_this->toUnicodeStatus)
{
i = _this->invalidCharLength;
@ -321,25 +313,24 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this,
else
{
int32_t currentOffset = offsets[myTargetIndex-1];
int32_t My_i = myTargetIndex;
*err = U_ILLEGAL_CHAR_FOUND;
_this->invalidCharLength = (int8_t)i;
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = (const char*)mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* To do HSYS: more smarts here, including offsets */
ToU_CALLBACK_MACRO(_this->toUContext,
ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this->toUContext,
args,
srcTemp,
1,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
/* Needed explicit cast for mySource on MVS to make compiler happy - JJD */
@ -347,9 +338,7 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this,
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - (const char*)mySource;
}
}
}
}
else
@ -605,7 +594,6 @@ UChar32 T_UConverter_getNextUChar_UTF8(UConverter* converter,
UConverterToUnicodeArgs args;
/*Input boundary check*/
args.sourceStart = *source;
if ((*source) >= sourceLimit)
{
*err = U_INDEX_OUTOFBOUNDS_ERROR;
@ -686,9 +674,9 @@ UChar32 T_UConverter_getNextUChar_UTF8(UConverter* converter,
/*It is very likely that the ErrorFunctor will write to the
*internal buffers */
args.converter = converter;
args.pTarget = &myUCharPtr;
args.target = myUCharPtr;
args.targetLimit = myUCharPtr + 1;
args.pSource = &sourceFinal;
args.source = sourceFinal;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;
@ -696,7 +684,7 @@ UChar32 T_UConverter_getNextUChar_UTF8(UConverter* converter,
converter->fromCharErrorBehaviour(converter->toUContext,
&args,
sourceFinal,
1,
sourceLimit-sourceFinal,
UCNV_UNASSIGNED,
err);

View file

@ -72,15 +72,15 @@ static void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
unsigned char *myTarget = (unsigned char *) *target, *tgtTemp;
const UChar *mySource = *source;
unsigned char *myTarget = (unsigned char *) *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - (char *) myTarget;
int32_t sourceLength = sourceLimit - mySource;
UConverterFromUnicodeArgs args;
UConverterCallbackReason reason;
args.sourceStart = *source;
/*writing the char to the output stream */
while (mySourceIndex < sourceLength)
{
@ -95,33 +95,61 @@ static void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this,
else
{
*err = U_INVALID_CHAR_FOUND;
_this->invalidUCharBuffer[0] = (UChar) mySource[mySourceIndex++];
reason = UCNV_UNASSIGNED;
_this->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength = 1;
if (UTF_IS_LEAD(mySource[mySourceIndex++]))
{
if (mySourceIndex < sourceLength)
{
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
{
_this->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength++;
mySourceIndex++;
}
else
{
reason = UCNV_ILLEGAL;
}
}
else if (flush == TRUE)
{
reason = UCNV_ILLEGAL;
*err = U_TRUNCATED_CHAR_FOUND;
}
else
{
_this->fromUSurrogateLead = _this->invalidUCharBuffer[0];
/* do not call the callback */
}
}
if (_this->fromUSurrogateLead == 0)
{
int32_t currentOffset = myTargetIndex;
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
args.converter = _this;
args.target = (char*)myTarget + myTargetIndex;;
args.targetLimit = targetLimit;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = (char**)&tgtTemp;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
1,
(UChar32) (*srcTemp),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
myTargetIndex = (unsigned char *) (*(args.pTarget)) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
_this->invalidUCharBuffer,
_this->invalidUCharLength,
(UChar32) (_this->invalidUCharLength == 2 ?
UTF16_GET_PAIR_VALUE(_this->invalidUCharBuffer[0],
_this->invalidUCharBuffer[2])
: _this->invalidUCharBuffer[0]),
reason,
err);
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
}
}
}
else

View file

@ -78,8 +78,8 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const char *mySource = *source, *srcTemp;
UChar *myTarget = *target, *tgtTemp;
const char *mySource = *source;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -90,8 +90,6 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this,
UBool *myStarters = NULL;
UConverterToUnicodeArgs args;
args.sourceStart = *source;
myToUnicode = &_this->sharedData->table->mbcs.toUnicode;
myToUnicodeFallback = &_this->sharedData->table->mbcs.toUnicodeFallback;
myStarters = _this->sharedData->table->mbcs.starters;
@ -157,28 +155,24 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this,
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
/* to do hsys: add more smarts to the codeUnits and length later */
ToU_CALLBACK_MACRO(_this->toUContext,
args,
srcTemp,
1,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
}
@ -218,8 +212,8 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const char *mySource = *source, *srcTemp;
UChar *myTarget = *target, *tgtTemp;
const char *mySource = *source;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -231,7 +225,6 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
UBool *myStarters = NULL;
UConverterToUnicodeArgs args;
args.sourceStart = *source;
myToUnicode = &_this->sharedData->table->mbcs.toUnicode;
myToUnicodeFallback = &_this->sharedData->table->mbcs.toUnicodeFallback;
myStarters = _this->sharedData->table->mbcs.starters;
@ -304,6 +297,7 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
if (targetUniChar == missingUCharMarker)
{
int32_t currentOffset = offsets[myTargetIndex-1] + ((oldMySourceChar>0x00FF)?2:1);
int32_t My_i = myTargetIndex;
*err = U_INVALID_CHAR_FOUND;
if (mySourceChar > 0xff)
@ -318,28 +312,23 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
_this->invalidCharBuffer[0] = (char) mySourceChar;
}
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* to do hsys: add more smarts to the codeUnits and length later and offsets */
ToU_CALLBACK_MACRO(_this->toUContext,
ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this->toUContext,
args,
srcTemp,
1,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
_this->invalidCharLength = 0;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
}
}
}
@ -380,8 +369,8 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
char *myTarget = *target, *tgtTemp;
const UChar *mySource = *source;
char *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -390,8 +379,8 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this,
UChar targetUniChar = 0x0000;
UChar mySourceChar = 0x0000;
UConverterFromUnicodeArgs args;
UConverterCallbackReason reason;
args.sourceStart = *source;
myFromUnicode = &_this->sharedData->table->mbcs.fromUnicode;
myFromUnicodeFallback = &_this->sharedData->table->mbcs.fromUnicodeFallback;
@ -453,33 +442,61 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this,
}
if (targetUniChar == missingCharMarker)
{
*err = U_INVALID_CHAR_FOUND;
_this->invalidUCharBuffer[0] = (UChar) mySourceChar;
_this->invalidUCharLength = 1;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = (offsets)?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts */
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
1,
(UChar32) (*srcTemp),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err)) break;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidUCharLength = 0;
if (UTF_IS_LEAD(mySource[mySourceIndex-1]))
{
if (mySource < sourceLimit)
{
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
{
_this->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength++;
mySourceIndex++;
}
else
{
reason = UCNV_ILLEGAL;
}
}
else if (flush == TRUE)
{
reason = UCNV_ILLEGAL;
*err = U_TRUNCATED_CHAR_FOUND;
}
else
{
_this->fromUSurrogateLead = _this->invalidUCharBuffer[0];
/* do not call the callback */
}
}
if (_this->fromUSurrogateLead == 0)
{
args.converter = _this;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts */
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
_this->invalidUCharBuffer,
_this->invalidUCharLength,
(UChar32) (_this->invalidUCharLength == 2 ?
UTF16_GET_PAIR_VALUE(_this->invalidUCharBuffer[0],
_this->invalidUCharBuffer[2])
: _this->invalidUCharBuffer[0]),
reason,
err);
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
}
}
}
else
@ -508,8 +525,8 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
char *myTarget = *target, *tgtTemp;
const UChar *mySource = *source;
char *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -518,8 +535,8 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
UChar targetUniChar = 0x0000;
UChar mySourceChar = 0x0000;
UConverterFromUnicodeArgs args;
UConverterCallbackReason reason;
args.sourceStart = *source;
myFromUnicode = &_this->sharedData->table->mbcs.fromUnicode;
myFromUnicodeFallback = &_this->sharedData->table->mbcs.fromUnicodeFallback;
@ -590,37 +607,65 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this,
if (targetUniChar == missingCharMarker)
{
int32_t currentOffset = mySourceIndex -1;
int32_t My_i = myTargetIndex;
*err = U_INVALID_CHAR_FOUND;
_this->invalidUCharBuffer[0] = (UChar) mySourceChar;
reason = UCNV_UNASSIGNED;
_this->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex - 1];
_this->invalidUCharLength = 1;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts including offsets*/
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
1,
(UChar32) (*srcTemp),
UCNV_UNASSIGNED,
err);
if (UTF_IS_LEAD(mySource[mySourceIndex-1]))
{
if (mySource < sourceLimit)
{
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
{
_this->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength++;
mySourceIndex++;
}
else
{
reason = UCNV_ILLEGAL;
}
}
else if (flush == TRUE)
{
reason = UCNV_ILLEGAL;
*err = U_TRUNCATED_CHAR_FOUND;
}
else
{
_this->fromUSurrogateLead = _this->invalidUCharBuffer[0];
/* do not call the callback */
}
}
if (_this->fromUSurrogateLead == 0)
{
args.converter = _this;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts including offsets*/
FromU_CALLBACK_OFFSETS_LOGIC_MACRO(args.converter->fromUContext,
args,
_this->invalidUCharBuffer,
_this->invalidUCharLength,
(UChar32) (_this->invalidUCharLength == 2 ?
UTF16_GET_PAIR_VALUE(_this->invalidUCharBuffer[0],
_this->invalidUCharBuffer[2])
: _this->invalidUCharBuffer[0]),
reason,
err);
if (U_FAILURE (*err)) break;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidUCharLength = 0;
}
if (U_FAILURE (*err)) break;
_this->invalidUCharLength = 0;
}
}
}
else
{
@ -654,7 +699,6 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter,
*err = U_INDEX_OUTOFBOUNDS_ERROR;
return 0xFFFD;
}
args.sourceStart = *source;
/*Checks to see if the byte is a lead*/
if (converter->sharedData->table->mbcs.starters[(uint8_t)**source] == FALSE)
{
@ -702,13 +746,13 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter,
*err = U_INVALID_CHAR_FOUND;
*source = sourceInitial;
/*It's is very likely that the ErrorFunctor will write to the
*internal buffers */
args.converter = converter;
args.pTarget = &myUCharPtr;
args.target = myUCharPtr;
args.targetLimit = myUCharPtr + 1;
args.pSource = &sourceFinal;
args.source = sourceFinal;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;
@ -716,7 +760,7 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter,
converter->fromCharErrorBehaviour(converter->toUContext,
&args,
sourceFinal,
1,
sourceLimit-sourceFinal,
UCNV_UNASSIGNED,
err);

View file

@ -69,8 +69,7 @@ void T_UConverter_toUnicode_SBCS (UConverter * _this,
UErrorCode * err)
{
char *mySource = (char *) *source;
const char *srcTemp;
UChar *myTarget = *target, *tgtTemp;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -81,7 +80,6 @@ void T_UConverter_toUnicode_SBCS (UConverter * _this,
myToUnicode = _this->sharedData->table->sbcs.toUnicode;
myToUnicodeFallback = _this->sharedData->table->sbcs.toUnicodeFallback;
args.sourceStart = *source;
while (mySourceIndex < sourceLength)
{
@ -115,27 +113,23 @@ void T_UConverter_toUnicode_SBCS (UConverter * _this,
_this->invalidCharLength = 1;
args.converter = _this;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
/* to do hsys: add more smarts to the codeUnits and length later */
ToU_CALLBACK_MACRO(_this->toUContext,
args,
srcTemp,
1,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
/* Hsys: calculate the source and target advancement */
if (U_FAILURE (*err)) break;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidCharLength = 0;
}
}
@ -162,9 +156,8 @@ void T_UConverter_fromUnicode_SBCS (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
const UChar *mySource = *source;
unsigned char *myTarget = (unsigned char *) *target;
char *tgtTemp;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - (char *) myTarget;
@ -172,11 +165,17 @@ void T_UConverter_fromUnicode_SBCS (UConverter * _this,
CompactByteArray *myFromUnicode = NULL, *myFromUnicodeFallback = NULL;
unsigned char targetChar = 0x00;
UConverterFromUnicodeArgs args;
UConverterCallbackReason reason;
myFromUnicode = &_this->sharedData->table->sbcs.fromUnicode;
myFromUnicodeFallback = &_this->sharedData->table->sbcs.fromUnicodeFallback;
args.sourceStart = *source;
/*writing the char to the output stream */
/* HSYS : to do : finish the combining of the surrogate characters later */
/*
if (_this->fromUSurrogateLead != 0 && UTF_IS_TRAIL(mySource[mySourceIndex]))
{
}
*/
while (mySourceIndex < sourceLength)
{
targetChar = ucmp8_getu (myFromUnicode, mySource[mySourceIndex]);
@ -203,35 +202,67 @@ void T_UConverter_fromUnicode_SBCS (UConverter * _this,
if (targetChar == 0 && mySource[mySourceIndex-1] != 0)
{
*err = U_INVALID_CHAR_FOUND;
reason = UCNV_UNASSIGNED;
_this->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex - 1];
_this->invalidUCharLength = 1;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts */
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
1,
(UChar32) (*srcTemp),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err))
{
break;
}
myTargetIndex = *(args.pTarget) - (char*)myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidUCharLength = 0;
if (UTF_IS_LEAD(mySource[mySourceIndex-1]))
{
if (mySource < sourceLimit)
{
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
{
_this->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength++;
mySourceIndex++;
}
else
{
reason = UCNV_ILLEGAL;
}
}
else if (flush == TRUE)
{
reason = UCNV_ILLEGAL;
*err = U_TRUNCATED_CHAR_FOUND;
}
else
{
_this->fromUSurrogateLead = _this->invalidUCharBuffer[0];
/* do not call the callback */
}
}
if (_this->fromUSurrogateLead == 0)
{
args.converter = _this;
args.target = (char *)myTarget+myTargetIndex;
args.targetLimit = targetLimit;
args.source = mySource+mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets;
args.size = sizeof(args);
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* Check if we have encountered a surrogate pair. If first UChar is lead byte
and second UChar is trail byte, it's a surrogate char. If UChar is lead byte
but second UChar is not trail byte, it's illegal sequence. If neither, it's
plain unassigned code point.*/
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
_this->invalidUCharBuffer,
_this->invalidUCharLength,
(UChar32) (_this->invalidUCharLength == 2 ?
UTF16_GET_PAIR_VALUE(_this->invalidUCharBuffer[0],
_this->invalidUCharBuffer[2])
: _this->invalidUCharBuffer[0]),
reason,
err);
if (U_FAILURE (*err))
{
break;
}
_this->invalidUCharLength = 0;
}
}
}
else
@ -265,7 +296,6 @@ UChar32 T_UConverter_getNextUChar_SBCS(UConverter* converter,
return 0xFFFD;
}
args.sourceStart = *source;
/*Gets the corresponding codepoint*/
myUChar = converter->sharedData->table->sbcs.toUnicode[(unsigned char)*((*source)++)];
@ -290,9 +320,9 @@ UChar32 T_UConverter_getNextUChar_SBCS(UConverter* converter,
/*It's is very likely that the ErrorFunctor will write to the
*internal buffers */
args.converter = converter;
args.pTarget = &myUCharPtr;
args.target = myUCharPtr;
args.targetLimit = myUCharPtr + 1;
args.pSource = &sourceFinal;
args.source = sourceFinal;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;
@ -389,8 +419,8 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const char *mySource = ( char *) *source, *srcTemp;
UChar *myTarget = *target, *tgtTemp;
const char *mySource = ( char *) *source;
UChar *myTarget = *target;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - myTarget;
@ -402,7 +432,6 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this,
myToUnicode = &_this->sharedData->table->dbcs.toUnicode;
myToUnicodeFallback = &_this->sharedData->table->dbcs.toUnicodeFallback;
args.sourceStart = *source;
while (mySourceIndex < sourceLength)
{
@ -449,28 +478,24 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this,
_this->invalidCharBuffer[1] = (char) mySourceChar;
_this->invalidCharLength = 2;
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.target = myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.offsets = offsets;
args.size = sizeof(args);
/* to do hsys: add more smarts to the codeUnits and length later */
ToU_CALLBACK_MACRO(_this->toUContext,
args,
srcTemp,
2,
_this->invalidCharBuffer,
_this->invalidCharLength,
UCNV_UNASSIGNED,
err);
/* Hsys: calculate the source and target advancement */
if (U_FAILURE (*err)) break;
myTargetIndex = *(args.pTarget) - myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidCharLength = 0;
}
}
@ -512,9 +537,8 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this,
UBool flush,
UErrorCode * err)
{
const UChar *mySource = *source, *srcTemp;
const UChar *mySource = *source;
unsigned char *myTarget = (unsigned char *) *target;
char *tgtTemp;
int32_t mySourceIndex = 0;
int32_t myTargetIndex = 0;
int32_t targetLength = targetLimit - (char *) myTarget;
@ -523,10 +547,10 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this,
UChar targetUniChar = 0x0000;
UChar mySourceChar = 0x0000;
UConverterFromUnicodeArgs args;
UConverterCallbackReason reason;
myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode;
myFromUnicodeFallback = &_this->sharedData->table->dbcs.fromUnicodeFallback;
args.sourceStart = *source;
/*writing the char to the output stream */
while (mySourceIndex < sourceLength)
@ -577,36 +601,67 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this,
if (targetUniChar == missingCharMarker)
{
*err = U_INVALID_CHAR_FOUND;
_this->invalidUCharBuffer[0] = (UChar) mySourceChar;
reason = UCNV_UNASSIGNED;
_this->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex - 1];
_this->invalidUCharLength = 1;
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* HSYS: to do: more smarts */
srcTemp = mySource + mySourceIndex;
tgtTemp = myTarget + myTargetIndex;
args.converter = _this;
args.pTarget = &tgtTemp;
args.targetLimit = targetLimit;
args.pSource = &srcTemp;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets?offsets+myTargetIndex:0;
args.size = sizeof(args);
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
srcTemp,
1,
(UChar32) (*srcTemp),
UCNV_UNASSIGNED,
err);
if (U_FAILURE (*err))
{
break;
}
myTargetIndex = *(args.pTarget) - (char*)myTarget;
mySourceIndex = *(args.pSource) - mySource;
_this->invalidUCharLength = 0;
if (UTF_IS_LEAD(mySource[mySourceIndex-1]))
{
if (mySource < sourceLimit)
{
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
{
_this->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
_this->invalidUCharLength++;
mySourceIndex++;
}
else
{
reason = UCNV_ILLEGAL;
}
}
else if (flush == TRUE)
{
reason = UCNV_ILLEGAL;
*err = U_TRUNCATED_CHAR_FOUND;
}
else
{
_this->fromUSurrogateLead = _this->invalidUCharBuffer[0];
/* do not call the callback */
}
}
if (_this->fromUSurrogateLead == 0)
{
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
/* Check if we have encountered a surrogate pair. If first UChar is lead byte
and second UChar is trail byte, it's a surrogate char. If UChar is lead byte
but second UChar is not trail byte, it's illegal sequence. If neither, it's
plain unassigned code point.*/
args.converter = _this;
args.target = (char*)myTarget + myTargetIndex;
args.targetLimit = targetLimit;
args.source = mySource + mySourceIndex;
args.sourceLimit = sourceLimit;
args.flush = flush;
args.offsets = offsets;
args.size = sizeof(args);
FromU_CALLBACK_MACRO(args.converter->fromUContext,
args,
_this->invalidUCharBuffer,
_this->invalidUCharLength,
(UChar32) (_this->invalidUCharLength == 2 ?
UTF16_GET_PAIR_VALUE(_this->invalidUCharBuffer[0],
_this->invalidUCharBuffer[2])
: _this->invalidUCharBuffer[0]),
reason,
err);
if (U_FAILURE (*err))
{
break;
}
_this->invalidUCharLength = 0;
}
}
}
else
@ -649,7 +704,6 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter,
return 0xFFFD;
}
args.sourceStart = *source;
/*Gets the corresponding codepoint*/
myUChar = ucmp16_getu((&converter->sharedData->table->dbcs.toUnicode),
(uint16_t)(((UChar)((**source)) << 8) |((uint8_t)*((*source)+1))));
@ -680,9 +734,9 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter,
*err = U_INVALID_CHAR_FOUND;
args.converter = converter;
args.pTarget = &myUCharPtr;
args.target = myUCharPtr;
args.targetLimit = myUCharPtr + 1;
args.pSource = &sourceFinal;
args.source = sourceFinal;
args.sourceLimit = sourceLimit;
args.flush = TRUE;
args.offsets = NULL;
@ -692,7 +746,7 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter,
converter->fromCharErrorBehaviour(converter->toUContext,
&args,
sourceFinal,
1,
2,
UCNV_UNASSIGNED,
err);
/*makes the internal caching transparent to the user*/

View file

@ -32,14 +32,16 @@
* @param args : callback fromUnicode arguments
* @param target : output target buffer of the callback result.
* @param length : the length of target buffer
* @param offsetIndex : the relative offset index from callback.
* @param err error status <TT>U_BUFFER_OVERFLOW</TT>
* @see ucnv_cbFromUWriteSub
* @draft
*/
U_CAPI void U_EXPORT2 ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args,
const char* target,
const char* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err);
/**
@ -49,13 +51,35 @@ U_CAPI void U_EXPORT2 ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args,
* @param args : callback fromUnicode arguments
* @param target : output target buffer of the callback result.
* @param length : the length of target buffer
* @param offsetIndex : the relative offset index from callback.
* @param err error status <TT>U_BUFFER_OVERFLOW</TT>
* @see ucnv_cbFromUWriteBytes
* @draft
*/
U_CAPI void U_EXPORT2 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args,
int32_t offsetIndex,
UErrorCode * err);
/**
* Used by the callback functions. This function will write out the error
* 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 offsetIndex : the relative offset index from callback.
* @param err error status <TT>U_BUFFER_OVERFLOW</TT>
* @see ucnv_cbToUWriteSub
* @draft
*/
U_CAPI void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args,
const UChar* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err);
/**
* Used by the callback functions. This function will write out the error
* character(s) to the target UChar buffer.
@ -63,26 +87,30 @@ U_CAPI void U_EXPORT2 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args,
* @param args : callback toUnicode arguments
* @param target : output target buffer of the callback result.
* @param length : the length of target buffer
* @param offsetIndex : the relative offset index from callback.
* @param err error status <TT>U_BUFFER_OVERFLOW</TT>
* @see ucnv_cbToUWriteSub
* @draft
*/
U_CAPI void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args,
UChar* target,
UChar* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err);
/**
* Used by the callback functions. This function will write out the error
* character(s) to the substitution character.
*
* @param args : callback fromUnicode arguments
* @param offsetIndex : the relative offset index from callback.
* @param err error status <TT>U_BUFFER_OVERFLOW</TT>
* @see ucnv_cbToUWriteUChars
* @draft
*/
U_CAPI void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args,
int32_t offsetIndex,
UErrorCode * err);
#endif

View file

@ -68,10 +68,9 @@ typedef struct {
uint16_t size;
UBool flush;
UConverter *converter;
const UChar *sourceStart;
const UChar **pSource;
const UChar *source;
const UChar *sourceLimit;
char **pTarget;
char *target;
const char *targetLimit;
int32_t *offsets; /* *offset = blah ; offset++; */
} UConverterFromUnicodeArgs;
@ -84,10 +83,9 @@ typedef struct {
uint16_t size;
UBool flush;
UConverter *converter;
const char *sourceStart;
const char **pSource;
const char *source;
const char *sourceLimit;
UChar **pTarget;
UChar *target;
const UChar *targetLimit;
int32_t *offsets;
} UConverterToUnicodeArgs;

View file

@ -197,8 +197,8 @@ void TestConvert()
}
};
UConverterFromUCallback oldFromUAction;
UConverterToUCallback oldToUAction;
UConverterFromUCallback oldFromUAction = NULL;
UConverterToUCallback oldToUAction = NULL;
void* oldFromUContext = NULL;
void* oldToUContext = NULL;

View file

@ -435,7 +435,7 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const char *ex
char junk[9999];
char offset_str[9999];
char *p;
UConverterFromUCallback oldAction;
UConverterFromUCallback oldAction = NULL;
void* oldContext = NULL;
@ -619,7 +619,7 @@ UBool testConvertToUnicode( const char *source, int sourcelen, const UChar *expe
char offset_str[9999];
UChar *p;
UConverterToUCallback action;
UConverterToUCallback oldAction;
UConverterToUCallback oldAction = NULL;
void* oldContext = NULL;
int32_t realBufferSize;