#ifndef COMMON_DEFS_H
#define COMMON_DEFS_H
#define MAGIC_NUMBER 201513
#define ICV_BOM_IN_BIG_ENDIAN 0x00feff
#define ICV_BOM_IN_LITTLE_ENDIAN_UCS4 0xfffe0000
#if defined(UCS_2) || defined(UCS_2BE) || defined(UCS_2LE) || \
defined(UTF_16) || defined(UTF_16BE) || defined(UTF_16LE)
#define ICV_BOM_IN_LITTLE_ENDIAN 0x00fffe
#else
#define ICV_BOM_IN_LITTLE_ENDIAN 0xfffe0000
#endif
#define ICV_TYPE_NON_IDENTICAL_CHAR (-1)
#define ICV_TYPE_ILLEGAL_CHAR (-2)
#define ICV_CHAR_ASCII_REPLACEMENT ('?')
#define ICV_CHAR_UTF8_REPLACEMENT (0x00efbfbd)
#define ICV_CHAR_UCS2_REPLACEMENT (0xfffd)
typedef enum { false = 0, true = 1 } boolean;
typedef struct {
unsigned int u8;
signed char size;
} to_utf8_table_component_t;
typedef struct {
unsigned int u8;
unsigned char sb;
} to_sb_table_component_t;
typedef struct {
boolean bom_written;
boolean little_endian;
} ucs_state_t;
typedef struct {
ucs_state_t input;
ucs_state_t output;
} ucs_ucs_state_t;
typedef struct {
boolean bom_written;
boolean little_endian;
boolean in_the_middle_of_utf7_sequence;
unsigned int remnant;
signed char remnant_count;
unsigned char prevch;
} utf7_state_t;
#define IL_ ICV_TYPE_ILLEGAL_CHAR
static const char number_of_bytes_in_utf8_char[0x100] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 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0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x9f, 0xbf, 0xbf,
0xbf, 0xbf, 0xbf, 0xbf, 0x8f, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
#define ICV_UTF8_BIT_SHIFT 6
#define ICV_UTF8_BIT_MASK 0x3f
#define ICV_FETCH_UTF8_BOM_SIZE 6
#define ICV_FETCH_UCS4_SIZE 4
#if defined(UCS_2) || defined(UCS_2BE) || defined(UCS_2LE) || \
defined(UTF_16) || defined(UTF_16BE) || defined(UTF_16LE)
#define ICV_FETCH_UCS_SIZE 2
#define ICV_FETCH_UCS_SIZE_TWO 4
#elif defined(UCS_4) || defined(UCS_4BE) || defined(UCS_4LE) || \
defined(UTF_32) || defined(UTF_32BE) || defined(UTF_32LE)
#define ICV_FETCH_UCS_SIZE 4
#define ICV_FETCH_UCS_SIZE_TWO 8
#endif
#define ICV_UTF8_REPRESENTATION_d800 (0x00eda080UL)
#define ICV_UTF8_REPRESENTATION_dfff (0x00edbfbfUL)
#define ICV_UTF8_REPRESENTATION_fdd0 (0x00efb790UL)
#define ICV_UTF8_REPRESENTATION_fdef (0x00efb7afUL)
#define ICV_UTF8_REPRESENTATION_fffe (0x000fbfbeUL)
#define ICV_UTF8_REPRESENTATION_ffff (0x000fbfbfUL)
#define ICV_UTF8_REPRESENTATION_ffff_mask (0x000fffffUL)
#define ICV_UTF8_REPRESENTATION_10fffd (0xf48fbfbdUL)
#define ICV_UTF32_NONCHAR_fffe (0xfffeU)
#define ICV_UTF32_NONCHAR_ffff (0xffffU)
#define ICV_UTF32_NONCHAR_mask (0xffffU)
#define ICV_UTF32_SURROGATE_START_d800 (0xd800U)
#define ICV_UTF32_SURROGATE_END_dfff (0xdfffU)
#define ICV_UTF32_ARABIC_NONCHAR_START_fdd0 (0xfdd0U)
#define ICV_UTF32_ARABIC_NONCHAR_END_fdef (0xfdefU)
#define ICV_UTF32_LAST_VALID_CHAR (0x10fffdU)
#define ICV_UCS4_LAST_VALID_CHAR (0x7fffffff)
#endif