2001-02-20 22:00:03 +00:00
|
|
|
/*
|
2000-02-05 00:19:15 +00:00
|
|
|
**********************************************************************
|
2007-06-11 18:44:06 +00:00
|
|
|
* Copyright (C) 2000-2007, International Business Machines
|
2000-02-05 00:19:15 +00:00
|
|
|
* 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
|
2001-02-20 22:00:03 +00:00
|
|
|
* 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.
|
2001-02-20 22:00:03 +00:00
|
|
|
* 10/31/2000 Ram Implemented offsets logic functions
|
2000-02-05 00:19:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-09-20 01:54:48 +00:00
|
|
|
|
2004-08-26 22:51:40 +00:00
|
|
|
#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION
|
2002-09-20 01:54:48 +00:00
|
|
|
|
2001-11-02 02:43:22 +00:00
|
|
|
#include "unicode/ucnv.h"
|
2003-04-09 00:00:51 +00:00
|
|
|
#include "unicode/uset.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
2001-11-02 02:43:22 +00:00
|
|
|
#include "unicode/ucnv_cb.h"
|
2003-12-16 05:16:55 +00:00
|
|
|
#include "ucnv_imp.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "ucnv_bld.h"
|
2000-02-05 00:19:15 +00:00
|
|
|
#include "ucnv_cnv.h"
|
2001-05-07 23:54:01 +00:00
|
|
|
#include "ucnvmbcs.h"
|
2000-08-14 23:56:19 +00:00
|
|
|
#include "cstring.h"
|
2001-11-02 02:43:22 +00:00
|
|
|
#include "cmemory.h"
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
|
|
|
/*
|
|
|
|
* I am disabling the generic ISO-2022 converter after proposing to do so on
|
|
|
|
* the icu mailing list two days ago.
|
|
|
|
*
|
|
|
|
* Reasons:
|
|
|
|
* 1. It does not fully support the ISO-2022/ECMA-35 specification with all of
|
|
|
|
* its designation sequences, single shifts with return to the previous state,
|
|
|
|
* switch-with-no-return to UTF-16BE or similar, etc.
|
|
|
|
* This is unlike the language-specific variants like ISO-2022-JP which
|
|
|
|
* require a much smaller repertoire of ISO-2022 features.
|
|
|
|
* These variants continue to be supported.
|
|
|
|
* 2. I believe that no one is really using the generic ISO-2022 converter
|
|
|
|
* but rather always one of the language-specific variants.
|
|
|
|
* Note that ICU's generic ISO-2022 converter has always output one escape
|
|
|
|
* sequence followed by UTF-8 for the whole stream.
|
|
|
|
* 3. Switching between subcharsets is extremely slow, because each time
|
|
|
|
* the previous converter is closed and a new one opened,
|
|
|
|
* without any kind of caching, least-recently-used list, etc.
|
|
|
|
* 4. The code is currently buggy, and given the above it does not seem
|
|
|
|
* reasonable to spend the time on maintenance.
|
2003-12-09 01:18:21 +00:00
|
|
|
* 5. ISO-2022 subcharsets should normally be used with 7-bit byte encodings.
|
|
|
|
* This means, for example, that when ISO-8859-7 is designated, the following
|
|
|
|
* ISO-2022 bytes 00..7f should be interpreted as ISO-8859-7 bytes 80..ff.
|
|
|
|
* The ICU ISO-2022 converter does not handle this - and has no information
|
|
|
|
* about which subconverter would have to be shifted vs. which is designed
|
|
|
|
* for 7-bit ISO-2022.
|
2003-12-03 22:53:14 +00:00
|
|
|
*
|
|
|
|
* Markus Scherer 2003-dec-03
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
2003-12-10 02:03:42 +00:00
|
|
|
static const char SHIFT_IN_STR[] = "\x0F";
|
|
|
|
static const char SHIFT_OUT_STR[] = "\x0E";
|
2000-09-19 01:41:17 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
#define CR 0x0D
|
|
|
|
#define LF 0x0A
|
|
|
|
#define H_TAB 0x09
|
|
|
|
#define V_TAB 0x0B
|
|
|
|
#define SPACE 0x20
|
2000-09-19 01:41:17 +00:00
|
|
|
|
2007-08-30 23:35:19 +00:00
|
|
|
enum {
|
|
|
|
HWKANA_START=0xff61,
|
|
|
|
HWKANA_END=0xff9f
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 94-character sets with native byte values A1..FE are encoded in ISO 2022
|
|
|
|
* as bytes 21..7E. (Subtract 0x80.)
|
|
|
|
* 96-character sets with native byte values A0..FF are encoded in ISO 2022
|
|
|
|
* as bytes 20..7F. (Subtract 0x80.)
|
|
|
|
* Do not encode C1 control codes with native bytes 80..9F
|
|
|
|
* as bytes 00..1F (C0 control codes).
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
GR94_START=0xa1,
|
|
|
|
GR94_END=0xfe,
|
|
|
|
GR96_START=0xa0,
|
|
|
|
GR96_END=0xff
|
|
|
|
};
|
|
|
|
|
2005-06-03 20:17:54 +00:00
|
|
|
/*
|
|
|
|
* ISO 2022 control codes must not be converted from Unicode
|
|
|
|
* because they would mess up the byte stream.
|
|
|
|
* The bit mask 0x0800c000 has bits set at bit positions 0xe, 0xf, 0x1b
|
|
|
|
* corresponding to SO, SI, and ESC.
|
|
|
|
*/
|
|
|
|
#define IS_2022_CONTROL(c) (((c)<0x20) && (((uint32_t)1<<(c))&0x0800c000)!=0)
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* for ISO-2022-JP and -CN implementations */
|
2000-08-14 23:56:19 +00:00
|
|
|
typedef enum {
|
2003-12-03 17:45:32 +00:00
|
|
|
/* shared values */
|
|
|
|
INVALID_STATE=-1,
|
2000-10-28 01:09:46 +00:00
|
|
|
ASCII = 0,
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
SS2_STATE=0x10,
|
|
|
|
SS3_STATE,
|
|
|
|
|
|
|
|
/* JP */
|
2000-10-28 01:09:46 +00:00
|
|
|
ISO8859_1 = 1 ,
|
|
|
|
ISO8859_7 = 2 ,
|
|
|
|
JISX201 = 3,
|
|
|
|
JISX208 = 4,
|
|
|
|
JISX212 = 5,
|
|
|
|
GB2312 =6,
|
|
|
|
KSC5601 =7,
|
2001-02-23 04:39:32 +00:00
|
|
|
HWKANA_7BIT=8, /* Halfwidth Katakana 7 bit */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* CN */
|
|
|
|
/* the first few enum constants must keep their values because they correspond to myConverterArray[] */
|
|
|
|
GB2312_1=1,
|
|
|
|
ISO_IR_165=2,
|
|
|
|
CNS_11643=3,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* these are used in StateEnum and ISO2022State variables,
|
|
|
|
* but CNS_11643 must be used to index into myConverterArray[]
|
|
|
|
*/
|
|
|
|
CNS_11643_0=0x20,
|
|
|
|
CNS_11643_1,
|
|
|
|
CNS_11643_2,
|
|
|
|
CNS_11643_3,
|
|
|
|
CNS_11643_4,
|
|
|
|
CNS_11643_5,
|
|
|
|
CNS_11643_6,
|
|
|
|
CNS_11643_7
|
2000-08-14 23:56:19 +00:00
|
|
|
} StateEnum;
|
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* is the StateEnum charset value for a DBCS charset? */
|
|
|
|
#define IS_JP_DBCS(cs) (JISX208<=(cs) && (cs)<=KSC5601)
|
|
|
|
|
2003-12-04 16:19:50 +00:00
|
|
|
#define CSM(cs) ((uint16_t)1<<(cs))
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2003-12-04 16:19:50 +00:00
|
|
|
/*
|
2003-12-06 01:52:37 +00:00
|
|
|
* Each of these charset masks (with index x) contains a bit for a charset in exact correspondence
|
|
|
|
* to whether that charset is used in the corresponding version x of ISO_2022,locale=ja,version=x
|
|
|
|
*
|
|
|
|
* Note: The converter uses some leniency:
|
|
|
|
* - The escape sequence ESC ( I for half-width 7-bit Katakana is recognized in
|
|
|
|
* all versions, not just JIS7 and JIS8.
|
|
|
|
* - ICU does not distinguish between different versions of JIS X 0208.
|
2003-12-04 16:19:50 +00:00
|
|
|
*/
|
|
|
|
static const uint16_t jpCharsetMasks[5]={
|
|
|
|
CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT),
|
|
|
|
CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212),
|
|
|
|
CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7),
|
|
|
|
CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7),
|
|
|
|
CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7)
|
|
|
|
};
|
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,
|
2003-12-04 16:19:50 +00:00
|
|
|
MBCS,
|
|
|
|
HWKANA
|
2000-08-16 19:57:24 +00:00
|
|
|
}Cnv2022Type;
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
typedef struct ISO2022State {
|
|
|
|
int8_t cs[4]; /* charset number for SI (G0)/SO (G1)/SS2 (G2)/SS3 (G3) */
|
|
|
|
int8_t g; /* 0..3 for G0..G3 (SI/SO/SS2/SS3) */
|
|
|
|
int8_t prevG; /* g before single shift (SS2 or SS3) */
|
|
|
|
} ISO2022State;
|
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
#define UCNV_OPTIONS_VERSION_MASK 0xf
|
2002-08-05 22:55:17 +00:00
|
|
|
#define UCNV_2022_MAX_CONVERTERS 10
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-09-19 01:41:17 +00:00
|
|
|
typedef struct{
|
2006-06-20 22:27:15 +00:00
|
|
|
UConverterSharedData *myConverterArray[UCNV_2022_MAX_CONVERTERS];
|
2000-08-14 23:56:19 +00:00
|
|
|
UConverter *currentConverter;
|
2000-11-20 23:40:14 +00:00
|
|
|
Cnv2022Type currentType;
|
2003-12-03 17:45:32 +00:00
|
|
|
ISO2022State toU2022State, fromU2022State;
|
2000-10-20 02:45:38 +00:00
|
|
|
uint32_t key;
|
2000-10-28 01:09:46 +00:00
|
|
|
uint32_t version;
|
2006-06-20 22:27:15 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
|
|
|
UBool isFirstBuffer;
|
|
|
|
#endif
|
2000-11-22 02:05:29 +00:00
|
|
|
char name[30];
|
2006-06-20 22:27:15 +00:00
|
|
|
char locale[3];
|
2000-09-19 01:41:17 +00:00
|
|
|
}UConverterDataISO2022;
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/* Protos */
|
2000-02-05 00:19:15 +00:00
|
|
|
/* ISO-2022 ----------------------------------------------------------------- */
|
|
|
|
|
2000-08-25 23:14:10 +00:00
|
|
|
/*Forward declaration */
|
2007-08-07 01:38:29 +00:00
|
|
|
U_CFUNC void
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_fromUnicode_UTF8(UConverterFromUnicodeArgs * args,
|
|
|
|
UErrorCode * err);
|
2007-08-07 01:38:29 +00:00
|
|
|
U_CFUNC void
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_fromUnicode_UTF8_OFFSETS_LOGIC(UConverterFromUnicodeArgs * args,
|
|
|
|
UErrorCode * err);
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
#define ESC_2022 0x1B /*ESC*/
|
2000-08-16 19:57:24 +00:00
|
|
|
|
2001-02-20 22:00:03 +00:00
|
|
|
typedef enum
|
2000-02-05 00:19:15 +00:00
|
|
|
{
|
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*/
|
2003-12-03 17:45:32 +00:00
|
|
|
VALID_MAYBE_TERMINAL_2022 = 2 /*so far matches one iso 2022 escape sequence, but by adding more characters might match another escape sequence*/
|
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
|
2001-02-20 22:00:03 +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
|
2001-02-20 22:00:03 +00:00
|
|
|
* 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
|
2001-02-20 22:00:03 +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*/
|
2001-08-24 00:22:07 +00:00
|
|
|
static const 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
|
2001-02-23 04:39:32 +00:00
|
|
|
,0 ,0 ,0 ,0 ,0 ,0 ,4 ,7 ,29 ,0
|
2000-11-20 18:08:49 +00:00
|
|
|
,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
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
|
|
|
/*
|
|
|
|
* When the generic ISO-2022 converter is completely removed, not just disabled
|
|
|
|
* per #ifdef, then the following state table and the associated tables that are
|
|
|
|
* dimensioned with MAX_STATES_2022 should be trimmed.
|
|
|
|
*
|
|
|
|
* Especially, VALID_MAYBE_TERMINAL_2022 will not be used any more, and all of
|
|
|
|
* the associated escape sequences starting with ESC ( B should be removed.
|
|
|
|
* This includes the ones with key values 1097 and all of the ones above 1000000.
|
|
|
|
*
|
|
|
|
* For the latter, the tables can simply be truncated.
|
|
|
|
* For the former, since the tables must be kept parallel, it is probably best
|
|
|
|
* to simply duplicate an adjacent table cell, parallel in all tables.
|
|
|
|
*
|
|
|
|
* It may make sense to restructure the tables, especially by using small search
|
|
|
|
* tables for the variants instead of indexing them parallel to the table here.
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
#define MAX_STATES_2022 74
|
2001-08-24 00:22:07 +00:00
|
|
|
static const int32_t escSeqStateTable_Key_2022[MAX_STATES_2022] = {
|
2001-02-23 04:39:32 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
1 ,34 ,36 ,39 ,55 ,57 ,60 ,61 ,1093 ,1096
|
|
|
|
,1097 ,1098 ,1099 ,1100 ,1101 ,1102 ,1103 ,1104 ,1105 ,1106
|
|
|
|
,1109 ,1154 ,1157 ,1160 ,1161 ,1176 ,1178 ,1179 ,1254 ,1257
|
|
|
|
,1768 ,1773 ,1957 ,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 ,35947636 ,35947638
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
2000-11-20 18:08:49 +00:00
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2000-11-20 18:08:49 +00:00
|
|
|
|
2001-08-24 00:22:07 +00:00
|
|
|
static const char* const escSeqStateTable_Result_2022[MAX_STATES_2022] = {
|
2001-02-23 04:39:32 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
|
|
|
|
NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"latin1" ,"latin1"
|
2004-09-09 07:57:06 +00:00
|
|
|
,"latin1" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"JISX0201" ,"JISX0201" ,"latin1"
|
2003-01-13 21:26:27 +00:00
|
|
|
,"latin1" ,NULL ,"JISX-208" ,"ibm-5478" ,"JISX-208" ,NULL ,NULL ,NULL ,NULL ,"UTF8"
|
2001-02-23 04:39:32 +00:00
|
|
|
,"ISO-8859-1" ,"ISO-8859-7" ,"JIS-X-208" ,NULL ,"ibm-955" ,"ibm-367" ,"ibm-952" ,"ibm-949" ,"JISX-212" ,"ibm-1383"
|
2003-01-13 21:26:27 +00:00
|
|
|
,"ibm-952" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-5478" ,"ibm-949" ,"ISO-IR-165"
|
2001-02-23 04:39:32 +00:00
|
|
|
,"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
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-24 00:22:07 +00:00
|
|
|
static const UCNV_TableStates_2022 escSeqStateTable_Value_2022[MAX_STATES_2022] = {
|
2001-02-23 04:39:32 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2003-12-03 17:45:32 +00:00
|
|
|
VALID_NON_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_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
2001-02-23 04:39:32 +00:00
|
|
|
,VALID_MAYBE_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_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_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 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
|
2000-10-05 02:25:53 +00:00
|
|
|
};
|
2000-11-20 18:08:49 +00:00
|
|
|
|
|
|
|
|
2000-11-17 03:01:23 +00:00
|
|
|
/* Type def for refactoring changeState_2022 code*/
|
2001-02-20 22:00:03 +00:00
|
|
|
typedef enum{
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2000-11-17 03:01:23 +00:00
|
|
|
ISO_2022=0,
|
2003-12-03 22:53:14 +00:00
|
|
|
#endif
|
2000-11-17 03:01:23 +00:00
|
|
|
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-10-05 02:25:53 +00:00
|
|
|
/*********** ISO 2022 Converter Protos ***********/
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 19:57:05 +00:00
|
|
|
_ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode);
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ISO2022Close(UConverter *converter);
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 19:57:05 +00:00
|
|
|
_ISO2022Reset(UConverter *converter, UConverterResetChoice choice);
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static const char*
|
2001-03-22 19:57:05 +00:00
|
|
|
_ISO2022getName(const UConverter* cnv);
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 19:57:05 +00:00
|
|
|
_ISO_2022_WriteSub(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode *err);
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static UConverter *
|
2001-03-22 19:57:05 +00:00
|
|
|
_ISO_2022_SafeClone(const UConverter *cnv, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status);
|
2001-02-23 04:39:32 +00:00
|
|
|
|
2003-12-04 22:46:02 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2003-08-14 02:32:31 +00:00
|
|
|
T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC(UConverterToUnicodeArgs* args, UErrorCode* err);
|
2003-12-04 22:46:02 +00:00
|
|
|
#endif
|
2001-03-22 19:57:05 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*const UConverterSharedData _ISO2022Data;*/
|
|
|
|
static const UConverterSharedData _ISO2022JPData;
|
|
|
|
static const UConverterSharedData _ISO2022KRData;
|
|
|
|
static const UConverterSharedData _ISO2022CNData;
|
|
|
|
|
|
|
|
/*************** Converter implementations ******************/
|
|
|
|
|
2006-07-25 04:53:53 +00:00
|
|
|
/* The purpose of this function is to get around gcc compiler warnings. */
|
|
|
|
static U_INLINE void
|
|
|
|
fromUWriteUInt8(UConverter *cnv,
|
|
|
|
const char *bytes, int32_t length,
|
|
|
|
uint8_t **target, const char *targetLimit,
|
|
|
|
int32_t **offsets,
|
|
|
|
int32_t sourceIndex,
|
|
|
|
UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
char *targetChars = (char *)*target;
|
|
|
|
ucnv_fromUWriteBytes(cnv, bytes, length, &targetChars, targetLimit,
|
|
|
|
offsets, sourceIndex, pErrorCode);
|
|
|
|
*target = (uint8_t*)targetChars;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static U_INLINE void
|
2003-08-14 02:32:31 +00:00
|
|
|
setInitialStateToUnicodeKR(UConverter* converter, UConverterDataISO2022 *myConverterData){
|
2003-12-09 01:18:21 +00:00
|
|
|
if(myConverterData->version == 1) {
|
|
|
|
UConverter *cnv = myConverterData->currentConverter;
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
cnv->toUnicodeStatus=0; /* offset */
|
|
|
|
cnv->mode=0; /* state */
|
|
|
|
cnv->toULength=0; /* byteIndex */
|
2003-12-09 01:18:21 +00:00
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static U_INLINE void
|
2003-08-14 02:32:31 +00:00
|
|
|
setInitialStateFromUnicodeKR(UConverter* converter,UConverterDataISO2022 *myConverterData){
|
2003-12-06 01:52:37 +00:00
|
|
|
/* in ISO-2022-KR the designator sequence appears only once
|
2003-08-14 02:32:31 +00:00
|
|
|
* in a file so we append it only once
|
|
|
|
*/
|
|
|
|
if( converter->charErrorBufferLength==0){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
converter->charErrorBufferLength = 4;
|
|
|
|
converter->charErrorBuffer[0] = 0x1b;
|
|
|
|
converter->charErrorBuffer[1] = 0x24;
|
|
|
|
converter->charErrorBuffer[2] = 0x29;
|
|
|
|
converter->charErrorBuffer[3] = 0x43;
|
|
|
|
}
|
2003-12-09 01:18:21 +00:00
|
|
|
if(myConverterData->version == 1) {
|
|
|
|
UConverter *cnv = myConverterData->currentConverter;
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
cnv->fromUChar32=0;
|
|
|
|
cnv->fromUnicodeStatus=1; /* prevLength */
|
2003-12-09 01:18:21 +00:00
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2000-11-22 02:05:29 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2003-08-14 02:32:31 +00:00
|
|
|
_ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
char myLocale[6]={' ',' ',' ',' ',' ',' '};
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
cnv->extraInfo = uprv_malloc (sizeof (UConverterDataISO2022));
|
|
|
|
if(cnv->extraInfo != NULL) {
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) cnv->extraInfo;
|
2003-12-04 16:19:50 +00:00
|
|
|
uint32_t version;
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
uprv_memset(myConverterData, 0, sizeof(UConverterDataISO2022));
|
|
|
|
myConverterData->currentType = ASCII1;
|
2003-08-14 02:32:31 +00:00
|
|
|
cnv->fromUnicodeStatus =FALSE;
|
|
|
|
if(locale){
|
|
|
|
uprv_strncpy(myLocale, locale, sizeof(myLocale));
|
|
|
|
}
|
2003-12-04 16:19:50 +00:00
|
|
|
version = options & UCNV_OPTIONS_VERSION_MASK;
|
2006-06-20 22:27:15 +00:00
|
|
|
myConverterData->version = version;
|
2007-08-07 01:38:29 +00:00
|
|
|
if(myLocale[0]=='j' && (myLocale[1]=='a'|| myLocale[1]=='p') &&
|
2006-06-20 22:27:15 +00:00
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0'))
|
|
|
|
{
|
2004-12-08 01:05:40 +00:00
|
|
|
size_t len=0;
|
2003-08-14 02:32:31 +00:00
|
|
|
/* open the required converters and cache them */
|
2003-12-04 16:19:50 +00:00
|
|
|
if(jpCharsetMasks[version]&CSM(ISO8859_7)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[ISO8859_7]= ucnv_loadSharedData("ISO8859_7", NULL, errorCode);
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
2004-09-09 07:57:06 +00:00
|
|
|
myConverterData->myConverterArray[JISX201] = ucnv_loadSharedData("JISX0201", NULL, errorCode);
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[JISX208] = ucnv_loadSharedData("jisx-208", NULL, errorCode);
|
2003-12-04 16:19:50 +00:00
|
|
|
if(jpCharsetMasks[version]&CSM(JISX212)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[JISX212] = ucnv_loadSharedData("jisx-212", NULL, errorCode);
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
|
|
|
if(jpCharsetMasks[version]&CSM(GB2312)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[GB2312] = ucnv_loadSharedData("ibm-5478", NULL, errorCode); /* gb_2312_80-1 */
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
|
|
|
if(jpCharsetMasks[version]&CSM(KSC5601)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[KSC5601] = ucnv_loadSharedData("ksc_5601", NULL, errorCode);
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/* set the function pointers to appropriate funtions */
|
|
|
|
cnv->sharedData=(UConverterSharedData*)(&_ISO2022JPData);
|
|
|
|
uprv_strcpy(myConverterData->locale,"ja");
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ja,version=");
|
2003-11-14 23:01:06 +00:00
|
|
|
len = uprv_strlen(myConverterData->name);
|
2003-08-14 02:32:31 +00:00
|
|
|
myConverterData->name[len]=(char)(myConverterData->version+(int)'0');
|
|
|
|
myConverterData->name[len+1]='\0';
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
else if(myLocale[0]=='k' && (myLocale[1]=='o'|| myLocale[1]=='r') &&
|
2006-06-20 22:27:15 +00:00
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0'))
|
|
|
|
{
|
|
|
|
if (version==1){
|
|
|
|
myConverterData->currentConverter=
|
|
|
|
ucnv_open("icu-internal-25546",errorCode);
|
2003-12-09 01:18:21 +00:00
|
|
|
|
2006-06-20 22:27:15 +00:00
|
|
|
if (U_FAILURE(*errorCode)) {
|
|
|
|
_ISO2022Close(cnv);
|
|
|
|
return;
|
|
|
|
}
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ko,version=1");
|
2006-07-05 23:08:50 +00:00
|
|
|
uprv_memcpy(cnv->subChars, myConverterData->currentConverter->subChars, 4);
|
2006-06-20 22:27:15 +00:00
|
|
|
cnv->subCharLen = myConverterData->currentConverter->subCharLen;
|
2003-08-14 02:32:31 +00:00
|
|
|
}else{
|
2006-06-20 22:27:15 +00:00
|
|
|
myConverterData->currentConverter=ucnv_open("ibm-949",errorCode);
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2006-06-20 22:27:15 +00:00
|
|
|
if (U_FAILURE(*errorCode)) {
|
|
|
|
_ISO2022Close(cnv);
|
|
|
|
return;
|
|
|
|
}
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2006-06-20 22:27:15 +00:00
|
|
|
myConverterData->version = 0;
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ko,version=0");
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
/* initialize the state variables */
|
|
|
|
setInitialStateToUnicodeKR(cnv, myConverterData);
|
2006-06-20 22:27:15 +00:00
|
|
|
setInitialStateFromUnicodeKR(cnv, myConverterData);
|
2003-12-09 01:18:21 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/* set the function pointers to appropriate funtions */
|
|
|
|
cnv->sharedData=(UConverterSharedData*)&_ISO2022KRData;
|
|
|
|
uprv_strcpy(myConverterData->locale,"ko");
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
else if(((myLocale[0]=='z' && myLocale[1]=='h') || (myLocale[0]=='c'&& myLocale[1]=='n'))&&
|
2006-06-20 22:27:15 +00:00
|
|
|
(myLocale[2]=='_' || myLocale[2]=='\0'))
|
|
|
|
{
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
/* open the required converters and cache them */
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[GB2312_1] = ucnv_loadSharedData("ibm-5478", NULL, errorCode);
|
2003-12-04 19:36:20 +00:00
|
|
|
if(version==1) {
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[ISO_IR_165] = ucnv_loadSharedData("iso-ir-165", NULL, errorCode);
|
2003-12-04 19:36:20 +00:00
|
|
|
}
|
2003-12-16 05:16:55 +00:00
|
|
|
myConverterData->myConverterArray[CNS_11643] = ucnv_loadSharedData("cns-11643-1992", NULL, errorCode);
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2001-02-20 22:00:03 +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");
|
2001-03-06 18:19:16 +00:00
|
|
|
|
2006-06-20 22:27:15 +00:00
|
|
|
if (version==1){
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=zh,version=1");
|
2001-02-23 04:39:32 +00:00
|
|
|
}else{
|
2001-02-24 02:41:29 +00:00
|
|
|
myConverterData->version = 0;
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=zh,version=0");
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
2000-08-14 23:56:19 +00:00
|
|
|
else{
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2006-06-20 22:27:15 +00:00
|
|
|
myConverterData->isFirstBuffer = TRUE;
|
|
|
|
|
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 */
|
2000-11-22 02:05:29 +00:00
|
|
|
uprv_strcpy(myConverterData->name,"ISO_2022");
|
2003-12-03 22:53:14 +00:00
|
|
|
#else
|
|
|
|
*errorCode = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
#endif
|
2000-08-14 23:56:19 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-10-30 22:54:18 +00:00
|
|
|
cnv->maxBytesPerUChar=cnv->sharedData->staticData->maxBytesPerChar;
|
2003-12-16 05:16:55 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
|
|
|
_ISO2022Close(cnv);
|
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
} else {
|
|
|
|
*errorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-14 23:56:19 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
static void
|
|
|
|
_ISO2022Close(UConverter *converter) {
|
2003-12-04 16:19:50 +00:00
|
|
|
UConverterDataISO2022* myData =(UConverterDataISO2022 *) (converter->extraInfo);
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverterSharedData **array = myData->myConverterArray;
|
2003-12-04 16:19:50 +00:00
|
|
|
int32_t i;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
if (converter->extraInfo != NULL) {
|
2002-08-05 22:55:17 +00:00
|
|
|
/*close the array of converter pointers and free the memory*/
|
2003-12-04 16:19:50 +00:00
|
|
|
for (i=0; i<UCNV_2022_MAX_CONVERTERS; i++) {
|
|
|
|
if(array[i]!=NULL) {
|
2003-12-16 05:16:55 +00:00
|
|
|
ucnv_unloadSharedDataIfReady(array[i]);
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
2002-08-05 22:55:17 +00:00
|
|
|
}
|
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
ucnv_close(myData->currentConverter);
|
2002-08-05 22:55:17 +00:00
|
|
|
|
2003-05-13 21:05:05 +00:00
|
|
|
if(!converter->isExtraLocal){
|
2001-09-05 22:51:53 +00:00
|
|
|
uprv_free (converter->extraInfo);
|
2003-12-16 05:16:55 +00:00
|
|
|
converter->extraInfo = NULL;
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-25 23:14:10 +00:00
|
|
|
|
2001-09-06 18:10:06 +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);
|
2003-12-03 17:45:32 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
uprv_memset(&myConverterData->toU2022State, 0, sizeof(ISO2022State));
|
|
|
|
myConverterData->key = 0;
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
uprv_memset(&myConverterData->fromU2022State, 0, sizeof(ISO2022State));
|
|
|
|
}
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
|
|
|
if(myConverterData->locale[0] == 0){
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
2001-03-09 00:41:14 +00:00
|
|
|
myConverterData->isFirstBuffer = TRUE;
|
2003-12-03 17:45:32 +00:00
|
|
|
myConverterData->key = 0;
|
2000-12-20 21:18:46 +00:00
|
|
|
if (converter->mode == UCNV_SO){
|
|
|
|
ucnv_close (myConverterData->currentConverter);
|
|
|
|
myConverterData->currentConverter=NULL;
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
converter->mode = UCNV_SI;
|
2000-12-20 21:18:46 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2003-12-03 22:53:14 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2000-10-05 02:25:53 +00:00
|
|
|
/* reset the state variables */
|
2003-12-06 01:52:37 +00:00
|
|
|
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
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static const char*
|
2001-03-22 19:57:05 +00:00
|
|
|
_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
|
|
|
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*************** to unicode *******************/
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
*/
|
2003-12-06 01:52:37 +00:00
|
|
|
static const StateEnum nextStateToUnicodeJP[MAX_STATES_2022]= {
|
2003-08-14 02:32:31 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2003-12-03 17:45:32 +00:00
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,SS2_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
2003-08-14 02:32:31 +00:00
|
|
|
,ASCII ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX201 ,HWKANA_7BIT ,JISX201 ,INVALID_STATE
|
|
|
|
,INVALID_STATE ,INVALID_STATE ,JISX208 ,GB2312 ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
|
|
|
|
,ISO8859_1 ,ISO8859_7 ,JISX208 ,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 ,INVALID_STATE ,INVALID_STATE
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************** to unicode *******************/
|
2003-12-06 01:52:37 +00:00
|
|
|
static const StateEnum nextStateToUnicodeCN[MAX_STATES_2022]= {
|
2003-08-14 02:32:31 +00:00
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
2003-12-03 17:45:32 +00:00
|
|
|
INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,SS2_STATE ,SS3_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_1 ,CNS_11643_2 ,CNS_11643_3 ,CNS_11643_4 ,CNS_11643_5 ,CNS_11643_6 ,CNS_11643_7 ,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
|
2003-08-14 02:32:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static UCNV_TableStates_2022
|
2003-08-14 02:32:31 +00:00
|
|
|
getKey_2022(char c,int32_t* key,int32_t* offset){
|
2003-12-03 17:45:32 +00:00
|
|
|
int32_t togo;
|
2003-08-14 02:32:31 +00:00
|
|
|
int32_t low = 0;
|
|
|
|
int32_t hi = MAX_STATES_2022;
|
|
|
|
int32_t oldmid=0;
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
togo = normalize_esq_chars_2022[(uint8_t)c];
|
|
|
|
if(togo == 0) {
|
|
|
|
/* not a valid character anywhere in an escape sequence */
|
|
|
|
*key = 0;
|
|
|
|
*offset = 0;
|
|
|
|
return INVALID_2022;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
togo = (*key << 5) + togo;
|
2003-08-14 02:32:31 +00:00
|
|
|
|
|
|
|
while (hi != low) /*binary search*/{
|
|
|
|
|
|
|
|
register int32_t mid = (hi+low) >> 1; /*Finds median*/
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
if (mid == oldmid)
|
2003-08-14 02:32:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (escSeqStateTable_Key_2022[mid] > togo){
|
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
else if (escSeqStateTable_Key_2022[mid] < togo){
|
|
|
|
low = mid;
|
|
|
|
}
|
|
|
|
else /*we found it*/{
|
|
|
|
*key = togo;
|
|
|
|
*offset = mid;
|
|
|
|
return escSeqStateTable_Value_2022[mid];
|
|
|
|
}
|
|
|
|
oldmid = mid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*key = 0;
|
|
|
|
*offset = 0;
|
|
|
|
return INVALID_2022;
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*runs through a state machine to determine the escape sequence - codepage correspondance
|
|
|
|
*/
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2003-08-14 02:32:31 +00:00
|
|
|
changeState_2022(UConverter* _this,
|
2007-08-07 01:38:29 +00:00
|
|
|
const char** source,
|
2003-08-14 02:32:31 +00:00
|
|
|
const char* sourceLimit,
|
2003-12-03 17:45:32 +00:00
|
|
|
Variant2022 var,
|
2003-08-14 02:32:31 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
UCNV_TableStates_2022 value;
|
|
|
|
UConverterDataISO2022* myData2022 = ((UConverterDataISO2022*)_this->extraInfo);
|
|
|
|
uint32_t key = myData2022->key;
|
2004-12-07 23:43:48 +00:00
|
|
|
int32_t offset = 0;
|
2003-12-03 17:45:32 +00:00
|
|
|
char c;
|
2003-08-14 02:32:31 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
value = VALID_NON_TERMINAL_2022;
|
|
|
|
while (*source < sourceLimit) {
|
|
|
|
c = *(*source)++;
|
|
|
|
_this->toUBytes[_this->toULength++]=(uint8_t)c;
|
|
|
|
value = getKey_2022(c,(int32_t *) &key, &offset);
|
2007-08-07 01:38:29 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
switch (value){
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
case VALID_NON_TERMINAL_2022 :
|
|
|
|
/* continue with the loop */
|
2003-08-14 02:32:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VALID_TERMINAL_2022:
|
2003-12-03 17:45:32 +00:00
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
2003-08-14 02:32:31 +00:00
|
|
|
|
|
|
|
case INVALID_2022:
|
2003-12-03 17:45:32 +00:00
|
|
|
goto DONE;
|
2003-08-14 02:32:31 +00:00
|
|
|
|
|
|
|
case VALID_MAYBE_TERMINAL_2022:
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2003-12-03 17:45:32 +00:00
|
|
|
/* ESC ( B is ambiguous only for ISO_2022 itself */
|
|
|
|
if(var == ISO_2022) {
|
|
|
|
/* discard toUBytes[] for ESC ( B because this sequence is correct and complete */
|
|
|
|
_this->toULength = 0;
|
2003-08-14 02:32:31 +00:00
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
/* TODO need to indicate that ESC ( B was seen; if failure, then need to replay from source or from MBCS-style replay */
|
2003-08-14 02:32:31 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* continue with the loop */
|
|
|
|
value = VALID_NON_TERMINAL_2022;
|
2003-08-14 02:32:31 +00:00
|
|
|
break;
|
2003-12-03 22:53:14 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2003-12-03 17:45:32 +00:00
|
|
|
/* not ISO_2022 itself, finish here */
|
|
|
|
value = VALID_TERMINAL_2022;
|
|
|
|
key = 0;
|
|
|
|
goto DONE;
|
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
|
|
|
|
DONE:
|
|
|
|
myData2022->key = key;
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
if (value == VALID_NON_TERMINAL_2022) {
|
|
|
|
/* indicate that the escape sequence is incomplete: key!=0 */
|
2003-08-14 02:32:31 +00:00
|
|
|
return;
|
2003-12-03 17:45:32 +00:00
|
|
|
} else if (value == INVALID_2022 ) {
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
return;
|
|
|
|
} else /* value == VALID_TERMINAL_2022 */ {
|
|
|
|
switch(var){
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2003-12-03 17:45:32 +00:00
|
|
|
case ISO_2022:
|
|
|
|
{
|
|
|
|
const char *chosenConverterName = escSeqStateTable_Result_2022[offset];
|
|
|
|
if(chosenConverterName == NULL) {
|
|
|
|
/* SS2 or SS3 */
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
_this->mode = UCNV_SI;
|
2003-12-03 17:45:32 +00:00
|
|
|
ucnv_close(myData2022->currentConverter);
|
|
|
|
myData2022->currentConverter = myUConverter = ucnv_open(chosenConverterName, err);
|
|
|
|
if(U_SUCCESS(*err)) {
|
|
|
|
myUConverter->fromCharErrorBehaviour = UCNV_TO_U_CALLBACK_STOP;
|
2003-12-09 01:18:21 +00:00
|
|
|
_this->mode = UCNV_SO;
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2003-12-03 22:53:14 +00:00
|
|
|
#endif
|
2003-12-03 17:45:32 +00:00
|
|
|
case ISO_2022_JP:
|
|
|
|
{
|
2003-12-06 01:52:37 +00:00
|
|
|
StateEnum tempState=nextStateToUnicodeJP[offset];
|
|
|
|
switch(tempState) {
|
|
|
|
case INVALID_STATE:
|
2003-12-03 17:45:32 +00:00
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
2003-12-06 01:52:37 +00:00
|
|
|
break;
|
|
|
|
case SS2_STATE:
|
|
|
|
if(myData2022->toU2022State.cs[2]!=0) {
|
|
|
|
if(myData2022->toU2022State.g<2) {
|
|
|
|
myData2022->toU2022State.prevG=myData2022->toU2022State.g;
|
|
|
|
}
|
|
|
|
myData2022->toU2022State.g=2;
|
|
|
|
} else {
|
|
|
|
/* illegal to have SS2 before a matching designator */
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* case SS3_STATE: not used in ISO-2022-JP-x */
|
|
|
|
case ISO8859_1:
|
|
|
|
case ISO8859_7:
|
|
|
|
if((jpCharsetMasks[myData2022->version] & CSM(tempState)) == 0) {
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
} else {
|
|
|
|
/* G2 charset for SS2 */
|
|
|
|
myData2022->toU2022State.cs[2]=(int8_t)tempState;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if((jpCharsetMasks[myData2022->version] & CSM(tempState)) == 0) {
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
} else {
|
|
|
|
/* G0 charset */
|
|
|
|
myData2022->toU2022State.cs[0]=(int8_t)tempState;
|
|
|
|
}
|
|
|
|
break;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
break;
|
|
|
|
case ISO_2022_CN:
|
|
|
|
{
|
2003-12-06 01:52:37 +00:00
|
|
|
StateEnum tempState=nextStateToUnicodeCN[offset];
|
|
|
|
switch(tempState) {
|
|
|
|
case INVALID_STATE:
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
break;
|
|
|
|
case SS2_STATE:
|
|
|
|
if(myData2022->toU2022State.cs[2]!=0) {
|
|
|
|
if(myData2022->toU2022State.g<2) {
|
|
|
|
myData2022->toU2022State.prevG=myData2022->toU2022State.g;
|
|
|
|
}
|
|
|
|
myData2022->toU2022State.g=2;
|
|
|
|
} else {
|
|
|
|
/* illegal to have SS2 before a matching designator */
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SS3_STATE:
|
|
|
|
if(myData2022->toU2022State.cs[3]!=0) {
|
|
|
|
if(myData2022->toU2022State.g<2) {
|
|
|
|
myData2022->toU2022State.prevG=myData2022->toU2022State.g;
|
|
|
|
}
|
|
|
|
myData2022->toU2022State.g=3;
|
|
|
|
} else {
|
|
|
|
/* illegal to have SS3 before a matching designator */
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISO_IR_165:
|
|
|
|
if(myData2022->version==0) {
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-03 02:54:26 +00:00
|
|
|
/*fall through*/
|
2003-12-06 01:52:37 +00:00
|
|
|
case GB2312_1:
|
2005-08-03 02:54:26 +00:00
|
|
|
/*fall through*/
|
2003-12-06 01:52:37 +00:00
|
|
|
case CNS_11643_1:
|
|
|
|
myData2022->toU2022State.cs[1]=(int8_t)tempState;
|
|
|
|
break;
|
|
|
|
case CNS_11643_2:
|
|
|
|
myData2022->toU2022State.cs[2]=(int8_t)tempState;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* other CNS 11643 planes */
|
|
|
|
if(myData2022->version==0) {
|
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
|
|
|
} else {
|
|
|
|
myData2022->toU2022State.cs[3]=(int8_t)tempState;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISO_2022_KR:
|
|
|
|
if(offset==0x30){
|
2003-12-09 01:18:21 +00:00
|
|
|
/* nothing to be done, just accept this one escape sequence */
|
2003-08-14 02:32:31 +00:00
|
|
|
} else {
|
2003-12-03 17:45:32 +00:00
|
|
|
*err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
break;
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
default:
|
|
|
|
*err = U_ILLEGAL_ESCAPE_SEQUENCE;
|
|
|
|
break;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
if(U_SUCCESS(*err)) {
|
|
|
|
_this->toULength = 0;
|
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*Checks the characters of the buffer against valid 2022 escape sequences
|
|
|
|
*if the match we return a pointer to the initial start of the sequence otherwise
|
|
|
|
*we return sourceLimit
|
|
|
|
*/
|
|
|
|
/*for 2022 looks ahead in the stream
|
|
|
|
*to determine the longest possible convertible
|
|
|
|
*data stream
|
|
|
|
*/
|
2007-08-07 01:38:29 +00:00
|
|
|
static U_INLINE const char*
|
2003-08-14 02:32:31 +00:00
|
|
|
getEndOfBuffer_2022(const char** source,
|
|
|
|
const char* sourceLimit,
|
|
|
|
UBool flush){
|
2000-11-17 03:01:23 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
const char* mySource = *source;
|
2000-02-08 23:41:16 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2007-08-07 01:38:29 +00:00
|
|
|
if (*source >= sourceLimit)
|
2003-08-14 02:32:31 +00:00
|
|
|
return sourceLimit;
|
2000-08-29 21:47:40 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
do{
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +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-08-29 21:47:40 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/* Kludge: I could not
|
|
|
|
* figure out the reason for validating an escape sequence
|
|
|
|
* twice - once here and once in changeState_2022().
|
|
|
|
* is it possible to have an ESC character in a ISO2022
|
|
|
|
* byte stream which is valid in a code page? Is it legal?
|
|
|
|
*/
|
2007-08-07 01:38:29 +00:00
|
|
|
for (i=0;
|
2003-08-14 02:32:31 +00:00
|
|
|
(mySource+i < sourceLimit)&&(value == VALID_NON_TERMINAL_2022);
|
|
|
|
i++) {
|
|
|
|
value = getKey_2022(*(mySource+i), &key, &offset);
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
if (value > 0 || *mySource==ESC_2022)
|
2003-08-14 02:32:31 +00:00
|
|
|
return mySource;
|
2001-06-18 22:48:33 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
if ((value == VALID_NON_TERMINAL_2022)&&(!flush) )
|
2003-08-14 02:32:31 +00:00
|
|
|
return sourceLimit;
|
|
|
|
}
|
|
|
|
}while (++mySource < sourceLimit);
|
2001-08-17 00:24:58 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
return sourceLimit;
|
2003-12-06 01:52:37 +00:00
|
|
|
#else
|
|
|
|
while(mySource < sourceLimit && *mySource != ESC_2022) {
|
|
|
|
++mySource;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
return mySource;
|
|
|
|
#endif
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
|
2001-06-18 22:48:33 +00:00
|
|
|
/* This inline function replicates code in _MBCSFromUChar32() function in ucnvmbcs.c
|
2007-08-23 05:46:49 +00:00
|
|
|
* any future change in _MBCSFromUChar32() function should be reflected here.
|
|
|
|
* @return number of bytes in *value; negative number if fallback; 0 if no mapping
|
2001-06-18 22:48:33 +00:00
|
|
|
*/
|
2007-08-23 05:46:49 +00:00
|
|
|
static U_INLINE int32_t
|
2001-06-18 22:48:33 +00:00
|
|
|
MBCS_FROM_UCHAR32_ISO2022(UConverterSharedData* sharedData,
|
2007-08-07 01:38:29 +00:00
|
|
|
UChar32 c,
|
|
|
|
uint32_t* value,
|
|
|
|
UBool useFallback,
|
2001-08-17 00:24:58 +00:00
|
|
|
int outputType)
|
|
|
|
{
|
2003-12-15 00:40:24 +00:00
|
|
|
const int32_t *cx;
|
|
|
|
const uint16_t *table;
|
2001-06-18 22:48:33 +00:00
|
|
|
uint32_t stage2Entry;
|
2003-12-15 00:40:24 +00:00
|
|
|
uint32_t myValue;
|
2007-08-23 05:46:49 +00:00
|
|
|
int32_t length;
|
2001-06-18 22:48:33 +00:00
|
|
|
const uint8_t *p;
|
2007-08-23 05:46:49 +00:00
|
|
|
/*
|
|
|
|
* TODO(markus): Use and require new, faster MBCS conversion table structures.
|
|
|
|
* Use internal version of ucnv_open() that verifies that the new structures are available,
|
|
|
|
* else U_INTERNAL_PROGRAM_ERROR.
|
|
|
|
*/
|
2001-06-18 22:48:33 +00:00
|
|
|
/* BMP-only codepages are stored without stage 1 entries for supplementary code points */
|
2003-11-08 00:09:50 +00:00
|
|
|
if(c<0x10000 || (sharedData->mbcs.unicodeMask&UCNV_HAS_SUPPLEMENTARY)) {
|
2003-12-15 00:40:24 +00:00
|
|
|
table=sharedData->mbcs.fromUnicodeTable;
|
2001-06-18 22:48:33 +00:00
|
|
|
stage2Entry=MBCS_STAGE_2_FROM_U(table, c);
|
|
|
|
/* get the bytes and the length for the output */
|
|
|
|
if(outputType==MBCS_OUTPUT_2){
|
2003-11-08 00:09:50 +00:00
|
|
|
myValue=MBCS_VALUE_2_FROM_STAGE_2(sharedData->mbcs.fromUnicodeBytes, stage2Entry, c);
|
2001-06-18 22:48:33 +00:00
|
|
|
if(myValue<=0xff) {
|
2007-08-23 05:46:49 +00:00
|
|
|
length=1;
|
2001-06-18 22:48:33 +00:00
|
|
|
} else {
|
2007-08-23 05:46:49 +00:00
|
|
|
length=2;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
2003-12-15 00:40:24 +00:00
|
|
|
} else /* outputType==MBCS_OUTPUT_3 */ {
|
2003-11-08 00:09:50 +00:00
|
|
|
p=MBCS_POINTER_3_FROM_STAGE_2(sharedData->mbcs.fromUnicodeBytes, stage2Entry, c);
|
2001-06-18 22:48:33 +00:00
|
|
|
myValue=((uint32_t)*p<<16)|((uint32_t)p[1]<<8)|p[2];
|
|
|
|
if(myValue<=0xff) {
|
2007-08-23 05:46:49 +00:00
|
|
|
length=1;
|
2001-06-18 22:48:33 +00:00
|
|
|
} else if(myValue<=0xffff) {
|
2007-08-23 05:46:49 +00:00
|
|
|
length=2;
|
2001-06-18 22:48:33 +00:00
|
|
|
} else {
|
2007-08-23 05:46:49 +00:00
|
|
|
length=3;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-23 05:46:49 +00:00
|
|
|
/*
|
|
|
|
* TODO(markus): Use Shift-JIS table for JIS X 0208, to save mapping table space.
|
|
|
|
* Pass in parameter for type of output bytes, for validation and shifting:
|
|
|
|
* - Direct: Pass bytes through, but forbid control codes 00-1F (except SI/SO/ESC) and space 20?
|
|
|
|
* (Need to allow some (TAB/LF/CR) or most of them for ASCII and maybe JIS X 0201.)
|
|
|
|
* - A1-FE: Subtract 80 after range check.
|
|
|
|
* - SJIS: Shift DBCS result to 21-7E x 21-7E.
|
|
|
|
*/
|
2001-06-18 22:48:33 +00:00
|
|
|
/* is this code point assigned, or do we use fallbacks? */
|
2007-08-23 05:46:49 +00:00
|
|
|
if((stage2Entry&(1<<(16+(c&0xf))))!=0) {
|
|
|
|
/* assigned */
|
|
|
|
*value=myValue;
|
|
|
|
return length;
|
|
|
|
} else if(FROM_U_USE_FALLBACK(useFallback, c) && myValue!=0) {
|
2001-06-18 22:48:33 +00:00
|
|
|
/*
|
2003-12-03 17:45:32 +00:00
|
|
|
* We allow a 0 byte output if the "assigned" bit is set for this entry.
|
2001-06-18 22:48:33 +00:00
|
|
|
* There is no way with this data structure for fallback output
|
2003-12-03 17:45:32 +00:00
|
|
|
* to be a zero byte.
|
2001-06-18 22:48:33 +00:00
|
|
|
*/
|
|
|
|
*value=myValue;
|
2007-08-23 05:46:49 +00:00
|
|
|
return -length;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-15 00:40:24 +00:00
|
|
|
|
|
|
|
cx=sharedData->mbcs.extIndexes;
|
|
|
|
if(cx!=NULL) {
|
2007-08-23 05:46:49 +00:00
|
|
|
return ucnv_extSimpleMatchFromU(cx, c, value, useFallback);
|
2003-12-15 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* unassigned */
|
2007-08-23 05:46:49 +00:00
|
|
|
return 0;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
2001-10-22 22:51:49 +00:00
|
|
|
|
2001-06-18 22:48:33 +00:00
|
|
|
/* This inline function replicates code in _MBCSSingleFromUChar32() function in ucnvmbcs.c
|
2007-08-23 05:46:49 +00:00
|
|
|
* any future change in _MBCSSingleFromUChar32() function should be reflected here.
|
|
|
|
* @param retval pointer to output byte
|
|
|
|
* @return 1 roundtrip byte 0 no mapping -1 fallback byte
|
2001-06-18 22:48:33 +00:00
|
|
|
*/
|
2007-08-23 05:46:49 +00:00
|
|
|
static U_INLINE int32_t
|
2001-06-18 22:48:33 +00:00
|
|
|
MBCS_SINGLE_FROM_UCHAR32(UConverterSharedData* sharedData,
|
2007-08-07 01:38:29 +00:00
|
|
|
UChar32 c,
|
|
|
|
uint32_t* retval,
|
2001-08-17 00:24:58 +00:00
|
|
|
UBool useFallback)
|
|
|
|
{
|
2007-08-07 01:38:29 +00:00
|
|
|
const uint16_t *table;
|
2001-06-18 22:48:33 +00:00
|
|
|
int32_t value;
|
|
|
|
/* BMP-only codepages are stored without stage 1 entries for supplementary code points */
|
2003-11-08 00:09:50 +00:00
|
|
|
if(c>=0x10000 && !(sharedData->mbcs.unicodeMask&UCNV_HAS_SUPPLEMENTARY)) {
|
2007-08-23 05:46:49 +00:00
|
|
|
return 0;
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
|
|
|
/* convert the Unicode code point in c into codepage bytes (same as in _MBCSFromUnicodeWithOffsets) */
|
2003-11-08 00:09:50 +00:00
|
|
|
table=sharedData->mbcs.fromUnicodeTable;
|
2001-06-18 22:48:33 +00:00
|
|
|
/* get the byte for the output */
|
2003-11-08 00:09:50 +00:00
|
|
|
value=MBCS_SINGLE_RESULT_FROM_U(table, (uint16_t *)sharedData->mbcs.fromUnicodeBytes, c);
|
2001-06-18 22:48:33 +00:00
|
|
|
/* is this code point assigned, or do we use fallbacks? */
|
2007-08-23 05:46:49 +00:00
|
|
|
*retval=(uint32_t)(value&0xff);
|
|
|
|
if(value>=0xf00) {
|
|
|
|
return 1; /* roundtrip */
|
|
|
|
} else if(useFallback ? value>=0x800 : value>=0xc00) {
|
|
|
|
return -1; /* fallback taken */
|
2001-06-18 22:48:33 +00:00
|
|
|
} else {
|
2007-08-23 05:46:49 +00:00
|
|
|
return 0; /* no mapping */
|
2001-06-18 22:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
|
|
|
|
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
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
|
2000-10-05 02:25:53 +00:00
|
|
|
UErrorCode* err){
|
2003-08-01 14:42:29 +00:00
|
|
|
const char* mySourceLimit, *realSourceLimit;
|
|
|
|
const char* sourceStart;
|
|
|
|
const UChar* myTargetStart;
|
2001-01-23 01:29:06 +00:00
|
|
|
UConverter* saveThis;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022* myData;
|
2003-08-01 14:42:29 +00:00
|
|
|
int8_t length;
|
|
|
|
|
|
|
|
saveThis = args->converter;
|
|
|
|
myData=((UConverterDataISO2022*)(saveThis->extraInfo));
|
|
|
|
|
|
|
|
realSourceLimit = args->sourceLimit;
|
|
|
|
while (args->source < realSourceLimit) {
|
|
|
|
if(myData->key == 0) { /* are we in the middle of an escape sequence? */
|
|
|
|
/*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
|
|
|
|
mySourceLimit = getEndOfBuffer_2022(&(args->source), realSourceLimit, args->flush);
|
|
|
|
|
|
|
|
if(args->source < mySourceLimit) {
|
|
|
|
if(myData->currentConverter==NULL) {
|
|
|
|
myData->currentConverter = ucnv_open("ASCII",err);
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
return;
|
|
|
|
}
|
2001-07-18 23:45:04 +00:00
|
|
|
|
2003-08-01 14:42:29 +00:00
|
|
|
myData->currentConverter->fromCharErrorBehaviour = UCNV_TO_U_CALLBACK_STOP;
|
|
|
|
saveThis->mode = UCNV_SO;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-01 14:42:29 +00:00
|
|
|
/* convert to before the ESC or until the end of the buffer */
|
|
|
|
myData->isFirstBuffer=FALSE;
|
|
|
|
sourceStart = args->source;
|
|
|
|
myTargetStart = args->target;
|
|
|
|
args->converter = myData->currentConverter;
|
|
|
|
ucnv_toUnicode(args->converter,
|
|
|
|
&args->target,
|
|
|
|
args->targetLimit,
|
|
|
|
&args->source,
|
|
|
|
mySourceLimit,
|
|
|
|
args->offsets,
|
|
|
|
(UBool)(args->flush && mySourceLimit == realSourceLimit),
|
|
|
|
err);
|
|
|
|
args->converter = saveThis;
|
|
|
|
|
|
|
|
if (*err == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
/* move the overflow buffer */
|
|
|
|
length = saveThis->UCharErrorBufferLength = myData->currentConverter->UCharErrorBufferLength;
|
|
|
|
myData->currentConverter->UCharErrorBufferLength = 0;
|
|
|
|
if(length > 0) {
|
|
|
|
uprv_memcpy(saveThis->UCharErrorBuffer,
|
|
|
|
myData->currentConverter->UCharErrorBuffer,
|
|
|
|
length*U_SIZEOF_UCHAR);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-01 14:42:29 +00:00
|
|
|
/*
|
|
|
|
* At least one of:
|
|
|
|
* -Error while converting
|
|
|
|
* -Done with entire buffer
|
|
|
|
* -Need to write offsets or update the current offset
|
|
|
|
* (leave that up to the code in ucnv.c)
|
|
|
|
*
|
|
|
|
* or else we just stopped at an ESC byte and continue with changeState_2022()
|
|
|
|
*/
|
|
|
|
if (U_FAILURE(*err) ||
|
|
|
|
(args->source == realSourceLimit) ||
|
|
|
|
(args->offsets != NULL && (args->target != myTargetStart || args->source != sourceStart) ||
|
|
|
|
(mySourceLimit < realSourceLimit && myData->currentConverter->toULength > 0))
|
|
|
|
) {
|
|
|
|
/* copy partial or error input for truncated detection and error handling */
|
|
|
|
if(U_FAILURE(*err)) {
|
|
|
|
length = saveThis->invalidCharLength = myData->currentConverter->invalidCharLength;
|
|
|
|
if(length > 0) {
|
|
|
|
uprv_memcpy(saveThis->invalidCharBuffer, myData->currentConverter->invalidCharBuffer, length);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
length = saveThis->toULength = myData->currentConverter->toULength;
|
|
|
|
if(length > 0) {
|
|
|
|
uprv_memcpy(saveThis->toUBytes, myData->currentConverter->toUBytes, length);
|
|
|
|
if(args->source < mySourceLimit) {
|
|
|
|
*err = U_TRUNCATED_CHAR_FOUND; /* truncated input before ESC */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
sourceStart = args->source;
|
|
|
|
changeState_2022(args->converter,
|
2007-08-07 01:38:29 +00:00
|
|
|
&(args->source),
|
2003-08-01 14:42:29 +00:00
|
|
|
realSourceLimit,
|
2000-11-17 03:01:23 +00:00
|
|
|
ISO_2022,
|
|
|
|
err);
|
2003-08-01 14:42:29 +00:00
|
|
|
if (U_FAILURE(*err) || (args->source != sourceStart && args->offsets != NULL)) {
|
|
|
|
/* let the ucnv.c code update its current offset */
|
|
|
|
return;
|
|
|
|
}
|
2001-09-07 01:48:46 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#endif
|
|
|
|
|
2001-02-28 02:54:39 +00:00
|
|
|
/*
|
|
|
|
* To Unicode Callback helper function
|
|
|
|
*/
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2003-08-01 14:42:29 +00:00
|
|
|
toUnicodeCallback(UConverter *cnv,
|
|
|
|
const uint32_t sourceChar, const uint32_t targetUniChar,
|
|
|
|
UErrorCode* err){
|
2001-02-28 02:54:39 +00:00
|
|
|
if(sourceChar>0xff){
|
2003-08-01 14:42:29 +00:00
|
|
|
cnv->toUBytes[0] = (uint8_t)(sourceChar>>8);
|
|
|
|
cnv->toUBytes[1] = (uint8_t)sourceChar;
|
|
|
|
cnv->toULength = 2;
|
2001-02-28 02:54:39 +00:00
|
|
|
}
|
|
|
|
else{
|
2003-08-01 14:42:29 +00:00
|
|
|
cnv->toUBytes[0] =(char) sourceChar;
|
|
|
|
cnv->toULength = 2;
|
2001-02-28 02:54:39 +00:00
|
|
|
}
|
|
|
|
|
2001-05-14 17:43:10 +00:00
|
|
|
if(targetUniChar == (missingCharMarker-1/*0xfffe*/)){
|
2001-02-28 02:54:39 +00:00
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*err = U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
}
|
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().
|
2007-08-07 01:38:29 +00:00
|
|
|
* The converter iterates over each Unicode codepoint
|
|
|
|
* 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
|
2000-10-05 02:25:53 +00:00
|
|
|
* would do as far as possible.
|
|
|
|
*
|
2007-08-07 01:38:29 +00:00
|
|
|
* If the implementation of these macros or structure of sharedData struct change in the future, make
|
|
|
|
* sure that ISO-2022 is also changed.
|
2000-10-05 02:25:53 +00:00
|
|
|
***************************************************************************************************
|
|
|
|
*/
|
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
|
2007-08-07 01:38:29 +00:00
|
|
|
* (i) Escape sequences must be fully contained within a line they should not
|
2000-10-05 02:25:53 +00:00
|
|
|
* 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
|
2007-08-07 01:38:29 +00:00
|
|
|
* (iii) If the first character on the line is represented by two bytes then a two
|
|
|
|
* byte character escape sequence should precede it
|
2000-10-05 02:25:53 +00:00
|
|
|
* (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
|
2001-02-20 22:00:03 +00:00
|
|
|
* GB2312 : alias to ibm-1386 mapping table
|
2000-10-05 02:25:53 +00:00
|
|
|
* 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
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* preference order of JP charsets */
|
|
|
|
static const StateEnum jpCharsetPref[]={
|
|
|
|
ASCII,
|
|
|
|
JISX201,
|
|
|
|
ISO8859_1,
|
|
|
|
ISO8859_7,
|
|
|
|
JISX208,
|
|
|
|
JISX212,
|
|
|
|
GB2312,
|
|
|
|
KSC5601,
|
|
|
|
HWKANA_7BIT
|
2000-10-28 01:09:46 +00:00
|
|
|
};
|
2003-12-06 01:52:37 +00:00
|
|
|
|
2005-06-03 16:13:57 +00:00
|
|
|
/*
|
|
|
|
* The escape sequences must be in order of the enum constants like JISX201 = 3,
|
|
|
|
* not in order of jpCharsetPref[]!
|
|
|
|
*/
|
2003-12-06 01:52:37 +00:00
|
|
|
static const char escSeqChars[][6] ={
|
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 */
|
2001-02-23 04:39:32 +00:00
|
|
|
"\x1B\x28\x49" /* <ESC>(I HWKANA_7BIT */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
};
|
2003-12-06 01:52:37 +00:00
|
|
|
static const int32_t escSeqCharsLen[] ={
|
2003-12-04 16:19:50 +00:00
|
|
|
3, /* length of <ESC>(B ASCII */
|
2001-02-28 22:37:49 +00:00
|
|
|
3, /* length of <ESC>.A ISO-8859-1 */
|
|
|
|
3, /* length of <ESC>.F ISO-8859-7 */
|
|
|
|
3, /* length of <ESC>(J JISX-201 */
|
|
|
|
3, /* length of <ESC>$B JISX-208 */
|
|
|
|
4, /* length of <ESC>$(D JISX-212 */
|
|
|
|
3, /* length of <ESC>$A GB2312 */
|
|
|
|
4, /* length of <ESC>$(C KSC5601 */
|
|
|
|
3 /* length of <ESC>(I HWKANA_7BIT */
|
2001-02-02 03:51:57 +00:00
|
|
|
};
|
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
|
2007-08-07 01:38:29 +00:00
|
|
|
* iii) Before changing the state increment the current state check if the current state
|
2000-10-05 02:25:53 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*
|
2007-08-07 01:38:29 +00:00
|
|
|
* TODO: Implement a priority technique where the users are allowed to set the priority of code pages
|
2000-10-05 02:25:53 +00:00
|
|
|
*/
|
2001-02-28 02:54:39 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2003-12-06 01:52:37 +00:00
|
|
|
UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err) {
|
2007-08-23 05:46:49 +00:00
|
|
|
UConverter *cnv = args->converter;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022 *converterData;
|
2003-12-06 01:52:37 +00:00
|
|
|
ISO2022State *pFromU2022State;
|
|
|
|
uint8_t *target = (uint8_t *) args->target;
|
|
|
|
const uint8_t *targetLimit = (const uint8_t *) args->targetLimit;
|
2001-02-28 22:37:49 +00:00
|
|
|
const UChar* source = args->source;
|
2001-02-02 03:51:57 +00:00
|
|
|
const UChar* sourceLimit = args->sourceLimit;
|
|
|
|
int32_t* offsets = args->offsets;
|
2003-12-06 01:52:37 +00:00
|
|
|
UChar32 sourceChar;
|
|
|
|
char buffer[8];
|
|
|
|
int32_t len, outLen;
|
|
|
|
int8_t choices[10];
|
|
|
|
int32_t choiceCount;
|
2004-12-07 23:43:48 +00:00
|
|
|
uint32_t targetValue = 0;
|
2003-12-06 01:52:37 +00:00
|
|
|
UBool useFallback;
|
|
|
|
|
|
|
|
int32_t i;
|
|
|
|
int8_t cs, g;
|
|
|
|
|
|
|
|
/* set up the state */
|
2007-08-23 05:46:49 +00:00
|
|
|
converterData = (UConverterDataISO2022*)cnv->extraInfo;
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State = &converterData->fromU2022State;
|
|
|
|
|
|
|
|
choiceCount = 0;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
/* check if the last codepoint of previous buffer was a lead surrogate*/
|
2007-08-23 05:46:49 +00:00
|
|
|
if((sourceChar = cnv->fromUChar32)!=0 && target< targetLimit) {
|
2000-11-08 23:16:20 +00:00
|
|
|
goto getTrail;
|
|
|
|
}
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
while(source < sourceLimit) {
|
|
|
|
if(target < targetLimit) {
|
2001-02-02 03:51:57 +00:00
|
|
|
|
|
|
|
sourceChar = *(source++);
|
2003-12-06 01:52:37 +00:00
|
|
|
/*check if the char is a First surrogate*/
|
2005-06-03 20:17:54 +00:00
|
|
|
if(UTF_IS_SURROGATE(sourceChar)) {
|
2003-12-06 01:52:37 +00:00
|
|
|
if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
|
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
|
|
|
if(source < sourceLimit) {
|
|
|
|
/* test the following code unit */
|
|
|
|
UChar trail=(UChar) *source;
|
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
|
|
|
source++;
|
|
|
|
sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=0x00;
|
2003-12-06 01:52:37 +00:00
|
|
|
/* convert this supplementary code point */
|
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-12-06 01:52:37 +00:00
|
|
|
break;
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
} else {
|
|
|
|
/* no more input */
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2001-02-23 04:39:32 +00:00
|
|
|
break;
|
2000-10-28 01:09:46 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-12-06 01:52:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2005-06-03 20:17:54 +00:00
|
|
|
/* do not convert SO/SI/ESC */
|
|
|
|
if(IS_2022_CONTROL(sourceChar)) {
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2005-06-03 20:17:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* do the conversion */
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
if(choiceCount == 0) {
|
|
|
|
uint16_t csm;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/*
|
|
|
|
* The csm variable keeps track of which charsets are allowed
|
|
|
|
* and not used yet while building the choices[].
|
|
|
|
*/
|
|
|
|
csm = jpCharsetMasks[converterData->version];
|
|
|
|
choiceCount = 0;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* JIS7/8: try single-byte half-width Katakana before JISX208 */
|
|
|
|
if(converterData->version == 3 || converterData->version == 4) {
|
2007-08-23 23:43:03 +00:00
|
|
|
choices[choiceCount++] = (int8_t)HWKANA_7BIT;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
2007-08-23 23:43:03 +00:00
|
|
|
/* Do not try single-byte half-width Katakana for other versions. */
|
|
|
|
csm &= ~CSM(HWKANA_7BIT);
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* try the current G0 charset */
|
|
|
|
choices[choiceCount++] = cs = pFromU2022State->cs[0];
|
|
|
|
csm &= ~CSM(cs);
|
2000-10-28 01:09:46 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* try the current G2 charset */
|
|
|
|
if((cs = pFromU2022State->cs[2]) != 0) {
|
|
|
|
choices[choiceCount++] = cs;
|
|
|
|
csm &= ~CSM(cs);
|
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* try all the other possible charsets */
|
|
|
|
for(i = 0; i < LENGTHOF(jpCharsetPref); ++i) {
|
|
|
|
cs = (int8_t)jpCharsetPref[i];
|
|
|
|
if(CSM(cs) & csm) {
|
|
|
|
choices[choiceCount++] = cs;
|
|
|
|
csm &= ~CSM(cs);
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
cs = g = 0;
|
2007-08-23 05:46:49 +00:00
|
|
|
/*
|
|
|
|
* len==0: no mapping found yet
|
|
|
|
* len<0: found a fallback result: continue looking for a roundtrip but no further fallbacks
|
|
|
|
* len>0: found a roundtrip result, done
|
|
|
|
*/
|
2003-12-06 01:52:37 +00:00
|
|
|
len = 0;
|
2007-08-23 23:43:03 +00:00
|
|
|
/*
|
|
|
|
* We will turn off useFallback after finding a fallback,
|
|
|
|
* but we still get fallbacks from PUA code points as usual.
|
|
|
|
* Therefore, we will also need to check that we don't overwrite
|
|
|
|
* an early fallback with a later one.
|
|
|
|
*/
|
2007-08-23 05:46:49 +00:00
|
|
|
useFallback = cnv->useFallback;
|
2003-12-06 01:52:37 +00:00
|
|
|
|
2007-08-23 05:46:49 +00:00
|
|
|
for(i = 0; i < choiceCount && len <= 0; ++i) {
|
|
|
|
uint32_t value;
|
|
|
|
int32_t len2;
|
|
|
|
int8_t cs0 = choices[i];
|
|
|
|
switch(cs0) {
|
2003-12-06 01:52:37 +00:00
|
|
|
case ASCII:
|
|
|
|
if(sourceChar <= 0x7f) {
|
|
|
|
targetValue = (uint32_t)sourceChar;
|
|
|
|
len = 1;
|
2007-08-23 05:46:49 +00:00
|
|
|
cs = cs0;
|
|
|
|
g = 0;
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
break;
|
|
|
|
case ISO8859_1:
|
2007-08-30 23:35:19 +00:00
|
|
|
if(GR96_START <= sourceChar && sourceChar <= GR96_END) {
|
2003-12-06 01:52:37 +00:00
|
|
|
targetValue = (uint32_t)sourceChar - 0x80;
|
|
|
|
len = 1;
|
2007-08-23 05:46:49 +00:00
|
|
|
cs = cs0;
|
2003-12-06 01:52:37 +00:00
|
|
|
g = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HWKANA_7BIT:
|
2007-08-30 23:35:19 +00:00
|
|
|
if((uint32_t)(HWKANA_END-sourceChar)<=(HWKANA_END-HWKANA_START)) {
|
2003-12-06 01:52:37 +00:00
|
|
|
if(converterData->version==3) {
|
|
|
|
/* JIS7: use G1 (SO) */
|
2007-08-23 23:43:03 +00:00
|
|
|
/* Shift U+FF61..U+FF9F to bytes 21..5F. */
|
2007-08-30 23:35:19 +00:00
|
|
|
targetValue = (uint32_t)(sourceChar - (HWKANA_START - 0x21));
|
2007-08-23 05:46:49 +00:00
|
|
|
len = 1;
|
|
|
|
pFromU2022State->cs[1] = cs = cs0; /* do not output an escape sequence */
|
2003-12-06 01:52:37 +00:00
|
|
|
g = 1;
|
|
|
|
} else if(converterData->version==4) {
|
|
|
|
/* JIS8: use 8-bit bytes with any single-byte charset, see escape sequence output below */
|
2007-08-23 23:43:03 +00:00
|
|
|
/* Shift U+FF61..U+FF9F to bytes A1..DF. */
|
2007-08-30 23:35:19 +00:00
|
|
|
targetValue = (uint32_t)(sourceChar - (HWKANA_START - 0xa1));
|
2007-08-23 05:46:49 +00:00
|
|
|
len = 1;
|
2003-12-06 01:52:37 +00:00
|
|
|
|
2007-08-23 05:46:49 +00:00
|
|
|
cs = pFromU2022State->cs[0];
|
|
|
|
if(IS_JP_DBCS(cs)) {
|
2003-12-06 01:52:37 +00:00
|
|
|
/* switch from a DBCS charset to JISX201 */
|
|
|
|
cs = (int8_t)JISX201;
|
2001-04-07 01:24:30 +00:00
|
|
|
}
|
2007-08-23 05:46:49 +00:00
|
|
|
/* else stay in the current G0 charset */
|
|
|
|
g = 0;
|
2001-02-20 22:00:03 +00:00
|
|
|
}
|
2007-08-23 05:46:49 +00:00
|
|
|
/* else do not use HWKANA_7BIT with other versions */
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
break;
|
|
|
|
case JISX201:
|
|
|
|
/* G0 SBCS */
|
2007-08-23 05:46:49 +00:00
|
|
|
len2 = MBCS_SINGLE_FROM_UCHAR32(
|
|
|
|
converterData->myConverterArray[cs0],
|
|
|
|
sourceChar, &value,
|
|
|
|
useFallback);
|
2007-08-23 23:43:03 +00:00
|
|
|
if(len2 != 0 && !(len2 < 0 && len != 0) && value <= 0x7f) {
|
2007-08-23 05:46:49 +00:00
|
|
|
targetValue = value;
|
|
|
|
len = len2;
|
|
|
|
cs = cs0;
|
|
|
|
g = 0;
|
|
|
|
useFallback = FALSE;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISO8859_7:
|
|
|
|
/* G0 SBCS forced to 7-bit output */
|
2007-08-23 05:46:49 +00:00
|
|
|
len2 = MBCS_SINGLE_FROM_UCHAR32(
|
|
|
|
converterData->myConverterArray[cs0],
|
|
|
|
sourceChar, &value,
|
|
|
|
useFallback);
|
2007-08-30 23:35:19 +00:00
|
|
|
if(len2 != 0 && !(len2 < 0 && len != 0) && GR96_START <= value && value <= GR96_END) {
|
2007-08-23 05:46:49 +00:00
|
|
|
targetValue = value - 0x80;
|
|
|
|
len = len2;
|
|
|
|
cs = cs0;
|
2003-12-06 01:52:37 +00:00
|
|
|
g = 2;
|
2007-08-23 05:46:49 +00:00
|
|
|
useFallback = FALSE;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* G0 DBCS */
|
2007-08-23 05:46:49 +00:00
|
|
|
len2 = MBCS_FROM_UCHAR32_ISO2022(
|
|
|
|
converterData->myConverterArray[cs0],
|
|
|
|
sourceChar, &value,
|
|
|
|
useFallback, MBCS_OUTPUT_2);
|
2007-08-23 23:43:03 +00:00
|
|
|
if(len2 == 2 || (len2 == -2 && len == 0)) { /* only accept DBCS: abs(len)==2 */
|
2007-08-23 05:46:49 +00:00
|
|
|
if(cs0 == KSC5601) {
|
2007-08-30 23:35:19 +00:00
|
|
|
/*
|
|
|
|
* Check for valid bytes for the encoding scheme.
|
|
|
|
* This is necessary because the sub-converter (windows-949)
|
|
|
|
* has a broader encoding scheme than is valid for 2022.
|
|
|
|
*
|
|
|
|
* Check that the result is a 2-byte value with each byte in the range A1..FE
|
|
|
|
* (strict EUC-KR DBCS) before accepting it and subtracting 0x80 from each byte
|
|
|
|
* to move it to the ISO 2022 range 21..7E.
|
|
|
|
*/
|
2007-08-23 05:46:49 +00:00
|
|
|
if( (uint16_t)(value - 0xa1a1) <= (0xfefe - 0xa1a1) &&
|
|
|
|
(uint8_t)(value - 0xa1) <= (0xfe - 0xa1)
|
|
|
|
) {
|
|
|
|
value -= 0x8080; /* shift down to 21..7e byte range */
|
|
|
|
} else {
|
|
|
|
break; /* not valid for ISO 2022 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
targetValue = value;
|
|
|
|
len = len2;
|
|
|
|
cs = cs0;
|
|
|
|
g = 0;
|
|
|
|
useFallback = FALSE;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2007-08-23 05:46:49 +00:00
|
|
|
if(len != 0) {
|
|
|
|
if(len < 0) {
|
|
|
|
len = -len; /* fallback */
|
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
outLen = 0; /* count output bytes */
|
|
|
|
|
|
|
|
/* write SI if necessary (only for JIS7) */
|
|
|
|
if(pFromU2022State->g == 1 && g == 0) {
|
|
|
|
buffer[outLen++] = UCNV_SI;
|
|
|
|
pFromU2022State->g = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the designation sequence if necessary */
|
|
|
|
if(cs != pFromU2022State->cs[g]) {
|
|
|
|
int32_t escLen = escSeqCharsLen[cs];
|
|
|
|
uprv_memcpy(buffer + outLen, escSeqChars[cs], escLen);
|
|
|
|
outLen += escLen;
|
|
|
|
pFromU2022State->cs[g] = cs;
|
|
|
|
|
|
|
|
/* invalidate the choices[] */
|
|
|
|
choiceCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the shift sequence if necessary */
|
|
|
|
if(g != pFromU2022State->g) {
|
|
|
|
switch(g) {
|
|
|
|
/* case 0 handled before writing escapes */
|
|
|
|
case 1:
|
|
|
|
buffer[outLen++] = UCNV_SO;
|
|
|
|
pFromU2022State->g = 1;
|
|
|
|
break;
|
|
|
|
default: /* case 2 */
|
|
|
|
buffer[outLen++] = 0x1b;
|
|
|
|
buffer[outLen++] = 0x4e;
|
|
|
|
break;
|
|
|
|
/* no case 3: no SS3 in ISO-2022-JP-x */
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-24 00:28:47 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* write the output bytes */
|
|
|
|
if(len == 1) {
|
|
|
|
buffer[outLen++] = (char)targetValue;
|
|
|
|
} else /* len == 2 */ {
|
|
|
|
buffer[outLen++] = (char)(targetValue >> 8);
|
|
|
|
buffer[outLen++] = (char)targetValue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
2007-08-07 01:38:29 +00:00
|
|
|
* if we cannot find the character after checking all codepages
|
2003-12-06 01:52:37 +00:00
|
|
|
* then this is an error
|
|
|
|
*/
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-07-24 00:28:47 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
|
|
|
|
if(sourceChar == CR || sourceChar == LF) {
|
|
|
|
/* reset the G2 state at the end of a line (conversion got us into ASCII or JISX201 already) */
|
|
|
|
pFromU2022State->cs[2] = 0;
|
|
|
|
choiceCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output outLen>0 bytes in buffer[] */
|
|
|
|
if(outLen == 1) {
|
|
|
|
*target++ = buffer[0];
|
|
|
|
if(offsets) {
|
2004-12-08 01:05:40 +00:00
|
|
|
*offsets++ = (int32_t)(source - args->source - 1); /* -1: known to be ASCII */
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
} else if(outLen == 2 && (target + 2) <= targetLimit) {
|
|
|
|
*target++ = buffer[0];
|
|
|
|
*target++ = buffer[1];
|
|
|
|
if(offsets) {
|
|
|
|
int32_t sourceIndex = (int32_t)(source - args->source - U16_LENGTH(sourceChar));
|
|
|
|
*offsets++ = sourceIndex;
|
|
|
|
*offsets++ = sourceIndex;
|
|
|
|
}
|
|
|
|
} else {
|
2006-07-25 04:53:53 +00:00
|
|
|
fromUWriteUInt8(
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv,
|
2003-12-06 01:52:37 +00:00
|
|
|
buffer, outLen,
|
2006-07-25 04:53:53 +00:00
|
|
|
&target, (const char *)targetLimit,
|
2003-12-06 01:52:37 +00:00
|
|
|
&offsets, (int32_t)(source - args->source - U16_LENGTH(sourceChar)),
|
|
|
|
err);
|
|
|
|
if(U_FAILURE(*err)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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;
|
2001-02-20 22:00:03 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2003-12-10 02:03:42 +00:00
|
|
|
/*
|
|
|
|
* the end of the input stream and detection of truncated input
|
|
|
|
* are handled by the framework, but for ISO-2022-JP conversion
|
|
|
|
* we need to be in ASCII mode at the very end
|
|
|
|
*
|
|
|
|
* conditions:
|
|
|
|
* successful
|
|
|
|
* in SO mode or not in ASCII mode
|
|
|
|
* end of input and no truncated input
|
|
|
|
*/
|
|
|
|
if( U_SUCCESS(*err) &&
|
|
|
|
(pFromU2022State->g!=0 || pFromU2022State->cs[0]!=ASCII) &&
|
2007-08-23 05:46:49 +00:00
|
|
|
args->flush && source>=sourceLimit && cnv->fromUChar32==0
|
2003-12-10 02:03:42 +00:00
|
|
|
) {
|
|
|
|
int32_t sourceIndex;
|
|
|
|
|
|
|
|
outLen = 0;
|
|
|
|
|
|
|
|
if(pFromU2022State->g != 0) {
|
|
|
|
buffer[outLen++] = UCNV_SI;
|
|
|
|
pFromU2022State->g = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pFromU2022State->cs[0] != ASCII) {
|
|
|
|
int32_t escLen = escSeqCharsLen[ASCII];
|
|
|
|
uprv_memcpy(buffer + outLen, escSeqChars[ASCII], escLen);
|
|
|
|
outLen += escLen;
|
|
|
|
pFromU2022State->cs[0] = (int8_t)ASCII;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the source index of the last input character */
|
|
|
|
/*
|
|
|
|
* TODO this would be simpler and more reliable if we used a pair
|
|
|
|
* of sourceIndex/prevSourceIndex like in ucnvmbcs.c
|
|
|
|
* so that we could simply use the prevSourceIndex here;
|
|
|
|
* this code gives an incorrect result for the rare case of an unmatched
|
|
|
|
* trail surrogate that is alone in the last buffer of the text stream
|
|
|
|
*/
|
|
|
|
sourceIndex=(int32_t)(source-args->source);
|
|
|
|
if(sourceIndex>0) {
|
|
|
|
--sourceIndex;
|
|
|
|
if( U16_IS_TRAIL(args->source[sourceIndex]) &&
|
|
|
|
(sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
|
|
|
|
) {
|
|
|
|
--sourceIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sourceIndex=-1;
|
|
|
|
}
|
|
|
|
|
2006-07-25 04:53:53 +00:00
|
|
|
fromUWriteUInt8(
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv,
|
2003-12-10 02:03:42 +00:00
|
|
|
buffer, outLen,
|
2006-07-25 04:53:53 +00:00
|
|
|
&target, (const char *)targetLimit,
|
2003-12-10 02:03:42 +00:00
|
|
|
&offsets, sourceIndex,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->source = source;
|
|
|
|
args->target = (char*)target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************** to unicode *******************/
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
2003-12-06 01:52:37 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
char tempBuf[3];
|
|
|
|
const char *mySource = (char *) args->source;
|
2001-02-20 22:00:03 +00:00
|
|
|
UChar *myTarget = args->target;
|
2000-11-02 04:09:34 +00:00
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
2001-02-16 20:16:09 +00:00
|
|
|
uint32_t targetUniChar = 0x0000;
|
|
|
|
uint32_t mySourceChar = 0x0000;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022* myData;
|
2003-12-06 01:52:37 +00:00
|
|
|
ISO2022State *pToU2022State;
|
|
|
|
StateEnum cs;
|
2001-02-03 03:15:29 +00:00
|
|
|
|
2001-07-18 23:45:04 +00:00
|
|
|
myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2003-12-06 01:52:37 +00:00
|
|
|
pToU2022State = &myData->toU2022State;
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
if(myData->key != 0) {
|
|
|
|
/* continue with a partial escape sequence */
|
|
|
|
goto escape;
|
|
|
|
} else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
|
|
|
|
/* continue with a partial double-byte character */
|
|
|
|
mySourceChar = args->converter->toUBytes[0];
|
|
|
|
args->converter->toULength = 0;
|
|
|
|
cs = (StateEnum)pToU2022State->cs[pToU2022State->g];
|
|
|
|
goto getTrailByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(mySource < mySourceLimit){
|
|
|
|
|
|
|
|
targetUniChar =missingCharMarker;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2007-08-07 06:53:10 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2003-12-06 01:52:37 +00:00
|
|
|
|
|
|
|
switch(mySourceChar) {
|
|
|
|
case UCNV_SI:
|
|
|
|
if(myData->version==3) {
|
|
|
|
pToU2022State->g=0;
|
2001-02-23 04:39:32 +00:00
|
|
|
continue;
|
2003-12-06 01:52:37 +00:00
|
|
|
} else {
|
|
|
|
/* only JIS7 uses SI/SO, not ISO-2022-JP-x */
|
|
|
|
break;
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
case UCNV_SO:
|
|
|
|
if(myData->version==3) {
|
|
|
|
/* JIS7: switch to G1 half-width Katakana */
|
|
|
|
pToU2022State->cs[1] = (int8_t)HWKANA_7BIT;
|
|
|
|
pToU2022State->g=1;
|
2001-05-07 23:54:01 +00:00
|
|
|
continue;
|
2003-12-06 01:52:37 +00:00
|
|
|
} else {
|
|
|
|
/* only JIS7 uses SI/SO, not ISO-2022-JP-x */
|
|
|
|
break;
|
2001-05-07 23:54:01 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
case ESC_2022:
|
|
|
|
mySource--;
|
|
|
|
escape:
|
2007-08-07 01:38:29 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
2003-12-06 01:52:37 +00:00
|
|
|
mySourceLimit, ISO_2022_JP,err);
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* invalid or illegal escape sequence */
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
return;
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
continue;
|
2001-02-03 03:15:29 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* ISO-2022-JP does not use single-byte (C1) SS2 and SS3 */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
case CR:
|
|
|
|
/*falls through*/
|
|
|
|
case LF:
|
|
|
|
/* automatically reset to single-byte mode */
|
|
|
|
if((StateEnum)pToU2022State->cs[0] != ASCII && (StateEnum)pToU2022State->cs[0] != JISX201) {
|
|
|
|
pToU2022State->cs[0] = (int8_t)ASCII;
|
|
|
|
}
|
|
|
|
pToU2022State->cs[2] = 0;
|
|
|
|
pToU2022State->g = 0;
|
|
|
|
/* falls through */
|
|
|
|
default:
|
|
|
|
/* convert one or two bytes */
|
|
|
|
cs = (StateEnum)pToU2022State->cs[pToU2022State->g];
|
|
|
|
if( (uint8_t)(mySourceChar - 0xa1) <= (0xdf - 0xa1) && myData->version==4 &&
|
|
|
|
!IS_JP_DBCS(cs)
|
|
|
|
) {
|
2001-02-23 04:39:32 +00:00
|
|
|
/* 8-bit halfwidth katakana in any single-byte mode for JIS8 */
|
2007-08-30 23:35:19 +00:00
|
|
|
targetUniChar = mySourceChar + (HWKANA_START - 0xa1);
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2003-12-06 01:52:37 +00:00
|
|
|
/* return from a single-shift state to the previous one */
|
|
|
|
if(pToU2022State->g >= 2) {
|
|
|
|
pToU2022State->g=pToU2022State->prevG;
|
|
|
|
}
|
|
|
|
} else switch(cs) {
|
|
|
|
case ASCII:
|
|
|
|
if(mySourceChar <= 0x7f) {
|
|
|
|
targetUniChar = mySourceChar;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISO8859_1:
|
|
|
|
if(mySourceChar <= 0x7f) {
|
|
|
|
targetUniChar = mySourceChar + 0x80;
|
|
|
|
}
|
|
|
|
/* return from a single-shift state to the previous one */
|
|
|
|
pToU2022State->g=pToU2022State->prevG;
|
|
|
|
break;
|
|
|
|
case ISO8859_7:
|
|
|
|
if(mySourceChar <= 0x7f) {
|
|
|
|
/* convert mySourceChar+0x80 to use a normal 8-bit table */
|
|
|
|
targetUniChar =
|
|
|
|
_MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(
|
2003-12-16 05:16:55 +00:00
|
|
|
myData->myConverterArray[cs],
|
2003-12-06 01:52:37 +00:00
|
|
|
mySourceChar + 0x80);
|
|
|
|
}
|
|
|
|
/* return from a single-shift state to the previous one */
|
|
|
|
pToU2022State->g=pToU2022State->prevG;
|
|
|
|
break;
|
|
|
|
case JISX201:
|
|
|
|
if(mySourceChar <= 0x7f) {
|
|
|
|
targetUniChar =
|
|
|
|
_MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(
|
2003-12-16 05:16:55 +00:00
|
|
|
myData->myConverterArray[cs],
|
2003-12-06 01:52:37 +00:00
|
|
|
mySourceChar);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HWKANA_7BIT:
|
|
|
|
if((uint8_t)(mySourceChar - 0x21) <= (0x5f - 0x21)) {
|
|
|
|
/* 7-bit halfwidth Katakana */
|
2007-08-30 23:35:19 +00:00
|
|
|
targetUniChar = mySourceChar + (HWKANA_START - 0x21);
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* G0 DBCS */
|
|
|
|
if(mySource < mySourceLimit) {
|
|
|
|
char trailByte;
|
|
|
|
getTrailByte:
|
|
|
|
tempBuf[0] = (char) (mySourceChar);
|
|
|
|
tempBuf[1] = trailByte = *mySource++;
|
|
|
|
mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
|
2004-09-16 04:00:12 +00:00
|
|
|
targetUniChar = ucnv_MBCSSimpleGetNextUChar(myData->myConverterArray[cs], tempBuf, 2, FALSE);
|
2003-12-06 01:52:37 +00:00
|
|
|
} else {
|
|
|
|
args->converter->toUBytes[0] = (uint8_t)mySourceChar;
|
|
|
|
args->converter->toULength = 1;
|
|
|
|
goto endloop;
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
} /* End of inner switch */
|
2001-02-23 04:39:32 +00:00
|
|
|
break;
|
2007-08-07 01:38:29 +00:00
|
|
|
} /* End of outer switch */
|
2001-05-14 17:43:10 +00:00
|
|
|
if(targetUniChar < (missingCharMarker-1/*0xfffe*/)){
|
2001-02-02 03:51:57 +00:00
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
else if(targetUniChar > missingCharMarker){
|
|
|
|
/* disassemble the surrogate pair and write to output*/
|
|
|
|
targetUniChar-=0x0010000;
|
|
|
|
*myTarget = (UChar)(0xd800+(UChar)(targetUniChar>>10));
|
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
++myTarget;
|
2007-08-07 01:38:29 +00:00
|
|
|
if(myTarget< args->targetLimit){
|
2003-12-06 01:52:37 +00:00
|
|
|
*myTarget = (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
|
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
|
|
|
++myTarget;
|
|
|
|
}else{
|
|
|
|
args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++]=
|
|
|
|
(UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
|
|
|
|
}
|
|
|
|
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2001-01-02 23:12:52 +00:00
|
|
|
else{
|
2001-02-28 02:54:39 +00:00
|
|
|
/* Call the callback function*/
|
2003-08-01 14:42:29 +00:00
|
|
|
toUnicodeCallback(args->converter,mySourceChar,targetUniChar,err);
|
|
|
|
break;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-07 01:38:29 +00:00
|
|
|
else{ /* goes with "if(myTarget < args->targetLimit)" way up near top of function */
|
2000-11-02 04:09:34 +00:00
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
endloop:
|
2000-11-02 04:09:34 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* Rules for ISO-2022-KR encoding
|
2007-08-07 01:38:29 +00:00
|
|
|
* i) The KSC5601 designator sequence should appear only once in a file,
|
2000-11-02 04:09:34 +00:00
|
|
|
* 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
|
2001-02-20 22:00:03 +00:00
|
|
|
* and SI to shift into single byte mode
|
2000-11-02 04:09:34 +00:00
|
|
|
*/
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
2001-02-24 02:41:29 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
UConverter* saveConv = args->converter;
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)saveConv->extraInfo;
|
|
|
|
args->converter=myConverterData->currentConverter;
|
|
|
|
|
|
|
|
myConverterData->currentConverter->fromUChar32 = saveConv->fromUChar32;
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_MBCSFromUnicodeWithOffsets(args,err);
|
2003-12-09 01:18:21 +00:00
|
|
|
saveConv->fromUChar32 = myConverterData->currentConverter->fromUChar32;
|
|
|
|
|
|
|
|
if(*err == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
if(myConverterData->currentConverter->charErrorBufferLength > 0) {
|
|
|
|
uprv_memcpy(
|
|
|
|
saveConv->charErrorBuffer,
|
|
|
|
myConverterData->currentConverter->charErrorBuffer,
|
|
|
|
myConverterData->currentConverter->charErrorBufferLength);
|
|
|
|
}
|
|
|
|
saveConv->charErrorBufferLength = myConverterData->currentConverter->charErrorBufferLength;
|
|
|
|
myConverterData->currentConverter->charErrorBufferLength = 0;
|
|
|
|
}
|
|
|
|
args->converter=saveConv;
|
2001-02-24 02:41:29 +00:00
|
|
|
}
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-03-02 23:57:58 +00:00
|
|
|
const UChar *source = args->source;
|
|
|
|
const UChar *sourceLimit = args->sourceLimit;
|
|
|
|
unsigned char *target = (unsigned char *) args->target;
|
|
|
|
unsigned char *targetLimit = (unsigned char *) args->targetLimit;
|
2001-02-02 03:51:57 +00:00
|
|
|
int32_t* offsets = args->offsets;
|
2001-03-02 23:57:58 +00:00
|
|
|
uint32_t targetByteUnit = 0x0000;
|
|
|
|
UChar32 sourceChar = 0x0000;
|
2001-07-18 23:45:04 +00:00
|
|
|
UBool isTargetByteDBCS;
|
|
|
|
UBool oldIsTargetByteDBCS;
|
|
|
|
UConverterDataISO2022 *converterData;
|
|
|
|
UConverterSharedData* sharedData;
|
|
|
|
UBool useFallback;
|
2001-02-02 03:51:57 +00:00
|
|
|
int32_t length =0;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-07-18 23:45:04 +00:00
|
|
|
converterData=(UConverterDataISO2022*)args->converter->extraInfo;
|
2007-08-07 01:38:29 +00:00
|
|
|
/* if the version is 1 then the user is requesting
|
|
|
|
* conversion with ibm-25546 pass the arguments to
|
2001-02-23 04:39:32 +00:00
|
|
|
* MBCS converter and return
|
|
|
|
*/
|
2001-03-02 23:57:58 +00:00
|
|
|
if(converterData->version==1){
|
2001-02-24 02:41:29 +00:00
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(args,err);
|
2001-02-23 04:39:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-12-09 01:18:21 +00:00
|
|
|
|
|
|
|
/* initialize data */
|
|
|
|
sharedData = converterData->currentConverter->sharedData;
|
|
|
|
useFallback = args->converter->useFallback;
|
|
|
|
isTargetByteDBCS=(UBool)args->converter->fromUnicodeStatus;
|
|
|
|
oldIsTargetByteDBCS = isTargetByteDBCS;
|
2007-08-07 01:38:29 +00:00
|
|
|
|
2001-03-02 23:57:58 +00:00
|
|
|
isTargetByteDBCS = (UBool) args->converter->fromUnicodeStatus;
|
2003-07-24 00:28:47 +00:00
|
|
|
if((sourceChar = args->converter->fromUChar32)!=0 && target <targetLimit) {
|
2001-02-24 02:41:29 +00:00
|
|
|
goto getTrail;
|
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
while(source < sourceLimit){
|
2007-08-07 01:38:29 +00:00
|
|
|
|
2001-03-02 23:57:58 +00:00
|
|
|
targetByteUnit = missingCharMarker;
|
|
|
|
|
|
|
|
if(target < (unsigned char*) args->targetLimit){
|
|
|
|
sourceChar = *source++;
|
2005-06-03 20:17:54 +00:00
|
|
|
|
|
|
|
/* do not convert SO/SI/ESC */
|
|
|
|
if(IS_2022_CONTROL(sourceChar)) {
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
args->converter->fromUChar32=sourceChar;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-23 05:46:49 +00:00
|
|
|
length = MBCS_FROM_UCHAR32_ISO2022(sharedData,sourceChar,&targetByteUnit,useFallback,MBCS_OUTPUT_2);
|
|
|
|
if(length < 0) {
|
|
|
|
length = -length; /* fallback */
|
|
|
|
}
|
2000-08-25 23:14:10 +00:00
|
|
|
/* only DBCS or SBCS characters are expected*/
|
2003-12-09 01:18:21 +00:00
|
|
|
/* DB characters with high bit set to 1 are expected */
|
2001-03-02 23:57:58 +00:00
|
|
|
if(length > 2 || length==0 ||(((targetByteUnit & 0x8080) != 0x8080)&& length==2)){
|
|
|
|
targetByteUnit=missingCharMarker;
|
2000-11-02 04:09:34 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
if (targetByteUnit != missingCharMarker){
|
|
|
|
|
|
|
|
oldIsTargetByteDBCS = isTargetByteDBCS;
|
|
|
|
isTargetByteDBCS = (UBool)(targetByteUnit>0x00FF);
|
|
|
|
/* append the shift sequence */
|
|
|
|
if (oldIsTargetByteDBCS != isTargetByteDBCS ){
|
2007-08-07 01:38:29 +00:00
|
|
|
|
|
|
|
if (isTargetByteDBCS)
|
2001-03-02 23:57:58 +00:00
|
|
|
*target++ = UCNV_SO;
|
2007-08-07 01:38:29 +00:00
|
|
|
else
|
2001-03-02 23:57:58 +00:00
|
|
|
*target++ = UCNV_SI;
|
|
|
|
if(offsets)
|
2004-12-08 01:05:40 +00:00
|
|
|
*(offsets++) = (int32_t)(source - args->source-1);
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
/* write the targetUniChar to target */
|
|
|
|
if(targetByteUnit <= 0x00FF){
|
|
|
|
if( target < targetLimit){
|
|
|
|
*(target++) = (unsigned char) targetByteUnit;
|
2001-04-07 01:24:30 +00:00
|
|
|
if(offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
*(offsets++) = (int32_t)(source - args->source-1);
|
2001-04-07 01:24:30 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
}else{
|
2001-03-02 23:57:58 +00:00
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit);
|
2001-02-02 03:51:57 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}else{
|
2001-03-02 23:57:58 +00:00
|
|
|
if(target < targetLimit){
|
|
|
|
*(target++) =(unsigned char) ((targetByteUnit>>8) -0x80);
|
2001-04-07 01:24:30 +00:00
|
|
|
if(offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
*(offsets++) = (int32_t)(source - args->source-1);
|
2001-04-07 01:24:30 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
if(target < targetLimit){
|
|
|
|
*(target++) =(unsigned char) (targetByteUnit -0x80);
|
2001-04-07 01:24:30 +00:00
|
|
|
if(offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
*(offsets++) = (int32_t)(source - args->source-1);
|
2001-04-07 01:24:30 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
}else{
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit -0x80);
|
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
}else{
|
2001-03-02 23:57:58 +00:00
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) ((targetByteUnit>>8) -0x80);
|
|
|
|
args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit-0x80);
|
2001-02-02 03:51:57 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-04-07 01:24:30 +00:00
|
|
|
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
|
|
|
else{
|
2001-02-23 04:39:32 +00:00
|
|
|
/* oops.. the code point is unassingned
|
|
|
|
* set the error and reason
|
|
|
|
*/
|
2001-03-02 23:57:58 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
/*check if the char is a First surrogate*/
|
2001-03-02 23:57:58 +00:00
|
|
|
if(UTF_IS_SURROGATE(sourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
|
2001-02-02 03:51:57 +00:00
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
2001-03-02 23:57:58 +00:00
|
|
|
if(source < sourceLimit) {
|
2001-02-02 03:51:57 +00:00
|
|
|
/* test the following code unit */
|
2001-03-02 23:57:58 +00:00
|
|
|
UChar trail=(UChar) *source;
|
2001-02-02 03:51:57 +00:00
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
2001-03-02 23:57:58 +00:00
|
|
|
source++;
|
2003-07-24 00:28:47 +00:00
|
|
|
sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
|
2001-07-18 23:45:04 +00:00
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2001-03-02 23:57:58 +00:00
|
|
|
/* convert this surrogate code point */
|
2001-02-02 03:51:57 +00:00
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched trail code unit (2nd surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
|
|
|
}
|
2003-07-24 00:28:47 +00:00
|
|
|
} else {
|
|
|
|
/* callback(unassigned) for a BMP code point */
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
|
2003-07-24 00:28:47 +00:00
|
|
|
args->converter->fromUChar32=sourceChar;
|
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2001-03-02 23:57:58 +00:00
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
2000-10-20 02:45:38 +00:00
|
|
|
else{
|
2001-03-02 23:57:58 +00:00
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
2000-10-05 02:25:53 +00:00
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-03-02 23:57:58 +00:00
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
|
|
|
|
2003-12-10 02:03:42 +00:00
|
|
|
/*
|
|
|
|
* the end of the input stream and detection of truncated input
|
|
|
|
* are handled by the framework, but for ISO-2022-KR conversion
|
|
|
|
* we need to be in ASCII mode at the very end
|
|
|
|
*
|
|
|
|
* conditions:
|
|
|
|
* successful
|
|
|
|
* not in ASCII mode
|
|
|
|
* end of input and no truncated input
|
|
|
|
*/
|
|
|
|
if( U_SUCCESS(*err) &&
|
|
|
|
isTargetByteDBCS &&
|
|
|
|
args->flush && source>=sourceLimit && args->converter->fromUChar32==0
|
|
|
|
) {
|
|
|
|
int32_t sourceIndex;
|
|
|
|
|
|
|
|
/* we are switching to ASCII */
|
|
|
|
isTargetByteDBCS=FALSE;
|
|
|
|
|
|
|
|
/* get the source index of the last input character */
|
|
|
|
/*
|
|
|
|
* TODO this would be simpler and more reliable if we used a pair
|
|
|
|
* of sourceIndex/prevSourceIndex like in ucnvmbcs.c
|
|
|
|
* so that we could simply use the prevSourceIndex here;
|
|
|
|
* this code gives an incorrect result for the rare case of an unmatched
|
|
|
|
* trail surrogate that is alone in the last buffer of the text stream
|
|
|
|
*/
|
|
|
|
sourceIndex=(int32_t)(source-args->source);
|
|
|
|
if(sourceIndex>0) {
|
|
|
|
--sourceIndex;
|
|
|
|
if( U16_IS_TRAIL(args->source[sourceIndex]) &&
|
|
|
|
(sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
|
|
|
|
) {
|
|
|
|
--sourceIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sourceIndex=-1;
|
|
|
|
}
|
|
|
|
|
2006-07-25 04:53:53 +00:00
|
|
|
fromUWriteUInt8(
|
2003-12-10 02:03:42 +00:00
|
|
|
args->converter,
|
|
|
|
SHIFT_IN_STR, 1,
|
2006-07-25 04:53:53 +00:00
|
|
|
&target, (const char *)targetLimit,
|
2003-12-10 02:03:42 +00:00
|
|
|
&offsets, sourceIndex,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
|
2001-03-02 23:57:58 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->source = source;
|
|
|
|
args->target = (char*)target;
|
2001-03-06 18:19:16 +00:00
|
|
|
args->converter->fromUnicodeStatus = (uint32_t)isTargetByteDBCS;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
/************************ To Unicode ***************************************/
|
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(UConverterToUnicodeArgs *args,
|
2001-02-23 04:39:32 +00:00
|
|
|
UErrorCode* err){
|
|
|
|
char const* sourceStart;
|
|
|
|
UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
UConverterToUnicodeArgs subArgs;
|
|
|
|
int32_t minArgsSize;
|
|
|
|
|
|
|
|
/* set up the subconverter arguments */
|
|
|
|
if(args->size<sizeof(UConverterToUnicodeArgs)) {
|
|
|
|
minArgsSize = args->size;
|
|
|
|
} else {
|
|
|
|
minArgsSize = (int32_t)sizeof(UConverterToUnicodeArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_memcpy(&subArgs, args, minArgsSize);
|
|
|
|
subArgs.size = (uint16_t)minArgsSize;
|
|
|
|
subArgs.converter = myData->currentConverter;
|
|
|
|
|
|
|
|
/* remember the original start of the input for offsets */
|
|
|
|
sourceStart = args->source;
|
|
|
|
|
|
|
|
if(myData->key != 0) {
|
|
|
|
/* continue with a partial escape sequence */
|
|
|
|
goto escape;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(U_SUCCESS(*err) && args->source < args->sourceLimit) {
|
2001-02-23 04:39:32 +00:00
|
|
|
/*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
|
2003-12-09 01:18:21 +00:00
|
|
|
subArgs.source = args->source;
|
|
|
|
subArgs.sourceLimit = getEndOfBuffer_2022(&(args->source), args->sourceLimit, args->flush);
|
|
|
|
if(subArgs.source != subArgs.sourceLimit) {
|
|
|
|
/*
|
|
|
|
* get the current partial byte sequence
|
|
|
|
*
|
|
|
|
* it needs to be moved between the public and the subconverter
|
|
|
|
* so that the conversion framework, which only sees the public
|
|
|
|
* converter, can handle truncated and illegal input etc.
|
|
|
|
*/
|
|
|
|
if(args->converter->toULength > 0) {
|
|
|
|
uprv_memcpy(subArgs.converter->toUBytes, args->converter->toUBytes, args->converter->toULength);
|
|
|
|
}
|
|
|
|
subArgs.converter->toULength = args->converter->toULength;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert up to the end of the input, or to before the next escape character.
|
|
|
|
* Does not handle conversion extensions because the preToU[] state etc.
|
|
|
|
* is not copied.
|
|
|
|
*/
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_MBCSToUnicodeWithOffsets(&subArgs, err);
|
2003-12-09 01:18:21 +00:00
|
|
|
|
|
|
|
if(args->offsets != NULL && sourceStart != args->source) {
|
|
|
|
/* update offsets to base them on the actual start of the input */
|
|
|
|
int32_t *offsets = args->offsets;
|
|
|
|
UChar *target = args->target;
|
|
|
|
int32_t delta = (int32_t)(args->source - sourceStart);
|
|
|
|
while(target < subArgs.target) {
|
|
|
|
if(*offsets >= 0) {
|
|
|
|
*offsets += delta;
|
|
|
|
}
|
|
|
|
++offsets;
|
|
|
|
++target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
args->source = subArgs.source;
|
|
|
|
args->target = subArgs.target;
|
|
|
|
args->offsets = subArgs.offsets;
|
|
|
|
|
|
|
|
/* copy input/error/overflow buffers */
|
|
|
|
if(subArgs.converter->toULength > 0) {
|
|
|
|
uprv_memcpy(args->converter->toUBytes, subArgs.converter->toUBytes, subArgs.converter->toULength);
|
|
|
|
}
|
|
|
|
args->converter->toULength = subArgs.converter->toULength;
|
|
|
|
|
|
|
|
if(*err == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
if(subArgs.converter->UCharErrorBufferLength > 0) {
|
|
|
|
uprv_memcpy(args->converter->UCharErrorBuffer, subArgs.converter->UCharErrorBuffer,
|
|
|
|
subArgs.converter->UCharErrorBufferLength);
|
|
|
|
}
|
|
|
|
args->converter->UCharErrorBufferLength=subArgs.converter->UCharErrorBufferLength;
|
|
|
|
subArgs.converter->UCharErrorBufferLength = 0;
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
if (U_FAILURE(*err) || (args->source == args->sourceLimit)) {
|
2001-02-23 04:39:32 +00:00
|
|
|
return;
|
2003-12-09 01:18:21 +00:00
|
|
|
}
|
2001-02-23 04:39:32 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
escape:
|
2001-02-23 04:39:32 +00:00
|
|
|
changeState_2022(args->converter,
|
2007-08-07 01:38:29 +00:00
|
|
|
&(args->source),
|
2003-12-04 01:09:57 +00:00
|
|
|
args->sourceLimit,
|
2001-02-24 02:41:29 +00:00
|
|
|
ISO_2022_KR,
|
2001-02-23 04:39:32 +00:00
|
|
|
err);
|
2003-12-09 01:18:21 +00:00
|
|
|
}
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
2000-10-20 02:45:38 +00:00
|
|
|
UErrorCode* err){
|
2003-11-11 18:42:09 +00:00
|
|
|
char tempBuf[2];
|
2000-10-20 02:45:38 +00:00
|
|
|
const char *mySource = ( char *) args->source;
|
|
|
|
UChar *myTarget = args->target;
|
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
|
|
|
UChar32 targetUniChar = 0x0000;
|
|
|
|
UChar mySourceChar = 0x0000;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022* myData;
|
|
|
|
UConverterSharedData* sharedData ;
|
|
|
|
UBool useFallback;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
|
|
|
if(myData->version==1){
|
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(args,err);
|
2000-10-05 02:25:53 +00:00
|
|
|
return;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2003-12-09 01:18:21 +00:00
|
|
|
|
2001-07-18 23:45:04 +00:00
|
|
|
/* initialize state */
|
2003-12-06 01:52:37 +00:00
|
|
|
sharedData = myData->currentConverter->sharedData;
|
2001-07-18 23:45:04 +00:00
|
|
|
useFallback = args->converter->useFallback;
|
2007-08-07 01:38:29 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
if(myData->key != 0) {
|
|
|
|
/* continue with a partial escape sequence */
|
|
|
|
goto escape;
|
|
|
|
} else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
|
|
|
|
/* continue with a partial double-byte character */
|
|
|
|
mySourceChar = args->converter->toUBytes[0];
|
|
|
|
args->converter->toULength = 0;
|
|
|
|
goto getTrailByte;
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
while(mySource< mySourceLimit){
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-10-20 02:45:38 +00:00
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-05-07 23:54:01 +00:00
|
|
|
if(mySourceChar==UCNV_SI){
|
2003-12-09 01:18:21 +00:00
|
|
|
myData->toU2022State.g = 0;
|
2001-05-07 23:54:01 +00:00
|
|
|
/*consume the source */
|
|
|
|
continue;
|
|
|
|
}else if(mySourceChar==UCNV_SO){
|
2003-12-09 01:18:21 +00:00
|
|
|
myData->toU2022State.g = 1;
|
2001-05-07 23:54:01 +00:00
|
|
|
/*consume the source */
|
|
|
|
continue;
|
2003-12-09 01:18:21 +00:00
|
|
|
}else if(mySourceChar==ESC_2022){
|
|
|
|
mySource--;
|
|
|
|
escape:
|
2007-08-07 01:38:29 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
2003-12-09 01:18:21 +00:00
|
|
|
mySourceLimit, ISO_2022_KR, err);
|
2001-05-07 23:54:01 +00:00
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
2007-08-07 01:38:29 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
if(myData->toU2022State.g == 1) {
|
|
|
|
if(mySource < mySourceLimit) {
|
|
|
|
char trailByte;
|
|
|
|
getTrailByte:
|
|
|
|
trailByte = *mySource++;
|
|
|
|
tempBuf[0] = (char)(mySourceChar + 0x80);
|
|
|
|
tempBuf[1] = (char)(trailByte + 0x80);
|
|
|
|
mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
|
|
|
|
if((mySourceChar & 0x8080) == 0) {
|
2004-09-16 04:00:12 +00:00
|
|
|
targetUniChar = ucnv_MBCSSimpleGetNextUChar(sharedData, tempBuf, 2, useFallback);
|
2003-12-09 01:18:21 +00:00
|
|
|
} else {
|
|
|
|
/* illegal bytes > 0x7f */
|
|
|
|
targetUniChar = missingCharMarker;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args->converter->toUBytes[0] = (uint8_t)mySourceChar;
|
|
|
|
args->converter->toULength = 1;
|
|
|
|
break;
|
2000-10-20 02:45:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2004-09-16 04:00:12 +00:00
|
|
|
targetUniChar = ucnv_MBCSSimpleGetNextUChar(sharedData, mySource - 1, 1, useFallback);
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2003-11-11 18:42:09 +00:00
|
|
|
if(targetUniChar < 0xfffe){
|
2003-12-09 01:18:21 +00:00
|
|
|
if(args->offsets) {
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2003-12-09 01:18:21 +00:00
|
|
|
}
|
2000-10-20 02:45:38 +00:00
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
}
|
2001-05-07 23:54:01 +00:00
|
|
|
else {
|
2001-02-28 02:54:39 +00:00
|
|
|
/* Call the callback function*/
|
2003-08-01 14:42:29 +00:00
|
|
|
toUnicodeCallback(args->converter,mySourceChar,targetUniChar,err);
|
|
|
|
break;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 *********************************
|
2001-02-20 22:00:03 +00:00
|
|
|
*
|
2000-11-02 04:09:34 +00:00
|
|
|
* Rules for ISO-2022-CN Encoding:
|
2003-12-03 17:45:32 +00:00
|
|
|
* i) The designator sequence must appear once on a line before any instance
|
2000-11-02 04:09:34 +00:00
|
|
|
* of character set it designates.
|
|
|
|
* ii) If two lines contain characters from the same character set, both lines
|
|
|
|
* must include the designator sequence.
|
2003-12-03 17:45:32 +00:00
|
|
|
* iii) Once the designator sequence is known, a shifting sequence has to be found
|
2000-11-02 04:09:34 +00:00
|
|
|
* to invoke the shifting
|
2001-02-20 22:00:03 +00:00
|
|
|
* iv) All lines start in ASCII and end in ASCII.
|
2000-11-02 04:09:34 +00:00
|
|
|
* v) Four shifting sequences are employed for this purpose:
|
|
|
|
*
|
|
|
|
* Sequcence ASCII Eq Charsets
|
2001-02-20 22:00:03 +00:00
|
|
|
* ---------- ------- ---------
|
2003-12-03 17:45:32 +00:00
|
|
|
* SI <SI> US-ASCII
|
|
|
|
* SO <SO> CNS-11643-1992 Plane 1, GB2312, ISO-IR-165
|
|
|
|
* SS2 <ESC>N CNS-11643-1992 Plane 2
|
|
|
|
* SS3 <ESC>O CNS-11643-1992 Planes 3-7
|
2000-11-02 04:09:34 +00:00
|
|
|
*
|
2001-02-20 22:00:03 +00:00
|
|
|
* vi)
|
2000-11-02 04:09:34 +00:00
|
|
|
* 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
|
2001-02-20 22:00:03 +00:00
|
|
|
*
|
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
|
2007-08-07 01:38:29 +00:00
|
|
|
* (Meaning <ESC>N must preceed every 2 byte
|
2000-11-20 18:08:49 +00:00
|
|
|
* 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
|
2007-08-07 01:38:29 +00:00
|
|
|
* (Meaning <ESC>O must preceed every 2 byte
|
2001-02-20 22:00:03 +00:00
|
|
|
* 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
|
2007-08-07 01:38:29 +00:00
|
|
|
* (In English: <ESC>O must preceed every 2 byte
|
2001-02-20 22:00:03 +00:00
|
|
|
* 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
|
2001-02-02 03:51:57 +00:00
|
|
|
* has its own designation information before any Chinese characters
|
|
|
|
* appear
|
|
|
|
*
|
|
|
|
*/
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2001-08-31 22:00:00 +00:00
|
|
|
/* The following are defined this way to make the strings truely readonly */
|
|
|
|
static const char GB_2312_80_STR[] = "\x1B\x24\x29\x41";
|
|
|
|
static const char ISO_IR_165_STR[] = "\x1B\x24\x29\x45";
|
|
|
|
static const char CNS_11643_1992_Plane_1_STR[] = "\x1B\x24\x29\x47";
|
|
|
|
static const char CNS_11643_1992_Plane_2_STR[] = "\x1B\x24\x2A\x48";
|
|
|
|
static const char CNS_11643_1992_Plane_3_STR[] = "\x1B\x24\x2B\x49";
|
|
|
|
static const char CNS_11643_1992_Plane_4_STR[] = "\x1B\x24\x2B\x4A";
|
|
|
|
static const char CNS_11643_1992_Plane_5_STR[] = "\x1B\x24\x2B\x4B";
|
|
|
|
static const char CNS_11643_1992_Plane_6_STR[] = "\x1B\x24\x2B\x4C";
|
|
|
|
static const char CNS_11643_1992_Plane_7_STR[] = "\x1B\x24\x2B\x4D";
|
2000-11-08 23:16:20 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
/********************** ISO2022-CN Data **************************/
|
2001-08-24 00:22:07 +00:00
|
|
|
static const char* const escSeqCharsCN[10] ={
|
2001-08-31 22:00:00 +00:00
|
|
|
SHIFT_IN_STR, /* ASCII */
|
|
|
|
GB_2312_80_STR,
|
|
|
|
ISO_IR_165_STR,
|
|
|
|
CNS_11643_1992_Plane_1_STR,
|
|
|
|
CNS_11643_1992_Plane_2_STR,
|
|
|
|
CNS_11643_1992_Plane_3_STR,
|
|
|
|
CNS_11643_1992_Plane_4_STR,
|
|
|
|
CNS_11643_1992_Plane_5_STR,
|
|
|
|
CNS_11643_1992_Plane_6_STR,
|
2002-07-16 00:29:25 +00:00
|
|
|
CNS_11643_1992_Plane_7_STR
|
2001-02-02 03:51:57 +00:00
|
|
|
};
|
2000-08-22 00:02:54 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
|
2007-08-23 05:46:49 +00:00
|
|
|
UConverter *cnv = args->converter;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022 *converterData;
|
2003-12-06 01:52:37 +00:00
|
|
|
ISO2022State *pFromU2022State;
|
2003-12-03 17:45:32 +00:00
|
|
|
uint8_t *target = (uint8_t *) args->target;
|
|
|
|
const uint8_t *targetLimit = (const uint8_t *) args->targetLimit;
|
2001-02-28 22:37:49 +00:00
|
|
|
const UChar* source = args->source;
|
2001-02-02 03:51:57 +00:00
|
|
|
const UChar* sourceLimit = args->sourceLimit;
|
|
|
|
int32_t* offsets = args->offsets;
|
2003-12-03 17:45:32 +00:00
|
|
|
UChar32 sourceChar;
|
|
|
|
char buffer[8];
|
|
|
|
int32_t len;
|
|
|
|
int8_t choices[3];
|
|
|
|
int32_t choiceCount;
|
2004-12-07 23:43:48 +00:00
|
|
|
uint32_t targetValue = 0;
|
2001-07-18 23:45:04 +00:00
|
|
|
UBool useFallback;
|
2000-11-02 04:09:34 +00:00
|
|
|
|
2001-07-18 23:45:04 +00:00
|
|
|
/* set up the state */
|
2007-08-23 05:46:49 +00:00
|
|
|
converterData = (UConverterDataISO2022*)cnv->extraInfo;
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State = &converterData->fromU2022State;
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
choiceCount = 0;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
/* check if the last codepoint of previous buffer was a lead surrogate*/
|
2007-08-23 05:46:49 +00:00
|
|
|
if((sourceChar = cnv->fromUChar32)!=0 && target< targetLimit) {
|
2000-11-08 23:16:20 +00:00
|
|
|
goto getTrail;
|
|
|
|
}
|
2001-07-18 23:45:04 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
while( source < sourceLimit){
|
|
|
|
if(target < targetLimit){
|
|
|
|
|
2001-02-28 02:54:39 +00:00
|
|
|
sourceChar = *(source++);
|
2001-02-02 03:51:57 +00:00
|
|
|
/*check if the char is a First surrogate*/
|
|
|
|
if(UTF_IS_SURROGATE(sourceChar)) {
|
|
|
|
if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
|
2000-11-08 23:16:20 +00:00
|
|
|
getTrail:
|
|
|
|
/*look ahead to find the trail surrogate*/
|
2001-02-02 03:51:57 +00:00
|
|
|
if(source < sourceLimit) {
|
2000-11-08 23:16:20 +00:00
|
|
|
/* test the following code unit */
|
2001-02-02 03:51:57 +00:00
|
|
|
UChar trail=(UChar) *source;
|
2000-11-08 23:16:20 +00:00
|
|
|
if(UTF_IS_SECOND_SURROGATE(trail)) {
|
2001-02-02 03:51:57 +00:00
|
|
|
source++;
|
2003-07-24 00:28:47 +00:00
|
|
|
sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=0x00;
|
2003-07-24 00:28:47 +00:00
|
|
|
/* convert this supplementary code point */
|
2000-11-08 23:16:20 +00:00
|
|
|
/* exit this condition tree */
|
|
|
|
} else {
|
|
|
|
/* this is an unmatched lead code unit (1st surrogate) */
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-07-24 00:28:47 +00:00
|
|
|
break;
|
2000-11-08 23:16:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no more input */
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
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
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-07-24 00:28:47 +00:00
|
|
|
break;
|
2000-10-05 02:25:53 +00:00
|
|
|
}
|
2000-08-29 21:47:40 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
|
|
|
/* do the conversion */
|
2003-12-03 17:45:32 +00:00
|
|
|
if(sourceChar <= 0x007f ){
|
2005-06-03 20:17:54 +00:00
|
|
|
/* do not convert SO/SI/ESC */
|
|
|
|
if(IS_2022_CONTROL(sourceChar)) {
|
|
|
|
/* callback(illegal) */
|
|
|
|
*err=U_ILLEGAL_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2005-06-03 20:17:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* US-ASCII */
|
2003-12-06 01:52:37 +00:00
|
|
|
if(pFromU2022State->g == 0) {
|
2003-12-03 17:45:32 +00:00
|
|
|
buffer[0] = (char)sourceChar;
|
|
|
|
len = 1;
|
|
|
|
} else {
|
|
|
|
buffer[0] = UCNV_SI;
|
|
|
|
buffer[1] = (char)sourceChar;
|
|
|
|
len = 2;
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State->g = 0;
|
|
|
|
choiceCount = 0;
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
|
|
|
if(sourceChar == CR || sourceChar == LF) {
|
|
|
|
/* reset the state at the end of a line */
|
2003-12-06 01:52:37 +00:00
|
|
|
uprv_memset(pFromU2022State, 0, sizeof(ISO2022State));
|
|
|
|
choiceCount = 0;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2000-08-22 00:02:54 +00:00
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
else{
|
2003-12-03 17:45:32 +00:00
|
|
|
/* convert U+0080..U+10ffff */
|
|
|
|
int32_t i;
|
|
|
|
int8_t cs, g;
|
|
|
|
|
|
|
|
if(choiceCount == 0) {
|
|
|
|
/* try the current SO/G1 converter first */
|
2003-12-06 01:52:37 +00:00
|
|
|
choices[0] = pFromU2022State->cs[1];
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
/* default to GB2312_1 if none is designated yet */
|
|
|
|
if(choices[0] == 0) {
|
|
|
|
choices[0] = GB2312_1;
|
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
if(converterData->version == 0) {
|
|
|
|
/* ISO-2022-CN */
|
|
|
|
|
|
|
|
/* try the other SO/G1 converter; a CNS_11643_1 lookup may result in any plane */
|
|
|
|
if(choices[0] == GB2312_1) {
|
|
|
|
choices[1] = (int8_t)CNS_11643_1;
|
|
|
|
} else {
|
|
|
|
choices[1] = (int8_t)GB2312_1;
|
2001-02-08 19:45:07 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
choiceCount = 2;
|
|
|
|
} else {
|
|
|
|
/* ISO-2022-CN-EXT */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* try one of the other converters */
|
|
|
|
switch(choices[0]) {
|
|
|
|
case GB2312_1:
|
|
|
|
choices[1] = (int8_t)CNS_11643_1;
|
|
|
|
choices[2] = (int8_t)ISO_IR_165;
|
|
|
|
break;
|
|
|
|
case ISO_IR_165:
|
|
|
|
choices[1] = (int8_t)GB2312_1;
|
|
|
|
choices[2] = (int8_t)CNS_11643_1;
|
|
|
|
break;
|
|
|
|
default: /* CNS_11643_x */
|
|
|
|
choices[1] = (int8_t)GB2312_1;
|
|
|
|
choices[2] = (int8_t)ISO_IR_165;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
choiceCount = 3;
|
|
|
|
}
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
cs = g = 0;
|
2007-08-23 05:46:49 +00:00
|
|
|
/*
|
|
|
|
* len==0: no mapping found yet
|
|
|
|
* len<0: found a fallback result: continue looking for a roundtrip but no further fallbacks
|
|
|
|
* len>0: found a roundtrip result, done
|
|
|
|
*/
|
2003-12-03 17:45:32 +00:00
|
|
|
len = 0;
|
2007-08-23 23:43:03 +00:00
|
|
|
/*
|
|
|
|
* We will turn off useFallback after finding a fallback,
|
|
|
|
* but we still get fallbacks from PUA code points as usual.
|
|
|
|
* Therefore, we will also need to check that we don't overwrite
|
|
|
|
* an early fallback with a later one.
|
|
|
|
*/
|
2007-08-23 05:46:49 +00:00
|
|
|
useFallback = cnv->useFallback;
|
|
|
|
|
|
|
|
for(i = 0; i < choiceCount && len <= 0; ++i) {
|
|
|
|
int8_t cs0 = choices[i];
|
|
|
|
if(cs0 > 0) {
|
|
|
|
uint32_t value;
|
|
|
|
int32_t len2;
|
|
|
|
if(cs0 > CNS_11643_0) {
|
|
|
|
len2 = MBCS_FROM_UCHAR32_ISO2022(
|
|
|
|
converterData->myConverterArray[CNS_11643],
|
|
|
|
sourceChar,
|
|
|
|
&value,
|
|
|
|
useFallback,
|
|
|
|
MBCS_OUTPUT_3);
|
2007-08-23 23:43:03 +00:00
|
|
|
if(len2 == 3 || (len2 == -3 && len == 0)) {
|
2007-08-23 05:46:49 +00:00
|
|
|
targetValue = value;
|
|
|
|
cs = (int8_t)(CNS_11643_0 + (value >> 16) - 0x80);
|
|
|
|
if(len2 >= 0) {
|
|
|
|
len = 2;
|
|
|
|
} else {
|
|
|
|
len = -2;
|
|
|
|
useFallback = FALSE;
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
if(cs == CNS_11643_1) {
|
|
|
|
g = 1;
|
|
|
|
} else if(cs == CNS_11643_2) {
|
|
|
|
g = 2;
|
|
|
|
} else /* plane 3..7 */ if(converterData->version == 1) {
|
|
|
|
g = 3;
|
|
|
|
} else {
|
|
|
|
/* ISO-2022-CN (without -EXT) does not support plane 3..7 */
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* GB2312_1 or ISO-IR-165 */
|
2007-08-23 05:46:49 +00:00
|
|
|
len2 = MBCS_FROM_UCHAR32_ISO2022(
|
|
|
|
converterData->myConverterArray[cs0],
|
|
|
|
sourceChar,
|
|
|
|
&value,
|
|
|
|
useFallback,
|
|
|
|
MBCS_OUTPUT_2);
|
2007-08-23 23:43:03 +00:00
|
|
|
if(len2 == 2 || (len2 == -2 && len == 0)) {
|
2007-08-23 05:46:49 +00:00
|
|
|
targetValue = value;
|
|
|
|
len = len2;
|
|
|
|
cs = cs0;
|
|
|
|
g = 1;
|
|
|
|
useFallback = FALSE;
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
2001-08-17 00:24:58 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2007-08-23 05:46:49 +00:00
|
|
|
if(len != 0) {
|
|
|
|
len = 0; /* count output bytes; it must have been abs(len) == 2 */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* write the designation sequence if necessary */
|
2003-12-06 01:52:37 +00:00
|
|
|
if(cs != pFromU2022State->cs[g]) {
|
2003-12-03 17:45:32 +00:00
|
|
|
if(cs < CNS_11643) {
|
|
|
|
uprv_memcpy(buffer, escSeqCharsCN[cs], 4);
|
|
|
|
} else {
|
|
|
|
uprv_memcpy(buffer, escSeqCharsCN[CNS_11643 + (cs - CNS_11643_1)], 4);
|
2001-04-07 01:24:30 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
len = 4;
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State->cs[g] = cs;
|
2003-12-03 17:45:32 +00:00
|
|
|
if(g == 1) {
|
|
|
|
/* changing the SO/G1 charset invalidates the choices[] */
|
|
|
|
choiceCount = 0;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write the shift sequence if necessary */
|
2003-12-06 01:52:37 +00:00
|
|
|
if(g != pFromU2022State->g) {
|
2003-12-03 17:45:32 +00:00
|
|
|
switch(g) {
|
|
|
|
case 1:
|
|
|
|
buffer[len++] = UCNV_SO;
|
|
|
|
|
|
|
|
/* set the new state only if it is the locking shift SO/G1, not for SS2 or SS3 */
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State->g = 1;
|
2003-12-03 17:45:32 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
buffer[len++] = 0x1b;
|
|
|
|
buffer[len++] = 0x4e;
|
|
|
|
break;
|
|
|
|
default: /* case 3 */
|
|
|
|
buffer[len++] = 0x1b;
|
|
|
|
buffer[len++] = 0x4f;
|
|
|
|
break;
|
2003-08-14 02:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-16 20:16:09 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* write the two output bytes */
|
|
|
|
buffer[len++] = (char)(targetValue >> 8);
|
|
|
|
buffer[len++] = (char)targetValue;
|
|
|
|
} else {
|
2007-08-07 01:38:29 +00:00
|
|
|
/* if we cannot find the character after checking all codepages
|
2003-12-03 17:45:32 +00:00
|
|
|
* then this is an error
|
|
|
|
*/
|
|
|
|
*err = U_INVALID_CHAR_FOUND;
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv->fromUChar32=sourceChar;
|
2003-12-03 17:45:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-11-17 03:01:23 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
/* output len>0 bytes in buffer[] */
|
|
|
|
if(len == 1) {
|
|
|
|
*target++ = buffer[0];
|
|
|
|
if(offsets) {
|
2004-12-08 01:05:40 +00:00
|
|
|
*offsets++ = (int32_t)(source - args->source - 1); /* -1: known to be ASCII */
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
|
|
|
} else if(len == 2 && (target + 2) <= targetLimit) {
|
|
|
|
*target++ = buffer[0];
|
|
|
|
*target++ = buffer[1];
|
|
|
|
if(offsets) {
|
|
|
|
int32_t sourceIndex = (int32_t)(source - args->source - U16_LENGTH(sourceChar));
|
|
|
|
*offsets++ = sourceIndex;
|
|
|
|
*offsets++ = sourceIndex;
|
|
|
|
}
|
|
|
|
} else {
|
2006-07-25 04:53:53 +00:00
|
|
|
fromUWriteUInt8(
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv,
|
2003-12-03 17:45:32 +00:00
|
|
|
buffer, len,
|
2006-07-25 04:53:53 +00:00
|
|
|
&target, (const char *)targetLimit,
|
2003-12-03 17:45:32 +00:00
|
|
|
&offsets, (int32_t)(source - args->source - U16_LENGTH(sourceChar)),
|
|
|
|
err);
|
|
|
|
if(U_FAILURE(*err)) {
|
|
|
|
break;
|
|
|
|
}
|
2003-08-01 14:42:29 +00:00
|
|
|
}
|
2003-08-14 02:32:31 +00:00
|
|
|
} /* end if(myTargetIndex<myTargetLength) */
|
|
|
|
else{
|
|
|
|
*err =U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
}/* end while(mySourceIndex<mySourceLength) */
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-10 02:03:42 +00:00
|
|
|
/*
|
|
|
|
* the end of the input stream and detection of truncated input
|
|
|
|
* are handled by the framework, but for ISO-2022-CN conversion
|
|
|
|
* we need to be in ASCII mode at the very end
|
|
|
|
*
|
|
|
|
* conditions:
|
|
|
|
* successful
|
|
|
|
* not in ASCII mode
|
|
|
|
* end of input and no truncated input
|
|
|
|
*/
|
|
|
|
if( U_SUCCESS(*err) &&
|
|
|
|
pFromU2022State->g!=0 &&
|
2007-08-23 05:46:49 +00:00
|
|
|
args->flush && source>=sourceLimit && cnv->fromUChar32==0
|
2003-12-10 02:03:42 +00:00
|
|
|
) {
|
|
|
|
int32_t sourceIndex;
|
|
|
|
|
|
|
|
/* we are switching to ASCII */
|
|
|
|
pFromU2022State->g=0;
|
|
|
|
|
|
|
|
/* get the source index of the last input character */
|
|
|
|
/*
|
|
|
|
* TODO this would be simpler and more reliable if we used a pair
|
|
|
|
* of sourceIndex/prevSourceIndex like in ucnvmbcs.c
|
|
|
|
* so that we could simply use the prevSourceIndex here;
|
|
|
|
* this code gives an incorrect result for the rare case of an unmatched
|
|
|
|
* trail surrogate that is alone in the last buffer of the text stream
|
|
|
|
*/
|
|
|
|
sourceIndex=(int32_t)(source-args->source);
|
|
|
|
if(sourceIndex>0) {
|
|
|
|
--sourceIndex;
|
|
|
|
if( U16_IS_TRAIL(args->source[sourceIndex]) &&
|
|
|
|
(sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
|
|
|
|
) {
|
|
|
|
--sourceIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sourceIndex=-1;
|
|
|
|
}
|
|
|
|
|
2006-07-25 04:53:53 +00:00
|
|
|
fromUWriteUInt8(
|
2007-08-23 05:46:49 +00:00
|
|
|
cnv,
|
2003-12-10 02:03:42 +00:00
|
|
|
SHIFT_IN_STR, 1,
|
2006-07-25 04:53:53 +00:00
|
|
|
&target, (const char *)targetLimit,
|
2003-12-10 02:03:42 +00:00
|
|
|
&offsets, sourceIndex,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
/*save the state and return */
|
|
|
|
args->source = source;
|
|
|
|
args->target = (char*)target;
|
2001-02-20 22:00:03 +00:00
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static void
|
2001-03-22 18:35:08 +00:00
|
|
|
UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
|
|
|
|
UErrorCode* err){
|
2000-10-04 00:11:50 +00:00
|
|
|
char tempBuf[3];
|
2003-12-06 01:52:37 +00:00
|
|
|
const char *mySource = (char *) args->source;
|
2000-09-21 00:34:21 +00:00
|
|
|
UChar *myTarget = args->target;
|
|
|
|
const char *mySourceLimit = args->sourceLimit;
|
2001-02-08 19:45:07 +00:00
|
|
|
uint32_t targetUniChar = 0x0000;
|
|
|
|
uint32_t mySourceChar = 0x0000;
|
2001-07-18 23:45:04 +00:00
|
|
|
UConverterDataISO2022* myData;
|
2003-12-06 01:52:37 +00:00
|
|
|
ISO2022State *pToU2022State;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
myData=(UConverterDataISO2022*)(args->converter->extraInfo);
|
2003-12-06 01:52:37 +00:00
|
|
|
pToU2022State = &myData->toU2022State;
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
if(myData->key != 0) {
|
|
|
|
/* continue with a partial escape sequence */
|
|
|
|
goto escape;
|
|
|
|
} else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
|
|
|
|
/* continue with a partial double-byte character */
|
|
|
|
mySourceChar = args->converter->toUBytes[0];
|
|
|
|
args->converter->toULength = 0;
|
|
|
|
goto getTrailByte;
|
2000-09-19 01:41:17 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
|
|
|
|
while(mySource < mySourceLimit){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-16 20:16:09 +00:00
|
|
|
targetUniChar =missingCharMarker;
|
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
if(myTarget < args->targetLimit){
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-02 03:51:57 +00:00
|
|
|
mySourceChar= (unsigned char) *mySource++;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2000-09-21 00:34:21 +00:00
|
|
|
switch(mySourceChar){
|
2001-02-23 04:39:32 +00:00
|
|
|
case UCNV_SI:
|
2003-12-06 01:52:37 +00:00
|
|
|
pToU2022State->g=0;
|
2001-02-23 04:39:32 +00:00
|
|
|
continue;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-23 04:39:32 +00:00
|
|
|
case UCNV_SO:
|
2003-12-06 01:52:37 +00:00
|
|
|
if(pToU2022State->cs[1] != 0) {
|
|
|
|
pToU2022State->g=1;
|
2003-12-03 17:45:32 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* illegal to have SO before a matching designator */
|
2001-02-23 04:39:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-23 04:39:32 +00:00
|
|
|
case ESC_2022:
|
|
|
|
mySource--;
|
2003-12-03 17:45:32 +00:00
|
|
|
escape:
|
2007-08-07 01:38:29 +00:00
|
|
|
changeState_2022(args->converter,&(mySource),
|
2003-12-03 17:45:32 +00:00
|
|
|
mySourceLimit, ISO_2022_CN,err);
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2001-02-23 04:39:32 +00:00
|
|
|
/* invalid or illegal escape sequence */
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-03 17:45:32 +00:00
|
|
|
/* ISO-2022-CN does not use single-byte (C1) SS2 and SS3 */
|
|
|
|
|
|
|
|
case CR:
|
|
|
|
/*falls through*/
|
|
|
|
case LF:
|
2003-12-06 01:52:37 +00:00
|
|
|
uprv_memset(pToU2022State, 0, sizeof(ISO2022State));
|
2003-12-03 17:45:32 +00:00
|
|
|
/* falls through */
|
|
|
|
default:
|
|
|
|
/* convert one or two bytes */
|
2003-12-06 01:52:37 +00:00
|
|
|
if(pToU2022State->g != 0) {
|
2003-12-03 17:45:32 +00:00
|
|
|
if(mySource < mySourceLimit) {
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverterSharedData *cnv;
|
2003-12-03 17:45:32 +00:00
|
|
|
StateEnum tempState;
|
|
|
|
int32_t tempBufLen;
|
2003-12-06 01:52:37 +00:00
|
|
|
char trailByte;
|
|
|
|
getTrailByte:
|
|
|
|
trailByte = *mySource++;
|
|
|
|
tempState = (StateEnum)pToU2022State->cs[pToU2022State->g];
|
2003-12-03 17:45:32 +00:00
|
|
|
if(tempState > CNS_11643_0) {
|
|
|
|
cnv = myData->myConverterArray[CNS_11643];
|
|
|
|
tempBuf[0] = (char) (0x80+(tempState-CNS_11643_0));
|
|
|
|
tempBuf[1] = (char) (mySourceChar);
|
|
|
|
tempBuf[2] = trailByte;
|
|
|
|
tempBufLen = 3;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
cnv = myData->myConverterArray[tempState];
|
|
|
|
tempBuf[0] = (char) (mySourceChar);
|
|
|
|
tempBuf[1] = trailByte;
|
|
|
|
tempBufLen = 2;
|
|
|
|
}
|
|
|
|
mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
|
2003-12-06 01:52:37 +00:00
|
|
|
if(pToU2022State->g>=2) {
|
2003-12-03 17:45:32 +00:00
|
|
|
/* return from a single-shift state to the previous one */
|
2003-12-06 01:52:37 +00:00
|
|
|
pToU2022State->g=pToU2022State->prevG;
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
2004-09-16 04:00:12 +00:00
|
|
|
targetUniChar = ucnv_MBCSSimpleGetNextUChar(cnv, tempBuf, tempBufLen, FALSE);
|
2003-12-03 17:45:32 +00:00
|
|
|
} else {
|
|
|
|
args->converter->toUBytes[0] = (uint8_t)mySourceChar;
|
|
|
|
args->converter->toULength = 1;
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(mySourceChar <= 0x7f) {
|
|
|
|
targetUniChar = (UChar) mySourceChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
2001-05-14 17:43:10 +00:00
|
|
|
if(targetUniChar < (missingCharMarker-1/*0xfffe*/)){
|
2001-02-02 03:51:57 +00:00
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2000-09-21 00:34:21 +00:00
|
|
|
}
|
|
|
|
*(myTarget++)=(UChar)targetUniChar;
|
|
|
|
}
|
2001-05-14 17:43:10 +00:00
|
|
|
else if(targetUniChar > missingCharMarker){
|
2001-05-07 23:54:01 +00:00
|
|
|
/* disassemble the surrogate pair and write to output*/
|
2001-05-11 02:25:35 +00:00
|
|
|
targetUniChar-=0x0010000;
|
2003-12-03 17:45:32 +00:00
|
|
|
*myTarget = (UChar)(0xd800+(UChar)(targetUniChar>>10));
|
2001-08-17 00:24:58 +00:00
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2001-05-07 23:54:01 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
++myTarget;
|
2007-08-07 01:38:29 +00:00
|
|
|
if(myTarget< args->targetLimit){
|
2003-12-03 17:45:32 +00:00
|
|
|
*myTarget = (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
|
2001-05-07 23:54:01 +00:00
|
|
|
if(args->offsets){
|
2004-12-08 01:05:40 +00:00
|
|
|
args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
|
2001-05-07 23:54:01 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
++myTarget;
|
2001-05-07 23:54:01 +00:00
|
|
|
}else{
|
|
|
|
args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++]=
|
|
|
|
(UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-02-16 20:16:09 +00:00
|
|
|
else{
|
2001-02-28 02:54:39 +00:00
|
|
|
/* Call the callback function*/
|
2003-08-01 14:42:29 +00:00
|
|
|
toUnicodeCallback(args->converter,mySourceChar,targetUniChar,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
|
|
|
}
|
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
endloop:
|
2000-09-21 00:34:21 +00:00
|
|
|
args->target = myTarget;
|
|
|
|
args->source = mySource;
|
|
|
|
}
|
2001-02-02 03:51:57 +00:00
|
|
|
|
2001-09-06 18:10:06 +00:00
|
|
|
static void
|
2001-02-02 03:51:57 +00:00
|
|
|
_ISO_2022_WriteSub(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode *err) {
|
|
|
|
UConverter *cnv = args->converter;
|
|
|
|
UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) cnv->extraInfo;
|
2003-12-06 01:52:37 +00:00
|
|
|
ISO2022State *pFromU2022State=&myConverterData->fromU2022State;
|
2003-12-09 01:18:21 +00:00
|
|
|
char *p, *subchar;
|
2003-12-06 01:52:37 +00:00
|
|
|
char buffer[8];
|
2003-12-09 01:18:21 +00:00
|
|
|
int32_t length;
|
|
|
|
|
2006-07-05 23:08:50 +00:00
|
|
|
subchar=(char *)cnv->subChars;
|
2003-12-09 01:18:21 +00:00
|
|
|
length=cnv->subCharLen; /* assume length==1 for most variants */
|
2001-02-02 03:51:57 +00:00
|
|
|
|
|
|
|
p = buffer;
|
|
|
|
switch(myConverterData->locale[0]){
|
2001-02-23 04:39:32 +00:00
|
|
|
case 'j':
|
2003-12-06 01:52:37 +00:00
|
|
|
{
|
|
|
|
int8_t cs;
|
|
|
|
|
|
|
|
if(pFromU2022State->g == 1) {
|
|
|
|
/* JIS7: switch from G1 to G0 */
|
|
|
|
pFromU2022State->g = 0;
|
|
|
|
*p++ = UCNV_SI;
|
|
|
|
}
|
|
|
|
|
|
|
|
cs = pFromU2022State->cs[0];
|
|
|
|
if(cs != ASCII && cs != JISX201) {
|
|
|
|
/* not in ASCII or JIS X 0201: switch to ASCII */
|
|
|
|
pFromU2022State->cs[0] = (int8_t)ASCII;
|
2001-02-23 04:39:32 +00:00
|
|
|
*p++ = '\x1b';
|
|
|
|
*p++ = '\x28';
|
|
|
|
*p++ = '\x42';
|
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
|
2003-12-09 01:18:21 +00:00
|
|
|
*p++ = subchar[0];
|
2001-02-02 03:51:57 +00:00
|
|
|
break;
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
2001-02-23 04:39:32 +00:00
|
|
|
case 'c':
|
2003-12-06 01:52:37 +00:00
|
|
|
if(pFromU2022State->g != 0) {
|
2003-12-03 17:45:32 +00:00
|
|
|
/* not in ASCII mode: switch to ASCII */
|
2003-12-06 01:52:37 +00:00
|
|
|
pFromU2022State->g = 0;
|
2003-12-03 17:45:32 +00:00
|
|
|
*p++ = UCNV_SI;
|
|
|
|
}
|
2003-12-09 01:18:21 +00:00
|
|
|
*p++ = subchar[0];
|
2001-02-23 04:39:32 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
2003-12-09 01:18:21 +00:00
|
|
|
if(myConverterData->version == 0) {
|
|
|
|
if(length == 1) {
|
|
|
|
if((UBool)args->converter->fromUnicodeStatus) {
|
|
|
|
/* in DBCS mode: switch to SBCS */
|
|
|
|
args->converter->fromUnicodeStatus = 0;
|
|
|
|
*p++ = UCNV_SI;
|
|
|
|
}
|
|
|
|
*p++ = subchar[0];
|
|
|
|
} else /* length == 2*/ {
|
|
|
|
if(!(UBool)args->converter->fromUnicodeStatus) {
|
|
|
|
/* in SBCS mode: switch to DBCS */
|
|
|
|
args->converter->fromUnicodeStatus = 1;
|
|
|
|
*p++ = UCNV_SO;
|
|
|
|
}
|
|
|
|
*p++ = subchar[0];
|
|
|
|
*p++ = subchar[1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
2006-07-05 23:08:50 +00:00
|
|
|
/* save the subconverter's substitution string */
|
|
|
|
uint8_t *currentSubChars = myConverterData->currentConverter->subChars;
|
|
|
|
int8_t currentSubCharLen = myConverterData->currentConverter->subCharLen;
|
|
|
|
|
|
|
|
/* set our substitution string into the subconverter */
|
|
|
|
myConverterData->currentConverter->subChars = (uint8_t *)subchar;
|
2003-12-09 01:18:21 +00:00
|
|
|
myConverterData->currentConverter->subCharLen = (int8_t)length;
|
|
|
|
|
2006-07-05 23:08:50 +00:00
|
|
|
/* let the subconverter write the subchar, set/retrieve fromUChar32 state */
|
|
|
|
args->converter = myConverterData->currentConverter;
|
2003-12-09 01:18:21 +00:00
|
|
|
myConverterData->currentConverter->fromUChar32 = cnv->fromUChar32;
|
|
|
|
ucnv_cbFromUWriteSub(args, 0, err);
|
|
|
|
cnv->fromUChar32 = myConverterData->currentConverter->fromUChar32;
|
2006-07-05 23:08:50 +00:00
|
|
|
args->converter = cnv;
|
|
|
|
|
|
|
|
/* restore the subconverter's substitution string */
|
|
|
|
myConverterData->currentConverter->subChars = currentSubChars;
|
|
|
|
myConverterData->currentConverter->subCharLen = currentSubCharLen;
|
2003-12-09 01:18:21 +00:00
|
|
|
|
|
|
|
if(*err == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
if(myConverterData->currentConverter->charErrorBufferLength > 0) {
|
|
|
|
uprv_memcpy(
|
|
|
|
cnv->charErrorBuffer,
|
|
|
|
myConverterData->currentConverter->charErrorBuffer,
|
|
|
|
myConverterData->currentConverter->charErrorBufferLength);
|
|
|
|
}
|
|
|
|
cnv->charErrorBufferLength = myConverterData->currentConverter->charErrorBufferLength;
|
|
|
|
myConverterData->currentConverter->charErrorBufferLength = 0;
|
|
|
|
}
|
|
|
|
return;
|
2001-02-23 04:39:32 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* not expected */
|
|
|
|
break;
|
2001-02-02 03:51:57 +00:00
|
|
|
}
|
|
|
|
ucnv_cbFromUWriteBytes(args,
|
|
|
|
buffer, (int32_t)(p - buffer),
|
|
|
|
offsetIndex, err);
|
|
|
|
}
|
2001-02-16 22:22:40 +00:00
|
|
|
|
2006-06-27 16:17:06 +00:00
|
|
|
/*
|
|
|
|
* Structure for cloning an ISO 2022 converter into a single memory block.
|
|
|
|
* ucnv_safeClone() of the converter will align the entire cloneStruct,
|
|
|
|
* and then ucnv_safeClone() of the sub-converter may additionally align
|
|
|
|
* currentConverter inside the cloneStruct, for which we need the deadSpace
|
|
|
|
* after currentConverter.
|
|
|
|
* This is because UAlignedMemory may be larger than the actually
|
|
|
|
* necessary alignment size for the platform.
|
|
|
|
* The other cloneStruct fields will not be moved around,
|
|
|
|
* and are aligned properly with cloneStruct's alignment.
|
|
|
|
*/
|
2001-02-16 22:22:40 +00:00
|
|
|
struct cloneStruct
|
|
|
|
{
|
2001-02-20 22:00:03 +00:00
|
|
|
UConverter cnv;
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverter currentConverter;
|
2006-06-27 16:17:06 +00:00
|
|
|
UAlignedMemory deadSpace;
|
2006-06-20 22:27:15 +00:00
|
|
|
UConverterDataISO2022 mydata;
|
2001-02-16 22:22:40 +00:00
|
|
|
};
|
|
|
|
|
2002-08-05 22:55:17 +00:00
|
|
|
|
2007-08-07 01:38:29 +00:00
|
|
|
static UConverter *
|
2001-02-16 22:22:40 +00:00
|
|
|
_ISO_2022_SafeClone(
|
2007-08-07 01:38:29 +00:00
|
|
|
const UConverter *cnv,
|
|
|
|
void *stackBuffer,
|
|
|
|
int32_t *pBufferSize,
|
2001-02-20 22:00:03 +00:00
|
|
|
UErrorCode *status)
|
2001-02-16 22:22:40 +00:00
|
|
|
{
|
2001-02-20 22:00:03 +00:00
|
|
|
struct cloneStruct * localClone;
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverterDataISO2022 *cnvData;
|
|
|
|
int32_t i, size;
|
2002-08-05 22:55:17 +00:00
|
|
|
|
|
|
|
if (*pBufferSize == 0) { /* 'preflighting' request - set needed size into *pBufferSize */
|
2003-12-16 05:16:55 +00:00
|
|
|
*pBufferSize = (int32_t)sizeof(struct cloneStruct);
|
|
|
|
return NULL;
|
2002-08-05 22:55:17 +00:00
|
|
|
}
|
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
cnvData = (UConverterDataISO2022 *)cnv->extraInfo;
|
2001-02-16 22:22:40 +00:00
|
|
|
localClone = (struct cloneStruct *)stackBuffer;
|
2001-02-20 22:00:03 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
/* ucnv.c/ucnv_safeClone() copied the main UConverter already */
|
2001-09-05 22:51:53 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
uprv_memcpy(&localClone->mydata, cnvData, sizeof(UConverterDataISO2022));
|
2006-06-27 16:17:06 +00:00
|
|
|
localClone->cnv.extraInfo = &localClone->mydata; /* set pointer to extra data */
|
|
|
|
localClone->cnv.isExtraLocal = TRUE;
|
2002-08-13 16:08:33 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
/* share the subconverters */
|
|
|
|
|
|
|
|
if(cnvData->currentConverter != NULL) {
|
2006-06-16 23:13:50 +00:00
|
|
|
size = (int32_t)(sizeof(UConverter) + sizeof(UAlignedMemory)); /* include size of padding */
|
2006-06-20 22:27:15 +00:00
|
|
|
localClone->mydata.currentConverter =
|
2003-12-16 05:16:55 +00:00
|
|
|
ucnv_safeClone(cnvData->currentConverter,
|
|
|
|
&localClone->currentConverter,
|
2006-06-20 22:27:15 +00:00
|
|
|
&size, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-05 22:55:17 +00:00
|
|
|
}
|
2002-08-13 16:08:33 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
for(i=0; i<UCNV_2022_MAX_CONVERTERS; ++i) {
|
|
|
|
if(cnvData->myConverterArray[i] != NULL) {
|
|
|
|
ucnv_incrementRefCount(cnvData->myConverterArray[i]);
|
2002-08-05 22:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-05 22:51:53 +00:00
|
|
|
|
2001-02-20 22:00:03 +00:00
|
|
|
return &localClone->cnv;
|
2001-02-16 22:22:40 +00:00
|
|
|
}
|
2002-08-05 22:55:17 +00:00
|
|
|
|
2003-04-09 00:00:51 +00:00
|
|
|
static void
|
|
|
|
_ISO_2022_GetUnicodeSet(const UConverter *cnv,
|
2004-12-02 04:18:35 +00:00
|
|
|
const USetAdder *sa,
|
2003-04-09 00:00:51 +00:00
|
|
|
UConverterUnicodeSet which,
|
|
|
|
UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
UConverterDataISO2022* cnvData;
|
|
|
|
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-04 19:36:20 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2003-04-09 00:00:51 +00:00
|
|
|
if (cnv->sharedData == &_ISO2022Data) {
|
|
|
|
/* We use UTF-8 in this case */
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0xd7FF);
|
|
|
|
sa->addRange(sa->set, 0xE000, 0x10FFFF);
|
2003-04-09 00:00:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-12-04 19:36:20 +00:00
|
|
|
#endif
|
2003-04-09 00:00:51 +00:00
|
|
|
|
|
|
|
cnvData = (UConverterDataISO2022*)cnv->extraInfo;
|
|
|
|
|
2003-12-04 16:19:50 +00:00
|
|
|
/* open a set and initialize it with code points that are algorithmically round-tripped */
|
|
|
|
switch(cnvData->locale[0]){
|
|
|
|
case 'j':
|
|
|
|
if(jpCharsetMasks[cnvData->version]&CSM(ISO8859_1)) {
|
|
|
|
/* include Latin-1 for some variants of JP */
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0xff);
|
2003-12-04 16:19:50 +00:00
|
|
|
} else {
|
|
|
|
/* include ASCII for JP */
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0x7f);
|
2003-12-04 16:19:50 +00:00
|
|
|
}
|
2003-12-06 01:52:37 +00:00
|
|
|
if(jpCharsetMasks[cnvData->version]&CSM(HWKANA_7BIT)) {
|
|
|
|
/* include half-width Katakana for JP */
|
2007-08-30 23:35:19 +00:00
|
|
|
sa->addRange(sa->set, HWKANA_START, HWKANA_END);
|
2003-12-06 01:52:37 +00:00
|
|
|
}
|
2003-12-04 16:19:50 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'z':
|
|
|
|
/* include ASCII for CN */
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0x7f);
|
2003-12-04 16:19:50 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
/* there is only one converter for KR, and it is not in the myConverterArray[] */
|
2004-09-07 17:59:53 +00:00
|
|
|
cnvData->currentConverter->sharedData->impl->getUnicodeSet(
|
|
|
|
cnvData->currentConverter, sa, which, pErrorCode);
|
2005-06-03 20:17:54 +00:00
|
|
|
/* the loop over myConverterArray[] will simply not find another converter */
|
|
|
|
break;
|
2003-12-04 16:19:50 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-06-03 20:17:54 +00:00
|
|
|
* Version-specific for CN:
|
2003-12-04 16:19:50 +00:00
|
|
|
* CN version 0 does not map CNS planes 3..7 although
|
|
|
|
* they are all available in the CNS conversion table;
|
|
|
|
* CN version 1 does map them all.
|
2005-06-03 20:17:54 +00:00
|
|
|
* The two versions create different Unicode sets.
|
2003-12-04 16:19:50 +00:00
|
|
|
*/
|
2003-12-03 17:45:32 +00:00
|
|
|
for (i=0; i<UCNV_2022_MAX_CONVERTERS; i++) {
|
|
|
|
if(cnvData->myConverterArray[i]!=NULL) {
|
2003-12-04 19:36:20 +00:00
|
|
|
if( (cnvData->locale[0]=='c' || cnvData->locale[0]=='z') &&
|
|
|
|
cnvData->version==0 && i==CNS_11643
|
|
|
|
) {
|
|
|
|
/* special handling for non-EXT ISO-2022-CN: add only code points for CNS planes 1 and 2 */
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_MBCSGetUnicodeSetForBytes(
|
2003-12-04 19:36:20 +00:00
|
|
|
cnvData->myConverterArray[i],
|
2004-09-07 17:59:53 +00:00
|
|
|
sa, UCNV_ROUNDTRIP_SET,
|
2003-12-04 19:36:20 +00:00
|
|
|
0, 0x81, 0x82,
|
|
|
|
pErrorCode);
|
|
|
|
} else {
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_MBCSGetUnicodeSetForUnicode(cnvData->myConverterArray[i], sa, which, pErrorCode);
|
2003-12-04 19:36:20 +00:00
|
|
|
}
|
2003-12-03 17:45:32 +00:00
|
|
|
}
|
2003-04-09 00:00:51 +00:00
|
|
|
}
|
2005-06-03 20:17:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ISO 2022 converters must not convert SO/SI/ESC despite what
|
|
|
|
* sub-converters do by themselves.
|
|
|
|
* Remove these characters from the set.
|
|
|
|
*/
|
|
|
|
sa->remove(sa->set, 0x0e);
|
|
|
|
sa->remove(sa->set, 0x0f);
|
|
|
|
sa->remove(sa->set, 0x1b);
|
2003-04-09 00:00:51 +00:00
|
|
|
}
|
|
|
|
|
2003-08-14 02:32:31 +00:00
|
|
|
static const UConverterImpl _ISO2022Impl={
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
2003-12-03 22:53:14 +00:00
|
|
|
#ifdef U_ENABLE_GENERIC_ISO_2022
|
2003-08-14 02:32:31 +00:00
|
|
|
T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC,
|
|
|
|
T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC,
|
2004-09-16 04:00:12 +00:00
|
|
|
ucnv_fromUnicode_UTF8,
|
|
|
|
ucnv_fromUnicode_UTF8_OFFSETS_LOGIC,
|
2003-12-03 22:53:14 +00:00
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#endif
|
2003-08-14 02:32:31 +00:00
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName,
|
|
|
|
_ISO_2022_WriteSub,
|
|
|
|
_ISO_2022_SafeClone,
|
|
|
|
_ISO_2022_GetUnicodeSet
|
|
|
|
};
|
|
|
|
static const UConverterStaticData _ISO2022StaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
|
|
|
"ISO_2022",
|
|
|
|
2022,
|
|
|
|
UCNV_IBM,
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
1,
|
2003-10-30 22:54:18 +00:00
|
|
|
3, /* max 3 bytes per UChar from UTF-8 (4 bytes from surrogate _pair_) */
|
2003-08-14 02:32:31 +00:00
|
|
|
{ 0x1a, 0, 0, 0 },
|
|
|
|
1,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
|
|
|
|
};
|
|
|
|
const UConverterSharedData _ISO2022Data={
|
|
|
|
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_OFFSETS_LOGIC,
|
|
|
|
UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName,
|
|
|
|
_ISO_2022_WriteSub,
|
|
|
|
_ISO_2022_SafeClone,
|
|
|
|
_ISO_2022_GetUnicodeSet
|
|
|
|
};
|
|
|
|
static const UConverterStaticData _ISO2022JPStaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
|
|
|
"ISO_2022_JP",
|
|
|
|
0,
|
|
|
|
UCNV_IBM,
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
1,
|
2003-10-30 22:54:18 +00:00
|
|
|
6, /* max 6 bytes per UChar: 4-byte escape sequence + DBCS */
|
2003-08-14 02:32:31 +00:00
|
|
|
{ 0x1a, 0, 0, 0 },
|
|
|
|
1,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
|
|
|
|
};
|
|
|
|
static const UConverterSharedData _ISO2022JPData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022JPStaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022JPImpl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/************* KR ***************/
|
|
|
|
static const UConverterImpl _ISO2022KRImpl={
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
|
|
|
UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName,
|
|
|
|
_ISO_2022_WriteSub,
|
|
|
|
_ISO_2022_SafeClone,
|
|
|
|
_ISO_2022_GetUnicodeSet
|
|
|
|
};
|
|
|
|
static const UConverterStaticData _ISO2022KRStaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
|
|
|
"ISO_2022_KR",
|
|
|
|
0,
|
|
|
|
UCNV_IBM,
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
1,
|
2003-10-30 22:54:18 +00:00
|
|
|
3, /* max 3 bytes per UChar: SO+DBCS */
|
2003-08-14 02:32:31 +00:00
|
|
|
{ 0x1a, 0, 0, 0 },
|
|
|
|
1,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
|
|
|
|
};
|
|
|
|
static const UConverterSharedData _ISO2022KRData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022KRStaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022KRImpl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************** CN ***************/
|
|
|
|
static const UConverterImpl _ISO2022CNImpl={
|
|
|
|
|
|
|
|
UCNV_ISO_2022,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
_ISO2022Open,
|
|
|
|
_ISO2022Close,
|
|
|
|
_ISO2022Reset,
|
|
|
|
|
|
|
|
UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
|
|
|
UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
|
|
|
UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
_ISO2022getName,
|
|
|
|
_ISO_2022_WriteSub,
|
|
|
|
_ISO_2022_SafeClone,
|
|
|
|
_ISO_2022_GetUnicodeSet
|
|
|
|
};
|
|
|
|
static const UConverterStaticData _ISO2022CNStaticData={
|
|
|
|
sizeof(UConverterStaticData),
|
|
|
|
"ISO_2022_CN",
|
|
|
|
0,
|
|
|
|
UCNV_IBM,
|
|
|
|
UCNV_ISO_2022,
|
2006-06-16 21:54:08 +00:00
|
|
|
1,
|
2003-10-30 22:54:18 +00:00
|
|
|
8, /* max 8 bytes per UChar: 4-byte CNS designator + 2 bytes for SS2/SS3 + DBCS */
|
2003-08-14 02:32:31 +00:00
|
|
|
{ 0x1a, 0, 0, 0 },
|
|
|
|
1,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
|
|
|
|
};
|
|
|
|
static const UConverterSharedData _ISO2022CNData={
|
|
|
|
sizeof(UConverterSharedData),
|
|
|
|
~((uint32_t) 0),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&_ISO2022CNStaticData,
|
|
|
|
FALSE,
|
|
|
|
&_ISO2022CNImpl,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
|