2 *******************************************************************************
4 * Copyright (C) 2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2003jun20
14 * created by: Markus W. Scherer
16 * Definitions for the .ucm file parser and handler module ucm.c.
22 #include "unicode/utypes.h"
31 * Per-mapping data structure
33 * u if uLen==1: Unicode code point
34 * else index to uLen code points
35 * b if bLen<=4: up to 4 bytes
36 * else index to bLen bytes
37 * uLen number of code points
38 * bLen number of words containing left-justified bytes
39 * bIsMultipleChars indicates that the bytes contain more than one sequence
40 * according to the state table
41 * f flag for roundtrip (0), fallback (1), sub mapping (2), reverse fallback (3)
42 * same values as in the source file after |
44 typedef struct UCMapping
{
50 int8_t uLen
, bLen
, f
, moveFlag
;
54 UCM_FLAGS_INITIAL
, /* no mappings parsed yet */
55 UCM_FLAGS_EXPLICIT
, /* .ucm file has mappings with | fallback indicators */
56 UCM_FLAGS_IMPLICIT
, /* .ucm file has mappings without | fallback indicators, later wins */
57 UCM_FLAGS_MIXED
/* both implicit and explicit */
60 typedef struct UCMTable
{
62 int32_t mappingsCapacity
, mappingsLength
;
65 int32_t codePointsCapacity
, codePointsLength
;
68 int32_t bytesCapacity
, bytesLength
;
70 /* index map for mapping by bytes first */
74 int8_t flagsType
; /* UCM_FLAGS_INITIAL etc. */
79 MBCS_STATE_FLAG_DIRECT
=1,
80 MBCS_STATE_FLAG_SURROGATES
,
82 MBCS_STATE_FLAG_READY
=16
85 typedef struct UCMStates
{
86 int32_t stateTable
[MBCS_MAX_STATE_COUNT
][256];
87 uint32_t stateFlags
[MBCS_MAX_STATE_COUNT
],
88 stateOffsetSum
[MBCS_MAX_STATE_COUNT
];
90 int32_t countStates
, minCharLength
, maxCharLength
, countToUCodeUnits
;
91 int8_t conversionType
, outputType
;
94 typedef struct UCMFile
{
98 char baseName
[UCNV_MAX_CONVERTER_NAME_LENGTH
];
101 /* simple accesses ---------------------------------------------------------- */
103 #define UCM_GET_CODE_POINTS(t, m) \
104 (((m)->uLen==1) ? &(m)->u : (t)->codePoints+(m)->u)
106 #define UCM_GET_BYTES(t, m) \
107 (((m)->bLen<=4) ? (m)->b.bytes : (t)->bytes+(m)->b.index)
109 /* APIs --------------------------------------------------------------------- */
111 U_CAPI UCMFile
* U_EXPORT2
114 U_CAPI
void U_EXPORT2
115 ucm_close(UCMFile
*ucm
);
117 U_CAPI UBool U_EXPORT2
118 ucm_parseHeaderLine(UCMFile
*ucm
,
119 char *line
, char **pKey
, char **pValue
);
121 /* @return -1 illegal bytes 0 suitable for base table 1 needs to go into extension table */
122 U_CAPI
int32_t U_EXPORT2
123 ucm_mappingType(UCMStates
*baseStates
,
125 UChar32 codePoints
[UCNV_EXT_MAX_UCHARS
],
126 uint8_t bytes
[UCNV_EXT_MAX_BYTES
]);
128 /* add a mapping to the base or extension table as appropriate */
129 U_CAPI UBool U_EXPORT2
130 ucm_addMappingAuto(UCMFile
*ucm
, UBool forBase
, UCMStates
*baseStates
,
132 UChar32 codePoints
[UCNV_EXT_MAX_UCHARS
],
133 uint8_t bytes
[UCNV_EXT_MAX_BYTES
]);
135 U_CAPI UBool U_EXPORT2
136 ucm_addMappingFromLine(UCMFile
*ucm
, const char *line
, UBool forBase
, UCMStates
*baseStates
);
139 U_CAPI UCMTable
* U_EXPORT2
142 U_CAPI
void U_EXPORT2
143 ucm_closeTable(UCMTable
*table
);
145 U_CAPI
void U_EXPORT2
146 ucm_resetTable(UCMTable
*table
);
148 U_CAPI
void U_EXPORT2
149 ucm_sortTable(UCMTable
*t
);
152 * Read a table from a .ucm file, from after the CHARMAP line to
153 * including the END CHARMAP line.
155 U_CAPI
void U_EXPORT2
156 ucm_readTable(UCMFile
*ucm
, FileStream
* convFile
,
157 UBool forBase
, UCMStates
*baseStates
,
158 UErrorCode
*pErrorCode
);
161 * Check the validity of mappings against a base table's states;
162 * necessary for extension-only tables that were read before their base tables.
164 U_CAPI UBool U_EXPORT2
165 ucm_checkValidity(UCMTable
*ext
, UCMStates
*baseStates
);
168 * Check a base table against an extension table.
169 * Set the moveTarget!=NULL if it is possible to move mappings from the base.
170 * This is the case where base and extension tables are parsed from a single file
172 * or when delta file mappings are subtracted from a base table.
174 * When a base table cannot be modified because a delta file is parsed in makeconv,
175 * then set moveTarget=NULL.
177 * if(intersectBase) then mappings that exist in the base table but not in
178 * the extension table are moved to moveTarget instead of showing an error.
181 * If intersectBase==2 for a DBCS extension table, then SBCS mappings are
182 * not moved out of the base unless their Unicode input requires it.
183 * This helps ucmkbase generate base tables for DBCS-only extension .cnv files.
185 * For both tables in the same file, the extension table is automatically
187 * For separate files, the extension file can use a complete mapping table,
188 * so that common mappings need not be stripped out manually.
191 * Sort both tables, and then for each mapping direction:
193 * If intersectBase is TRUE and the base table contains a mapping
194 * that does not exist in the extension table, then this mapping is moved
199 * If the base table contains a mapping for which the input sequence is
200 * the same as the extension input, then
201 * - if the output is the same: remove the extension mapping
204 * If the base table contains a mapping for which the input sequence is
205 * a prefix of the extension input, then
206 * - if moveTarget!=NULL: move the base mapping to the moveTarget table
209 * @return FALSE in case of an irreparable error
211 U_CAPI UBool U_EXPORT2
212 ucm_checkBaseExt(UCMStates
*baseStates
, UCMTable
*base
, UCMTable
*ext
,
213 UCMTable
*moveTarget
, UBool intersectBase
);
215 U_CAPI
void U_EXPORT2
216 ucm_printTable(UCMTable
*table
, FILE *f
, UBool byUnicode
);
218 U_CAPI
void U_EXPORT2
219 ucm_printMapping(UCMTable
*table
, UCMapping
*m
, FILE *f
);
222 U_CAPI
void U_EXPORT2
223 ucm_addState(UCMStates
*states
, const char *s
);
225 U_CAPI
void U_EXPORT2
226 ucm_processStates(UCMStates
*states
);
228 U_CAPI
int32_t U_EXPORT2
229 ucm_countChars(UCMStates
*states
,
230 const uint8_t *bytes
, int32_t length
);
233 U_CAPI
int8_t U_EXPORT2
234 ucm_parseBytes(uint8_t bytes
[UCNV_EXT_MAX_BYTES
], const char *line
, const char **ps
);
236 U_CAPI UBool U_EXPORT2
237 ucm_parseMappingLine(UCMapping
*m
,
238 UChar32 codePoints
[UCNV_EXT_MAX_UCHARS
],
239 uint8_t bytes
[UCNV_EXT_MAX_BYTES
],
242 U_CAPI
void U_EXPORT2
243 ucm_addMapping(UCMTable
*table
,
245 UChar32 codePoints
[UCNV_EXT_MAX_UCHARS
],
246 uint8_t bytes
[UCNV_EXT_MAX_BYTES
]);
248 /* very makeconv-specific functions ----------------------------------------- */
250 /* finalize and optimize states after the toUnicode mappings are processed */
251 U_CAPI
void U_EXPORT2
252 ucm_optimizeStates(UCMStates
*states
,
253 uint16_t **pUnicodeCodeUnits
,
254 _MBCSToUFallback
*toUFallbacks
, int32_t countToUFallbacks
,
257 /* moved here because it is used inside ucmstate.c */
258 U_CAPI
int32_t U_EXPORT2
259 ucm_findFallback(_MBCSToUFallback
*toUFallbacks
, int32_t countToUFallbacks
,
262 /* very rptp2ucm-specific functions ----------------------------------------- */
265 * Input: Separate tables with mappings from/to Unicode,
266 * subchar and subchar1 (0 if none).
267 * All mappings must have flag 0.
269 * Output: fromUTable will contain the union of mappings with the correct
270 * precision flags, and be sorted.
272 U_CAPI
void U_EXPORT2
273 ucm_mergeTables(UCMTable
*fromUTable
, UCMTable
*toUTable
,
274 const uint8_t *subchar
, int32_t subcharLength
,
277 U_CAPI UBool U_EXPORT2
278 ucm_separateMappings(UCMFile
*ucm
, UBool isSISO
);