ucnvmbcs.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 2000-2013, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. * file name: ucnvmbcs.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2000jul07
  16. * created by: Markus W. Scherer
  17. */
  18. #ifndef __UCNVMBCS_H__
  19. #define __UCNVMBCS_H__
  20. #include "unicode/utypes.h"
  21. #if !UCONFIG_NO_CONVERSION
  22. #include "unicode/ucnv.h"
  23. #include "ucnv_cnv.h"
  24. #include "ucnv_ext.h"
  25. /**
  26. * ICU conversion (.cnv) data file structure, following the usual UDataInfo
  27. * header.
  28. *
  29. * Format version: 6.2
  30. *
  31. * struct UConverterStaticData -- struct containing the converter name, IBM CCSID,
  32. * min/max bytes per character, etc.
  33. * see ucnv_bld.h
  34. *
  35. * --------------------
  36. *
  37. * The static data is followed by conversionType-specific data structures.
  38. * At the moment, there are only variations of MBCS converters. They all have
  39. * the same toUnicode structures, while the fromUnicode structures for SBCS
  40. * differ from those for other MBCS-style converters.
  41. *
  42. * _MBCSHeader.version 5 is optional and not backward-compatible
  43. * (as usual for changes in the major version field).
  44. *
  45. * Versions 5.m work like versions 4.m except:
  46. * - The _MBCSHeader has variable length (and is always longer than in version 4).
  47. * See the struct _MBCSHeader further description below.
  48. * - There is a set of flags which indicate further incompatible changes.
  49. * (Reader code must reject the file if it does not recognize them all.)
  50. * - In particular, one of these flags indicates that most of the fromUnicode
  51. * data is missing and must be reconstituted from the toUnicode data
  52. * and from the utf8Friendly mbcsIndex at load time.
  53. * (This only works with a utf8Friendly table.)
  54. * In this case, makeconv may increase maxFastUChar automatically to U+FFFF.
  55. *
  56. * The first of these versions is 5.3, which is like 4.3 except for the differences above.
  57. *
  58. * When possible, makeconv continues to generate version 4.m files.
  59. *
  60. * _MBCSHeader.version 5.4/4.4 supports "good one-way" mappings (|4)
  61. * in the extension tables (fromUTableValues bit 30). See ucnv_ext.h for details.
  62. *
  63. * _MBCSHeader.version 4.3 optionally modifies the fromUnicode data structures
  64. * slightly and optionally adds a table for conversion to MBCS (non-SBCS)
  65. * charsets.
  66. *
  67. * The modifications are to make the data utf8Friendly. Not every 4.3 file
  68. * file contains utf8Friendly data.
  69. * It is utf8Friendly if _MBCSHeader.version[2]!=0.
  70. * In this case, the data structures are utf8Friendly up to the code point
  71. * maxFastUChar=((_MBCSHeader.version[2]<<8)|0xff)
  72. *
  73. * A utf8Friendly file has fromUnicode stage 3 entries for code points up to
  74. * maxFastUChar allocated in blocks of 64 for indexing with the 6 bits from
  75. * a UTF-8 trail byte. ASCII is allocated linearly with 128 contiguous entries.
  76. *
  77. * In addition, a utf8Friendly MBCS file contains an additional
  78. * uint16_t mbcsIndex[(maxFastUChar+1)>>6];
  79. * which replaces the stage 1 and 2 tables for indexing with bits from the
  80. * UTF-8 lead byte and middle trail byte. Unlike the older MBCS stage 2 table,
  81. * the mbcsIndex does not contain roundtrip flags. Therefore, all fallbacks
  82. * from code points up to maxFastUChar (and roundtrips to 0x00) are moved to
  83. * the extension data structure. This also allows for faster roundtrip
  84. * conversion from UTF-16.
  85. *
  86. * SBCS files do not contain an additional sbcsIndex[] array because the
  87. * proportional size increase would be noticeable, but the runtime
  88. * code builds one for the code point range for which the runtime conversion
  89. * code is optimized.
  90. *
  91. * For SBCS, maxFastUChar should be at least U+0FFF. The initial makeconv
  92. * implementation sets it to U+1FFF. Because the sbcsIndex is not stored in
  93. * the file, a larger maxFastUChar only affects stage 3 block allocation size
  94. * and is free in empty blocks. (Larger blocks with sparse contents cause larger
  95. * files.) U+1FFF includes almost all of the small scripts.
  96. * U+0FFF covers UTF-8 two-byte sequences and three-byte sequences starting with
  97. * 0xe0. This includes most scripts with legacy SBCS charsets.
  98. * The initial runtime implementation using 4.3 files only builds an sbcsIndex
  99. * for code points up to U+0FFF.
  100. *
  101. * For MBCS, maxFastUChar should be at least U+D7FF (=initial value).
  102. * This boundary is convenient because practically all of the commonly used
  103. * characters are below it, and because it is the boundary to surrogate
  104. * code points, above which special handling is necessary anyway.
  105. * (Surrogate pair assembly for UTF-16, validity checking for UTF-8.)
  106. *
  107. * maxFastUChar could be up to U+FFFF to cover the whole BMP, which could be
  108. * useful especially for conversion from UTF-8 when the input can be assumed
  109. * to be valid, because the surrogate range would then not have to be
  110. * checked.
  111. * (With maxFastUChar=0xffff, makeconv would have to check for mbcsIndex value
  112. * overflow because with the all-unassigned block 0 and nearly full mappings
  113. * from the BMP it is theoretically possible that an index into stage 3
  114. * exceeds 16 bits.)
  115. *
  116. * _MBCSHeader.version 4.2 adds an optional conversion extension data structure.
  117. * If it is present, then an ICU version reading header versions 4.0 or 4.1
  118. * will be able to use the base table and ignore the extension.
  119. *
  120. * The unicodeMask in the static data is part of the base table data structure.
  121. * Especially, the UCNV_HAS_SUPPLEMENTARY flag determines the length of the
  122. * fromUnicode stage 1 array.
  123. * The static data unicodeMask refers only to the base table's properties if
  124. * a base table is included.
  125. * In an extension-only file, the static data unicodeMask is 0.
  126. * The extension data indexes have a separate field with the unicodeMask flags.
  127. *
  128. * MBCS-style data structure following the static data.
  129. * Offsets are counted in bytes from the beginning of the MBCS header structure.
  130. * Details about usage in comments in ucnvmbcs.c.
  131. *
  132. * struct _MBCSHeader (see the definition in this header file below)
  133. * contains 32-bit fields as follows:
  134. * 8 values:
  135. * 0 uint8_t[4] MBCS version in UVersionInfo format (currently 4.3.x.0)
  136. * 1 uint32_t countStates
  137. * 2 uint32_t countToUFallbacks
  138. * 3 uint32_t offsetToUCodeUnits
  139. * 4 uint32_t offsetFromUTable
  140. * 5 uint32_t offsetFromUBytes
  141. * 6 uint32_t flags, bits:
  142. * 31.. 8 offsetExtension -- _MBCSHeader.version 4.2 (ICU 2.8) and higher
  143. * 0 for older versions and if
  144. * there is not extension structure
  145. * 7.. 0 outputType
  146. * 7 uint32_t fromUBytesLength -- _MBCSHeader.version 4.1 (ICU 2.4) and higher
  147. * counts bytes in fromUBytes[]
  148. *
  149. * New and required in version 5:
  150. * 8 uint32_t options, bits:
  151. * 31..16 reserved for flags that can be added without breaking
  152. * backward compatibility
  153. * 15.. 6 reserved for flags whose addition will break
  154. * backward compatibility
  155. * 6 MBCS_OPT_FROM_U -- if set,
  156. * then most of the fromUnicode data is omitted;
  157. * fullStage2Length is present and the missing
  158. * bottom part of stage 2 must be reconstituted from
  159. * the toUnicode data;
  160. * stage 3 is missing completely as well;
  161. * not used for SBCS tables
  162. * 5.. 0 length of the _MBCSHeader (number of uint32_t)
  163. *
  164. * New and optional in version 5:
  165. * 9 uint32_t fullStage2Length: used if MBCS_OPT_FROM_U is set
  166. * specifies the full length of stage 2
  167. * including the omitted part
  168. *
  169. * if(outputType==MBCS_OUTPUT_EXT_ONLY) {
  170. * -- base table name for extension-only table
  171. * char baseTableName[variable]; -- with NUL plus padding for 4-alignment
  172. *
  173. * -- all _MBCSHeader fields except for version and flags are 0
  174. * } else {
  175. * -- normal base table with optional extension
  176. *
  177. * int32_t stateTable[countStates][256];
  178. *
  179. * struct _MBCSToUFallback { (fallbacks are sorted by offset)
  180. * uint32_t offset;
  181. * UChar32 codePoint;
  182. * } toUFallbacks[countToUFallbacks];
  183. *
  184. * uint16_t unicodeCodeUnits[(offsetFromUTable-offsetToUCodeUnits)/2];
  185. * (padded to an even number of units)
  186. *
  187. * -- stage 1 tables
  188. * if(staticData.unicodeMask&UCNV_HAS_SUPPLEMENTARY) {
  189. * -- stage 1 table for all of Unicode
  190. * uint16_t fromUTable[0x440]; (32-bit-aligned)
  191. * } else {
  192. * -- BMP-only tables have a smaller stage 1 table
  193. * uint16_t fromUTable[0x40]; (32-bit-aligned)
  194. * }
  195. *
  196. * -- stage 2 tables
  197. * length determined by top of stage 1 and bottom of stage 3 tables
  198. * if(outputType==MBCS_OUTPUT_1) {
  199. * -- SBCS: pure indexes
  200. * uint16_t stage 2 indexes[?];
  201. * } else {
  202. * -- DBCS, MBCS, EBCDIC_STATEFUL, ...: roundtrip flags and indexes
  203. * uint32_t stage 2 flags and indexes[?];
  204. * if(options&MBCS_OPT_NO_FROM_U) {
  205. * stage 2 really has length fullStage2Length
  206. * and the omitted lower part must be reconstituted from
  207. * the toUnicode data
  208. * }
  209. * }
  210. *
  211. * -- stage 3 tables with byte results
  212. * if(outputType==MBCS_OUTPUT_1) {
  213. * -- SBCS: each 16-bit result contains flags and the result byte, see ucnvmbcs.c
  214. * uint16_t fromUBytes[fromUBytesLength/2];
  215. * } else if(!(options&MBCS_OPT_NO_FROM_U)) {
  216. * -- DBCS, MBCS, EBCDIC_STATEFUL, ... 2/3/4 bytes result, see ucnvmbcs.c
  217. * uint8_t fromUBytes[fromUBytesLength]; or
  218. * uint16_t fromUBytes[fromUBytesLength/2]; or
  219. * uint32_t fromUBytes[fromUBytesLength/4];
  220. * } else {
  221. * fromUBytes[] must be reconstituted from the toUnicode data
  222. * }
  223. *
  224. * -- optional utf8Friendly mbcsIndex -- _MBCSHeader.version 4.3 (ICU 3.8) and higher
  225. * if(outputType!=MBCS_OUTPUT_1 &&
  226. * _MBCSHeader.version[1]>=3 &&
  227. * (maxFastUChar=_MBCSHeader.version[2])!=0
  228. * ) {
  229. * maxFastUChar=(maxFastUChar<<8)|0xff;
  230. * uint16_t mbcsIndex[(maxFastUChar+1)>>6];
  231. * }
  232. * }
  233. *
  234. * -- extension table, details see ucnv_ext.h
  235. * int32_t indexes[>=32]; ...
  236. */
  237. /* MBCS converter data and state -------------------------------------------- */
  238. enum {
  239. MBCS_MAX_STATE_COUNT=128
  240. };
  241. /**
  242. * MBCS action codes for conversions to Unicode.
  243. * These values are in bits 23..20 of the state table entries.
  244. */
  245. enum {
  246. MBCS_STATE_VALID_DIRECT_16,
  247. MBCS_STATE_VALID_DIRECT_20,
  248. MBCS_STATE_FALLBACK_DIRECT_16,
  249. MBCS_STATE_FALLBACK_DIRECT_20,
  250. MBCS_STATE_VALID_16,
  251. MBCS_STATE_VALID_16_PAIR,
  252. MBCS_STATE_UNASSIGNED,
  253. MBCS_STATE_ILLEGAL,
  254. MBCS_STATE_CHANGE_ONLY
  255. };
  256. /* Macros for state table entries */
  257. #define MBCS_ENTRY_TRANSITION(state, offset) (int32_t)(((int32_t)(state)<<24L)|(offset))
  258. #define MBCS_ENTRY_TRANSITION_SET_OFFSET(entry, offset) (int32_t)(((entry)&0xff000000)|(offset))
  259. #define MBCS_ENTRY_TRANSITION_ADD_OFFSET(entry, offset) (int32_t)((entry)+(offset))
  260. #define MBCS_ENTRY_FINAL(state, action, value) (int32_t)(0x80000000|((int32_t)(state)<<24L)|((action)<<20L)|(value))
  261. #define MBCS_ENTRY_SET_FINAL(entry) (int32_t)((entry)|0x80000000)
  262. #define MBCS_ENTRY_FINAL_SET_ACTION(entry, action) (int32_t)(((entry)&0xff0fffff)|((int32_t)(action)<<20L))
  263. #define MBCS_ENTRY_FINAL_SET_VALUE(entry, value) (int32_t)(((entry)&0xfff00000)|(value))
  264. #define MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, action, value) (int32_t)(((entry)&0xff000000)|((int32_t)(action)<<20L)|(value))
  265. #define MBCS_ENTRY_SET_STATE(entry, state) (int32_t)(((entry)&0x80ffffff)|((int32_t)(state)<<24L))
  266. #define MBCS_ENTRY_STATE(entry) ((((uint32_t)entry)>>24)&0x7f)
  267. #define MBCS_ENTRY_IS_TRANSITION(entry) ((entry)>=0)
  268. #define MBCS_ENTRY_IS_FINAL(entry) ((entry)<0)
  269. #define MBCS_ENTRY_TRANSITION_STATE(entry) (((uint32_t)entry)>>24)
  270. #define MBCS_ENTRY_TRANSITION_OFFSET(entry) ((entry)&0xffffff)
  271. #define MBCS_ENTRY_FINAL_STATE(entry) ((((uint32_t)entry)>>24)&0x7f)
  272. #define MBCS_ENTRY_FINAL_IS_VALID_DIRECT_16(entry) ((entry)<(int32_t)0x80100000)
  273. #define MBCS_ENTRY_FINAL_ACTION(entry) ((((uint32_t)entry)>>20)&0xf)
  274. #define MBCS_ENTRY_FINAL_VALUE(entry) ((entry)&0xfffff)
  275. #define MBCS_ENTRY_FINAL_VALUE_16(entry) (uint16_t)(entry)
  276. #define IS_ASCII_ROUNDTRIP(b, asciiRoundtrips) (((asciiRoundtrips) & (1<<((b)>>2)))!=0)
  277. /* single-byte fromUnicode: get the 16-bit result word */
  278. #define MBCS_SINGLE_RESULT_FROM_U(table, results, c) (results)[ (table)[ (table)[(c)>>10] +(((c)>>4)&0x3f) ] +((c)&0xf) ]
  279. /* single-byte fromUnicode using the sbcsIndex */
  280. #define SBCS_RESULT_FROM_LOW_BMP(table, results, c) (results)[ (table)[(c)>>6] +((c)&0x3f) ]
  281. /* single-byte fromUTF8 using the sbcsIndex; l and t must be masked externally; can be l=0 and t<=0x7f */
  282. #define SBCS_RESULT_FROM_UTF8(table, results, l, t) (results)[ (table)[l] +(t) ]
  283. /* multi-byte fromUnicode: get the 32-bit stage 2 entry */
  284. #define MBCS_STAGE_2_FROM_U(table, c) ((const uint32_t *)(table))[ (table)[(c)>>10] +(((c)>>4)&0x3f) ]
  285. #define MBCS_FROM_U_IS_ROUNDTRIP(stage2Entry, c) ( ((stage2Entry) & ((uint32_t)1<< (16+((c)&0xf)) )) !=0)
  286. #define MBCS_VALUE_2_FROM_STAGE_2(bytes, stage2Entry, c) ((uint16_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
  287. #define MBCS_VALUE_4_FROM_STAGE_2(bytes, stage2Entry, c) ((uint32_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
  288. #define MBCS_POINTER_3_FROM_STAGE_2(bytes, stage2Entry, c) ((bytes)+(16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf))*3)
  289. /* double-byte fromUnicode using the mbcsIndex */
  290. #define DBCS_RESULT_FROM_MOST_BMP(table, results, c) (results)[ (table)[(c)>>6] +((c)&0x3f) ]
  291. /* double-byte fromUTF8 using the mbcsIndex; l and t1 combined into lt1; lt1 and t2 must be masked externally */
  292. #define DBCS_RESULT_FROM_UTF8(table, results, lt1, t2) (results)[ (table)[lt1] +(t2) ]
  293. /**
  294. * MBCS output types for conversions from Unicode.
  295. * These per-converter types determine the storage method in stage 3 of the lookup table,
  296. * mostly how many bytes are stored per entry.
  297. */
  298. enum {
  299. MBCS_OUTPUT_1, /* 0 */
  300. MBCS_OUTPUT_2, /* 1 */
  301. MBCS_OUTPUT_3, /* 2 */
  302. MBCS_OUTPUT_4, /* 3 */
  303. MBCS_OUTPUT_3_EUC=8, /* 8 */
  304. MBCS_OUTPUT_4_EUC, /* 9 */
  305. MBCS_OUTPUT_2_SISO=12, /* c */
  306. MBCS_OUTPUT_2_HZ, /* d */
  307. MBCS_OUTPUT_EXT_ONLY, /* e */
  308. MBCS_OUTPUT_COUNT,
  309. MBCS_OUTPUT_DBCS_ONLY=0xdb /* runtime-only type for DBCS-only handling of SISO tables */
  310. };
  311. /**
  312. * Fallbacks to Unicode are stored outside the normal state table and code point structures
  313. * in a vector of items of this type. They are sorted by offset.
  314. */
  315. typedef struct {
  316. uint32_t offset;
  317. UChar32 codePoint;
  318. } _MBCSToUFallback;
  319. /** Constants for fast and UTF-8-friendly conversion. */
  320. enum {
  321. SBCS_FAST_MAX=0x0fff, /* maximum code point with UTF-8-friendly SBCS runtime code, see makeconv SBCS_UTF8_MAX */
  322. SBCS_FAST_LIMIT=SBCS_FAST_MAX+1, /* =0x1000 */
  323. MBCS_FAST_MAX=0xd7ff, /* maximum code point with UTF-8-friendly MBCS runtime code, see makeconv MBCS_UTF8_MAX */
  324. MBCS_FAST_LIMIT=MBCS_FAST_MAX+1 /* =0xd800 */
  325. };
  326. /**
  327. * This is the MBCS part of the UConverterTable union (a runtime data structure).
  328. * It keeps all the per-converter data and points into the loaded mapping tables.
  329. *
  330. * utf8Friendly data structures added with _MBCSHeader.version 4.3
  331. */
  332. typedef struct UConverterMBCSTable {
  333. /* toUnicode */
  334. uint8_t countStates, dbcsOnlyState, stateTableOwned;
  335. uint32_t countToUFallbacks;
  336. const int32_t (*stateTable)/*[countStates]*/[256];
  337. int32_t (*swapLFNLStateTable)/*[countStates]*/[256]; /* for swaplfnl */
  338. const uint16_t *unicodeCodeUnits/*[countUnicodeResults]*/;
  339. const _MBCSToUFallback *toUFallbacks;
  340. /* fromUnicode */
  341. const uint16_t *fromUnicodeTable;
  342. const uint16_t *mbcsIndex; /* for fast conversion from most of BMP to MBCS (utf8Friendly data) */
  343. uint16_t sbcsIndex[SBCS_FAST_LIMIT>>6]; /* for fast conversion from low BMP to SBCS (utf8Friendly data) */
  344. const uint8_t *fromUnicodeBytes;
  345. uint8_t *swapLFNLFromUnicodeBytes; /* for swaplfnl */
  346. uint32_t fromUBytesLength;
  347. uint8_t outputType, unicodeMask;
  348. UBool utf8Friendly; /* for utf8Friendly data */
  349. UChar maxFastUChar; /* for utf8Friendly data */
  350. /* roundtrips */
  351. uint32_t asciiRoundtrips;
  352. /* reconstituted data that was omitted from the .cnv file */
  353. uint8_t *reconstitutedData;
  354. /* converter name for swaplfnl */
  355. char *swapLFNLName;
  356. /* extension data */
  357. struct UConverterSharedData *baseSharedData;
  358. const int32_t *extIndexes;
  359. } UConverterMBCSTable;
  360. #define UCNV_MBCS_TABLE_INITIALIZER { \
  361. /* toUnicode */ \
  362. 0, 0, 0, \
  363. 0, \
  364. \
  365. NULL, \
  366. NULL, \
  367. NULL, \
  368. NULL, \
  369. \
  370. /* fromUnicode */ \
  371. NULL, \
  372. NULL, \
  373. { 0 }, \
  374. NULL, \
  375. NULL, \
  376. 0, \
  377. 0, 0, \
  378. FALSE, \
  379. 0, \
  380. \
  381. /* roundtrips */ \
  382. 0, \
  383. \
  384. /* reconstituted data that was omitted from the .cnv file */ \
  385. NULL, \
  386. \
  387. /* converter name for swaplfnl */ \
  388. NULL, \
  389. \
  390. /* extension data */ \
  391. NULL, \
  392. NULL \
  393. }
  394. enum {
  395. MBCS_OPT_LENGTH_MASK=0x3f,
  396. MBCS_OPT_NO_FROM_U=0x40,
  397. /*
  398. * If any of the following options bits are set,
  399. * then the file must be rejected.
  400. */
  401. MBCS_OPT_INCOMPATIBLE_MASK=0xffc0,
  402. /*
  403. * Remove bits from this mask as more options are recognized
  404. * by all implementations that use this constant.
  405. */
  406. MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK=0xff80
  407. };
  408. enum {
  409. MBCS_HEADER_V4_LENGTH=8,
  410. MBCS_HEADER_V5_MIN_LENGTH=9
  411. };
  412. /**
  413. * MBCS data header. See data format description above.
  414. */
  415. typedef struct {
  416. UVersionInfo version;
  417. uint32_t countStates,
  418. countToUFallbacks,
  419. offsetToUCodeUnits,
  420. offsetFromUTable,
  421. offsetFromUBytes,
  422. flags,
  423. fromUBytesLength;
  424. /* new and required in version 5 */
  425. uint32_t options;
  426. /* new and optional in version 5; used if options&MBCS_OPT_NO_FROM_U */
  427. uint32_t fullStage2Length; /* number of 32-bit units */
  428. } _MBCSHeader;
  429. #define UCNV_MBCS_HEADER_INITIALIZER { { 0 }, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  430. /*
  431. * This is a simple version of _MBCSGetNextUChar() that is used
  432. * by other converter implementations.
  433. * It only returns an "assigned" result if it consumes the entire input.
  434. * It does not use state from the converter, nor error codes.
  435. * It does not handle the EBCDIC swaplfnl option (set in UConverter).
  436. * It handles conversion extensions but not GB 18030.
  437. *
  438. * Return value:
  439. * U+fffe unassigned
  440. * U+ffff illegal
  441. * otherwise the Unicode code point
  442. */
  443. U_CFUNC UChar32
  444. ucnv_MBCSSimpleGetNextUChar(UConverterSharedData *sharedData,
  445. const char *source, int32_t length,
  446. UBool useFallback);
  447. /**
  448. * This version of _MBCSSimpleGetNextUChar() is optimized for single-byte, single-state codepages.
  449. * It does not handle the EBCDIC swaplfnl option (set in UConverter).
  450. * It does not handle conversion extensions (_extToU()).
  451. */
  452. U_CFUNC UChar32
  453. ucnv_MBCSSingleSimpleGetNextUChar(UConverterSharedData *sharedData,
  454. uint8_t b, UBool useFallback);
  455. /**
  456. * This macro version of _MBCSSingleSimpleGetNextUChar() gets a code point from a byte.
  457. * It works for single-byte, single-state codepages that only map
  458. * to and from BMP code points, and it always
  459. * returns fallback values.
  460. */
  461. #define _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(sharedData, b) \
  462. (UChar)MBCS_ENTRY_FINAL_VALUE_16((sharedData)->mbcs.stateTable[0][(uint8_t)(b)])
  463. /**
  464. * This is an internal function that allows other converter implementations
  465. * to check whether a byte is a lead byte.
  466. */
  467. U_CFUNC UBool
  468. ucnv_MBCSIsLeadByte(UConverterSharedData *sharedData, char byte);
  469. /** This is a macro version of _MBCSIsLeadByte(). */
  470. #define _MBCS_IS_LEAD_BYTE(sharedData, byte) \
  471. (UBool)MBCS_ENTRY_IS_TRANSITION((sharedData)->mbcs.stateTable[0][(uint8_t)(byte)])
  472. /*
  473. * This is another simple conversion function for internal use by other
  474. * conversion implementations.
  475. * It does not use the converter state nor call callbacks.
  476. * It does not handle the EBCDIC swaplfnl option (set in UConverter).
  477. * It handles conversion extensions but not GB 18030.
  478. *
  479. * It converts one single Unicode code point into codepage bytes, encoded
  480. * as one 32-bit value. The function returns the number of bytes in *pValue:
  481. * 1..4 the number of bytes in *pValue
  482. * 0 unassigned (*pValue undefined)
  483. * -1 illegal (currently not used, *pValue undefined)
  484. *
  485. * *pValue will contain the resulting bytes with the last byte in bits 7..0,
  486. * the second to last byte in bits 15..8, etc.
  487. * Currently, the function assumes but does not check that 0<=c<=0x10ffff.
  488. */
  489. U_CFUNC int32_t
  490. ucnv_MBCSFromUChar32(UConverterSharedData *sharedData,
  491. UChar32 c, uint32_t *pValue,
  492. UBool useFallback);
  493. /**
  494. * This version of _MBCSFromUChar32() is optimized for single-byte codepages.
  495. * It does not handle the EBCDIC swaplfnl option (set in UConverter).
  496. *
  497. * It returns the codepage byte for the code point, or -1 if it is unassigned.
  498. */
  499. U_CFUNC int32_t
  500. ucnv_MBCSSingleFromUChar32(UConverterSharedData *sharedData,
  501. UChar32 c,
  502. UBool useFallback);
  503. /**
  504. * SBCS, DBCS, and EBCDIC_STATEFUL are replaced by MBCS, but
  505. * we cheat a little about the type, returning the old types if appropriate.
  506. */
  507. U_CFUNC UConverterType
  508. ucnv_MBCSGetType(const UConverter* converter);
  509. U_CFUNC void
  510. ucnv_MBCSFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
  511. UErrorCode *pErrorCode);
  512. U_CFUNC void
  513. ucnv_MBCSToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
  514. UErrorCode *pErrorCode);
  515. /*
  516. * Internal function returning a UnicodeSet for toUnicode() conversion.
  517. * Currently only used for ISO-2022-CN, and only handles roundtrip mappings.
  518. * In the future, if we add support for fallback sets, this function
  519. * needs to be updated.
  520. * Handles extensions.
  521. * Does not empty the set first.
  522. */
  523. U_CFUNC void
  524. ucnv_MBCSGetUnicodeSetForUnicode(const UConverterSharedData *sharedData,
  525. const USetAdder *sa,
  526. UConverterUnicodeSet which,
  527. UErrorCode *pErrorCode);
  528. /*
  529. * Same as ucnv_MBCSGetUnicodeSetForUnicode() but
  530. * the set can be filtered by encoding scheme.
  531. * Used by stateful converters which share regular conversion tables
  532. * but only use a subset of their mappings.
  533. */
  534. U_CFUNC void
  535. ucnv_MBCSGetFilteredUnicodeSetForUnicode(const UConverterSharedData *sharedData,
  536. const USetAdder *sa,
  537. UConverterUnicodeSet which,
  538. UConverterSetFilter filter,
  539. UErrorCode *pErrorCode);
  540. #endif
  541. #endif