2000-02-05 00:19:15 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 2000, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
2000-08-29 21:47:40 +00:00
|
|
|
* file name: ucnv2022.c
|
2000-02-05 00:19:15 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2000feb03
|
|
|
|
* created by: Markus W. Scherer
|
2000-06-27 20:47:56 +00:00
|
|
|
*
|
|
|
|
* Change history:
|
|
|
|
*
|
2000-11-20 18:08:49 +00:00
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
|
|
|
* 08/08/2000 Ram Included support for ISO-2022-JP-2
|
2000-11-29 01:04:03 +00:00
|
|
|
* Changed implementation of toUnicode
|
|
|
|
* function
|
2000-11-20 18:08:49 +00:00
|
|
|
* 08/21/2000 Ram Added support for ISO-2022-KR
|
|
|
|
* 08/29/2000 Ram Seperated implementation of EBCDIC to
|
2000-11-29 01:04:03 +00:00
|
|
|
* ucnvebdc.c
|
2000-11-20 18:08:49 +00:00
|
|
|
* 09/20/2000 Ram Added support for ISO-2022-CN
|
2000-11-29 01:04:03 +00:00
|
|
|
* Added implementations for getNextUChar()
|
|
|
|
* for specific 2022 country variants.
|
2000-11-02 04:09:34 +00:00
|
|
|
* 10/31/2000 Ram Implemented offsets logic functions
|
2000-02-05 00:19:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "cmemory.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
|
|
|
#include "ucnv_bld.h"
|
2000-02-05 00:19:15 +00:00
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "ucnv_cnv.h"
|
2000-08-14 23:56:19 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
|
2000-08-23 01:21:23 +00:00
|
|
|
#define TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS, myConverterData, err){ \
|
|
|
|
if(*err ==U_BUFFER_OVERFLOW_ERROR){ \
|
2000-10-05 02:25:53 +00:00
|
|
|
/*save the state and return */ \
|
|
|
|
args->target += myTargetIndex; \
|
|
|
|
args->source += mySourceIndex; \
|
|
|
|
myConverterData->sourceIndex = 0; \
|
|
|
|
myConverterData->targetIndex = 0; \
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS; \
|
|
|
|
return; \
|
|
|
|
} \
|
2000-08-23 01:21:23 +00:00
|
|
|
}
|
2000-08-16 19:57:24 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
#define TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex, myConverterData, err){ \
|
|
|
|
if(*err ==U_BUFFER_OVERFLOW_ERROR){ \
|
2000-10-05 02:25:53 +00:00
|
|
|
/*save the state and return */ \
|
|
|
|
args->target += myTargetIndex; \
|
|
|
|
args->source += mySourceIndex; \
|
|
|
|
myConverterData->sourceIndex = 0; \
|
|
|
|
myConverterData->targetIndex = 0; \
|
|
|
|
return; \
|
|
|
|
} \
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-09-19 01:41:17 +00:00
|
|
|
#define UCNV_SS2 "\x1B\x4E"
|
|
|
|
#define UCNV_SS3 "\x1B\x4F"
|
|
|
|
|
|
|
|
#define ESC 0x0B
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
/* for ISO-2022JP implementation*/
|
2000-08-14 23:56:19 +00:00
|
|
|
typedef enum {
|
2000-10-28 01:09:46 +00:00
|
|
|
ASCII = 0,
|
|
|
|
ISO8859_1 = 1 ,
|
|
|
|
ISO8859_7 = 2 ,
|
|
|
|
JISX201 = 3,
|
|
|
|
JISX208 = 4,
|
|
|
|
JISX212 = 5,
|
|
|
|
GB2312 =6,
|
|
|
|
KSC5601 =7,
|
|
|
|
INVALID_STATE
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
} StateEnum;
|
|
|
|
|
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
typedef enum {
|
2000-11-02 04:09:34 +00:00
|
|
|
ASCII1=0,
|
|
|
|
LATIN1,
|
|
|
|
SBCS,
|
2000-10-05 02:25:53 +00:00
|
|
|
DBCS,
|
2000-11-02 18:47:42 +00:00
|
|
|
MBCS
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-08-16 19:57:24 +00:00
|
|
|
}Cnv2022Type;
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
#define UCNV_OPTIONS_VERSION_MASK 0xf
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-19 01:41:17 +00:00
|
|
|
typedef struct{
|
2000-08-14 23:56:19 +00:00
|
|
|
UConverter *currentConverter;
|
2000-08-29 21:47:40 +00:00
|
|
|
UConverter *fromUnicodeConverter;
|
|
|
|
UBool isFirstBuffer;
|
2000-11-02 04:09:34 +00:00
|
|
|
StateEnum toUnicodeCurrentState;
|
|
|
|
StateEnum fromUnicodeCurrentState;
|
2000-11-20 23:40:14 +00:00
|
|
|
Cnv2022Type currentType;
|
2000-09-19 01:41:17 +00:00
|
|
|
int plane;
|
2000-08-14 23:56:19 +00:00
|
|
|
uint8_t escSeq2022[10];
|
2000-10-05 02:25:53 +00:00
|
|
|
UConverter* myConverterArray[9];
|
2000-08-29 21:47:40 +00:00
|
|
|
int32_t targetIndex;
|
|
|
|
int32_t sourceIndex;
|
|
|
|
UBool isEscapeAppended;
|
2000-09-19 01:41:17 +00:00
|
|
|
UBool isShiftAppended;
|
2000-10-05 02:25:53 +00:00
|
|
|
UBool isLocaleSpecified;
|
2000-10-20 02:45:38 +00:00
|
|
|
uint32_t key;
|
2000-10-28 01:09:46 +00:00
|
|
|
uint32_t version;
|
2000-11-22 02:05:29 +00:00
|
|
|
char locale[3];
|
|
|
|
char name[30];
|
2000-09-19 01:41:17 +00:00
|
|
|
}UConverterDataISO2022;
|
2000-02-05 00:19:15 +00:00
|
|
|
|
|
|
|
/* ISO-2022 ----------------------------------------------------------------- */
|
|
|
|
|
2000-08-25 23:14:10 +00:00
|
|
|
/*Forward declaration */
|
2000-07-19 00:21:29 +00:00
|
|
|
U_CFUNC void T_UConverter_fromUnicode_UTF8 (UConverterFromUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-08-25 23:14:10 +00:00
|
|
|
U_CFUNC void T_UConverter_fromUnicode_UTF8_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Protos */
|
2000-09-21 00:34:21 +00:00
|
|
|
/***************** ISO-2022 ********************************/
|
2000-08-29 21:47:40 +00:00
|
|
|
U_CFUNC void T_UConverter_toUnicode_ISO_2022(UConverterToUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
U_CFUNC void T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC (UConverterToUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
|
|
|
U_CFUNC void T_UConverter_fromUnicode_ISO_2022(UConverterFromUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
|
|
|
U_CFUNC void T_UConverter_fromUnicode_ISO_2022_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
|
|
|
U_CFUNC UChar32 T_UConverter_getNextUChar_ISO_2022 (UConverterToUnicodeArgs * args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode * err);
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/***************** ISO-2022-JP ********************************/
|
2000-10-05 02:25:53 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_JP(UConverterFromUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_JP(UConverterToUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
/***************** ISO-2022-KR ********************************/
|
2000-08-22 00:02:54 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_KR(UConverterFromUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
2000-08-25 23:14:10 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_KR(UConverterToUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/***************** ISO-2022-CN ********************************/
|
2000-09-01 00:27:09 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_CN(UConverterFromUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-09-01 00:27:09 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
2000-09-01 00:27:09 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_CN(UConverterToUnicodeArgs* args,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
#define ESC_2022 0x1B /*ESC*/
|
2000-08-16 19:57:24 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2000-11-28 23:55:10 +00:00
|
|
|
INVALID_2022 = -1, /*Doesn't correspond to a valid iso 2022 escape sequence*/
|
2000-10-05 02:25:53 +00:00
|
|
|
VALID_NON_TERMINAL_2022 = 0, /*so far corresponds to a valid iso 2022 escape sequence*/
|
|
|
|
VALID_TERMINAL_2022 = 1, /*corresponds to a valid iso 2022 escape sequence*/
|
|
|
|
VALID_MAYBE_TERMINAL_2022 = 2, /*so far matches one iso 2022 escape sequence, but by adding more characters might match another escape sequence*/
|
|
|
|
VALID_SS2_SEQUENCE=3,
|
|
|
|
VALID_SS3_SEQUENCE=4
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
} UCNV_TableStates_2022;
|
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
/*
|
2000-10-05 02:25:53 +00:00
|
|
|
* The way these state transition arrays work is:
|
|
|
|
* ex : ESC$B is the sequence for JISX208
|
|
|
|
* a) First Iteration: char is ESC
|
|
|
|
* i) Get the value of ESC from normalize_esq_chars_2022[] with int value of ESC as index
|
2000-11-20 18:08:49 +00:00
|
|
|
* int x = normalize_esq_chars_2022[27] which is equal to 1
|
2000-10-05 02:25:53 +00:00
|
|
|
* ii) Search for this value in escSeqStateTable_Key_2022[]
|
2000-11-20 18:08:49 +00:00
|
|
|
* value of x is stored at escSeqStateTable_Key_2022[0]
|
2000-10-05 02:25:53 +00:00
|
|
|
* iii) Save this index as offset
|
|
|
|
* iv) Get state of this sequence from escSeqStateTable_Value_2022[]
|
2000-11-20 18:08:49 +00:00
|
|
|
* escSeqStateTable_Value_2022[offset], which is VALID_NON_TERMINAL_2022
|
2000-10-05 02:25:53 +00:00
|
|
|
* b) Switch on this state and continue to next char
|
|
|
|
* i) Get the value of $ from normalize_esq_chars_2022[] with int value of $ as index
|
2000-11-20 18:08:49 +00:00
|
|
|
* which is normalize_esq_chars_2022[36] == 4
|
2000-10-05 02:25:53 +00:00
|
|
|
* ii) x is currently 1(from above)
|
2000-11-20 18:08:49 +00:00
|
|
|
* x<<=5 -- x is now 32
|
|
|
|
* x+=normalize_esq_chars_2022[36]
|
|
|
|
* now x is 36
|
2000-10-05 02:25:53 +00:00
|
|
|
* iii) Search for this value in escSeqStateTable_Key_2022[]
|
2000-11-20 18:08:49 +00:00
|
|
|
* value of x is stored at escSeqStateTable_Key_2022[2], so offset is 2
|
2000-10-05 02:25:53 +00:00
|
|
|
* iv) Get state of this sequence from escSeqStateTable_Value_2022[]
|
2000-11-20 18:08:49 +00:00
|
|
|
* escSeqStateTable_Value_2022[offset], which is VALID_NON_TERMINAL_2022
|
2000-10-05 02:25:53 +00:00
|
|
|
* c) Switch on this state and continue to next char
|
2000-11-08 23:16:20 +00:00
|
|
|
* i) Get the value of B from normalize_esq_chars_2022[] with int value of B as index
|
|
|
|
* ii) x is currently 36 (from above)
|
2000-11-20 18:08:49 +00:00
|
|
|
* x<<=5 -- x is now 1152
|
|
|
|
* x+=normalize_esq_chars_2022[66]
|
|
|
|
* now x is 1161
|
2000-11-08 23:16:20 +00:00
|
|
|
* iii) Search for this value in escSeqStateTable_Key_2022[]
|
2000-11-20 18:08:49 +00:00
|
|
|
* value of x is stored at escSeqStateTable_Key_2022[21], so offset is 21
|
2000-11-08 23:16:20 +00:00
|
|
|
* iv) Get state of this sequence from escSeqStateTable_Value_2022[21]
|
2000-11-20 18:08:49 +00:00
|
|
|
* escSeqStateTable_Value_2022[offset], which is VALID_TERMINAL_2022
|
2000-11-08 23:16:20 +00:00
|
|
|
* v) Get the converter name form escSeqStateTable_Result_2022[21] which is JISX208
|
2000-10-05 02:25:53 +00:00
|
|
|
*/
|
2000-08-14 23:56:19 +00:00
|
|
|
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
/*Below are the 3 arrays depicting a state transition table*/
|
|
|
|
int8_t normalize_esq_chars_2022[256] = {
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,4 ,7 ,0 ,0
|
|
|
|
,2 ,24 ,26 ,27 ,0 ,3 ,23 ,6 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,5 ,8 ,9 ,10 ,11 ,12
|
|
|
|
,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,25 ,28
|
|
|
|
,0 ,0 ,21 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,22 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
|
|
|
|
,0 ,0 ,0 ,0 ,0 ,0
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
#define MAX_STATES_2022 74
|
2000-02-05 00:19:15 +00:00
|
|
|
int32_t escSeqStateTable_Key_2022[MAX_STATES_2022] = {
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
1 ,34 ,36 ,39 ,55 ,57 ,60 ,1093 ,1096 ,1097
|
2000-09-21 00:34:21 +00:00
|
|
|
,1098 ,1099 ,1100 ,1101 ,1102 ,1103 ,1104 ,1105 ,1106 ,1109
|
|
|
|
,1154 ,1157 ,1160 ,1161 ,1176 ,1178 ,1179 ,1254 ,1257 ,1768
|
|
|
|
,1773 ,35105 ,36933 ,36936 ,36937 ,36938 ,36939 ,36940 ,36942 ,36943
|
|
|
|
,36944 ,36945 ,36946 ,36947 ,36948 ,37640 ,37642 ,37644 ,37646 ,37711
|
|
|
|
,37744 ,37745 ,37746 ,37747 ,37748 ,40133 ,40136 ,40138 ,40139 ,40140
|
|
|
|
,40141 ,1123363 ,35947624 ,35947625 ,35947626 ,35947627 ,35947629 ,35947630 ,35947631 ,35947635
|
2000-10-05 02:25:53 +00:00
|
|
|
,35947636 ,35947638
|
|
|
|
};
|
2000-11-20 18:08:49 +00:00
|
|
|
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
const char* escSeqStateTable_Result_2022[MAX_STATES_2022] = {
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"latin1" ,"latin1" ,"latin1"
|
|
|
|
,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"JISX-201" ,"JISX-201" ,"latin1" ,"latin1"
|
|
|
|
,NULL ,"JISX-208" ,"gb_2312_80-1" ,"JISX-208" ,NULL ,NULL ,NULL ,NULL ,"UTF8" ,"ISO-8859-1"
|
|
|
|
,"ISO-8859-7" ,NULL ,"ibm-955" ,"ibm-367" ,"ibm-952" ,"ibm-949" ,"JISX-212" ,"ibm-1383" ,"ibm-952" ,"ibm-964"
|
|
|
|
,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"gb_2312_80-1" ,"ibm-949" ,"ISO-IR-165" ,"CNS-11643-1992,1" ,"CNS-11643-1992,2"
|
|
|
|
,"CNS-11643-1992,3" ,"CNS-11643-1992,4" ,"CNS-11643-1992,5" ,"CNS-11643-1992,6" ,"CNS-11643-1992,7" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian"
|
|
|
|
,"UTF16_PlatformEndian" ,NULL ,"latin1" ,"ibm-912" ,"ibm-913" ,"ibm-914" ,"ibm-813" ,"ibm-1089" ,"ibm-920" ,"ibm-915"
|
|
|
|
,"ibm-915" ,"latin1"
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
2000-11-20 18:08:49 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
UCNV_TableStates_2022 escSeqStateTable_Value_2022[MAX_STATES_2022] = {
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_SS2_SEQUENCE ,VALID_SS3_SEQUENCE ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_MAYBE_TERMINAL_2022
|
2000-11-20 18:08:49 +00:00
|
|
|
,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
2000-10-05 02:25:53 +00:00
|
|
|
,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
|
|
|
};
|
2000-11-20 18:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
/*for 2022 looks ahead in the stream
|
2000-10-05 02:25:53 +00:00
|
|
|
*to determine the longest possible convertible
|
|
|
|
*data stream
|
|
|
|
*/
|
2000-09-19 01:41:17 +00:00
|
|
|
static const char* getEndOfBuffer_2022(const char** source,
|
2000-02-05 00:19:15 +00:00
|
|
|
const char* sourceLimit,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool flush);
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Type def for refactoring changeState_2022 code*/
|
2000-11-28 23:55:10 +00:00
|
|
|
typedef enum{
|
2000-11-17 03:01:23 +00:00
|
|
|
ISO_2022=0,
|
|
|
|
ISO_2022_JP=1,
|
2000-12-14 03:34:08 +00:00
|
|
|
ISO_2022_KR=2,
|
|
|
|
ISO_2022_CN=3
|
2000-11-17 03:01:23 +00:00
|
|
|
} Variant2022;
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
/*runs through a state machine to determine the escape sequence - codepage correspondance
|
2000-10-05 02:25:53 +00:00
|
|
|
*changes the pointer pointed to be _this->extraInfo
|
|
|
|
*/
|
2000-11-17 03:01:23 +00:00
|
|
|
static void changeState_2022(UConverter* _this,
|
2000-10-05 02:25:53 +00:00
|
|
|
const char** source,
|
|
|
|
const char* sourceLimit,
|
2000-11-17 03:01:23 +00:00
|
|
|
UBool flush,Variant2022 var,int* plane,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err);
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
UCNV_TableStates_2022 getKey_2022(char source,
|
2000-10-05 02:25:53 +00:00
|
|
|
int32_t* key,
|
|
|
|
int32_t* offset);
|
|
|
|
|
|
|
|
/*********** ISO 2022 Converter Protos ***********/
|
2000-11-29 01:04:03 +00:00
|
|
|
static void _ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode);
|
2000-10-05 02:25:53 +00:00
|
|
|
static void _ISO2022Close(UConverter *converter);
|
2000-12-20 21:18:46 +00:00
|
|
|
static void _ISO2022Reset(UConverter *converter, UConverterResetChoice choice);
|
2000-11-27 17:40:41 +00:00
|
|
|
static const char* _ISO2022getName(const UConverter* cnv);
|
2000-11-17 03:01:23 +00:00
|
|
|
|
|
|
|
/************ protos of functions for setting the initial state *********************/
|
|
|
|
static void setInitialStateToUnicodeJPCN(UConverter* converter,UConverterDataISO2022 *myConverterData);
|
|
|
|
static void setInitialStateFromUnicodeJPCN(UConverterDataISO2022 *myConverterData);
|
|
|
|
static void setInitialStateToUnicodeKR(UConverter* converter,UConverterDataISO2022 *myConverterData);
|
|
|
|
static void setInitialStateFromUnicodeKR(UConverter* converter,UConverterDataISO2022 *myConverterData);
|
|
|
|
|
|
|
|
/*************** Converter implemenations ******************/
|
2000-11-22 02:05:29 +00:00
|
|
|
static const UConverterImpl _ISO2022Impl={
|
2000-10-05 02:25:53 +00:00
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
T_UConverter_toUnicode_ISO_2022,
|
|
|
|
T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC,
|
|
|
|
T_UConverter_fromUnicode_ISO_2022,
|
|
|
|
T_UConverter_fromUnicode_ISO_2022_OFFSETS_LOGIC,
|
|
|
|
T_UConverter_getNextUChar_ISO_2022,
|
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
NULL,
|
|
|
|
_ISO2022getName
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const UConverterStaticData _ISO2022StaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
2000-11-22 02:05:29 +00:00
|
|
|
"ISO_2022",
|
|
|
|
2022,
|
|
|
|
UCNV_IBM,
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{ 0x1a, 0, 0, 0 },
|
|
|
|
1,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
2000-12-19 23:07:50 +00:00
|
|
|
0,
|
|
|
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const UConverterSharedData _ISO2022Data={
|
2000-11-22 02:05:29 +00:00
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022StaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022Impl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************JP****************/
|
|
|
|
static const UConverterImpl _ISO2022JPImpl={
|
|
|
|
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
UConverter_toUnicode_ISO_2022_JP,
|
|
|
|
UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_JP,
|
|
|
|
UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC,
|
2000-12-19 00:29:27 +00:00
|
|
|
NULL,
|
2000-11-22 02:05:29 +00:00
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName
|
|
|
|
};
|
|
|
|
const UConverterSharedData _ISO2022JPData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022StaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022JPImpl,
|
|
|
|
0
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
2000-11-22 02:05:29 +00:00
|
|
|
/************* KR ***************/
|
|
|
|
static const UConverterImpl _ISO2022KRImpl={
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
UConverter_toUnicode_ISO_2022_KR,
|
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_KR,
|
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
2000-12-19 00:29:27 +00:00
|
|
|
NULL,
|
2000-11-22 02:05:29 +00:00
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName
|
|
|
|
};
|
|
|
|
|
|
|
|
const UConverterSharedData _ISO2022KRData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022StaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022KRImpl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
/*************** CN ***************/
|
|
|
|
static const UConverterImpl _ISO2022CNImpl={
|
|
|
|
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
UConverter_toUnicode_ISO_2022_CN,
|
|
|
|
UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_CN,
|
|
|
|
UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
2000-12-19 00:29:27 +00:00
|
|
|
NULL,
|
2000-11-22 02:05:29 +00:00
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName
|
|
|
|
};
|
|
|
|
const UConverterSharedData _ISO2022CNData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022StaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022CNImpl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
|
2000-11-29 01:04:03 +00:00
|
|
|
static void _ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
char myLocale[6]={' ',' ',' ',' ',' ',' '};
|
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
cnv->extraInfo = uprv_malloc (sizeof (UConverterDataISO2022));
|
|
|
|
if(cnv->extraInfo != NULL) {
|
2000-08-29 21:47:40 +00:00
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) cnv->extraInfo;
|
2000-10-05 02:25:53 +00:00
|
|
|
myConverterData->currentConverter = NULL;
|
|
|
|
myConverterData->fromUnicodeConverter = NULL;
|
|
|
|
myConverterData->plane = -1;
|
2000-10-20 02:45:38 +00:00
|
|
|
myConverterData->key =0;
|
2000-08-29 21:47:40 +00:00
|
|
|
cnv->fromUnicodeStatus =FALSE;
|
2000-10-05 02:25:53 +00:00
|
|
|
if(locale){
|
|
|
|
uprv_strcpy(myLocale,locale);
|
|
|
|
myConverterData->isLocaleSpecified = TRUE;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version= 0;
|
2000-08-14 23:56:19 +00:00
|
|
|
myConverterData->myConverterArray[0] =NULL;
|
2000-10-05 02:25:53 +00:00
|
|
|
if(myLocale[0]=='j' && (myLocale[1]=='a'|| myLocale[1]=='p') &&
|
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0')){
|
|
|
|
|
|
|
|
/* open the required converters and cache them */
|
2000-08-29 21:47:40 +00:00
|
|
|
myConverterData->myConverterArray[0]= ucnv_open("ASCII", errorCode );
|
|
|
|
myConverterData->myConverterArray[1]= ucnv_open("ISO8859_1", errorCode);
|
|
|
|
myConverterData->myConverterArray[2]= ucnv_open("ISO8859_7", errorCode);
|
|
|
|
myConverterData->myConverterArray[3]= ucnv_open("jisx-201", errorCode);
|
|
|
|
myConverterData->myConverterArray[4]= ucnv_open("jisx-208", errorCode);
|
|
|
|
myConverterData->myConverterArray[5]= ucnv_open("jisx-212", errorCode);
|
2000-10-05 02:25:53 +00:00
|
|
|
myConverterData->myConverterArray[6]= ucnv_open("gb_2312_80-1", errorCode);
|
2000-10-10 22:38:43 +00:00
|
|
|
myConverterData->myConverterArray[7]= ucnv_open("ksc_5601_1", errorCode);
|
2000-08-29 21:47:40 +00:00
|
|
|
myConverterData->myConverterArray[8]= NULL;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
/* initialize the state variables */
|
2000-11-17 03:01:23 +00:00
|
|
|
setInitialStateToUnicodeJPCN(cnv, myConverterData);
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
/*set the substitution chars*/
|
|
|
|
ucnv_setSubstChars(cnv,"\x1b\x28\x42\x1A", 4, errorCode);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
/* set the function pointers to appropriate funtions */
|
2000-11-22 02:05:29 +00:00
|
|
|
cnv->sharedData=(UConverterSharedData*)(&_ISO2022JPData);
|
|
|
|
uprv_strcpy(myConverterData->locale,"ja");
|
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=ja");
|
|
|
|
if(options){
|
2000-11-29 01:04:03 +00:00
|
|
|
switch (options & UCNV_OPTIONS_VERSION_MASK){
|
2000-11-22 02:05:29 +00:00
|
|
|
case 0:
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version = 0;
|
|
|
|
break;
|
2000-11-22 02:05:29 +00:00
|
|
|
case 1:
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version = 1;
|
2000-11-22 02:05:29 +00:00
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=ja,version=1");
|
2000-10-28 01:09:46 +00:00
|
|
|
break;
|
2000-11-22 02:05:29 +00:00
|
|
|
case 2:
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version = 2;
|
2000-11-22 02:05:29 +00:00
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=ja,version=2");
|
2000-10-28 01:51:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
myConverterData->version = 0;
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
else if(myLocale[0]=='k' && (myLocale[1]=='o'|| myLocale[1]=='r') &&
|
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0')){
|
|
|
|
|
|
|
|
/* initialize the state variables */
|
2000-11-17 03:01:23 +00:00
|
|
|
setInitialStateToUnicodeKR(cnv, myConverterData);
|
|
|
|
setInitialStateFromUnicodeKR(cnv,myConverterData);
|
|
|
|
|
2000-12-14 20:19:19 +00:00
|
|
|
myConverterData->currentConverter=myConverterData->fromUnicodeConverter = ucnv_open("ibm-949",errorCode);
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
/*set the substitution chars*/
|
|
|
|
ucnv_setSubstChars(cnv,"\x0F\x1A", 2, errorCode);
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
/* set the function pointers to appropriate funtions */
|
2000-11-22 02:05:29 +00:00
|
|
|
cnv->sharedData=(UConverterSharedData*)&_ISO2022KRData;
|
|
|
|
|
|
|
|
uprv_strcpy(myConverterData->locale,"kr");
|
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=kr");
|
|
|
|
myConverterData->version=0;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
else if((myLocale[0]=='z'|| myLocale[0]=='c') && (myLocale[1]=='h'|| myLocale[1]=='n') &&
|
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0')){
|
|
|
|
|
|
|
|
/* open the required converters and cache them */
|
2000-09-19 01:41:17 +00:00
|
|
|
myConverterData->myConverterArray[0] = ucnv_open("ASCII",errorCode);
|
2000-10-17 08:06:45 +00:00
|
|
|
myConverterData->myConverterArray[1] = ucnv_open("gb_2312_80-1",errorCode);
|
2000-09-19 01:41:17 +00:00
|
|
|
myConverterData->myConverterArray[2] = ucnv_open("ISO-IR-165",errorCode);
|
|
|
|
myConverterData->myConverterArray[3] = ucnv_open("CNS-11643-1992",errorCode);
|
|
|
|
myConverterData->myConverterArray[4] = NULL;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
/*initialize the state variables*/
|
2000-11-17 03:01:23 +00:00
|
|
|
setInitialStateToUnicodeJPCN(cnv, myConverterData);
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
ucnv_setSubstChars(cnv,"\x0F\x1A", 2, errorCode);
|
2000-11-22 02:05:29 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
/* set the function pointers to appropriate funtions */
|
2000-11-22 02:05:29 +00:00
|
|
|
cnv->sharedData=(UConverterSharedData*)&_ISO2022CNData;
|
|
|
|
uprv_strcpy(myConverterData->locale,"cn");
|
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=cn");
|
|
|
|
|
|
|
|
if(options){
|
2000-11-29 01:04:03 +00:00
|
|
|
switch (options & UCNV_OPTIONS_VERSION_MASK){
|
2000-11-22 02:05:29 +00:00
|
|
|
case 0:
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version = 0;
|
|
|
|
break;
|
2000-11-22 02:05:29 +00:00
|
|
|
case 1:
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->version = 1;
|
2000-11-22 02:05:29 +00:00
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022,locale=cn,version=1");
|
2000-10-28 01:09:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-10-28 01:51:00 +00:00
|
|
|
myConverterData->version = 0;
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
2000-08-14 23:56:19 +00:00
|
|
|
else{
|
2000-10-05 02:25:53 +00:00
|
|
|
/* append the UTF-8 escape sequence */
|
2000-08-14 23:56:19 +00:00
|
|
|
cnv->charErrorBufferLength = 3;
|
|
|
|
cnv->charErrorBuffer[0] = 0x1b;
|
|
|
|
cnv->charErrorBuffer[1] = 0x25;
|
|
|
|
cnv->charErrorBuffer[2] = 0x42;
|
2000-11-22 02:05:29 +00:00
|
|
|
|
|
|
|
cnv->sharedData=(UConverterSharedData*)&_ISO2022Data;
|
2000-10-05 02:25:53 +00:00
|
|
|
/* initialize the state variables */
|
|
|
|
myConverterData->isLocaleSpecified=FALSE;
|
2000-11-22 02:05:29 +00:00
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022");
|
2000-08-14 23:56:19 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
} else {
|
|
|
|
*errorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
static void
|
|
|
|
_ISO2022Close(UConverter *converter) {
|
2000-12-14 20:19:19 +00:00
|
|
|
UConverterDataISO2022* myData =(UConverterDataISO2022 *) (converter->extraInfo);
|
|
|
|
UConverter **array = myData->myConverterArray;
|
2000-09-19 01:41:17 +00:00
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
if (converter->extraInfo != NULL) {
|
2001-01-23 01:29:06 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
/*close the array of converter pointers and free the memory*/
|
|
|
|
while(*array!=NULL){
|
2000-12-14 20:19:19 +00:00
|
|
|
if(*array==myData->currentConverter){
|
|
|
|
myData->currentConverter=NULL;
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
ucnv_close(*array++);
|
2000-10-28 01:09:46 +00:00
|
|
|
|
|
|
|
}
|
2000-12-14 20:19:19 +00:00
|
|
|
if(myData->currentConverter){
|
|
|
|
ucnv_close(myData->currentConverter);
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
uprv_free (converter->extraInfo);
|
|
|
|
}
|
|
|
|
}
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
static void
|
2000-12-20 21:18:46 +00:00
|
|
|
_ISO2022Reset(UConverter *converter, UConverterResetChoice choice) {
|
2000-10-05 02:25:53 +00:00
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) (converter->extraInfo);
|
|
|
|
if(! myConverterData->isLocaleSpecified){
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
if (converter->mode == UCNV_SO){
|
|
|
|
ucnv_close (myConverterData->currentConverter);
|
|
|
|
myConverterData->currentConverter=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
/* re-append UTF-8 escape sequence */
|
|
|
|
converter->charErrorBufferLength = 3;
|
|
|
|
converter->charErrorBuffer[0] = 0x1b;
|
|
|
|
converter->charErrorBuffer[1] = 0x28;
|
|
|
|
converter->charErrorBuffer[2] = 0x42;
|
2000-12-19 02:28:33 +00:00
|
|
|
}
|
2000-08-14 23:56:19 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
else {
|
|
|
|
/* reset the state variables */
|
2000-12-19 02:28:33 +00:00
|
|
|
if(myConverterData->locale[0] == 'j' || myConverterData->locale[0] == 'c'){
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
setInitialStateToUnicodeJPCN(converter, myConverterData);
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
}
|
2000-12-19 02:28:33 +00:00
|
|
|
}
|
2001-01-23 01:29:06 +00:00
|
|
|
else if(myConverterData->locale[0] == 'k'){
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
setInitialStateToUnicodeKR(converter, myConverterData);
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
setInitialStateFromUnicodeKR(converter, myConverterData);
|
|
|
|
}
|
2000-12-19 02:28:33 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
2000-12-20 21:18:46 +00:00
|
|
|
|
2000-11-27 17:40:41 +00:00
|
|
|
static const char* _ISO2022getName(const UConverter* cnv){
|
2000-11-22 02:05:29 +00:00
|
|
|
if(cnv->extraInfo){
|
|
|
|
UConverterDataISO2022* myData= (UConverterDataISO2022*)cnv->extraInfo;
|
|
|
|
return myData->name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
|
|
|
|
static void setInitialStateToUnicodeJPCN(UConverter* converter,UConverterDataISO2022 *myConverterData ){
|
|
|
|
myConverterData->toUnicodeCurrentState =ASCII;
|
|
|
|
myConverterData->targetIndex = 0;
|
|
|
|
myConverterData->sourceIndex =0;
|
|
|
|
myConverterData->currentConverter = NULL;
|
|
|
|
myConverterData->isFirstBuffer = TRUE;
|
|
|
|
converter->mode = UCNV_SI;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setInitialStateFromUnicodeJPCN(UConverterDataISO2022 *myConverterData){
|
|
|
|
myConverterData->fromUnicodeCurrentState= ASCII;
|
|
|
|
myConverterData->targetIndex = 0;
|
|
|
|
myConverterData->sourceIndex =0;
|
|
|
|
myConverterData->isEscapeAppended=FALSE;
|
|
|
|
myConverterData->isShiftAppended=FALSE;
|
|
|
|
myConverterData->isLocaleSpecified=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setInitialStateToUnicodeKR(UConverter* converter, UConverterDataISO2022 *myConverterData){
|
|
|
|
|
|
|
|
myConverterData->isLocaleSpecified=TRUE;
|
|
|
|
converter->mode = UCNV_SI;
|
|
|
|
myConverterData->currentConverter = myConverterData->fromUnicodeConverter;
|
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
static void setInitialStateFromUnicodeKR(UConverter* converter,UConverterDataISO2022 *myConverterData){
|
|
|
|
/* in ISO-2022-KR the desginator sequence appears only once
|
|
|
|
* in a file so we append it only once
|
|
|
|
*/
|
|
|
|
if( converter->charErrorBufferLength==0){
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
converter->charErrorBufferLength = 4;
|
|
|
|
converter->charErrorBuffer[0] = 0x1b;
|
|
|
|
converter->charErrorBuffer[1] = 0x24;
|
|
|
|
converter->charErrorBuffer[2] = 0x29;
|
|
|
|
converter->charErrorBuffer[3] = 0x43;
|
|
|
|
}
|
|
|
|
myConverterData->isLocaleSpecified=TRUE;
|
|
|
|
myConverterData->isShiftAppended=FALSE;
|
|
|
|
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/**********************************************************************************
|
2000-10-05 02:25:53 +00:00
|
|
|
* ISO-2022 Converter
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2000-08-29 21:47:40 +00:00
|
|
|
|
|
|
|
U_CFUNC UChar32 T_UConverter_getNextUChar_ISO_2022(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2000-08-29 21:47:40 +00:00
|
|
|
const char* mySourceLimit;
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane=0; /*dummy variable*/
|
2000-08-29 21:47:40 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (args->sourceLimit < args->source){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffff;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
do{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
mySourceLimit = getEndOfBuffer_2022(&(args->source), args->sourceLimit, TRUE);
|
2000-08-29 21:47:40 +00:00
|
|
|
/*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
|
|
|
|
if (args->converter->mode == UCNV_SO) /*Already doing some conversion*/{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
return ucnv_getNextUChar(((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter,
|
|
|
|
&(args->source),
|
|
|
|
mySourceLimit,
|
|
|
|
err);
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
|
|
|
/*-Done with buffer with entire buffer
|
2000-10-05 02:25:53 +00:00
|
|
|
*-Error while converting
|
|
|
|
*/
|
2000-08-29 21:47:40 +00:00
|
|
|
changeState_2022(args->converter,
|
2000-11-20 18:08:49 +00:00
|
|
|
&(args->source),
|
2000-10-05 02:25:53 +00:00
|
|
|
args->sourceLimit,
|
|
|
|
TRUE,
|
2000-11-17 03:01:23 +00:00
|
|
|
ISO_2022,
|
|
|
|
&plane,
|
2000-10-05 02:25:53 +00:00
|
|
|
err);
|
2000-08-29 21:47:40 +00:00
|
|
|
}while(args->source < args->sourceLimit);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-07-19 00:21:29 +00:00
|
|
|
U_CFUNC void T_UConverter_fromUnicode_ISO_2022(UConverterFromUnicodeArgs *args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
|
|
|
|
T_UConverter_fromUnicode_UTF8(args, err);
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-19 00:21:29 +00:00
|
|
|
U_CFUNC void T_UConverter_fromUnicode_ISO_2022_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
char const* targetStart = args->target;
|
|
|
|
T_UConverter_fromUnicode_UTF8_OFFSETS_LOGIC(args, err);
|
|
|
|
{
|
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
int32_t len = args->target - targetStart;
|
|
|
|
int32_t i;
|
|
|
|
/* uprv_memmove(offsets+3, offsets, len); MEMMOVE SEEMS BROKEN --srl*/
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
for(i=len-1;i>=0;i--) args->offsets[i] = args->offsets[i];
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void T_UConverter_toUnicode_ISO_2022(UConverterToUnicodeArgs *args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
const char *mySourceLimit;
|
|
|
|
char const* sourceStart;
|
|
|
|
UConverter *saveThis;
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane =0 ;/*dummy variable*/
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
do{
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
/*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
|
2000-11-20 18:08:49 +00:00
|
|
|
mySourceLimit = getEndOfBuffer_2022(&(args->source), args->sourceLimit, args->flush);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
if (args->converter->mode == UCNV_SO) /*Already doing some conversion*/{
|
|
|
|
|
|
|
|
saveThis = args->converter;
|
|
|
|
args->offsets = NULL;
|
|
|
|
args->converter = ((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter;
|
|
|
|
ucnv_toUnicode(args->converter,
|
|
|
|
&args->target,
|
|
|
|
args->targetLimit,
|
|
|
|
&args->source,
|
|
|
|
mySourceLimit,
|
|
|
|
args->offsets,
|
|
|
|
args->flush,
|
|
|
|
err);
|
|
|
|
args->converter = saveThis;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
if((((UConverterDataISO2022 *)args->converter->extraInfo)->isFirstBuffer) && (args->source[0]!=(char)ESC_2022)
|
|
|
|
&& (((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter==NULL)){
|
|
|
|
|
|
|
|
|
|
|
|
saveThis = args->converter;
|
|
|
|
args->offsets = NULL;
|
|
|
|
((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter = ucnv_open("ASCII",err);
|
|
|
|
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
args->converter = ((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter;
|
|
|
|
ucnv_toUnicode(args->converter,
|
|
|
|
&args->target,
|
|
|
|
args->targetLimit,
|
|
|
|
&args->source,
|
|
|
|
mySourceLimit,
|
|
|
|
args->offsets,
|
|
|
|
args->flush,
|
|
|
|
err);
|
|
|
|
args->converter = saveThis;
|
|
|
|
args->converter->mode = UCNV_SO;
|
|
|
|
((UConverterDataISO2022*)(args->converter->extraInfo))->isFirstBuffer=FALSE;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
/*-Done with buffer with entire buffer
|
|
|
|
-Error while converting
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (U_FAILURE(*err) || (args->source == args->sourceLimit))
|
2000-09-21 00:34:21 +00:00
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
sourceStart = args->source;
|
|
|
|
changeState_2022(args->converter,
|
2000-11-20 18:08:49 +00:00
|
|
|
&(args->source),
|
2000-11-17 03:01:23 +00:00
|
|
|
args->sourceLimit,
|
|
|
|
TRUE,
|
|
|
|
ISO_2022,
|
|
|
|
&plane,
|
|
|
|
err);
|
2000-10-05 02:25:53 +00:00
|
|
|
/* args->source = sourceStart; */
|
|
|
|
|
|
|
|
|
|
|
|
}while(args->source < args->sourceLimit);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
((UConverterDataISO2022*)(args->converter->extraInfo))->isFirstBuffer=FALSE;
|
|
|
|
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
int32_t myOffset=0;
|
|
|
|
int32_t base = 0;
|
|
|
|
const char* mySourceLimit;
|
|
|
|
char const* sourceStart;
|
2001-01-23 01:29:06 +00:00
|
|
|
UConverter* saveThis;
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane =0;/*dummy variable*/
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
do{
|
2000-11-20 18:08:49 +00:00
|
|
|
mySourceLimit = getEndOfBuffer_2022(&(args->source), args->sourceLimit, args->flush);
|
2000-10-05 02:25:53 +00:00
|
|
|
/*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
|
|
|
|
|
|
|
|
if (args->converter->mode == UCNV_SO) /*Already doing some conversion*/{
|
|
|
|
const UChar* myTargetStart = args->target;
|
|
|
|
|
|
|
|
saveThis = args->converter;
|
|
|
|
args->converter = ((UConverterDataISO2022*)(saveThis->extraInfo))->currentConverter;
|
|
|
|
ucnv_toUnicode(args->converter,
|
|
|
|
&(args->target),
|
|
|
|
args->targetLimit,
|
|
|
|
&(args->source),
|
|
|
|
mySourceLimit,
|
|
|
|
args->offsets,
|
|
|
|
args->flush,
|
|
|
|
err);
|
|
|
|
|
|
|
|
args->converter = saveThis;
|
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
int32_t lim = args->target - myTargetStart;
|
|
|
|
int32_t i = 0;
|
2000-10-05 02:25:53 +00:00
|
|
|
for (i=base; i < lim;i++){
|
|
|
|
args->offsets[i] += myOffset;
|
|
|
|
}
|
2000-11-20 18:08:49 +00:00
|
|
|
base += lim;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
if(((UConverterDataISO2022 *)args->converter->extraInfo)->isFirstBuffer && args->source[0]!=ESC_2022
|
|
|
|
&& ((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter==NULL){
|
|
|
|
|
|
|
|
const UChar* myTargetStart = args->target;
|
2001-01-23 01:29:06 +00:00
|
|
|
saveThis = args->converter;
|
2000-10-05 02:25:53 +00:00
|
|
|
args->offsets = NULL;
|
|
|
|
((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter = ucnv_open("ASCII",err);
|
|
|
|
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
args->converter = ((UConverterDataISO2022*)(args->converter->extraInfo))->currentConverter;
|
|
|
|
ucnv_toUnicode(args->converter,
|
|
|
|
&args->target,
|
|
|
|
args->targetLimit,
|
|
|
|
&args->source,
|
|
|
|
mySourceLimit,
|
|
|
|
args->offsets,
|
|
|
|
args->flush,
|
|
|
|
err);
|
|
|
|
args->converter = saveThis;
|
|
|
|
args->converter->mode = UCNV_SO;
|
|
|
|
((UConverterDataISO2022*)(args->converter->extraInfo))->isFirstBuffer=FALSE;
|
2001-01-23 01:29:06 +00:00
|
|
|
/* args->converter = saveThis;*/
|
2000-10-05 02:25:53 +00:00
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
int32_t lim = args->target - myTargetStart;
|
|
|
|
int32_t i = 0;
|
2000-10-05 02:25:53 +00:00
|
|
|
for (i=base; i < lim;i++){
|
|
|
|
args->offsets[i] += myOffset;
|
|
|
|
}
|
2000-11-20 18:08:49 +00:00
|
|
|
base += lim;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
/*-Done with buffer with entire buffer
|
|
|
|
-Error while converting
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (U_FAILURE(*err) || (args->source == args->sourceLimit))
|
2000-09-21 00:34:21 +00:00
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
sourceStart = args->source;
|
|
|
|
changeState_2022(args->converter,
|
2000-11-20 18:08:49 +00:00
|
|
|
&(args->source),
|
2000-11-17 03:01:23 +00:00
|
|
|
args->sourceLimit,
|
|
|
|
TRUE,
|
|
|
|
ISO_2022,
|
|
|
|
&plane,
|
|
|
|
err);
|
2000-10-05 02:25:53 +00:00
|
|
|
myOffset += args->source - sourceStart;
|
|
|
|
|
|
|
|
}while(mySourceLimit != args->sourceLimit);
|
|
|
|
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
UCNV_TableStates_2022 getKey_2022(char c,
|
|
|
|
int32_t* key,
|
|
|
|
int32_t* offset){
|
|
|
|
int32_t togo = *key;
|
|
|
|
int32_t low = 0;
|
|
|
|
int32_t hi = MAX_STATES_2022;
|
|
|
|
int32_t oldmid=0;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (*key == 0){
|
|
|
|
togo = (int8_t)normalize_esq_chars_2022[(int)c];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
togo <<= 5;
|
|
|
|
togo += (int8_t)normalize_esq_chars_2022[(int)c];
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
while (hi != low) /*binary search*/{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
register int32_t mid = (hi+low) >> 1; /*Finds median*/
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (mid == oldmid)
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (escSeqStateTable_Key_2022[mid] > togo){
|
2000-10-05 02:25:53 +00:00
|
|
|
hi = mid;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else if (escSeqStateTable_Key_2022[mid] < togo){
|
2000-10-05 02:25:53 +00:00
|
|
|
low = mid;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else /*we found it*/{
|
2000-10-05 02:25:53 +00:00
|
|
|
*key = togo;
|
|
|
|
*offset = mid;
|
|
|
|
return escSeqStateTable_Value_2022[mid];
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
oldmid = mid;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
*key = 0;
|
|
|
|
*offset = 0;
|
|
|
|
return INVALID_2022;
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Checks the characters of the buffer against valid 2022 escape sequences
|
2000-10-05 02:25:53 +00:00
|
|
|
*if the match we return a pointer to the initial start of the sequence otherwise
|
|
|
|
*we return sourceLimit
|
|
|
|
*/
|
2000-09-21 00:34:21 +00:00
|
|
|
static const char* getEndOfBuffer_2022(const char** source,
|
2000-10-05 02:25:53 +00:00
|
|
|
const char* sourceLimit,
|
|
|
|
UBool flush){
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
const char* mySource = *source;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (*source >= sourceLimit)
|
|
|
|
return sourceLimit;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
do{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (*mySource == ESC_2022){
|
|
|
|
int8_t i;
|
|
|
|
int32_t key = 0;
|
|
|
|
int32_t offset;
|
|
|
|
UCNV_TableStates_2022 value = VALID_NON_TERMINAL_2022;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/* Kludge: I could not
|
2000-10-05 02:25:53 +00:00
|
|
|
* figure out the reason for validating an escape sequence
|
|
|
|
* twice - once here and once in changeState_2022().
|
2000-11-20 18:08:49 +00:00
|
|
|
* is it possible to have an ESC character in a ISO2022
|
|
|
|
* byte stream which is valid in a code page? Is it legal?
|
2000-10-05 02:25:53 +00:00
|
|
|
*/
|
2000-09-21 00:34:21 +00:00
|
|
|
for (i=0;
|
2000-10-05 02:25:53 +00:00
|
|
|
(mySource+i < sourceLimit)&&(value == VALID_NON_TERMINAL_2022);
|
|
|
|
i++) {
|
|
|
|
value = getKey_2022(*(mySource+i), &key, &offset);
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
if (value > 0 || *mySource==ESC_2022)
|
2000-10-05 02:25:53 +00:00
|
|
|
return mySource;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if ((value == VALID_NON_TERMINAL_2022)&&(!flush) )
|
|
|
|
return sourceLimit;
|
|
|
|
}
|
|
|
|
else if(*mySource == (char)UCNV_SI || *mySource==(char)UCNV_SO){
|
|
|
|
return mySource;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}while (mySource++ < sourceLimit);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
return sourceLimit;
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/**************************************ISO-2022-JP*************************************************/
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/************************************** IMPORTANT **************************************************
|
2001-01-02 23:12:52 +00:00
|
|
|
* The UConverter_fromUnicode_ISO2022_JP converter does not use ucnv_fromUnicode() functions for SBCS,DBCS and
|
|
|
|
* MBCS; instead, the values are obtained directly by calling _MBCSFromUChar32().
|
|
|
|
* The converter iterates over each Unicode codepoint
|
2000-10-05 02:25:53 +00:00
|
|
|
* to obtain the equivalent codepoints from the codepages supported. Since the source buffer is
|
|
|
|
* processed one char at a time it would make sense to reduce the extra processing a canned converter
|
|
|
|
* would do as far as possible.
|
|
|
|
*
|
|
|
|
* If the implementation of these macros or structure of sharedData struct change in the future, make
|
|
|
|
* sure that ISO-2022 is also changed.
|
|
|
|
***************************************************************************************************
|
|
|
|
*/
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/***************************************************************************************************
|
2000-10-05 02:25:53 +00:00
|
|
|
* Rules for ISO-2022-jp encoding
|
|
|
|
* (i) Escape sequences must be fully contained within a line they should not
|
|
|
|
* span new lines or CRs
|
|
|
|
* (ii) If the last character on a line is represented by two bytes then an ASCII or
|
|
|
|
* JIS-Roman character escape sequence should follow before the line terminates
|
|
|
|
* (iii) If the first character on the line is represented by two bytes then a two
|
|
|
|
* byte character escape sequence should precede it
|
|
|
|
* (iv) If no escape sequence is encountered then the characters are ASCII
|
|
|
|
* (v) Latin(ISO-8859-1) and Greek(ISO-8859-7) characters must be designated to G2,
|
|
|
|
* and invoked with SS2 (ESC N).
|
|
|
|
* (vi) If there is any G0 designation in text, there must be a switch to
|
|
|
|
* ASCII or to JIS X 0201-Roman before a space character (but not
|
|
|
|
* necessarily before "ESC 4/14 2/0" or "ESC N ' '") or control
|
|
|
|
* characters such as tab or CRLF.
|
|
|
|
* (vi) Supported encodings:
|
|
|
|
* ASCII, JISX201, JISX208, JISX212, GB2312, KSC5601, ISO-8859-1,ISO-8859-7
|
|
|
|
*
|
|
|
|
* source : RFC-1554
|
|
|
|
*
|
|
|
|
* JISX201, JISX208,JISX212 : new .cnv data files created
|
|
|
|
* KSC5601 : alias to ibm-949 mapping table
|
|
|
|
* GB2312 : alias to ibm-1386 mapping table
|
|
|
|
* ISO-8859-1 : Algorithmic implemented as LATIN1 case
|
|
|
|
* ISO-8859-7 : alisas to ibm-9409 mapping table
|
|
|
|
*/
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
static Cnv2022Type myConverterType[8]={
|
2000-10-28 01:09:46 +00:00
|
|
|
ASCII1,
|
2000-09-21 00:34:21 +00:00
|
|
|
LATIN1,
|
|
|
|
SBCS,
|
|
|
|
SBCS,
|
|
|
|
DBCS,
|
|
|
|
DBCS,
|
|
|
|
DBCS,
|
2000-10-10 22:38:43 +00:00
|
|
|
DBCS,
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
};
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
static StateEnum nextStateArray[3][8]= {
|
|
|
|
{JISX201,INVALID_STATE,INVALID_STATE,JISX208,ASCII,INVALID_STATE,INVALID_STATE,INVALID_STATE},
|
|
|
|
{JISX201,INVALID_STATE,INVALID_STATE,JISX208,JISX212,ASCII,INVALID_STATE,INVALID_STATE},
|
|
|
|
{ISO8859_1,ISO8859_7,JISX201,JISX208,JISX212,GB2312,KSC5601,ASCII}
|
|
|
|
};
|
2000-11-28 23:55:10 +00:00
|
|
|
static const char* escSeqChars[8] ={
|
2000-10-05 02:25:53 +00:00
|
|
|
"\x1B\x28\x42", /* <ESC>(B ASCII */
|
|
|
|
"\x1B\x2E\x41", /* <ESC>.A ISO-8859-1 */
|
|
|
|
"\x1B\x2E\x46", /* <ESC>.F ISO-8859-7 */
|
|
|
|
"\x1B\x28\x4A", /* <ESC>(J JISX-201 */
|
|
|
|
"\x1B\x24\x42", /* <ESC>$B JISX-208 */
|
|
|
|
"\x1B\x24\x28\x44", /* <ESC>$(D JISX-212 */
|
|
|
|
"\x1B\x24\x41", /* <ESC>$A GB2312 */
|
|
|
|
"\x1B\x24\x28\x43", /* <ESC>$(C KSC5601 */
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
};
|
2000-08-29 21:47:40 +00:00
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
static void concatChar(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-02 04:09:34 +00:00
|
|
|
int8_t charToAppend,UErrorCode* err,int32_t *sourceIndex);
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
static void concatEscape(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-20 18:08:49 +00:00
|
|
|
const char* strToAppend,UErrorCode* err,int len,int32_t *sourceIndex);
|
2000-08-14 23:56:19 +00:00
|
|
|
|
|
|
|
static void concatString(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-20 18:08:49 +00:00
|
|
|
const UChar32* strToAppend,UErrorCode* err,int32_t *sourceIndex);
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*
|
2000-10-05 02:25:53 +00:00
|
|
|
* The iteration over various code pages works this way:
|
|
|
|
* i) Get the currentState from myConverterData->currentState
|
|
|
|
* ii) Check if the character is mapped to a valid character in the currentState
|
|
|
|
* Yes -> a) set the initIterState to currentState
|
2000-11-20 18:08:49 +00:00
|
|
|
* b) remain in this state until an invalid character is found
|
2000-10-05 02:25:53 +00:00
|
|
|
* No -> a) go to the next code page and find the character
|
|
|
|
* iii) Before changing the state increment the current state check if the current state
|
|
|
|
* is equal to the intitIteration state
|
|
|
|
* Yes -> A character that cannot be represented in any of the supported encodings
|
2000-11-20 18:08:49 +00:00
|
|
|
* break and return a U_INVALID_CHARACTER error
|
2000-10-05 02:25:53 +00:00
|
|
|
* No -> Continue and find the character in next code page
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* TODO: Implement a priority technique where the users are allowed to set the priority of code pages
|
|
|
|
*/
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_JP(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
UChar* mySource =(UChar*)args->source;
|
2000-09-21 00:34:21 +00:00
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
UBool isEscapeAppended = FALSE;
|
|
|
|
StateEnum initIterState;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
const UChar *saveSource;
|
|
|
|
char *saveTarget;
|
|
|
|
int32_t myTargetLength = args->targetLimit - args->target;
|
|
|
|
int32_t mySourceLength = args->sourceLimit - args->source;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
UChar32 targetUniChar = missingCharMarker;
|
|
|
|
StateEnum currentState=ASCII;
|
2000-11-08 23:16:20 +00:00
|
|
|
Cnv2022Type myType =ASCII1;
|
2000-10-05 16:49:47 +00:00
|
|
|
UChar32 mySourceChar = 0x0000;
|
2000-09-21 00:34:21 +00:00
|
|
|
int iterCount = 0;
|
|
|
|
const char *escSeq = NULL;
|
|
|
|
UBool isShiftAppended = FALSE;
|
|
|
|
UBool isTargetUCharDBCS=FALSE,oldIsTargetUCharDBCS=FALSE;
|
|
|
|
isEscapeAppended =(UBool) myConverterData->isEscapeAppended;
|
|
|
|
isShiftAppended =(UBool) myConverterData->isShiftAppended;
|
|
|
|
initIterState =ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/* arguments check*/
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
initIterState = myConverterData->fromUnicodeCurrentState;
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex < myTargetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
while(mySourceIndex < mySourceLength){
|
2000-11-02 04:09:34 +00:00
|
|
|
currentState = myConverterData->fromUnicodeCurrentState;
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
2000-10-05 02:25:53 +00:00
|
|
|
myConverterData->myConverterArray[0] :
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
2000-09-21 00:34:21 +00:00
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(myTargetIndex < myTargetLength){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
myType= (Cnv2022Type) myConverterType[currentState];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/* I am handling surrogates in the begining itself so that I donot have to go through 8
|
2000-11-08 23:16:20 +00:00
|
|
|
* iterations on codepages that we support. Adapted from MBCS
|
2000-10-05 02:25:53 +00:00
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar)mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < mySourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-10-05 02:25:53 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
/*Do the conversion*/
|
2000-10-05 02:25:53 +00:00
|
|
|
if(mySourceChar == 0x0020){
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2000-10-11 00:59:29 +00:00
|
|
|
if(currentState > 2){
|
2000-11-20 18:08:49 +00:00
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength, escSeqChars[0],err,strlen(escSeqChars[0]),&mySourceIndex);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-11 00:59:29 +00:00
|
|
|
isTargetUCharDBCS=FALSE;
|
2000-10-10 22:38:43 +00:00
|
|
|
}
|
2000-10-28 01:09:46 +00:00
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&mySourceChar,err,&mySourceIndex);
|
2000-10-11 00:59:29 +00:00
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended =FALSE;
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-10-11 00:59:29 +00:00
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
/* if the source character is CR or LF then append the ASCII escape sequence*/
|
|
|
|
else if(mySourceChar== 0x000A || mySourceChar== 0x000D || mySourceChar==0x0009 || mySourceChar==0x000B){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
if((isTargetUCharDBCS || currentState==JISX201) && mySource[mySourceIndex-2]!=0x000D){
|
2000-11-20 18:08:49 +00:00
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength, escSeqChars[0],err,strlen(escSeqChars[0]),&mySourceIndex);
|
2000-09-21 00:34:21 +00:00
|
|
|
isTargetUCharDBCS=FALSE;
|
2000-11-20 18:08:49 +00:00
|
|
|
isShiftAppended =FALSE;
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended=FALSE;
|
|
|
|
myConverterData->isShiftAppended=FALSE;
|
2000-10-19 06:37:36 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&mySourceChar,err,&mySourceIndex);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(currentState==ISO8859_1 || currentState ==ISO8859_7)
|
|
|
|
isEscapeAppended =FALSE;
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
do{
|
|
|
|
switch (myType){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
case SBCS:
|
2000-12-20 20:34:23 +00:00
|
|
|
targetUniChar = (uint16_t)_MBCSSingleFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, FALSE);
|
|
|
|
/*
|
|
|
|
* If mySourceChar is unassigned, then _MBCSSingleFromUChar32() returns -1
|
|
|
|
* which becomes the same as missingCharMarker with the cast to uint16_t.
|
|
|
|
*/
|
2000-10-28 01:09:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
2001-01-02 23:12:52 +00:00
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
if(2 == _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, &value, FALSE)) {
|
|
|
|
targetUniChar = (uint16_t)value;
|
|
|
|
} else {
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-10-28 01:09:46 +00:00
|
|
|
case LATIN1:
|
|
|
|
if(mySourceChar < 0x0100){
|
|
|
|
targetUniChar = mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII1:
|
|
|
|
if(mySourceChar < 0x7f){
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
2000-10-28 01:09:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*not expected */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(targetUniChar==missingCharMarker){
|
|
|
|
isEscapeAppended = FALSE;
|
|
|
|
/* save the state */
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->fromUnicodeCurrentState=nextStateArray[myConverterData->version][currentState];
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
2000-11-02 04:09:34 +00:00
|
|
|
/* myConverterData->sourceIndex = mySourceIndex;
|
|
|
|
myConverterData->targetIndex = myTargetIndex;*/
|
|
|
|
currentState = myConverterData->fromUnicodeCurrentState;
|
2000-10-28 01:09:46 +00:00
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
2000-10-28 01:09:46 +00:00
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
|
|
|
myType= (Cnv2022Type) myConverterType[currentState];
|
|
|
|
}
|
|
|
|
|
|
|
|
}while(targetUniChar==missingCharMarker && initIterState != currentState);
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(targetUniChar!= missingCharMarker){
|
|
|
|
|
|
|
|
oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
isTargetUCharDBCS =(UBool) (targetUniChar >0x00FF);
|
|
|
|
args->converter->fromUnicodeStatus= isTargetUCharDBCS;
|
2000-11-20 18:08:49 +00:00
|
|
|
/* set the iteration state and iteration count */
|
2000-09-21 00:34:21 +00:00
|
|
|
initIterState = currentState;
|
|
|
|
iterCount =0;
|
|
|
|
/* Append the escpace sequence */
|
|
|
|
if(!isEscapeAppended){
|
|
|
|
escSeq = escSeqChars[(int)currentState];
|
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
2000-10-05 02:25:53 +00:00
|
|
|
escSeqChars[(int)currentState],
|
2000-11-02 04:09:34 +00:00
|
|
|
err,strlen(escSeqChars[(int)currentState]),&mySourceIndex);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
isEscapeAppended =TRUE;
|
|
|
|
myConverterData->isEscapeAppended=TRUE;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/* Append SSN for shifting to G2 */
|
|
|
|
if(currentState==ISO8859_1 || currentState==ISO8859_7){
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
2000-11-02 04:09:34 +00:00
|
|
|
UCNV_SS2,err,strlen(UCNV_SS2),&mySourceIndex);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-08-23 01:21:23 +00:00
|
|
|
}
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,
|
2000-10-05 02:25:53 +00:00
|
|
|
&targetUniChar,err, &mySourceIndex);
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
}/* end of end if(targetUniChar==missingCharMarker)*/
|
|
|
|
else{
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if we cannot find the character after checking all codepages
|
|
|
|
* then this is an error
|
2000-10-28 01:09:46 +00:00
|
|
|
*/
|
2000-09-21 00:34:21 +00:00
|
|
|
reason = UCNV_UNASSIGNED;
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2000-10-31 02:56:41 +00:00
|
|
|
args->converter->invalidUCharBuffer[0]=(UChar)mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidUCharLength++;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
CALLBACK:
|
|
|
|
saveSource = args->source;
|
|
|
|
saveTarget = args->target;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
args->target = (char*)myTarget + myTargetIndex;
|
|
|
|
args->source = mySource + mySourceIndex;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
args->converter->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
FromU_CALLBACK_MACRO(args->converter->fromUContext,
|
2000-10-05 02:25:53 +00:00
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
args->converter->invalidUCharLength,
|
|
|
|
(UChar32) (args->converter->invalidUCharLength == 2 ?
|
|
|
|
UTF16_GET_PAIR_VALUE(args->converter->invalidUCharBuffer[0],
|
|
|
|
args->converter->invalidUCharBuffer[1])
|
|
|
|
: args->converter->invalidUCharBuffer[0]),
|
|
|
|
reason,
|
|
|
|
err);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended=FALSE;
|
|
|
|
args->source=saveSource;
|
|
|
|
args->target=saveTarget;
|
2000-11-08 23:16:20 +00:00
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
2000-11-02 04:09:34 +00:00
|
|
|
initIterState = myConverterData->fromUnicodeCurrentState;
|
|
|
|
isTargetUCharDBCS = (UBool)(args->converter->fromUnicodeStatus);
|
|
|
|
args->converter->invalidUCharLength = 0;
|
2000-09-21 00:34:21 +00:00
|
|
|
if (U_FAILURE (*err)){
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
targetUniChar =missingCharMarker;
|
2000-09-21 00:34:21 +00:00
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
2000-08-29 21:47:40 +00:00
|
|
|
else{
|
2000-09-21 00:34:21 +00:00
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err) ){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
myConverterData->sourceIndex = 0;
|
|
|
|
myConverterData->targetIndex = 0;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
|
|
|
UChar* mySource =(UChar*)args->source;
|
|
|
|
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
UBool isEscapeAppended = FALSE;
|
|
|
|
StateEnum initIterState;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
const UChar *saveSource;
|
|
|
|
char *saveTarget;
|
|
|
|
int32_t *saveOffsets ;
|
|
|
|
int32_t myTargetLength = args->targetLimit - args->target;
|
|
|
|
int32_t mySourceLength = args->sourceLimit - args->source;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
UChar32 targetUniChar = missingCharMarker;
|
|
|
|
StateEnum currentState=ASCII;
|
2000-11-08 23:16:20 +00:00
|
|
|
Cnv2022Type myType=ASCII1;
|
2000-11-02 04:09:34 +00:00
|
|
|
UChar32 mySourceChar = 0x0000;
|
|
|
|
int iterCount = 0;
|
|
|
|
int32_t currentOffset;
|
|
|
|
const char *escSeq = NULL;
|
|
|
|
UBool isShiftAppended = FALSE;
|
|
|
|
UBool isTargetUCharDBCS=FALSE,oldIsTargetUCharDBCS=FALSE;
|
|
|
|
isEscapeAppended =(UBool) myConverterData->isEscapeAppended;
|
|
|
|
isShiftAppended =(UBool) myConverterData->isShiftAppended;
|
|
|
|
initIterState =ASCII;
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
/* arguments check*/
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
initIterState = myConverterData->fromUnicodeCurrentState;
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex < myTargetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
while(mySourceIndex < mySourceLength){
|
|
|
|
currentState = myConverterData->fromUnicodeCurrentState;
|
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
|
|
|
|
|
|
|
if(myTargetIndex < myTargetLength){
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
myType= (Cnv2022Type) myConverterType[currentState];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
/* I am handling surrogates in the begining itself so that I donot have to go through 8
|
|
|
|
* iterations on codepages that we support.
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar)mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < mySourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-11-02 04:09:34 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
/*Do the conversion*/
|
|
|
|
if(mySourceChar == 0x0020){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(currentState > 2){
|
2000-11-20 18:08:49 +00:00
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength, escSeqChars[0],err,strlen(escSeqChars[0]),&mySourceIndex);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
isTargetUCharDBCS=FALSE;
|
|
|
|
}
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&mySourceChar,err,&mySourceIndex);
|
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended =FALSE;
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-11-02 04:09:34 +00:00
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
/* if the source character is CR or LF then append the ASCII escape sequence*/
|
|
|
|
else if(mySourceChar== 0x000A || mySourceChar== 0x000D || mySourceChar==0x0009 || mySourceChar==0x000B){
|
|
|
|
|
|
|
|
if((isTargetUCharDBCS || currentState==JISX201) && mySource[mySourceIndex-2]!=0x000D){
|
2000-11-20 18:08:49 +00:00
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength, escSeqChars[0],err,strlen(escSeqChars[0]),&mySourceIndex);
|
2000-11-02 04:09:34 +00:00
|
|
|
isTargetUCharDBCS=FALSE;
|
2000-11-20 18:08:49 +00:00
|
|
|
isShiftAppended =FALSE;
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended=FALSE;
|
|
|
|
myConverterData->isShiftAppended=FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&mySourceChar,err,&mySourceIndex);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(currentState==ISO8859_1 || currentState ==ISO8859_7)
|
|
|
|
isEscapeAppended =FALSE;
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
else{
|
|
|
|
|
|
|
|
do{
|
|
|
|
switch (myType){
|
|
|
|
|
|
|
|
case SBCS:
|
2000-12-20 20:34:23 +00:00
|
|
|
targetUniChar = (uint16_t)_MBCSSingleFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, FALSE);
|
|
|
|
/*
|
|
|
|
* If mySourceChar is unassigned, then _MBCSSingleFromUChar32() returns -1
|
|
|
|
* which becomes the same as missingCharMarker with the cast to uint16_t.
|
|
|
|
*/
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
2001-01-02 23:12:52 +00:00
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
if(2 == _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, &value, FALSE)) {
|
|
|
|
targetUniChar = (uint16_t)value;
|
|
|
|
} else {
|
|
|
|
targetUniChar = missingCharMarker;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
case LATIN1:
|
|
|
|
if(mySourceChar < 0x0100){
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
break;
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
case ASCII1:
|
|
|
|
if(mySourceChar < 0x7f){
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*not expected */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(targetUniChar==missingCharMarker){
|
|
|
|
isEscapeAppended = FALSE;
|
|
|
|
/* save the state */
|
|
|
|
myConverterData->fromUnicodeCurrentState=nextStateArray[myConverterData->version][currentState];
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
|
|
|
currentState = myConverterData->fromUnicodeCurrentState;
|
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
|
|
|
myType= (Cnv2022Type) myConverterType[currentState];
|
|
|
|
}
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
}while(targetUniChar==missingCharMarker && initIterState != currentState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(targetUniChar!= missingCharMarker){
|
|
|
|
|
|
|
|
oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
isTargetUCharDBCS =(UBool) (targetUniChar >0x00FF);
|
|
|
|
args->converter->fromUnicodeStatus= isTargetUCharDBCS;
|
2000-11-20 18:08:49 +00:00
|
|
|
/* set the iteration state and iteration count */
|
2000-11-02 04:09:34 +00:00
|
|
|
initIterState = currentState;
|
|
|
|
iterCount =0;
|
|
|
|
/* Append the escpace sequence */
|
|
|
|
if(!isEscapeAppended){
|
|
|
|
escSeq = escSeqChars[(int)currentState];
|
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
|
|
|
escSeqChars[(int)currentState],
|
|
|
|
err,strlen(escSeqChars[(int)currentState]),&mySourceIndex);
|
|
|
|
|
|
|
|
isEscapeAppended =TRUE;
|
|
|
|
myConverterData->isEscapeAppended=TRUE;
|
|
|
|
|
|
|
|
/* Append SSN for shifting to G2 */
|
|
|
|
if(currentState==ISO8859_1 || currentState==ISO8859_7){
|
|
|
|
|
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
|
|
|
UCNV_SS2,err,strlen(UCNV_SS2),&mySourceIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,
|
|
|
|
&targetUniChar,err, &mySourceIndex);
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION(args,myTargetIndex, mySourceIndex, isTargetUCharDBCS,myConverterData, err);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
}/* end of end if(targetUniChar==missingCharMarker)*/
|
|
|
|
else{
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if we cannot find the character after checking all codepages
|
|
|
|
* then this is an error
|
2000-11-02 04:09:34 +00:00
|
|
|
*/
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
|
|
|
|
CALLBACK:
|
|
|
|
args->converter->invalidUCharBuffer[args->converter->invalidUCharLength++]=(UChar)mySourceChar;
|
|
|
|
currentOffset = args->offsets[myTargetIndex-1]+1;
|
|
|
|
saveSource = args->source;
|
|
|
|
saveTarget = args->target;
|
|
|
|
saveOffsets = args->offsets;
|
|
|
|
args->target = (char*)myTarget + myTargetIndex;
|
|
|
|
args->source = mySource + mySourceIndex;
|
|
|
|
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
|
|
|
myConverterData->sourceIndex = mySourceIndex;
|
|
|
|
myConverterData->targetIndex = myTargetIndex;
|
|
|
|
|
|
|
|
args->converter->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
|
|
|
|
|
|
|
|
args->offsets = args->offsets?args->offsets+myTargetIndex:0;
|
|
|
|
FromU_CALLBACK_OFFSETS_LOGIC_MACRO(args->converter->fromUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
args->converter->invalidUCharLength,
|
|
|
|
(UChar32) (args->converter->invalidUCharLength == 2 ?
|
|
|
|
UTF16_GET_PAIR_VALUE(args->converter->invalidUCharBuffer[0],
|
|
|
|
args->converter->invalidUCharBuffer[1])
|
|
|
|
: args->converter->invalidUCharBuffer[0]),
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
|
|
|
|
args->source=saveSource;
|
|
|
|
args->target=saveTarget;
|
|
|
|
args->offsets=saveOffsets;
|
|
|
|
initIterState = myConverterData->fromUnicodeCurrentState;
|
|
|
|
isTargetUCharDBCS = (UBool)(args->converter->fromUnicodeStatus);
|
2000-11-08 23:16:20 +00:00
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended=FALSE;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidUCharLength = 0;
|
2000-11-08 23:16:20 +00:00
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
2000-11-02 04:09:34 +00:00
|
|
|
if (U_FAILURE (*err)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
targetUniChar =missingCharMarker;
|
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2000-11-08 23:16:20 +00:00
|
|
|
/*If at the end of conversion we are still carrying state information
|
|
|
|
*flush is TRUE, we can deduce that the input stream is truncated
|
|
|
|
*/
|
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
myConverterData->sourceIndex = 0;
|
|
|
|
myConverterData->targetIndex = 0;
|
|
|
|
args->converter->fromUnicodeStatus = isTargetUCharDBCS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void concatString(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-20 18:08:49 +00:00
|
|
|
const UChar32* strToAppend,UErrorCode* err, int32_t *sourceIndex){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
if(*strToAppend < 0x00FF){
|
|
|
|
if( (*targetIndex)+1 >= *targetLength){
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) *strToAppend;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}else{
|
|
|
|
args->target[*targetIndex] = (unsigned char) *strToAppend;
|
|
|
|
|
|
|
|
if(args->offsets!=NULL){
|
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
|
|
|
}
|
|
|
|
(*targetIndex)++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(*targetIndex < *targetLength){
|
|
|
|
args->target[*targetIndex] =(unsigned char) (*strToAppend>>8);
|
|
|
|
if(args->offsets!=NULL){
|
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
|
|
|
}
|
|
|
|
(*targetIndex)++;
|
|
|
|
|
|
|
|
if(*targetIndex < *targetLength){
|
|
|
|
args->target[(*targetIndex)] =(unsigned char) (*strToAppend & 0x00FF);
|
|
|
|
|
|
|
|
if(args->offsets!=NULL){
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
(*targetIndex)++;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (*strToAppend & 0x00FF);
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (*strToAppend>>8);
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (*strToAppend & 0x00FF);
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
if(args->offsets!=NULL){
|
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void concatEscape(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-20 18:08:49 +00:00
|
|
|
const char* strToAppend,UErrorCode* err,int len,int32_t *sourceIndex){
|
2000-09-21 00:34:21 +00:00
|
|
|
while(len-->0){
|
|
|
|
if(*targetIndex < *targetLength){
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target[*targetIndex] = (unsigned char) *strToAppend;
|
|
|
|
if(args->offsets!=NULL){
|
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
|
|
|
}
|
|
|
|
(*targetIndex)++;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->charErrorBuffer[(int)args->converter->charErrorBufferLength++] = (unsigned char) *strToAppend;
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
strToAppend++;
|
|
|
|
}
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
static void concatChar(UConverterFromUnicodeArgs* args, int32_t *targetIndex, int32_t *targetLength,
|
2000-11-02 04:09:34 +00:00
|
|
|
int8_t charToAppend,UErrorCode* err,int32_t *sourceIndex){
|
2000-09-21 00:34:21 +00:00
|
|
|
if( *targetIndex < *targetLength){
|
|
|
|
args->target[(*targetIndex)++] = (unsigned char) charToAppend;
|
2000-11-02 04:09:34 +00:00
|
|
|
if(args->offsets!=NULL){
|
|
|
|
args->offsets[*targetIndex] = *sourceIndex-1;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}else{
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) charToAppend;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************** to unicode *******************/
|
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Recognized escape sequences are
|
|
|
|
* <ESC>(B ASCII
|
|
|
|
* <ESC>.A ISO-8859-1
|
|
|
|
* <ESC>.F ISO-8859-7
|
|
|
|
* <ESC>(J JISX-201
|
|
|
|
* <ESC>(I JISX-201
|
|
|
|
* <ESC>$B JISX-208
|
|
|
|
* <ESC>$@ JISX-208
|
|
|
|
* <ESC>$(D JISX-212
|
|
|
|
* <ESC>$A GB2312
|
|
|
|
* <ESC>$(C KSC5601
|
|
|
|
*/
|
|
|
|
static StateEnum nextStateToUnicodeJP[3][MAX_STATES_2022]= {
|
|
|
|
|
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,ASCII1
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX201 ,JISX201 ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,JISX208 ,INVALID_STATE ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2000-11-17 03:01:23 +00:00
|
|
|
,INVALID_STATE ,INVALID_STATE
|
|
|
|
},
|
2000-11-20 18:08:49 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,ASCII1
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX201 ,JISX201 ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,JISX208 ,INVALID_STATE ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX212 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2000-11-17 03:01:23 +00:00
|
|
|
,INVALID_STATE ,INVALID_STATE
|
|
|
|
},
|
2000-11-20 18:08:49 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,ASCII1
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX201 ,JISX201 ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,JISX208 ,GB2312 ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,ISO8859_1
|
|
|
|
,ISO8859_7 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,KSC5601 ,JISX212 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2000-11-17 03:01:23 +00:00
|
|
|
,INVALID_STATE ,INVALID_STATE
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
};
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_JP(UConverterToUnicodeArgs *args,
|
|
|
|
UErrorCode* err){
|
2000-11-02 18:47:42 +00:00
|
|
|
char tempBuf[2] ;
|
|
|
|
const char* pBuf;
|
2000-11-02 04:09:34 +00:00
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
2000-10-05 02:25:53 +00:00
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
2000-11-02 04:09:34 +00:00
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
2000-09-21 00:34:21 +00:00
|
|
|
UChar32 targetUniChar = 0x0000;
|
2000-11-02 04:09:34 +00:00
|
|
|
UChar mySourceChar = 0x0000;
|
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane=0; /*dummy variable*/
|
2000-11-02 18:47:42 +00:00
|
|
|
pBuf = &tempBuf[0];
|
2000-11-02 04:09:34 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(mySource< args->sourceLimit){
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(args->converter->mode==UCNV_SI){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if there are no escape sequences in the first buffer then they
|
2000-11-02 04:09:34 +00:00
|
|
|
* are assumed to be ASCII according to RFC-1554
|
|
|
|
*/
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
switch(mySourceChar){
|
|
|
|
case 0x0A:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0D:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x20:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* if we are in the middle of consuming an escape sequence
|
|
|
|
* we continue to next switch tag else we break
|
|
|
|
*/
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ESC_2022:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
|
|
|
args->sourceLimit, args->flush,ISO_2022_JP,&plane, err);
|
2000-12-14 03:34:08 +00:00
|
|
|
/* Invalid or Illegal escape sequence */
|
2000-11-02 04:09:34 +00:00
|
|
|
if(U_FAILURE(*err)){
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
switch(myConverterType[myData->toUnicodeCurrentState]){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
case ASCII1:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00 && mySourceChar < 0x7F){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
2000-12-20 20:34:23 +00:00
|
|
|
targetUniChar = _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(myData->currentConverter->sharedData, mySourceChar);
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
case DBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
else{
|
2001-01-02 23:12:52 +00:00
|
|
|
tempBuf[0] = (char) args->converter->toUnicodeStatus;
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[1] = (char) mySourceChar;
|
2001-01-02 23:12:52 +00:00
|
|
|
args->converter->toUnicodeStatus = 0;
|
|
|
|
pBuf = tempBuf;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData, &pBuf, tempBuf+2, FALSE);
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LATIN1:
|
|
|
|
if(args->converter->fromUnicodeStatus == 0x00 && mySourceChar < 0x100){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INVALID_STATE:
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-11-17 03:01:23 +00:00
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
/*not expected*/
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
if(targetUniChar < 0xfffe){
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
targetUniChar=missingCharMarker;
|
|
|
|
}
|
|
|
|
else if(targetUniChar>=0xfffe){
|
|
|
|
SAVE_STATE:
|
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
|
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
if(myConverterType[myData->toUnicodeCurrentState] > SBCS){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[0];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char) mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
ToU_CALLBACK_MACRO( args->converter->toUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
myTarget += args->target - myTarget;
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
args->converter->invalidCharLength=0;
|
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
else{
|
2000-11-02 04:09:34 +00:00
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
2000-09-21 00:34:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-11-02 04:09:34 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeJPCN(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
|
|
|
UErrorCode* err){
|
|
|
|
char tempBuf[2];
|
|
|
|
const char *mySource = ( char *) args->source;
|
2000-11-17 03:01:23 +00:00
|
|
|
UChar *myTarget = args->target;
|
2000-08-22 00:02:54 +00:00
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
2000-11-02 04:09:34 +00:00
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
2000-08-22 20:45:25 +00:00
|
|
|
UChar32 targetUniChar = 0x0000;
|
2000-11-02 04:09:34 +00:00
|
|
|
UChar mySourceChar = 0x0000;
|
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane = 0; /*dummy variable*/
|
2000-11-02 04:09:34 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(mySource< args->sourceLimit){
|
|
|
|
|
|
|
|
if(myTarget < args->targetLimit){
|
|
|
|
|
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
|
|
|
|
|
|
|
if(args->converter->mode==UCNV_SI){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if there are no escape sequences in the first buffer then they
|
2000-11-02 04:09:34 +00:00
|
|
|
* are assumed to be ASCII according to RFC-1554
|
|
|
|
*/
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(mySourceChar){
|
|
|
|
case 0x0A:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0D:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x20:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-11-02 04:09:34 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->toUnicodeCurrentState = ASCII;
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* if we are in the middle of consuming an escape sequence
|
|
|
|
* we continue to next switch tag else we break
|
|
|
|
*/
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ESC_2022:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
|
|
|
args->sourceLimit, args->flush,ISO_2022_JP,&plane, err);
|
2000-12-14 03:34:08 +00:00
|
|
|
/*Invalid or illegal escape sequence */
|
2000-11-02 04:09:34 +00:00
|
|
|
if(U_FAILURE(*err)){
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(myConverterType[myData->toUnicodeCurrentState]){
|
|
|
|
|
|
|
|
case ASCII1:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00 && mySourceChar < 0x7F){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
2000-12-20 20:34:23 +00:00
|
|
|
targetUniChar = _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(myData->currentConverter->sharedData, mySourceChar);
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
2001-01-02 23:12:52 +00:00
|
|
|
const char *pBuf;
|
|
|
|
|
|
|
|
tempBuf[0] = (char) args->converter->toUnicodeStatus;
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[1] = (char) mySourceChar;
|
2001-01-02 23:12:52 +00:00
|
|
|
args->converter->toUnicodeStatus = 0;
|
|
|
|
pBuf = tempBuf;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData, &pBuf, tempBuf+2, FALSE);
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LATIN1:
|
|
|
|
if(args->converter->fromUnicodeStatus == 0x00 && mySourceChar < 0x100){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INVALID_STATE:
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-11-17 03:01:23 +00:00
|
|
|
default:
|
|
|
|
/* For non-valid state MBCS and others */
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
if(targetUniChar < 0xfffe){
|
2000-11-17 03:01:23 +00:00
|
|
|
if(myConverterType[myData->toUnicodeCurrentState] > SBCS ){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source -2;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source - 1;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
targetUniChar=missingCharMarker;
|
|
|
|
}
|
2001-01-02 23:12:52 +00:00
|
|
|
else{
|
2000-11-02 04:09:34 +00:00
|
|
|
SAVE_STATE:
|
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
|
|
|
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
int32_t currentOffset ;
|
|
|
|
int32_t My_i = myTarget - args->target;
|
2000-11-17 03:01:23 +00:00
|
|
|
if(myConverterType[myData->toUnicodeCurrentState] > SBCS){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source - 2;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[0];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -1;
|
2000-11-17 03:01:23 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] =(char) mySourceChar;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
args->offsets = args->offsets?args->offsets+(myTarget - args->target):0;
|
|
|
|
args->target =myTarget;
|
|
|
|
myTarget =saveTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
ToU_CALLBACK_OFFSETS_LOGIC_MACRO( args->converter->toUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
args->converter->invalidCharLength=0;
|
|
|
|
myTarget=args->target;
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
/*args->offsets = saveOffsets;*/
|
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-11-02 04:09:34 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeJPCN(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* Rules for ISO-2022-KR encoding
|
|
|
|
* i) The KSC5601 designator sequence should appear only once in a file,
|
|
|
|
* at the begining of a line before any KSC5601 characters. This usually
|
|
|
|
* means that it appears by itself on the first line of the file
|
|
|
|
* ii) There are only 2 shifting sequences SO to shift into double byte mode
|
|
|
|
* and SI to shift into single byte mode
|
|
|
|
*/
|
|
|
|
const char* getEndOfBuffer_2022_KR(UConverterToUnicodeArgs* args, UErrorCode* err);
|
|
|
|
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_KR(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
|
|
|
|
|
|
|
const UChar *mySource = args->source;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
int32_t targetLength = args->targetLimit - args->target;
|
|
|
|
int32_t sourceLength = args->sourceLimit - args->source;
|
|
|
|
int32_t length=0;
|
2000-11-28 23:55:10 +00:00
|
|
|
uint32_t targetUniChar = 0x0000;
|
2000-11-08 23:16:20 +00:00
|
|
|
UChar32 mySourceChar = 0x0000;
|
2000-08-22 00:02:54 +00:00
|
|
|
UBool isTargetUCharDBCS = (UBool)args->converter->fromUnicodeStatus;
|
|
|
|
UBool oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-29 21:47:40 +00:00
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
2000-08-22 00:02:54 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex < targetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-08-22 00:02:54 +00:00
|
|
|
/*writing the char to the output stream */
|
|
|
|
while (mySourceIndex < sourceLength){
|
|
|
|
|
|
|
|
if (myTargetIndex < targetLength){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
/*Handle surrogates */
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar)mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < sourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
isTargetUCharDBCS=TRUE;
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-10-05 02:25:53 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-09-19 04:31:36 +00:00
|
|
|
length= _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData,
|
2000-11-08 23:16:20 +00:00
|
|
|
mySourceChar,&targetUniChar,args->converter->useFallback);
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-25 23:14:10 +00:00
|
|
|
/* only DBCS or SBCS characters are expected*/
|
2000-09-19 04:31:36 +00:00
|
|
|
if(length > 2 || length==0){
|
2000-08-25 23:14:10 +00:00
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
/* DB haracters with high bit set to 1 are expected */
|
|
|
|
if(((targetUniChar & 0x8080) != 0x8080)&& length==2){
|
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
isTargetUCharDBCS = (UBool)(targetUniChar>0x00FF);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
if (targetUniChar != missingCharMarker){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
if (oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isShiftAppended){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if (isTargetUCharDBCS)
|
|
|
|
args->target[myTargetIndex++] = UCNV_SO;
|
|
|
|
else
|
|
|
|
args->target[myTargetIndex++] = UCNV_SI;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
myConverterData->isShiftAppended=TRUE;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if ((!isTargetUCharDBCS)&&(myTargetIndex+1 >= targetLength)){
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (char) targetUniChar;
|
2000-09-21 00:34:21 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
else if (myTargetIndex+1 >= targetLength){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
args->converter->charErrorBuffer[0] = (char) ((targetUniChar >> 8) -0x80);
|
|
|
|
args->converter->charErrorBuffer[1] = (char)((targetUniChar & 0x00FF) -0x80);
|
2000-09-21 00:34:21 +00:00
|
|
|
args->converter->charErrorBufferLength = 2;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (!isTargetUCharDBCS){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
args->target[myTargetIndex++] = (char) targetUniChar;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->target[myTargetIndex++] = (char) ((targetUniChar >> 8) - 0x80);
|
|
|
|
if (myTargetIndex < targetLength){
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target[myTargetIndex++] = (char)((targetUniChar & 0x00FF) -0x80);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->converter->charErrorBuffer[0] = (char)((targetUniChar & 0x00FF) -0x80);
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->charErrorBufferLength = 1;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
|
|
|
CALLBACK:
|
2000-11-08 23:16:20 +00:00
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
const UChar* saveSource = args->source;
|
|
|
|
char* saveTarget = args->target;
|
2000-11-08 23:16:20 +00:00
|
|
|
int32_t *saveOffsets = args->offsets;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
isTargetUCharDBCS = oldIsTargetUCharDBCS;
|
2000-11-08 23:16:20 +00:00
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
args->converter->invalidUCharBuffer[0] = (UChar) mySourceChar;
|
|
|
|
args->converter->invalidUCharLength = 1;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
args->converter->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
|
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
FromU_CALLBACK_MACRO(args->converter->fromUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
1,
|
|
|
|
(UChar32) mySourceChar,
|
|
|
|
UCNV_UNASSIGNED,
|
|
|
|
err);
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffsets;
|
|
|
|
args->converter->invalidUCharLength = 0;
|
|
|
|
isTargetUCharDBCS=(UBool)args->converter->fromUnicodeStatus;
|
|
|
|
myConverterData->isShiftAppended =FALSE;
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
if (U_FAILURE (*err))
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
targetUniChar=missingCharMarker;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
/*If at the end of conversion we are still carrying state information
|
2000-11-17 03:01:23 +00:00
|
|
|
*flush is TRUE, we can deduce that the input stream is truncated
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == sourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == sourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeKR(args->converter,myConverterData);
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
args->converter->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
|
|
|
|
|
|
|
const UChar *mySource = args->source;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
int32_t targetLength = args->targetLimit - args->target;
|
|
|
|
int32_t sourceLength = args->sourceLimit - args->source;
|
2000-11-28 23:55:10 +00:00
|
|
|
uint32_t targetUniChar = 0x0000;
|
2000-11-02 04:09:34 +00:00
|
|
|
UChar32 mySourceChar = 0x0000;
|
|
|
|
UBool isTargetUCharDBCS = (UBool)args->converter->fromUnicodeStatus;
|
|
|
|
UBool oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
int32_t length =0;
|
|
|
|
|
|
|
|
isTargetUCharDBCS = (UBool) args->converter->fromUnicodeStatus;
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex <targetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
/*writing the char to the output stream */
|
|
|
|
while (mySourceIndex < sourceLength){
|
|
|
|
|
|
|
|
if (myTargetIndex < targetLength){
|
|
|
|
|
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
|
|
|
|
|
|
|
/*Handle surrogates */
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar) mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < sourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
isTargetUCharDBCS=TRUE;
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-11-02 04:09:34 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
length= _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData,
|
2000-11-08 23:16:20 +00:00
|
|
|
mySourceChar,&targetUniChar,args->converter->useFallback);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
/* only DBCS or SBCS characters are expected*/
|
|
|
|
if(length > 2 || length==0){
|
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
/* DB haracters with high bit set to 1 are expected */
|
|
|
|
if(((targetUniChar & 0x8080) != 0x8080)&& length==2){
|
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldIsTargetUCharDBCS = isTargetUCharDBCS;
|
|
|
|
isTargetUCharDBCS = (UBool)(targetUniChar>0x00FF);
|
|
|
|
if (targetUniChar != missingCharMarker){
|
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
if (oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isShiftAppended){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
args->offsets[myTargetIndex] = mySourceIndex-1;
|
|
|
|
|
|
|
|
if (isTargetUCharDBCS)
|
|
|
|
args->target[myTargetIndex++] = UCNV_SO;
|
|
|
|
else
|
|
|
|
args->target[myTargetIndex++] = UCNV_SI;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
myConverterData->isShiftAppended=TRUE;
|
2000-11-02 04:09:34 +00:00
|
|
|
if ((!isTargetUCharDBCS)&&(myTargetIndex+1 >= targetLength)){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
args->converter->charErrorBuffer[0] = (char) targetUniChar;
|
2000-09-21 00:34:21 +00:00
|
|
|
args->converter->charErrorBufferLength = 1;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-20 18:08:49 +00:00
|
|
|
else if (myTargetIndex+1 >= targetLength){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
args->converter->charErrorBuffer[0] = (char) ((targetUniChar >> 8)-0x80);
|
|
|
|
args->converter->charErrorBuffer[1] = (char) ((targetUniChar & 0x00FF)-0x80);
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->charErrorBufferLength = 2;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTargetUCharDBCS){
|
|
|
|
|
|
|
|
args->offsets[myTargetIndex] = mySourceIndex-1;
|
|
|
|
args->target[myTargetIndex++] = (char) targetUniChar;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->offsets[myTargetIndex] = mySourceIndex-1;
|
|
|
|
args->target[myTargetIndex++] = (char) ((targetUniChar >> 8)-0x80);
|
|
|
|
|
|
|
|
if (myTargetIndex < targetLength){
|
|
|
|
args->offsets[myTargetIndex] = mySourceIndex-1;
|
|
|
|
args->target[myTargetIndex++] = (char)((targetUniChar & 0x00FF)-0x80);
|
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->converter->charErrorBuffer[0] =(char) ((targetUniChar & 0x00FF)-0x80);
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->charErrorBufferLength = 1;
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
CALLBACK:
|
2000-11-08 23:16:20 +00:00
|
|
|
{
|
|
|
|
int32_t currentOffset = args->offsets[myTargetIndex-1]+1;
|
|
|
|
char * saveTarget = args->target;
|
|
|
|
const UChar* saveSource = args->source;
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
args->converter->invalidUCharBuffer[0] = (UChar) mySourceChar;
|
|
|
|
args->converter->invalidUCharLength = 1;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
/* Breaks out of the loop since behaviour was set to stop */
|
|
|
|
args->converter->fromUnicodeStatus = (int32_t)isTargetUCharDBCS;
|
2000-11-20 18:08:49 +00:00
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
args->offsets = args->offsets?args->offsets+myTargetIndex:0;
|
2000-11-08 23:16:20 +00:00
|
|
|
FromU_CALLBACK_OFFSETS_LOGIC_MACRO(args->converter->fromUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
1,
|
|
|
|
(UChar32)mySourceChar,
|
|
|
|
UCNV_UNASSIGNED,
|
|
|
|
err);
|
|
|
|
isTargetUCharDBCS=(UBool)args->converter->fromUnicodeStatus;
|
|
|
|
myConverterData->isShiftAppended =FALSE;
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets = saveOffsets;
|
2000-11-08 23:16:20 +00:00
|
|
|
args->converter->invalidUCharLength = 0;
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
2000-11-20 18:08:49 +00:00
|
|
|
if (U_FAILURE (*err))
|
2000-11-08 23:16:20 +00:00
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
targetUniChar=missingCharMarker;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
/*If at the end of conversion we are still carrying state information
|
|
|
|
*flush is TRUE, we can deduce that the input stream is truncated
|
|
|
|
*/
|
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == sourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == sourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeKR(args->converter,myConverterData);
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
|
|
|
|
/************************ To Unicode ***************************************/
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_KR(UConverterToUnicodeArgs *args,
|
|
|
|
UErrorCode* err){
|
|
|
|
char tempBuf[3];
|
|
|
|
const char* pBuf;
|
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
|
|
|
char *tempLimit = &tempBuf[2]+1;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
|
|
|
UChar32 targetUniChar = 0x0000;
|
|
|
|
UChar mySourceChar = 0x0000;
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane = 0; /*dummy variable*/
|
2000-10-20 02:45:38 +00:00
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
while(mySource< args->sourceLimit){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
|
|
|
|
|
|
|
switch(mySourceChar){
|
|
|
|
|
|
|
|
case UCNV_SI:
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = SBCS;
|
2000-10-20 02:45:38 +00:00
|
|
|
continue;
|
|
|
|
case UCNV_SO:
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = DBCS;
|
2000-10-20 02:45:38 +00:00
|
|
|
/*consume the source */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ESC_2022:
|
|
|
|
{
|
|
|
|
/* Already doing some conversion and found escape Sequence*/
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->mode == UCNV_SO){
|
2000-10-20 02:45:38 +00:00
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
2000-12-14 03:34:08 +00:00
|
|
|
args->sourceLimit, args->flush,ISO_2022_KR,&plane, err);
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType==DBCS){
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[0] = (char) (args->converter->toUnicodeStatus+0x80) ;
|
|
|
|
tempBuf[1] = (char) (mySourceChar+0x80);
|
2000-11-02 04:09:34 +00:00
|
|
|
mySourceChar= (UChar)(((args->converter->toUnicodeStatus << 8)+0x80) | ((mySourceChar & 0x00ff)+0x80));
|
2000-10-20 02:45:38 +00:00
|
|
|
args->converter->toUnicodeStatus =0x00;
|
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[2]+1;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->fromUnicodeConverter->sharedData,
|
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->fromUnicodeStatus == 0x00){
|
|
|
|
tempBuf[0] = (char) mySourceChar;
|
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[1];
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->fromUnicodeConverter->sharedData,
|
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
if(targetUniChar < 0xfffe){
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
else if(targetUniChar>=0xfffe){
|
|
|
|
SAVE_STATE:
|
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
|
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType== DBCS){
|
2000-11-17 03:01:23 +00:00
|
|
|
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[0]-0x80);
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[1]-0x80);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)mySourceChar;
|
|
|
|
}
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
ToU_CALLBACK_MACRO( args->converter->toUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
2000-11-20 18:08:49 +00:00
|
|
|
args->source = saveSource;
|
2000-11-02 04:09:34 +00:00
|
|
|
myTarget = args->target;
|
2000-11-20 18:08:49 +00:00
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffsets;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharLength=0;
|
2000-10-20 02:45:38 +00:00
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-10-20 02:45:38 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeKR(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
|
|
|
UErrorCode* err){
|
2000-11-02 04:09:34 +00:00
|
|
|
char tempBuf[3];
|
2000-10-20 02:45:38 +00:00
|
|
|
const char* pBuf;
|
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
|
|
|
char *tempLimit = &tempBuf[2]+1;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
|
|
|
UChar32 targetUniChar = 0x0000;
|
|
|
|
UChar mySourceChar = 0x0000;
|
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-11-17 03:01:23 +00:00
|
|
|
int plane =0; /*dummy variable */
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
while(mySource< args->sourceLimit){
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
|
|
|
|
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
|
|
|
|
|
|
|
switch(mySourceChar){
|
|
|
|
|
|
|
|
case UCNV_SI:
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = SBCS;
|
2000-10-20 02:45:38 +00:00
|
|
|
continue;
|
|
|
|
case UCNV_SO:
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType =DBCS;
|
2000-10-20 02:45:38 +00:00
|
|
|
/*consume the source */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* If we are in the process of consuming an escape sequence
|
|
|
|
* we fall through execute the the statements of next switch
|
|
|
|
* tag else we break;
|
|
|
|
*/
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ESC_2022:
|
|
|
|
{
|
|
|
|
/* Already doing some conversion and found escape Sequence*/
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->mode == UCNV_SO){
|
2000-10-20 02:45:38 +00:00
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
2000-12-14 03:34:08 +00:00
|
|
|
args->sourceLimit, args->flush,ISO_2022_KR,&plane, err);
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType==DBCS){
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[0] = (char) (args->converter->toUnicodeStatus+0x80) ;
|
|
|
|
tempBuf[1] = (char) (mySourceChar+0x80);
|
2000-11-02 04:09:34 +00:00
|
|
|
mySourceChar= (UChar)(((args->converter->toUnicodeStatus+0x80) << 8) | ((mySourceChar & 0x00ff)+0x80));
|
2000-10-20 02:45:38 +00:00
|
|
|
args->converter->toUnicodeStatus =0x00;
|
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[2]+1;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->fromUnicodeConverter->sharedData,
|
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(args->converter->fromUnicodeStatus == 0x00){
|
|
|
|
tempBuf[0] = (char) mySourceChar;
|
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[1];
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData,
|
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-08-22 00:02:54 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
if(targetUniChar < 0xfffe){
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType==DBCS){
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source - 2;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source - 1;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
}
|
|
|
|
else if(targetUniChar>=0xfffe){
|
|
|
|
SAVE_STATE:
|
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
UConverterCallbackReason reason;
|
2000-11-02 04:09:34 +00:00
|
|
|
int32_t currentOffset ;
|
|
|
|
int32_t My_i = myTarget - args->target;
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType== DBCS){
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[0]-0x80);
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[1]-0x80);
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -2;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)mySourceChar;
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -1;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
args->offsets = args->offsets?args->offsets+(myTarget - args->target):0;
|
2000-10-20 02:45:38 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
2000-11-02 04:09:34 +00:00
|
|
|
myTarget = saveTarget;
|
|
|
|
ToU_CALLBACK_OFFSETS_LOGIC_MACRO( args->converter->toUContext,
|
2000-10-20 02:45:38 +00:00
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharLength=0;
|
2000-11-20 18:08:49 +00:00
|
|
|
args->source = saveSource;
|
2000-11-02 04:09:34 +00:00
|
|
|
myTarget = args->target;
|
2000-11-20 18:08:49 +00:00
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffsets;
|
2000-10-20 02:45:38 +00:00
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-10-20 02:45:38 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeKR(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
/*************************** END ISO2022-KR *********************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************** ISO-2022-CN *********************************
|
|
|
|
*
|
|
|
|
* Rules for ISO-2022-CN Encoding:
|
|
|
|
* i) The desinator sequence must appear once on a line before any instance
|
|
|
|
* of character set it designates.
|
|
|
|
* ii) If two lines contain characters from the same character set, both lines
|
|
|
|
* must include the designator sequence.
|
|
|
|
* iii) Once the designator sequence is know, a shifting sequnce has to found
|
|
|
|
* to invoke the shifting
|
|
|
|
* iv) All lines start in ASCII and end in ASCII.
|
|
|
|
* v) Four shifting sequences are employed for this purpose:
|
|
|
|
*
|
|
|
|
* Sequcence ASCII Eq Charsets
|
|
|
|
* ---------- ------- ---------
|
2000-11-20 18:08:49 +00:00
|
|
|
* SS2 <ESC>N CNS-11643-1992 Planes 3-7
|
|
|
|
* SS3 <ESC>O CNS-11643-1992 Plane 2
|
|
|
|
* SI <SI>
|
|
|
|
* SO <SO> CNS-11643-1992 Plane 1, GB2312,ISO-IR-165
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* vi)
|
|
|
|
* SOdesignator : ESC "$" ")" finalchar_for_SO
|
|
|
|
* SS2designator : ESC "$" "*" finalchar_for_SS2
|
|
|
|
* SS3designator : ESC "$" "+" finalchar_for_SS3
|
|
|
|
*
|
|
|
|
* ESC $ ) A Indicates the bytes following SO are Chinese
|
2000-11-20 18:08:49 +00:00
|
|
|
* characters as defined in GB 2312-80, until
|
|
|
|
* another SOdesignation appears
|
|
|
|
*
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ ) E Indicates the bytes following SO are as defined
|
2000-11-20 18:08:49 +00:00
|
|
|
* in ISO-IR-165 (for details, see section 2.1),
|
|
|
|
* until another SOdesignation appears
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ ) G Indicates the bytes following SO are as defined
|
2000-11-20 18:08:49 +00:00
|
|
|
* in CNS 11643-plane-1, until another
|
|
|
|
* SOdesignation appears
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ * H Indicates the two bytes immediately following
|
2000-11-20 18:08:49 +00:00
|
|
|
* SS2 is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-2, until another SS2designation
|
|
|
|
* appears
|
|
|
|
* (Meaning <ESC>N must preceed every 2 byte
|
|
|
|
* sequence.)
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ + I Indicates the immediate two bytes following SS3
|
2000-11-20 18:08:49 +00:00
|
|
|
* is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-3, until another SS3designation
|
|
|
|
* appears
|
|
|
|
* (Meaning <ESC>O must preceed every 2 byte
|
|
|
|
* sequence.)
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ + J Indicates the immediate two bytes following SS3
|
2000-11-20 18:08:49 +00:00
|
|
|
* is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-4, until another SS3designation
|
|
|
|
* appears
|
|
|
|
* (In English: <ESC>N must preceed every 2 byte
|
|
|
|
* sequence.)
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ + K Indicates the immediate two bytes following SS3
|
2000-11-20 18:08:49 +00:00
|
|
|
* is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-5, until another SS3designation
|
|
|
|
* appears
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ + L Indicates the immediate two bytes following SS3
|
2000-11-20 18:08:49 +00:00
|
|
|
* is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-6, until another SS3designation
|
|
|
|
* appears
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* ESC $ + M Indicates the immediate two bytes following SS3
|
2000-11-20 18:08:49 +00:00
|
|
|
* is a Chinese character as defined in CNS
|
|
|
|
* 11643-plane-7, until another SS3designation
|
|
|
|
* appears
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
|
|
|
* As in ISO-2022-CN, each line starts in ASCII, and ends in ASCII, and
|
|
|
|
* has its own designation information before any Chinese characters
|
|
|
|
* appear
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/********************** ISO2022-CN Data **************************/
|
|
|
|
static const char* escSeqCharsCN[10] ={
|
|
|
|
"\x0F", /* ASCII */
|
|
|
|
"\x1B\x24\x29\x41", /* GB 2312-80 */
|
|
|
|
"\x1B\x24\x29\x45", /* ISO-IR-165 */
|
|
|
|
"\x1B\x24\x29\x47", /* CNS 11643-1992 Plane 1 */
|
|
|
|
"\x1B\x24\x2A\x48", /* CNS 11643-1992 Plane 2 */
|
|
|
|
"\x1B\x24\x2B\x49", /* CNS 11643-1992 Plane 3 */
|
|
|
|
"\x1B\x24\x2B\x4A", /* CNS 11643-1992 Plane 4 */
|
|
|
|
"\x1B\x24\x2B\x4B", /* CNS 11643-1992 Plane 5 */
|
|
|
|
"\x1B\x24\x2B\x4C", /* CNS 11643-1992 Plane 6 */
|
|
|
|
"\x1B\x24\x2B\x4D" /* CNS 11643-1992 Plane 7 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* shiftSeqCharsCN[10] ={
|
|
|
|
"",
|
|
|
|
(const char*) "\x0E",
|
|
|
|
(const char*) "\x0E",
|
|
|
|
(const char*) "\x0E",
|
|
|
|
(const char*) UCNV_SS2,
|
|
|
|
(const char*) UCNV_SS3,
|
|
|
|
(const char*) UCNV_SS3,
|
|
|
|
(const char*) UCNV_SS3,
|
|
|
|
(const char*) UCNV_SS3,
|
|
|
|
(const char*) UCNV_SS3
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ASCII_1=0,
|
|
|
|
GB2312_1=1,
|
|
|
|
ISO_IR_165=2,
|
|
|
|
CNS_11643=3
|
|
|
|
} StateEnumCN;
|
|
|
|
|
|
|
|
static Cnv2022Type myConverterTypeCN[4]={
|
2000-11-08 23:16:20 +00:00
|
|
|
ASCII1,
|
2000-11-02 04:09:34 +00:00
|
|
|
DBCS,
|
|
|
|
DBCS,
|
|
|
|
MBCS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_CN(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
|
|
|
|
|
|
|
UChar* mySource =(UChar*)args->source;
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
UBool isEscapeAppended = FALSE;
|
|
|
|
StateEnumCN initIterState;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
const UChar *saveSource;
|
|
|
|
uint32_t targetValue=0;
|
|
|
|
char *saveTarget;
|
|
|
|
int32_t myTargetLength = args->targetLimit - args->target;
|
|
|
|
int32_t mySourceLength = args->sourceLimit - args->source;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
int32_t length =0;
|
|
|
|
int plane = 0;
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
UChar32 targetUniChar = missingCharMarker;
|
|
|
|
|
|
|
|
StateEnumCN currentState=ASCII;
|
|
|
|
|
|
|
|
UChar32 mySourceChar = 0x0000;
|
|
|
|
int iterCount = 0;
|
|
|
|
const char *escSeq = NULL;
|
|
|
|
UBool isShiftAppended = FALSE;
|
|
|
|
|
|
|
|
isEscapeAppended =(UBool) myConverterData->isEscapeAppended;
|
|
|
|
isShiftAppended =(UBool) myConverterData->isShiftAppended;
|
2000-11-29 01:04:03 +00:00
|
|
|
initIterState = (StateEnumCN)myConverterData->fromUnicodeCurrentState;
|
2000-11-02 04:09:34 +00:00
|
|
|
/* arguments check*/
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex < myTargetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
while(mySourceIndex < mySourceLength){
|
|
|
|
currentState =(StateEnumCN) myConverterData->fromUnicodeCurrentState;
|
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
|
|
|
|
|
|
|
if(myTargetIndex < myTargetLength){
|
|
|
|
|
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
|
|
|
|
|
|
|
/* I am handling surrogates in the begining itself so that I donot have to go through 4
|
|
|
|
* iterations on codepages that we support.
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar)mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < mySourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-11-02 04:09:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-11-02 04:09:34 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if the source character is CR or LF then append the ASCII escape sequence*/
|
|
|
|
if(mySourceChar== 0x000A || mySourceChar== 0x000D){
|
|
|
|
|
|
|
|
if((int)currentState > 0 && isShiftAppended){
|
|
|
|
concatChar(args, &myTargetIndex, &myTargetLength, UCNV_SI,err,&mySourceIndex);
|
|
|
|
isShiftAppended=myConverterData->isShiftAppended=FALSE;
|
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
|
|
|
}
|
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended=FALSE;
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&targetUniChar,err,&mySourceIndex);
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
do{
|
|
|
|
switch (myConverterTypeCN[currentState]){
|
|
|
|
|
|
|
|
case DBCS:
|
|
|
|
if(( myConverterData->version) == 0 && currentState==ISO_IR_165){
|
|
|
|
targetUniChar=missingCharMarker;
|
2001-01-02 23:12:52 +00:00
|
|
|
} else {
|
|
|
|
uint32_t value;
|
|
|
|
if(2 == _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, &value, FALSE)) {
|
|
|
|
targetUniChar = (uint16_t)value;
|
|
|
|
} else {
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MBCS:
|
|
|
|
|
|
|
|
length= _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData,
|
|
|
|
mySourceChar,&targetValue,args->converter->useFallback);
|
|
|
|
|
|
|
|
targetUniChar = (UChar32) targetValue;
|
|
|
|
|
|
|
|
if(length==0){
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
|
|
|
else if(length==3){
|
2000-11-20 18:08:49 +00:00
|
|
|
uint8_t planeVal = (uint8_t) ((targetValue)>>16);
|
2000-11-02 04:09:34 +00:00
|
|
|
if(planeVal >0x80 && planeVal<0x89){
|
|
|
|
plane = (int)(planeVal - 0x80);
|
|
|
|
targetUniChar -= (planeVal<<16);
|
|
|
|
}else
|
|
|
|
plane =-1;
|
|
|
|
}
|
|
|
|
else if(length >3){
|
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
if(myConverterData->version == 0 && plane >2){
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
case ASCII1:
|
|
|
|
if(mySourceChar < 0x7f){
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
break;
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
case LATIN1:
|
2000-11-08 23:16:20 +00:00
|
|
|
/*not expected*/
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*not expected */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(targetUniChar==missingCharMarker){
|
|
|
|
iterCount = (iterCount<3)? iterCount+1 : 0;
|
2000-12-11 22:32:42 +00:00
|
|
|
myConverterData->fromUnicodeCurrentState=(StateEnum)((currentState<3)? currentState+1:0);
|
2000-11-02 04:09:34 +00:00
|
|
|
currentState =(StateEnumCN) myConverterData->fromUnicodeCurrentState;
|
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
|
|
|
targetUniChar =missingCharMarker;
|
|
|
|
isEscapeAppended = FALSE;
|
|
|
|
/* save the state */
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
myConverterData->sourceIndex = mySourceIndex;
|
|
|
|
myConverterData->targetIndex = myTargetIndex;
|
|
|
|
}
|
|
|
|
}while(targetUniChar==missingCharMarker && initIterState != currentState);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(targetUniChar!= missingCharMarker){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* set the iteration state and iteration count */
|
2000-11-02 04:09:34 +00:00
|
|
|
initIterState = currentState;
|
|
|
|
iterCount =0;
|
|
|
|
if(myConverterData->plane != plane){
|
|
|
|
isEscapeAppended=myConverterData->isEscapeAppended=FALSE;
|
|
|
|
myConverterData->plane = plane;
|
|
|
|
}
|
|
|
|
/* Append the escpace sequence */
|
|
|
|
if(!isEscapeAppended){
|
|
|
|
escSeq = (currentState==CNS_11643) ? escSeqCharsCN[(int)currentState+plane-1]:escSeqCharsCN[(int)currentState];
|
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
|
|
|
escSeq,err,strlen(escSeq),&mySourceIndex);
|
|
|
|
isEscapeAppended=myConverterData->isEscapeAppended=TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/* Append Shift Sequences */
|
|
|
|
if(currentState!=ASCII){
|
|
|
|
|
|
|
|
if(currentState!=CNS_11643 ){
|
|
|
|
if(!isShiftAppended){
|
|
|
|
concatEscape(args,&myTargetIndex,&myTargetLength,
|
|
|
|
shiftSeqCharsCN[currentState],err,
|
|
|
|
strlen(shiftSeqCharsCN[currentState]),&mySourceIndex);
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
concatEscape(args,&myTargetIndex,&myTargetLength,shiftSeqCharsCN[currentState+plane],
|
|
|
|
err,strlen(shiftSeqCharsCN[currentState+plane]),&mySourceIndex);
|
|
|
|
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended=FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,
|
|
|
|
&targetUniChar,err, &mySourceIndex);
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
}/* end of end if(targetUniChar==missingCharMarker)*/
|
|
|
|
else{
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if we cannot find the character after checking all codepages
|
|
|
|
* then this is an error
|
2000-11-02 04:09:34 +00:00
|
|
|
*/
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
args->converter->invalidUCharBuffer[0]=(UChar)mySourceChar;
|
|
|
|
args->converter->invalidUCharLength++;
|
|
|
|
|
|
|
|
CALLBACK:
|
|
|
|
saveSource = args->source;
|
|
|
|
saveTarget = args->target;
|
|
|
|
|
|
|
|
args->target = (char*)myTarget + myTargetIndex;
|
|
|
|
args->source = mySource + mySourceIndex;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
|
|
|
|
FromU_CALLBACK_MACRO(args->converter->fromUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
args->converter->invalidUCharLength,
|
|
|
|
(UChar32) (args->converter->invalidUCharLength == 2 ?
|
|
|
|
UTF16_GET_PAIR_VALUE(args->converter->invalidUCharBuffer[0],
|
|
|
|
args->converter->invalidUCharBuffer[1])
|
|
|
|
: args->converter->invalidUCharBuffer[0]),
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
args->converter->invalidUCharLength=0;
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended=FALSE;
|
|
|
|
args->source=saveSource;
|
|
|
|
args->target=saveTarget;
|
2000-11-08 23:16:20 +00:00
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
2000-11-29 01:04:03 +00:00
|
|
|
initIterState = (StateEnumCN) myConverterData->fromUnicodeCurrentState;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
if (U_FAILURE (*err)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
targetUniChar =missingCharMarker;
|
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
/*If at the end of conversion we are still carrying state information
|
2000-11-17 03:01:23 +00:00
|
|
|
*flush is TRUE, we can deduce that the input stream is truncated
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
|
|
|
myConverterData->sourceIndex = 0;
|
|
|
|
myConverterData->targetIndex = 0;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
U_CFUNC void UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
UChar* mySource =(UChar*)args->source;
|
2000-08-22 00:02:54 +00:00
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
|
|
|
UConverterCallbackReason reason;
|
2000-09-21 00:34:21 +00:00
|
|
|
UBool isEscapeAppended = FALSE;
|
|
|
|
StateEnumCN initIterState;
|
|
|
|
unsigned char *myTarget = (unsigned char *) args->target;
|
|
|
|
const UChar *saveSource;
|
|
|
|
uint32_t targetValue=0;
|
|
|
|
char *saveTarget;
|
|
|
|
int32_t *saveOffsets ;
|
|
|
|
int32_t myTargetLength = args->targetLimit - args->target;
|
|
|
|
int32_t mySourceLength = args->sourceLimit - args->source;
|
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
int32_t length =0;
|
|
|
|
int plane = 0;
|
|
|
|
UChar32 targetUniChar = missingCharMarker;
|
2000-11-02 04:09:34 +00:00
|
|
|
int32_t currentOffset=0;
|
2000-09-21 00:34:21 +00:00
|
|
|
StateEnumCN currentState=ASCII;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-05 16:49:47 +00:00
|
|
|
UChar32 mySourceChar = 0x0000;
|
2000-09-21 00:34:21 +00:00
|
|
|
int iterCount = 0;
|
|
|
|
const char *escSeq = NULL;
|
|
|
|
UBool isShiftAppended = FALSE;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
isEscapeAppended =(UBool) myConverterData->isEscapeAppended;
|
|
|
|
isShiftAppended =(UBool) myConverterData->isShiftAppended;
|
2000-11-29 01:04:03 +00:00
|
|
|
initIterState = (StateEnumCN)myConverterData->fromUnicodeCurrentState;
|
2000-09-21 00:34:21 +00:00
|
|
|
/* arguments check*/
|
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
if(args->converter->fromUSurrogateLead!=0 && myTargetIndex < myTargetLength) {
|
|
|
|
goto getTrail;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
while(mySourceIndex < mySourceLength){
|
2000-11-02 04:09:34 +00:00
|
|
|
currentState =(StateEnumCN) myConverterData->fromUnicodeCurrentState;
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
2000-10-05 02:25:53 +00:00
|
|
|
myConverterData->myConverterArray[0] :
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(myTargetIndex < myTargetLength){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
mySourceChar = (UChar) args->source[mySourceIndex++];
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
/* I am handling surrogates in the begining itself so that I donot have to go through 4
|
|
|
|
* iterations on codepages that we support.
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SURROGATE(mySourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
|
|
|
|
args->converter->fromUSurrogateLead=(UChar)mySourceChar;
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(mySourceIndex < mySourceLength) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) args->source[mySourceIndex];
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
++mySourceIndex;
|
|
|
|
mySourceChar=UTF16_GET_PAIR_VALUE(mySourceChar, trail);
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
|
|
|
/* convert this surrogate code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
2000-10-05 02:25:53 +00:00
|
|
|
reason=UCNV_ILLEGAL;
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
/* if the source character is CR or LF then append the ASCII escape sequence*/
|
2000-10-05 02:25:53 +00:00
|
|
|
if(mySourceChar== 0x000A || mySourceChar== 0x000D){
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if((int)currentState > 0 && isShiftAppended){
|
2000-11-02 04:09:34 +00:00
|
|
|
concatChar(args, &myTargetIndex, &myTargetLength, UCNV_SI,err,&mySourceIndex);
|
2000-09-21 00:34:21 +00:00
|
|
|
isShiftAppended=myConverterData->isShiftAppended=FALSE;
|
2000-10-05 02:25:53 +00:00
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended=FALSE;
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,&targetUniChar,err,&mySourceIndex);
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
2000-09-21 00:34:21 +00:00
|
|
|
|
|
|
|
continue;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
else{
|
2000-10-28 01:51:00 +00:00
|
|
|
do{
|
|
|
|
switch (myConverterTypeCN[currentState]){
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
case DBCS:
|
|
|
|
if(( myConverterData->version) == 0 && currentState==ISO_IR_165){
|
|
|
|
targetUniChar=missingCharMarker;
|
2001-01-02 23:12:52 +00:00
|
|
|
} else {
|
|
|
|
uint32_t value;
|
|
|
|
if(2 == _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData, mySourceChar, &value, FALSE)) {
|
|
|
|
targetUniChar = (uint16_t)value;
|
|
|
|
} else {
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
2000-10-28 01:51:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
case MBCS:
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
length= _MBCSFromUChar32(myConverterData->fromUnicodeConverter->sharedData,
|
|
|
|
mySourceChar,&targetValue,args->converter->useFallback);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
targetUniChar = (UChar32) targetValue;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
if(length==0){
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
|
|
|
else if(length==3){
|
2000-11-20 18:08:49 +00:00
|
|
|
uint8_t planeVal = (uint8_t) ((targetValue)>>16);
|
2000-10-28 01:51:00 +00:00
|
|
|
if(planeVal >0x80 && planeVal<0x89){
|
|
|
|
plane = (int)(planeVal - 0x80);
|
|
|
|
targetUniChar -= (planeVal<<16);
|
|
|
|
}else
|
|
|
|
plane =-1;
|
|
|
|
}
|
|
|
|
else if(length >3){
|
|
|
|
reason =UCNV_ILLEGAL;
|
|
|
|
*err =U_INVALID_CHAR_FOUND;
|
|
|
|
goto CALLBACK;
|
|
|
|
}
|
|
|
|
if(myConverterData->version == 0 && plane >2){
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
case ASCII1:
|
|
|
|
if(mySourceChar < 0x7f){
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
break;
|
|
|
|
|
2000-10-28 01:51:00 +00:00
|
|
|
case LATIN1:
|
2000-11-08 23:16:20 +00:00
|
|
|
/*not expected*/
|
|
|
|
break;
|
2000-10-28 01:51:00 +00:00
|
|
|
default:
|
|
|
|
/*not expected */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(targetUniChar==missingCharMarker){
|
|
|
|
iterCount = (iterCount<3)? iterCount+1 : 0;
|
2000-12-11 22:32:42 +00:00
|
|
|
myConverterData->fromUnicodeCurrentState=(StateEnum)((currentState<3)? currentState+1:0);
|
2000-11-02 04:09:34 +00:00
|
|
|
currentState =(StateEnumCN) myConverterData->fromUnicodeCurrentState;
|
2000-10-28 01:51:00 +00:00
|
|
|
myConverterData->fromUnicodeConverter = (myConverterData->fromUnicodeConverter == NULL) ?
|
|
|
|
myConverterData->myConverterArray[0] :
|
2000-11-02 04:09:34 +00:00
|
|
|
myConverterData->myConverterArray[(int)myConverterData->fromUnicodeCurrentState];
|
2000-10-28 01:51:00 +00:00
|
|
|
targetUniChar =missingCharMarker;
|
|
|
|
isEscapeAppended = FALSE;
|
|
|
|
/* save the state */
|
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
myConverterData->sourceIndex = mySourceIndex;
|
|
|
|
myConverterData->targetIndex = myTargetIndex;
|
|
|
|
}
|
|
|
|
}while(targetUniChar==missingCharMarker && initIterState != currentState);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(targetUniChar!= missingCharMarker){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* set the iteration state and iteration count */
|
2000-09-21 00:34:21 +00:00
|
|
|
initIterState = currentState;
|
|
|
|
iterCount =0;
|
|
|
|
if(myConverterData->plane != plane){
|
|
|
|
isEscapeAppended=myConverterData->isEscapeAppended=FALSE;
|
|
|
|
myConverterData->plane = plane;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
/* Append the escpace sequence */
|
|
|
|
if(!isEscapeAppended){
|
|
|
|
escSeq = (currentState==CNS_11643) ? escSeqCharsCN[(int)currentState+plane-1]:escSeqCharsCN[(int)currentState];
|
|
|
|
concatEscape(args, &myTargetIndex, &myTargetLength,
|
2000-11-02 04:09:34 +00:00
|
|
|
escSeq,err,strlen(escSeq),&mySourceIndex);
|
2000-09-21 00:34:21 +00:00
|
|
|
isEscapeAppended=myConverterData->isEscapeAppended=TRUE;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-19 06:37:36 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
/* Append Shift Sequences */
|
|
|
|
if(currentState!=ASCII){
|
2000-08-22 00:02:54 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(currentState!=CNS_11643 ){
|
|
|
|
if(!isShiftAppended){
|
2000-10-05 02:25:53 +00:00
|
|
|
concatEscape(args,&myTargetIndex,&myTargetLength,
|
|
|
|
shiftSeqCharsCN[currentState],err,
|
2000-11-02 04:09:34 +00:00
|
|
|
strlen(shiftSeqCharsCN[currentState]),&mySourceIndex);
|
2000-10-05 02:25:53 +00:00
|
|
|
myConverterData->isShiftAppended =isShiftAppended=TRUE;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-19 06:37:36 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-09-21 00:34:21 +00:00
|
|
|
concatEscape(args,&myTargetIndex,&myTargetLength,shiftSeqCharsCN[currentState+plane],
|
2000-11-02 04:09:34 +00:00
|
|
|
err,strlen(shiftSeqCharsCN[currentState+plane]),&mySourceIndex);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->isShiftAppended =isShiftAppended=FALSE;
|
2000-10-19 06:37:36 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
concatString(args, &myTargetIndex, &myTargetLength,
|
2000-10-05 02:25:53 +00:00
|
|
|
&targetUniChar,err, &mySourceIndex);
|
2000-11-20 18:08:49 +00:00
|
|
|
TEST_ERROR_CONDITION_CN(args,myTargetIndex, mySourceIndex,myConverterData, err);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}/* end of end if(targetUniChar==missingCharMarker)*/
|
2000-08-22 00:02:54 +00:00
|
|
|
else{
|
2000-10-28 01:51:00 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if we cannot find the character after checking all codepages
|
|
|
|
* then this is an error
|
2000-10-28 01:51:00 +00:00
|
|
|
*/
|
2000-09-21 00:34:21 +00:00
|
|
|
reason = UCNV_UNASSIGNED;
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
CALLBACK:
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidUCharBuffer[args->converter->invalidUCharLength++]=(UChar)mySourceChar;
|
|
|
|
currentOffset = args->offsets[myTargetIndex-1]+1;
|
2000-09-21 00:34:21 +00:00
|
|
|
saveSource = args->source;
|
|
|
|
saveTarget = args->target;
|
|
|
|
saveOffsets = args->offsets;
|
|
|
|
args->target = (char*)myTarget + myTargetIndex;
|
|
|
|
args->source = mySource + mySourceIndex;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->isEscapeAppended = isEscapeAppended;
|
|
|
|
myConverterData->isShiftAppended =isShiftAppended;
|
|
|
|
myConverterData->sourceIndex = mySourceIndex;
|
|
|
|
myConverterData->targetIndex = myTargetIndex;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
|
|
|
args->offsets = args->offsets?args->offsets+myTargetIndex:0;
|
|
|
|
FromU_CALLBACK_OFFSETS_LOGIC_MACRO(args->converter->fromUContext,
|
2000-10-05 02:25:53 +00:00
|
|
|
args,
|
|
|
|
args->converter->invalidUCharBuffer,
|
|
|
|
args->converter->invalidUCharLength,
|
|
|
|
(UChar32) (args->converter->invalidUCharLength == 2 ?
|
|
|
|
UTF16_GET_PAIR_VALUE(args->converter->invalidUCharBuffer[0],
|
|
|
|
args->converter->invalidUCharBuffer[1])
|
|
|
|
: args->converter->invalidUCharBuffer[0]),
|
|
|
|
reason,
|
|
|
|
err);
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidUCharLength=0;
|
|
|
|
args->source=saveSource;
|
|
|
|
args->target=saveTarget;
|
|
|
|
args->offsets=saveOffsets;
|
2000-11-29 01:04:03 +00:00
|
|
|
initIterState = (StateEnumCN)myConverterData->fromUnicodeCurrentState;
|
2000-11-08 23:16:20 +00:00
|
|
|
myConverterData->isEscapeAppended=isEscapeAppended=FALSE;
|
|
|
|
args->converter->fromUSurrogateLead=0x00;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if (U_FAILURE (*err)){
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
targetUniChar =missingCharMarker;
|
2000-09-21 00:34:21 +00:00
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
2000-08-22 00:02:54 +00:00
|
|
|
else{
|
2000-09-21 00:34:21 +00:00
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2000-11-08 23:16:20 +00:00
|
|
|
/*If at the end of conversion we are still carrying state information
|
|
|
|
*flush is TRUE, we can deduce that the input stream is truncated
|
|
|
|
*/
|
|
|
|
if (args->converter->fromUSurrogateLead !=0 && (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySourceIndex == mySourceLength) && args->flush){
|
|
|
|
setInitialStateFromUnicodeJPCN(myConverterData);
|
|
|
|
}
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*save the state and return */
|
2000-08-22 00:02:54 +00:00
|
|
|
args->target += myTargetIndex;
|
|
|
|
args->source += mySourceIndex;
|
2000-09-21 00:34:21 +00:00
|
|
|
myConverterData->sourceIndex = 0;
|
|
|
|
myConverterData->targetIndex = 0;
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-11-14 03:54:36 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*************** to unicode *******************/
|
2000-11-14 03:54:36 +00:00
|
|
|
static StateEnum nextStateToUnicodeCN[2][MAX_STATES_2022]= {
|
|
|
|
|
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2000-11-14 03:54:36 +00:00
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,GB2312_1 ,INVALID_STATE ,INVALID_STATE ,CNS_11643 ,CNS_11643
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2000-11-14 03:54:36 +00:00
|
|
|
,INVALID_STATE ,INVALID_STATE
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2000-11-20 18:08:49 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,GB2312_1 ,INVALID_STATE ,ISO_IR_165 ,CNS_11643 ,CNS_11643
|
|
|
|
,CNS_11643 ,CNS_11643 ,CNS_11643 ,CNS_11643 , CNS_11643 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2000-11-14 03:54:36 +00:00
|
|
|
,INVALID_STATE ,INVALID_STATE
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2000-08-22 00:02:54 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
static void changeState_2022(UConverter* _this,
|
2000-10-05 02:25:53 +00:00
|
|
|
const char** source,
|
|
|
|
const char* sourceLimit,
|
2000-11-17 03:01:23 +00:00
|
|
|
UBool flush,Variant2022 var,
|
|
|
|
int* plane,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2000-09-21 00:34:21 +00:00
|
|
|
UConverter* myUConverter;
|
|
|
|
UCNV_TableStates_2022 value;
|
|
|
|
UConverterDataISO2022* myData2022 = ((UConverterDataISO2022*)_this->extraInfo);
|
2000-10-20 02:45:38 +00:00
|
|
|
uint32_t key = myData2022->key;
|
2000-09-21 00:34:21 +00:00
|
|
|
const char* chosenConverterName = NULL;
|
2000-11-17 03:01:23 +00:00
|
|
|
/* const char* sourceStart =*source;*/
|
2000-09-21 00:34:21 +00:00
|
|
|
char c;
|
|
|
|
char cnvName[20];
|
|
|
|
int32_t offset;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*In case we were in the process of consuming an escape sequence
|
|
|
|
we need to reprocess it */
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
do{
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
value = getKey_2022(**source,(int32_t *) &key, &offset);
|
|
|
|
switch (value){
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_NON_TERMINAL_2022 :
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_TERMINAL_2022:
|
|
|
|
{
|
|
|
|
(*source)++;
|
|
|
|
chosenConverterName = escSeqStateTable_Result_2022[offset];
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
};
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
case INVALID_2022:
|
|
|
|
{
|
|
|
|
myData2022->key = 0;
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
return;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_SS2_SEQUENCE:
|
|
|
|
{
|
2000-09-21 00:34:21 +00:00
|
|
|
(*source)++;
|
2000-11-28 23:55:10 +00:00
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_SS3_SEQUENCE:
|
|
|
|
{
|
|
|
|
(*source)++;
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VALID_MAYBE_TERMINAL_2022:
|
|
|
|
{
|
|
|
|
const char* mySource = (*source+1);
|
|
|
|
int32_t myKey = key;
|
|
|
|
UCNV_TableStates_2022 myValue = value;
|
|
|
|
int32_t myOffset=0;
|
|
|
|
if(*mySource==ESC_2022){
|
|
|
|
while ((mySource < sourceLimit) &&
|
|
|
|
((myValue == VALID_MAYBE_TERMINAL_2022)||(myValue == VALID_NON_TERMINAL_2022))){
|
|
|
|
myValue = getKey_2022(*(mySource++), &myKey, &myOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
(*source)++;
|
|
|
|
myValue=(UCNV_TableStates_2022) 1;
|
|
|
|
myOffset = 7;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
switch (myValue){
|
|
|
|
case INVALID_2022:
|
|
|
|
{
|
|
|
|
/*Backs off*/
|
|
|
|
chosenConverterName = escSeqStateTable_Result_2022[offset];
|
|
|
|
value = VALID_TERMINAL_2022;
|
|
|
|
goto DONE;
|
|
|
|
};
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_TERMINAL_2022:
|
|
|
|
{
|
|
|
|
/*uses longer escape sequence*/
|
|
|
|
chosenConverterName = escSeqStateTable_Result_2022[myOffset];
|
|
|
|
key = 0;
|
|
|
|
value = VALID_TERMINAL_2022;
|
|
|
|
goto DONE;
|
|
|
|
};
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
/* Not expected. Added to make the gcc happy */
|
|
|
|
case VALID_SS2_SEQUENCE:
|
|
|
|
{
|
|
|
|
(*source)++;
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
/* Not expected. Added to make the gcc happy */
|
|
|
|
case VALID_SS3_SEQUENCE:
|
|
|
|
{
|
|
|
|
(*source)++;
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_NON_TERMINAL_2022:
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-28 23:55:10 +00:00
|
|
|
case VALID_MAYBE_TERMINAL_2022:
|
|
|
|
{
|
|
|
|
if (flush){
|
|
|
|
/*Backs off*/
|
|
|
|
chosenConverterName = escSeqStateTable_Result_2022[offset];
|
|
|
|
value = VALID_TERMINAL_2022;
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
key = myKey;
|
|
|
|
value = VALID_NON_TERMINAL_2022;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}while (++(*source) < sourceLimit);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
DONE:
|
2000-10-20 02:45:38 +00:00
|
|
|
myData2022->key = key;
|
2000-09-21 00:34:21 +00:00
|
|
|
if(chosenConverterName){
|
|
|
|
if(uprv_strstr(chosenConverterName,"CNS")!=NULL){
|
|
|
|
int i=0;
|
|
|
|
while((c=*chosenConverterName)!=0 && c!=UCNV_OPTION_SEP_CHAR ) {
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
cnvName[i++]=c;
|
|
|
|
++chosenConverterName;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
cnvName[i]=0;
|
|
|
|
if(c==UCNV_OPTION_SEP_CHAR){
|
|
|
|
chosenConverterName++;
|
|
|
|
*plane = atoi(chosenConverterName);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
uprv_strcpy(cnvName,chosenConverterName);
|
|
|
|
*plane=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((value == VALID_NON_TERMINAL_2022) || (value == VALID_MAYBE_TERMINAL_2022)) {
|
2000-10-05 02:25:53 +00:00
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
if (value > 0 ) {
|
|
|
|
if(value==3 || value==4 ){
|
|
|
|
_this->mode = UCNV_SI;
|
|
|
|
myUConverter =myData2022->currentConverter;
|
|
|
|
}
|
|
|
|
else{
|
2000-11-17 03:01:23 +00:00
|
|
|
switch(var){
|
|
|
|
case ISO_2022:
|
|
|
|
_this->mode = UCNV_SI;
|
|
|
|
ucnv_close(myData2022->currentConverter);
|
|
|
|
myData2022->currentConverter = myUConverter = ucnv_open(chosenConverterName, err);
|
|
|
|
break;
|
|
|
|
case ISO_2022_JP:
|
|
|
|
{
|
|
|
|
StateEnum tempState=nextStateToUnicodeJP[myData2022->version][offset];
|
|
|
|
_this->mode = UCNV_SI;
|
|
|
|
myData2022->currentConverter = myUConverter =
|
|
|
|
(tempState!=INVALID_STATE)? myData2022->myConverterArray[tempState]:NULL;
|
|
|
|
myData2022->toUnicodeCurrentState = tempState;
|
|
|
|
*err= (tempState==INVALID_STATE)?U_ILLEGAL_ESCAPE_SEQUENCE :U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISO_2022_CN:
|
|
|
|
{
|
|
|
|
StateEnumCN tempState=nextStateToUnicodeCN[myData2022->version][offset];
|
|
|
|
_this->mode = UCNV_SI;
|
|
|
|
myData2022->currentConverter = myUConverter =
|
|
|
|
(tempState!=INVALID_STATE)? myData2022->myConverterArray[tempState]:NULL;
|
2000-11-29 01:04:03 +00:00
|
|
|
myData2022->toUnicodeCurrentState =(StateEnum) tempState;
|
2000-11-17 03:01:23 +00:00
|
|
|
*err= (tempState==INVALID_STATE)?U_ILLEGAL_ESCAPE_SEQUENCE :U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
2000-12-14 03:34:08 +00:00
|
|
|
case ISO_2022_KR:
|
|
|
|
_this->mode = UCNV_SI;
|
|
|
|
myUConverter = myData2022->currentConverter=myData2022->fromUnicodeConverter;
|
|
|
|
break;
|
2000-11-20 23:40:14 +00:00
|
|
|
default:
|
|
|
|
myUConverter=NULL;
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
if (U_SUCCESS(*err)){
|
|
|
|
/*Customize the converter with the attributes set on the 2022 converter*/
|
|
|
|
myUConverter->fromUCharErrorBehaviour = _this->fromUCharErrorBehaviour;
|
|
|
|
myUConverter->fromUContext = _this->fromUContext;
|
|
|
|
myUConverter->fromCharErrorBehaviour = _this->fromCharErrorBehaviour;
|
|
|
|
myUConverter->toUContext = _this->toUContext;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
uprv_memcpy(myUConverter->subChar,
|
2000-10-05 02:25:53 +00:00
|
|
|
_this->subChar,
|
2000-11-20 18:08:49 +00:00
|
|
|
myUConverter->subCharLen = _this->subCharLen);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
_this->mode = UCNV_SO;
|
|
|
|
}
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_CN(UConverterToUnicodeArgs *args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2000-10-04 00:11:50 +00:00
|
|
|
char tempBuf[3];
|
2000-09-21 00:34:21 +00:00
|
|
|
int plane=0;
|
2000-11-02 19:51:05 +00:00
|
|
|
const char* pBuf;
|
2000-09-21 00:34:21 +00:00
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
|
|
|
char *tempLimit = &tempBuf[2]+1;
|
2000-09-19 01:41:17 +00:00
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
2000-09-21 00:34:21 +00:00
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
|
|
|
UChar32 targetUniChar = 0x0000;
|
2000-09-19 01:41:17 +00:00
|
|
|
UChar mySourceChar = 0x0000;
|
2000-09-21 00:34:21 +00:00
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-19 06:37:36 +00:00
|
|
|
plane=myData->plane;
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-19 01:41:17 +00:00
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
while(mySource< args->sourceLimit){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
|
|
|
|
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->mode==UCNV_SI){
|
|
|
|
|
2000-11-20 18:08:49 +00:00
|
|
|
/* if there are no escape sequences in the first buffer then they
|
2000-10-20 02:45:38 +00:00
|
|
|
* are assumed to be ASCII according to RFC-1922
|
|
|
|
*/
|
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-20 02:45:38 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
switch(mySourceChar){
|
2000-10-20 02:45:38 +00:00
|
|
|
case 0x0A:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-10-20 02:45:38 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-20 02:45:38 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
case 0x0D:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-10-20 02:45:38 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-20 02:45:38 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
case UCNV_SI:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-20 02:45:38 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
continue;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
case UCNV_SO:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = (plane>0) ? MBCS: DBCS;
|
2000-09-21 00:34:21 +00:00
|
|
|
continue;
|
2000-10-20 02:45:38 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* if we are in the middle of consuming an escape sequence
|
|
|
|
* we continue to next switch tag else we break
|
|
|
|
*/
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ESC_2022:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
|
|
|
args->sourceLimit, args->flush,ISO_2022_CN,&plane,err);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
myData->plane=plane;
|
|
|
|
if(plane>0){
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = MBCS;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else if(myData->currentConverter &&
|
|
|
|
uprv_stricmp("latin_1",
|
|
|
|
myData->currentConverter->sharedData->staticData->name)==0){
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType=ASCII1;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
/* illegal or invalid escape sequence */
|
2000-10-20 02:45:38 +00:00
|
|
|
if(U_FAILURE(*err)){
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
continue;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
switch(myData->currentType){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
case ASCII1:
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->fromUnicodeStatus == 0x00){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
case DBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
2001-01-02 23:12:52 +00:00
|
|
|
tempBuf[0] = (char) args->converter->toUnicodeStatus;
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[1] = (char) mySourceChar;
|
2001-01-02 23:12:52 +00:00
|
|
|
args->converter->toUnicodeStatus = 0;
|
|
|
|
pBuf = tempBuf;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData, &pBuf, tempBuf+2, FALSE);
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
case MBCS:
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
tempBuf[0] = (char)( 0x80+plane);
|
|
|
|
tempBuf[1] = (char) (args->converter->toUnicodeStatus);
|
|
|
|
tempBuf[2] = (char) (mySourceChar);
|
|
|
|
args->converter->toUnicodeStatus = 0;
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[2]+1;
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData,
|
2000-10-20 02:45:38 +00:00
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
|
|
|
}
|
|
|
|
break;
|
2000-11-28 23:55:10 +00:00
|
|
|
/* for LATIN1 and SBCS which are not expected */
|
|
|
|
default:
|
2000-10-20 02:45:38 +00:00
|
|
|
break;
|
2000-11-28 23:55:10 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
if(targetUniChar < 0xfffe){
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
}
|
|
|
|
else if(targetUniChar>=0xfffe){
|
|
|
|
SAVE_STATE:
|
2000-11-02 04:09:34 +00:00
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
|
|
|
UConverterCallbackReason reason;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
2000-11-20 23:40:14 +00:00
|
|
|
switch(myData->currentType){
|
2000-11-17 03:01:23 +00:00
|
|
|
case ASCII1:
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)mySourceChar;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[0];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MBCS:
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[2];
|
2001-01-23 01:29:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
/* There should be no other type */
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
ToU_CALLBACK_MACRO( args->converter->toUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
myTarget += args->target - myTarget;
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffsets;
|
|
|
|
args->converter->invalidCharLength=0;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-09-21 00:34:21 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-10-19 06:37:36 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeJPCN(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
}
|
2000-09-19 01:41:17 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
U_CFUNC void UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2000-10-04 00:11:50 +00:00
|
|
|
char tempBuf[3];
|
2000-09-21 00:34:21 +00:00
|
|
|
int plane=0;
|
2000-11-02 19:51:05 +00:00
|
|
|
const char* pBuf;
|
2000-09-21 00:34:21 +00:00
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
2000-10-04 00:11:50 +00:00
|
|
|
char *tempLimit = &tempBuf[3];
|
2000-09-21 00:34:21 +00:00
|
|
|
int32_t mySourceIndex = 0;
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
|
|
|
UChar32 targetUniChar = 0x0000;
|
|
|
|
UChar mySourceChar = 0x0000;
|
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
/*Arguments Check*/
|
|
|
|
if (U_FAILURE(*err))
|
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){
|
2000-10-05 02:25:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
while(mySource< args->sourceLimit){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
|
|
|
|
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
switch(mySourceChar){
|
2000-10-05 02:25:53 +00:00
|
|
|
case 0x0A:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-10-05 02:25:53 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-29 01:04:03 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-05 02:25:53 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0D:
|
2000-11-20 18:08:49 +00:00
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
2000-10-05 02:25:53 +00:00
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-29 01:04:03 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-05 02:25:53 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UCNV_SI:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
2000-11-29 01:04:03 +00:00
|
|
|
myData->currentType = ASCII1;
|
2000-10-05 02:25:53 +00:00
|
|
|
myData->plane=plane = 0;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case UCNV_SO:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = (plane>0) ? MBCS: DBCS;
|
2000-10-05 02:25:53 +00:00
|
|
|
continue;
|
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
default:
|
|
|
|
/* if we are in the middle of consuming an escape sequence
|
|
|
|
* we continue to next switch tag else we break
|
|
|
|
*/
|
|
|
|
if(myData->key==0){
|
|
|
|
break;
|
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
case ESC_2022:
|
|
|
|
if(args->converter->toUnicodeStatus != 0x00){
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
mySource--;
|
2000-11-17 03:01:23 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
|
|
|
args->sourceLimit, args->flush,ISO_2022_CN,&plane,err);
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
myData->plane=plane;
|
|
|
|
if(plane>0){
|
2000-11-20 23:40:14 +00:00
|
|
|
myData->currentType = MBCS;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
else if(myData->currentConverter &&
|
|
|
|
uprv_stricmp("latin_1",
|
|
|
|
myData->currentConverter->sharedData->staticData->name)==0){
|
|
|
|
|
2000-11-29 01:04:03 +00:00
|
|
|
myData->currentType=ASCII1;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
/* invalid or illegal escape sequence */
|
2000-10-20 02:45:38 +00:00
|
|
|
if(U_FAILURE(*err)){
|
2000-12-14 03:34:08 +00:00
|
|
|
goto END_LOOP;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
continue;
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
switch(myData->currentType){
|
2000-10-05 02:25:53 +00:00
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
case ASCII1:
|
2000-10-05 02:25:53 +00:00
|
|
|
|
|
|
|
if(args->converter->fromUnicodeStatus == 0x00){
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = (UChar) mySourceChar;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
goto SAVE_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
2001-01-02 23:12:52 +00:00
|
|
|
tempBuf[0] = (char) args->converter->toUnicodeStatus;
|
2000-11-20 18:08:49 +00:00
|
|
|
tempBuf[1] = (char) mySourceChar;
|
2001-01-02 23:12:52 +00:00
|
|
|
args->converter->toUnicodeStatus = 0;
|
|
|
|
pBuf = tempBuf;
|
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData, &pBuf, tempBuf+2, FALSE);
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MBCS:
|
|
|
|
|
|
|
|
if(args->converter->toUnicodeStatus == 0x00){
|
|
|
|
args->converter->toUnicodeStatus = (UChar) mySourceChar;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
tempBuf[0] = (char) (0x80+plane);
|
|
|
|
tempBuf[1] = (char) (args->converter->toUnicodeStatus);
|
|
|
|
tempBuf[2] = (char) (mySourceChar);
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
pBuf = &tempBuf[0];
|
|
|
|
tempLimit = &tempBuf[2]+1;
|
2000-11-20 18:08:49 +00:00
|
|
|
targetUniChar = _MBCSSimpleGetNextUChar(myData->currentConverter->sharedData,
|
2000-10-05 02:25:53 +00:00
|
|
|
&pBuf,tempLimit,args->converter->useFallback);
|
|
|
|
}
|
|
|
|
break;
|
2000-11-28 23:55:10 +00:00
|
|
|
/* for LATIN1 and SBCS which are not expected */
|
|
|
|
default:
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
if(targetUniChar < 0xfffe){
|
2000-11-20 23:40:14 +00:00
|
|
|
if(myData->currentType == ASCII1){
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source - 1;
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-11-20 18:08:49 +00:00
|
|
|
args->offsets[myTarget - args->target]= mySource - args->source - 2;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
}
|
|
|
|
else if(targetUniChar>=0xfffe){
|
|
|
|
SAVE_STATE:
|
2000-11-02 04:09:34 +00:00
|
|
|
{
|
|
|
|
const char *saveSource = args->source;
|
|
|
|
UChar *saveTarget = args->target;
|
|
|
|
int32_t *saveOffsets = args->offsets;
|
|
|
|
UConverterCallbackReason reason;
|
|
|
|
int32_t currentOffset ;
|
|
|
|
int32_t My_i = myTarget - args->target;
|
|
|
|
|
|
|
|
|
2000-11-20 23:40:14 +00:00
|
|
|
switch(myData->currentType){
|
2000-11-17 03:01:23 +00:00
|
|
|
case ASCII1:
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -1;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)mySourceChar;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DBCS:
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -2;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[0];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MBCS:
|
2000-11-20 18:08:49 +00:00
|
|
|
currentOffset= mySource - args->source -2;
|
2000-11-02 04:09:34 +00:00
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[1];
|
|
|
|
args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = tempBuf[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
currentOffset = mySource - args->source -1;
|
|
|
|
}
|
|
|
|
|
2000-11-08 23:16:20 +00:00
|
|
|
/*reason = (targetUniChar == 0xfffe) ? UCNV_UNASSIGNED:UCNV_ILLEGAL;
|
|
|
|
*err = (targetUniChar == 0xfffe) ? U_INVALID_CHAR_FOUND : U_ILLEGAL_CHAR_FOUND;*/
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
if(targetUniChar == 0xfffe){
|
|
|
|
reason = UCNV_UNASSIGNED;
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reason = UCNV_ILLEGAL;
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
args->offsets = args->offsets?args->offsets+(myTarget - args->target):0;
|
|
|
|
args->target =myTarget;
|
|
|
|
myTarget =saveTarget;
|
|
|
|
ToU_CALLBACK_OFFSETS_LOGIC_MACRO( args->converter->toUContext,
|
|
|
|
args,
|
|
|
|
args->converter->invalidCharBuffer,
|
|
|
|
args->converter->invalidCharLength,
|
|
|
|
reason,
|
|
|
|
err);
|
|
|
|
args->converter->invalidCharLength=0;
|
|
|
|
myTarget=args->target;
|
|
|
|
args->source = saveSource;
|
|
|
|
args->target = saveTarget;
|
|
|
|
args->offsets = saveOffsets;
|
2000-11-08 23:16:20 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*err))
|
|
|
|
break;
|
|
|
|
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-09-19 01:41:17 +00:00
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-14 03:34:08 +00:00
|
|
|
END_LOOP:
|
2000-09-21 00:34:21 +00:00
|
|
|
if((args->flush==TRUE)
|
|
|
|
&& (mySource == mySourceLimit)
|
|
|
|
&& ( args->converter->toUnicodeStatus !=0x00)){
|
|
|
|
if(U_SUCCESS(*err)){
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND;
|
|
|
|
args->converter->toUnicodeStatus = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Reset the state of converter if we consumed
|
|
|
|
* the source and flush is true
|
|
|
|
*/
|
|
|
|
if( (mySource == mySourceLimit) && args->flush){
|
|
|
|
setInitialStateToUnicodeJPCN(args->converter,myData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
}
|