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