sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (C) 1999-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * sl@0: * sl@0: * ucnv_bld.h: sl@0: * Contains internal data structure definitions sl@0: * Created by Bertrand A. Damiba sl@0: * sl@0: * Change history: sl@0: * sl@0: * 06/29/2000 helena Major rewrite of the callback APIs. sl@0: */ sl@0: sl@0: #ifndef UCNV_BLD_H sl@0: #define UCNV_BLD_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: sl@0: #if !UCONFIG_NO_CONVERSION sl@0: sl@0: #include "unicode/ucnv.h" sl@0: #include "unicode/ucnv_err.h" sl@0: #include "ucnv_cnv.h" sl@0: #include "ucnvmbcs.h" sl@0: #include "ucnv_ext.h" sl@0: #include "udataswp.h" sl@0: sl@0: /* size of the overflow buffers in UConverter, enough for escaping callbacks */ sl@0: #define UCNV_ERROR_BUFFER_LENGTH 32 sl@0: sl@0: /* at most 4 bytes per substitution character (part of .cnv file format! see UConverterStaticData) */ sl@0: #define UCNV_MAX_SUBCHAR_LEN 4 sl@0: sl@0: /* at most 8 bytes per character in toUBytes[] (UTF-8 uses up to 6) */ sl@0: #define UCNV_MAX_CHAR_LEN 8 sl@0: sl@0: /* converter options bits */ sl@0: #define UCNV_OPTION_VERSION 0xf sl@0: #define UCNV_OPTION_SWAP_LFNL 0x10 sl@0: sl@0: sl@0: U_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv sl@0: itself is compiled under C++, the linkage of the funcptrs will sl@0: work. sl@0: */ sl@0: sl@0: union UConverterTable { sl@0: UConverterMBCSTable mbcs; sl@0: }; sl@0: sl@0: typedef union UConverterTable UConverterTable; sl@0: sl@0: struct UConverterImpl; sl@0: typedef struct UConverterImpl UConverterImpl; sl@0: sl@0: /** values for the unicodeMask */ sl@0: #define UCNV_HAS_SUPPLEMENTARY 1 sl@0: #define UCNV_HAS_SURROGATES 2 sl@0: sl@0: typedef struct UConverterStaticData { /* +offset: size */ sl@0: uint32_t structSize; /* +0: 4 Size of this structure */ sl@0: sl@0: char name sl@0: [UCNV_MAX_CONVERTER_NAME_LENGTH]; /* +4: 60 internal name of the converter- invariant chars */ sl@0: sl@0: int32_t codepage; /* +64: 4 codepage # (now IBM-$codepage) */ sl@0: sl@0: int8_t platform; /* +68: 1 platform of the converter (only IBM now) */ sl@0: int8_t conversionType; /* +69: 1 conversion type */ sl@0: sl@0: int8_t minBytesPerChar; /* +70: 1 Minimum # bytes per char in this codepage */ sl@0: int8_t maxBytesPerChar; /* +71: 1 Maximum # bytes output per UChar in this codepage */ sl@0: sl@0: uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* +72: 4 [note: 4 and 8 byte boundary] */ sl@0: int8_t subCharLen; /* +76: 1 */ sl@0: sl@0: uint8_t hasToUnicodeFallback; /* +77: 1 UBool needs to be changed to UBool to be consistent across platform */ sl@0: uint8_t hasFromUnicodeFallback; /* +78: 1 */ sl@0: uint8_t unicodeMask; /* +79: 1 bit 0: has supplementary bit 1: has single surrogates */ sl@0: uint8_t subChar1; /* +80: 1 single-byte substitution character for IBM MBCS (0 if none) */ sl@0: uint8_t reserved[19]; /* +81: 19 to round out the structure */ sl@0: /* total size: 100 */ sl@0: } UConverterStaticData; sl@0: sl@0: /* sl@0: * Defines the UConverterSharedData struct, sl@0: * the immutable, shared part of UConverter. sl@0: */ sl@0: struct UConverterSharedData { sl@0: uint32_t structSize; /* Size of this structure */ sl@0: uint32_t referenceCounter; /* used to count number of clients, 0xffffffff for static SharedData */ sl@0: sl@0: const void *dataMemory; /* from udata_openChoice() - for cleanup */ sl@0: void *table; /* Unused. This used to be a UConverterTable - Pointer to conversion data - see mbcs below */ sl@0: sl@0: const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */ sl@0: sl@0: UBool sharedDataCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ sl@0: /*UBool staticDataOwned; TRUE if static data owned by shared data & should be freed with it, NEVER true for udata() loaded statics. This ignored variable was removed to make space for sharedDataCached. */ sl@0: sl@0: const UConverterImpl *impl; /* vtable-style struct of mostly function pointers */ sl@0: sl@0: /*initial values of some members of the mutable part of object */ sl@0: uint32_t toUnicodeStatus; sl@0: sl@0: /* sl@0: * Shared data structures currently come in two flavors: sl@0: * - readonly for built-in algorithmic converters sl@0: * - allocated for MBCS, with a pointer to an allocated UConverterTable sl@0: * which always has a UConverterMBCSTable sl@0: * sl@0: * To eliminate one allocation, I am making the UConverterMBCSTable sl@0: * a member of the shared data. It is the last member so that static sl@0: * definitions of UConverterSharedData work as before. sl@0: * The table field above also remains to avoid updating all static sl@0: * definitions, but is now unused. sl@0: * sl@0: * markus 2003-nov-07 sl@0: */ sl@0: UConverterMBCSTable mbcs; sl@0: }; sl@0: sl@0: /* Defines a UConverter, the lightweight mutable part the user sees */ sl@0: sl@0: struct UConverter { sl@0: /* sl@0: * Error function pointer called when conversion issues sl@0: * occur during a ucnv_fromUnicode call sl@0: */ sl@0: void (U_EXPORT2 *fromUCharErrorBehaviour) (const void *context, sl@0: UConverterFromUnicodeArgs *args, sl@0: const UChar *codeUnits, sl@0: int32_t length, sl@0: UChar32 codePoint, sl@0: UConverterCallbackReason reason, sl@0: UErrorCode *); sl@0: /* sl@0: * Error function pointer called when conversion issues sl@0: * occur during a ucnv_toUnicode call sl@0: */ sl@0: void (U_EXPORT2 *fromCharErrorBehaviour) (const void *context, sl@0: UConverterToUnicodeArgs *args, sl@0: const char *codeUnits, sl@0: int32_t length, sl@0: UConverterCallbackReason reason, sl@0: UErrorCode *); sl@0: sl@0: /* sl@0: * Pointer to additional data that depends on the converter type. sl@0: * Used by ISO 2022, SCSU, GB 18030 converters, possibly more. sl@0: */ sl@0: void *extraInfo; sl@0: sl@0: const void *fromUContext; sl@0: const void *toUContext; sl@0: sl@0: UConverterSharedData *sharedData; /* Pointer to the shared immutable part of the converter object */ sl@0: sl@0: uint32_t options; /* options flags from UConverterOpen, may contain additional bits */ sl@0: sl@0: UBool sharedDataIsCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ sl@0: UBool isCopyLocal; /* TRUE if UConverter is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ sl@0: UBool isExtraLocal; /* TRUE if extraInfo is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ sl@0: sl@0: UBool useFallback; sl@0: int8_t toULength; /* number of bytes in toUBytes */ sl@0: uint8_t toUBytes[UCNV_MAX_CHAR_LEN-1];/* more "toU status"; keeps the bytes of the current character */ sl@0: uint32_t toUnicodeStatus; /* Used to internalize stream status information */ sl@0: int32_t mode; sl@0: uint32_t fromUnicodeStatus; sl@0: sl@0: /* sl@0: * More fromUnicode() status. Serves 3 purposes: sl@0: * - keeps a lead surrogate between buffers (similar to toUBytes[]) sl@0: * - keeps a lead surrogate at the end of the stream, sl@0: * which the framework handles as truncated input sl@0: * - if the fromUnicode() implementation returns to the framework sl@0: * (ucnv.c ucnv_fromUnicode()), then the framework calls the callback sl@0: * for this code point sl@0: */ sl@0: UChar32 fromUChar32; sl@0: sl@0: /* sl@0: * value for ucnv_getMaxCharSize() sl@0: * sl@0: * usually simply copied from the static data, but ucnvmbcs.c modifies sl@0: * the value depending on the converter type and options sl@0: */ sl@0: int8_t maxBytesPerUChar; sl@0: sl@0: int8_t subCharLen; /* length of the codepage specific character sequence */ sl@0: int8_t invalidCharLength; sl@0: int8_t charErrorBufferLength; /* number of valid bytes in charErrorBuffer */ sl@0: sl@0: int8_t invalidUCharLength; sl@0: int8_t UCharErrorBufferLength; /* number of valid UChars in charErrorBuffer */ sl@0: sl@0: uint8_t subChar1; /* single-byte substitution character if different from subChar */ sl@0: UBool useSubChar1; sl@0: uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* codepage specific character sequence */ sl@0: char invalidCharBuffer[UCNV_MAX_CHAR_LEN]; /* bytes from last error/callback situation */ sl@0: uint8_t charErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* codepage output from Error functions */ sl@0: sl@0: UChar invalidUCharBuffer[U16_MAX_LENGTH]; /* UChars from last error/callback situation */ sl@0: UChar UCharErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* unicode output from Error functions */ sl@0: sl@0: /* fields for conversion extension */ sl@0: sl@0: /* store previous UChars/chars to continue partial matches */ sl@0: UChar32 preFromUFirstCP; /* >=0: partial match */ sl@0: UChar preFromU[UCNV_EXT_MAX_UCHARS]; sl@0: char preToU[UCNV_EXT_MAX_BYTES]; sl@0: int8_t preFromULength, preToULength; /* negative: replay */ sl@0: int8_t preToUFirstLength; /* length of first character */ sl@0: }; sl@0: sl@0: U_CDECL_END /* end of UConverter */ sl@0: sl@0: #define CONVERTER_FILE_EXTENSION ".cnv" sl@0: sl@0: sl@0: /** sl@0: * Return the number of all converter names. sl@0: * @param pErrorCode The error code sl@0: * @return the number of all converter names sl@0: */ sl@0: U_CFUNC uint16_t sl@0: ucnv_bld_countAvailableConverters(UErrorCode *pErrorCode); sl@0: sl@0: /** sl@0: * Return the (n)th converter name in mixed case, or NULL sl@0: * if there is none (typically, if the data cannot be loaded). sl@0: * 0<=indexreferenceCounter != ~0 sl@0: * and this function must be called inside umtx_lock(&cnvCacheMutex). sl@0: */ sl@0: void sl@0: ucnv_unload(UConverterSharedData *sharedData); sl@0: sl@0: /** sl@0: * Swap ICU .cnv conversion tables. See udataswp.h. sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: ucnv_swap(const UDataSwapper *ds, sl@0: const void *inData, int32_t length, void *outData, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #endif sl@0: sl@0: #endif /* _UCNV_BLD */