#ifndef __UCNVMBCS_H__
#define __UCNVMBCS_H__
#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "ucnv_bld.h"
enum {
MBCS_STATE_VALID_DIRECT_16,
MBCS_STATE_VALID_DIRECT_20,
MBCS_STATE_FALLBACK_DIRECT_16,
MBCS_STATE_FALLBACK_DIRECT_20,
MBCS_STATE_VALID_16,
MBCS_STATE_VALID_16_PAIR,
MBCS_STATE_UNASSIGNED,
MBCS_STATE_ILLEGAL,
MBCS_STATE_CHANGE_ONLY
};
#define MBCS_ENTRY_TRANSITION(state, offset) (int32_t)(((int32_t)(state)<<24L)|(offset))
#define MBCS_ENTRY_TRANSITION_SET_OFFSET(entry, offset) (int32_t)(((entry)&0xff000000)|(offset))
#define MBCS_ENTRY_TRANSITION_ADD_OFFSET(entry, offset) (int32_t)((entry)+(offset))
#define MBCS_ENTRY_FINAL(state, action, value) (int32_t)(0x80000000|((int32_t)(state)<<24L)|((action)<<20L)|(value))
#define MBCS_ENTRY_SET_FINAL(entry) (int32_t)((entry)|0x80000000)
#define MBCS_ENTRY_FINAL_SET_ACTION(entry, action) (int32_t)(((entry)&0xff0fffff)|((int32_t)(action)<<20L))
#define MBCS_ENTRY_FINAL_SET_VALUE(entry, value) (int32_t)(((entry)&0xfff00000)|(value))
#define MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, action, value) (int32_t)(((entry)&0xff000000)|((int32_t)(action)<<20L)|(value))
#define MBCS_ENTRY_SET_STATE(entry, state) (int32_t)(((entry)&0x80ffffff)|((int32_t)(state)<<24L))
#define MBCS_ENTRY_STATE(entry) (((entry)>>24)&0x7f)
#define MBCS_ENTRY_IS_TRANSITION(entry) ((entry)>=0)
#define MBCS_ENTRY_IS_FINAL(entry) ((entry)<0)
#define MBCS_ENTRY_TRANSITION_STATE(entry) ((entry)>>24)
#define MBCS_ENTRY_TRANSITION_OFFSET(entry) ((entry)&0xffffff)
#define MBCS_ENTRY_FINAL_STATE(entry) (((entry)>>24)&0x7f)
#define MBCS_ENTRY_FINAL_IS_VALID_DIRECT_16(entry) ((entry)<(int32_t)0x80100000)
#define MBCS_ENTRY_FINAL_ACTION(entry) (((entry)>>20)&0xf)
#define MBCS_ENTRY_FINAL_VALUE(entry) ((entry)&0xfffff)
#define MBCS_ENTRY_FINAL_VALUE_16(entry) (uint16_t)(entry)
#define MBCS_SINGLE_RESULT_FROM_U(table, results, c) (results)[ (table)[ (table)[(c)>>10] +(((c)>>4)&0x3f) ] +((c)&0xf) ]
#define MBCS_STAGE_2_FROM_U(table, c) ((const uint32_t *)(table))[ (table)[(c)>>10] +(((c)>>4)&0x3f) ]
#define MBCS_FROM_U_IS_ROUNDTRIP(stage2Entry, c) ( ((stage2Entry) & ((uint32_t)1<< (16+((c)&0xf)) )) !=0)
#define MBCS_VALUE_2_FROM_STAGE_2(bytes, stage2Entry, c) ((uint16_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
#define MBCS_VALUE_4_FROM_STAGE_2(bytes, stage2Entry, c) ((uint32_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
#define MBCS_POINTER_3_FROM_STAGE_2(bytes, stage2Entry, c) ((bytes)+(16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf))*3)
enum {
MBCS_OUTPUT_1,
MBCS_OUTPUT_2,
MBCS_OUTPUT_3,
MBCS_OUTPUT_4,
MBCS_OUTPUT_3_EUC=8,
MBCS_OUTPUT_4_EUC,
MBCS_OUTPUT_2_SISO=12,
MBCS_OUTPUT_2_HZ
};
typedef struct {
uint32_t offset;
UChar32 codePoint;
} _MBCSToUFallback;
typedef struct UConverterMBCSTable {
uint8_t countStates;
uint32_t countToUFallbacks;
const int32_t (*stateTable)[256];
int32_t (*swapLFNLStateTable)[256];
const uint16_t *unicodeCodeUnits;
const _MBCSToUFallback *toUFallbacks;
const uint16_t *fromUnicodeTable;
const uint8_t *fromUnicodeBytes;
uint8_t *swapLFNLFromUnicodeBytes;
uint32_t fromUBytesLength;
uint8_t outputType, unicodeMask;
char *swapLFNLName;
} UConverterMBCSTable;
typedef struct {
UVersionInfo version;
uint32_t countStates,
countToUFallbacks,
offsetToUCodeUnits,
offsetFromUTable,
offsetFromUBytes,
flags,
fromUBytesLength;
} _MBCSHeader;
U_CFUNC UChar32
_MBCSSimpleGetNextUChar(UConverterSharedData *sharedData,
const char **pSource, const char *sourceLimit,
UBool useFallback);
U_CFUNC UChar32
_MBCSSingleSimpleGetNextUChar(UConverterSharedData *sharedData,
uint8_t b, UBool useFallback);
#define _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(sharedData, b) \
(UChar)MBCS_ENTRY_FINAL_VALUE_16((sharedData)->table->mbcs.stateTable[0][(uint8_t)(b)])
U_CFUNC UBool
_MBCSIsLeadByte(UConverterSharedData *sharedData, char byte);
#define _MBCS_IS_LEAD_BYTE(sharedData, byte) \
(UBool)MBCS_ENTRY_IS_TRANSITION((sharedData)->table->mbcs.stateTable[0][(uint8_t)(byte)])
U_CFUNC int32_t
_MBCSFromUChar32(UConverterSharedData *sharedData,
UChar32 c, uint32_t *pValue,
UBool useFallback);
U_CFUNC int32_t
_MBCSSingleFromUChar32(UConverterSharedData *sharedData,
UChar32 c,
UBool useFallback);
U_CFUNC UConverterType
_MBCSGetType(const UConverter* converter);
U_CFUNC void
_MBCSFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
UErrorCode *pErrorCode);
U_CFUNC void
_MBCSToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
UErrorCode *pErrorCode);
#endif