2000-07-10 20:51:54 +00:00
|
|
|
/*
|
2000-02-07 17:35:21 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 2000, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* file name: ucnvlat1.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2000feb07
|
|
|
|
* created by: Markus W. Scherer
|
2000-06-27 20:47:56 +00:00
|
|
|
* Change history:
|
|
|
|
*
|
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
2000-02-07 17:35:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "ucmp16.h"
|
|
|
|
#include "ucmp8.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
|
|
|
#include "ucnv_bld.h"
|
2000-02-07 17:35:21 +00:00
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "ucnv_cnv.h"
|
|
|
|
|
|
|
|
/* ISO 8859-1 --------------------------------------------------------------- */
|
|
|
|
|
2000-07-17 23:36:52 +00:00
|
|
|
U_CFUNC void T_UConverter_toUnicode_LATIN_1 (UConverterToUnicodeArgs * args,
|
2000-02-07 17:35:21 +00:00
|
|
|
UErrorCode * err)
|
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
unsigned char *mySource = (unsigned char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
|
|
|
int32_t sourceLength = args->sourceLimit - (char *) mySource;
|
2000-02-07 17:35:21 +00:00
|
|
|
int32_t readLen = 0;
|
|
|
|
int32_t i = 0;
|
|
|
|
|
|
|
|
/*Since there is no risk of encountering illegal Chars
|
|
|
|
*we need to pad our latin1 chars to create Unicode codepoints
|
|
|
|
*we need to go as far a min(targetLen, sourceLen)
|
|
|
|
*in case we don't have enough buffer space
|
|
|
|
*we set the error flag accordingly
|
|
|
|
*/
|
2000-07-10 20:51:54 +00:00
|
|
|
if ((args->targetLimit - args->target) < sourceLength)
|
2000-02-07 17:35:21 +00:00
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
readLen = args->targetLimit - args->target;
|
2000-08-11 19:23:50 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
2000-02-07 17:35:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
readLen = args->sourceLimit - (char *) mySource;
|
2000-02-07 17:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < readLen; i++) myTarget[i] = (UChar) mySource[i];
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args->target += i;
|
|
|
|
args->source += i;
|
2000-02-07 17:35:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-19 00:21:29 +00:00
|
|
|
U_CFUNC void T_UConverter_fromUnicode_LATIN_1 (UConverterFromUnicodeArgs * args,
|
2000-02-07 17:35:21 +00:00
|
|
|
UErrorCode * err)
|
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
const UChar *mySource = args->source;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
2000-02-07 17:35:21 +00:00
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
2000-07-10 20:51:54 +00:00
|
|
|
int32_t targetLength = args->targetLimit - (char *) myTarget;
|
|
|
|
int32_t sourceLength = args->sourceLimit - mySource;
|
2000-06-30 17:38:47 +00:00
|
|
|
UConverterCallbackReason reason;
|
2000-02-07 17:35:21 +00:00
|
|
|
|
|
|
|
/*writing the char to the output stream */
|
|
|
|
while (mySourceIndex < sourceLength)
|
|
|
|
{
|
|
|
|
if (myTargetIndex < targetLength)
|
|
|
|
{
|
|
|
|
if (mySource[mySourceIndex] < 0x0100)
|
|
|
|
{
|
|
|
|
/*writes the char to the output stream */
|
|
|
|
myTarget[myTargetIndex++] = (char) mySource[mySourceIndex++];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2000-06-30 17:38:47 +00:00
|
|
|
reason = UCNV_UNASSIGNED;
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex];
|
|
|
|
args->converter->invalidUCharLength = 1;
|
2000-06-30 17:38:47 +00:00
|
|
|
if (UTF_IS_LEAD(mySource[mySourceIndex++]))
|
|
|
|
{
|
|
|
|
if (mySourceIndex < sourceLength)
|
|
|
|
{
|
|
|
|
if (UTF_IS_TRAIL(mySource[mySourceIndex]))
|
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->invalidUCharBuffer[1] = (UChar)mySource[mySourceIndex];
|
|
|
|
args->converter->invalidUCharLength++;
|
2000-06-30 17:38:47 +00:00
|
|
|
mySourceIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
}
|
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
else if (args->flush == TRUE)
|
2000-06-30 17:38:47 +00:00
|
|
|
{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->fromUSurrogateLead = args->converter->invalidUCharBuffer[0];
|
2000-06-30 17:38:47 +00:00
|
|
|
/* do not call the callback */
|
|
|
|
}
|
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
if (args->converter->fromUSurrogateLead == 0)
|
2000-06-30 17:38:47 +00:00
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
const UChar *saveSource = args->source;
|
|
|
|
char *saveTarget = args->target;
|
|
|
|
int32_t *saveOffset = args->offsets;
|
|
|
|
|
2000-06-30 17:38:47 +00:00
|
|
|
/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */
|
2000-07-10 20:51:54 +00:00
|
|
|
|
|
|
|
args->target = (char*)myTarget + myTargetIndex;;
|
|
|
|
args->source = mySource + mySourceIndex;
|
|
|
|
|
|
|
|
FromU_CALLBACK_MACRO(args->converter->fromUContext,
|
2000-06-30 17:38:47 +00:00
|
|
|
args,
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
args->converter->invalidUCharLength,
|
|
|
|
(UChar32) (args->converter->invalidUCharLength == 2 ?
|
|
|
|
UTF16_GET_PAIR_VALUE(args->converter->invalidUCharBuffer[0],
|
2000-07-13 23:55:33 +00:00
|
|
|
args->converter->invalidUCharBuffer[1])
|
2000-07-10 20:51:54 +00:00
|
|
|
: args->converter->invalidUCharBuffer[0]),
|
2000-06-30 17:38:47 +00:00
|
|
|
reason,
|
|
|
|
err);
|
2000-07-10 20:51:54 +00:00
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffset;
|
|
|
|
if (U_FAILURE (*err))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
args->converter->invalidUCharLength = 0;
|
2000-06-30 17:38:47 +00:00
|
|
|
}
|
2000-02-07 17:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-08-11 19:23:50 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
2000-02-07 17:35:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;;
|
2000-02-07 17:35:21 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-19 00:21:29 +00:00
|
|
|
U_CFUNC UChar32 T_UConverter_getNextUChar_LATIN_1(UConverterToUnicodeArgs* args,
|
2000-07-10 20:51:54 +00:00
|
|
|
UErrorCode* err)
|
2000-02-07 17:35:21 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Empties the internal buffers if need be
|
|
|
|
* In this case since ErrorFunctors are never called
|
|
|
|
* (LATIN_1 is a subset of Unicode)
|
|
|
|
*/
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
if (args->source+1 > args->sourceLimit)
|
2000-02-07 17:35:21 +00:00
|
|
|
{
|
|
|
|
*err = U_INDEX_OUTOFBOUNDS_ERROR;
|
2000-07-13 23:55:33 +00:00
|
|
|
return 0xffff;
|
2000-02-07 17:35:21 +00:00
|
|
|
}
|
2000-06-02 00:05:22 +00:00
|
|
|
|
|
|
|
/* make sure that we zero-extend, not sign-extend, the byte */
|
2000-07-10 20:51:54 +00:00
|
|
|
return (UChar)(uint8_t)*(args->source++);
|
2000-02-07 17:35:21 +00:00
|
|
|
}
|
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
static const UConverterImpl _Latin1Impl={
|
2000-02-07 17:35:21 +00:00
|
|
|
UCNV_LATIN_1,
|
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
2000-02-07 17:35:21 +00:00
|
|
|
T_UConverter_toUnicode_LATIN_1,
|
|
|
|
NULL,
|
|
|
|
T_UConverter_fromUnicode_LATIN_1,
|
|
|
|
NULL,
|
2000-02-09 19:15:17 +00:00
|
|
|
T_UConverter_getNextUChar_LATIN_1,
|
|
|
|
|
|
|
|
NULL
|
2000-02-07 17:35:21 +00:00
|
|
|
};
|
|
|
|
|
2000-04-19 23:05:27 +00:00
|
|
|
const UConverterStaticData _Latin1StaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
|
|
|
"LATIN_1",
|
|
|
|
819, UCNV_IBM, UCNV_LATIN_1, 1, 1,
|
|
|
|
1, { 0x1a, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-04-13 23:00:43 +00:00
|
|
|
const UConverterSharedData _Latin1Data={
|
2000-03-29 21:41:11 +00:00
|
|
|
sizeof(UConverterSharedData), ~((uint32_t) 0),
|
2000-04-19 23:05:27 +00:00
|
|
|
NULL, NULL, &_Latin1StaticData, FALSE, &_Latin1Impl,
|
|
|
|
0
|
2000-02-07 17:35:21 +00:00
|
|
|
};
|