2003-10-25 00:29:13 +00:00
|
|
|
/*
|
2007-07-27 03:12:12 +00:00
|
|
|
*******************************************************************************
|
2010-02-27 03:39:15 +00:00
|
|
|
* Copyright (C) 2003-2010, International Business Machines
|
2007-07-27 03:12:12 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: ucm.h
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2003jun20
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Definitions for the .ucm file parser and handler module ucm.c.
|
|
|
|
*/
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
#ifndef __UCM_H__
|
|
|
|
#define __UCM_H__
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "ucnvmbcs.h"
|
|
|
|
#include "ucnv_ext.h"
|
2003-11-07 23:57:24 +00:00
|
|
|
#include "filestrm.h"
|
2003-10-25 00:29:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-07-09 03:09:47 +00:00
|
|
|
#if !UCONFIG_NO_CONVERSION
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
U_CDECL_BEGIN
|
|
|
|
|
2007-02-06 05:24:14 +00:00
|
|
|
/* constants for UCMapping.moveFlag */
|
|
|
|
enum {
|
|
|
|
UCM_MOVE_TO_EXT=1,
|
|
|
|
UCM_REMOVE_MAPPING=2
|
|
|
|
};
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
/*
|
|
|
|
* Per-mapping data structure
|
|
|
|
*
|
|
|
|
* u if uLen==1: Unicode code point
|
|
|
|
* else index to uLen code points
|
|
|
|
* b if bLen<=4: up to 4 bytes
|
|
|
|
* else index to bLen bytes
|
|
|
|
* uLen number of code points
|
|
|
|
* bLen number of words containing left-justified bytes
|
|
|
|
* bIsMultipleChars indicates that the bytes contain more than one sequence
|
|
|
|
* according to the state table
|
|
|
|
* f flag for roundtrip (0), fallback (1), sub mapping (2), reverse fallback (3)
|
|
|
|
* same values as in the source file after |
|
|
|
|
*/
|
|
|
|
typedef struct UCMapping {
|
|
|
|
UChar32 u;
|
|
|
|
union {
|
2009-04-02 07:34:37 +00:00
|
|
|
uint32_t idx;
|
2003-10-25 00:29:13 +00:00
|
|
|
uint8_t bytes[4];
|
|
|
|
} b;
|
2003-11-07 23:57:24 +00:00
|
|
|
int8_t uLen, bLen, f, moveFlag;
|
2003-10-25 00:29:13 +00:00
|
|
|
} UCMapping;
|
|
|
|
|
2007-02-06 05:24:14 +00:00
|
|
|
/* constants for UCMTable.flagsType */
|
2003-10-25 00:29:13 +00:00
|
|
|
enum {
|
|
|
|
UCM_FLAGS_INITIAL, /* no mappings parsed yet */
|
|
|
|
UCM_FLAGS_EXPLICIT, /* .ucm file has mappings with | fallback indicators */
|
|
|
|
UCM_FLAGS_IMPLICIT, /* .ucm file has mappings without | fallback indicators, later wins */
|
|
|
|
UCM_FLAGS_MIXED /* both implicit and explicit */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct UCMTable {
|
|
|
|
UCMapping *mappings;
|
|
|
|
int32_t mappingsCapacity, mappingsLength;
|
|
|
|
|
|
|
|
UChar32 *codePoints;
|
|
|
|
int32_t codePointsCapacity, codePointsLength;
|
|
|
|
|
|
|
|
uint8_t *bytes;
|
|
|
|
int32_t bytesCapacity, bytesLength;
|
|
|
|
|
|
|
|
/* index map for mapping by bytes first */
|
|
|
|
int32_t *reverseMap;
|
|
|
|
|
|
|
|
uint8_t unicodeMask;
|
|
|
|
int8_t flagsType; /* UCM_FLAGS_INITIAL etc. */
|
2003-11-07 23:57:24 +00:00
|
|
|
UBool isSorted;
|
2003-10-25 00:29:13 +00:00
|
|
|
} UCMTable;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MBCS_STATE_FLAG_DIRECT=1,
|
|
|
|
MBCS_STATE_FLAG_SURROGATES,
|
|
|
|
|
|
|
|
MBCS_STATE_FLAG_READY=16
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct UCMStates {
|
|
|
|
int32_t stateTable[MBCS_MAX_STATE_COUNT][256];
|
|
|
|
uint32_t stateFlags[MBCS_MAX_STATE_COUNT],
|
|
|
|
stateOffsetSum[MBCS_MAX_STATE_COUNT];
|
|
|
|
|
|
|
|
int32_t countStates, minCharLength, maxCharLength, countToUCodeUnits;
|
|
|
|
int8_t conversionType, outputType;
|
|
|
|
} UCMStates;
|
|
|
|
|
|
|
|
typedef struct UCMFile {
|
|
|
|
UCMTable *base, *ext;
|
|
|
|
UCMStates states;
|
|
|
|
|
|
|
|
char baseName[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
|
|
|
} UCMFile;
|
|
|
|
|
|
|
|
/* simple accesses ---------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define UCM_GET_CODE_POINTS(t, m) \
|
|
|
|
(((m)->uLen==1) ? &(m)->u : (t)->codePoints+(m)->u)
|
|
|
|
|
|
|
|
#define UCM_GET_BYTES(t, m) \
|
2009-04-02 07:34:37 +00:00
|
|
|
(((m)->bLen<=4) ? (m)->b.bytes : (t)->bytes+(m)->b.idx)
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
/* APIs --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
U_CAPI UCMFile * U_EXPORT2
|
|
|
|
ucm_open(void);
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_close(UCMFile *ucm);
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_parseHeaderLine(UCMFile *ucm,
|
|
|
|
char *line, char **pKey, char **pValue);
|
|
|
|
|
2003-10-27 03:06:55 +00:00
|
|
|
/* @return -1 illegal bytes 0 suitable for base table 1 needs to go into extension table */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucm_mappingType(UCMStates *baseStates,
|
|
|
|
UCMapping *m,
|
|
|
|
UChar32 codePoints[UCNV_EXT_MAX_UCHARS],
|
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES]);
|
|
|
|
|
|
|
|
/* add a mapping to the base or extension table as appropriate */
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_addMappingAuto(UCMFile *ucm, UBool forBase, UCMStates *baseStates,
|
|
|
|
UCMapping *m,
|
|
|
|
UChar32 codePoints[UCNV_EXT_MAX_UCHARS],
|
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES]);
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_addMappingFromLine(UCMFile *ucm, const char *line, UBool forBase, UCMStates *baseStates);
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI UCMTable * U_EXPORT2
|
|
|
|
ucm_openTable(void);
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_closeTable(UCMTable *table);
|
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_resetTable(UCMTable *table);
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_sortTable(UCMTable *t);
|
|
|
|
|
2007-02-06 05:24:14 +00:00
|
|
|
/*
|
|
|
|
* Remove mappings with their move flag set from the base table
|
|
|
|
* and move some of them (with UCM_MOVE_TO_EXT) to the extension table.
|
|
|
|
*/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_moveMappings(UCMTable *base, UCMTable *ext);
|
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
/**
|
|
|
|
* Read a table from a .ucm file, from after the CHARMAP line to
|
|
|
|
* including the END CHARMAP line.
|
|
|
|
*/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_readTable(UCMFile *ucm, FileStream* convFile,
|
|
|
|
UBool forBase, UCMStates *baseStates,
|
|
|
|
UErrorCode *pErrorCode);
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
/**
|
|
|
|
* Check the validity of mappings against a base table's states;
|
|
|
|
* necessary for extension-only tables that were read before their base tables.
|
|
|
|
*/
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_checkValidity(UCMTable *ext, UCMStates *baseStates);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check a base table against an extension table.
|
2003-11-07 23:57:24 +00:00
|
|
|
* Set the moveTarget!=NULL if it is possible to move mappings from the base.
|
|
|
|
* This is the case where base and extension tables are parsed from a single file
|
|
|
|
* (moveTarget==ext)
|
|
|
|
* or when delta file mappings are subtracted from a base table.
|
|
|
|
*
|
|
|
|
* When a base table cannot be modified because a delta file is parsed in makeconv,
|
|
|
|
* then set moveTarget=NULL.
|
|
|
|
*
|
|
|
|
* if(intersectBase) then mappings that exist in the base table but not in
|
|
|
|
* the extension table are moved to moveTarget instead of showing an error.
|
|
|
|
*
|
2003-11-11 18:47:42 +00:00
|
|
|
* Special mode:
|
|
|
|
* If intersectBase==2 for a DBCS extension table, then SBCS mappings are
|
2003-11-07 23:57:24 +00:00
|
|
|
* not moved out of the base unless their Unicode input requires it.
|
2003-11-11 18:47:42 +00:00
|
|
|
* This helps ucmkbase generate base tables for DBCS-only extension .cnv files.
|
2003-10-25 00:29:13 +00:00
|
|
|
*
|
|
|
|
* For both tables in the same file, the extension table is automatically
|
|
|
|
* built.
|
2007-02-06 05:24:14 +00:00
|
|
|
* For separate files, the extension file can use a complete mapping table (.ucm file),
|
2003-10-25 00:29:13 +00:00
|
|
|
* so that common mappings need not be stripped out manually.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sort both tables, and then for each mapping direction:
|
|
|
|
*
|
2003-11-07 23:57:24 +00:00
|
|
|
* If intersectBase is TRUE and the base table contains a mapping
|
|
|
|
* that does not exist in the extension table, then this mapping is moved
|
|
|
|
* to moveTarget.
|
|
|
|
*
|
|
|
|
* - otherwise -
|
|
|
|
*
|
2003-10-25 00:29:13 +00:00
|
|
|
* If the base table contains a mapping for which the input sequence is
|
|
|
|
* the same as the extension input, then
|
|
|
|
* - if the output is the same: remove the extension mapping
|
|
|
|
* - else: error
|
|
|
|
*
|
|
|
|
* If the base table contains a mapping for which the input sequence is
|
|
|
|
* a prefix of the extension input, then
|
2003-11-07 23:57:24 +00:00
|
|
|
* - if moveTarget!=NULL: move the base mapping to the moveTarget table
|
2003-10-25 00:29:13 +00:00
|
|
|
* - else: error
|
|
|
|
*
|
|
|
|
* @return FALSE in case of an irreparable error
|
|
|
|
*/
|
|
|
|
U_CAPI UBool U_EXPORT2
|
2003-11-07 23:57:24 +00:00
|
|
|
ucm_checkBaseExt(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
|
|
|
|
UCMTable *moveTarget, UBool intersectBase);
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_printTable(UCMTable *table, FILE *f, UBool byUnicode);
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_printMapping(UCMTable *table, UCMapping *m, FILE *f);
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_addState(UCMStates *states, const char *s);
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
2010-02-27 03:39:15 +00:00
|
|
|
ucm_processStates(UCMStates *states, UBool ignoreSISOCheck);
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucm_countChars(UCMStates *states,
|
|
|
|
const uint8_t *bytes, int32_t length);
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int8_t U_EXPORT2
|
|
|
|
ucm_parseBytes(uint8_t bytes[UCNV_EXT_MAX_BYTES], const char *line, const char **ps);
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_parseMappingLine(UCMapping *m,
|
|
|
|
UChar32 codePoints[UCNV_EXT_MAX_UCHARS],
|
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES],
|
|
|
|
const char *line);
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_addMapping(UCMTable *table,
|
|
|
|
UCMapping *m,
|
|
|
|
UChar32 codePoints[UCNV_EXT_MAX_UCHARS],
|
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES]);
|
|
|
|
|
|
|
|
/* very makeconv-specific functions ----------------------------------------- */
|
|
|
|
|
|
|
|
/* finalize and optimize states after the toUnicode mappings are processed */
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_optimizeStates(UCMStates *states,
|
|
|
|
uint16_t **pUnicodeCodeUnits,
|
|
|
|
_MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks,
|
|
|
|
UBool verbose);
|
|
|
|
|
|
|
|
/* moved here because it is used inside ucmstate.c */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucm_findFallback(_MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks,
|
|
|
|
uint32_t offset);
|
|
|
|
|
2003-10-27 03:06:55 +00:00
|
|
|
/* very rptp2ucm-specific functions ----------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Input: Separate tables with mappings from/to Unicode,
|
|
|
|
* subchar and subchar1 (0 if none).
|
|
|
|
* All mappings must have flag 0.
|
|
|
|
*
|
|
|
|
* Output: fromUTable will contain the union of mappings with the correct
|
|
|
|
* precision flags, and be sorted.
|
|
|
|
*/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucm_mergeTables(UCMTable *fromUTable, UCMTable *toUTable,
|
|
|
|
const uint8_t *subchar, int32_t subcharLength,
|
|
|
|
uint8_t subchar1);
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucm_separateMappings(UCMFile *ucm, UBool isSISO);
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
U_CDECL_END
|
|
|
|
|
|
|
|
#endif
|
2005-07-09 03:09:47 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|