1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
3c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert*   Copyright (C) 1999-2015 International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*  ucnv_bld.h:
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*  Contains internal data structure definitions
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Created by Bertrand A. Damiba
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Change history:
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   06/29/2000  helena      Major rewrite of the callback APIs.
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef UCNV_BLD_H
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_BLD_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 "unicode/ucnv_err.h"
2683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius#include "unicode/utf16.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucnv_cnv.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucnvmbcs.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucnv_ext.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "udataswp.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* size of the overflow buffers in UConverter, enough for escaping callbacks */
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_ERROR_BUFFER_LENGTH 32
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* at most 4 bytes per substitution character (part of .cnv file format! see UConverterStaticData) */
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_MAX_SUBCHAR_LEN 4
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* at most 8 bytes per character in toUBytes[] (UTF-8 uses up to 6) */
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_MAX_CHAR_LEN 8
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* converter options bits */
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_OPTION_VERSION     0xf
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_OPTION_SWAP_LFNL   0x10
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define UCNV_GET_VERSION(cnv) ((cnv)->options&UCNV_OPTION_VERSION)
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 itself is compiled under C++, the linkage of the funcptrs will
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 work.
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              */
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruunion UConverterTable {
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterMBCSTable mbcs;
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef union UConverterTable UConverterTable;
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct UConverterImpl;
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct UConverterImpl UConverterImpl;
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** values for the unicodeMask */
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_HAS_SUPPLEMENTARY 1
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_HAS_SURROGATES    2
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct UConverterStaticData {   /* +offset: size */
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t structSize;                /* +0: 4 Size of this structure */
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char name
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      [UCNV_MAX_CONVERTER_NAME_LENGTH]; /* +4: 60  internal name of the converter- invariant chars */
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t codepage;               /* +64: 4 codepage # (now IBM-$codepage) */
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t platform;                /* +68: 1 platform of the converter (only IBM now) */
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t conversionType;          /* +69: 1 conversion type */
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t minBytesPerChar;         /* +70: 1 Minimum # bytes per char in this codepage */
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t maxBytesPerChar;         /* +71: 1 Maximum # bytes output per UChar in this codepage */
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* +72: 4  [note:  4 and 8 byte boundary] */
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t subCharLen;              /* +76: 1 */
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t hasToUnicodeFallback;   /* +77: 1 UBool needs to be changed to UBool to be consistent across platform */
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t hasFromUnicodeFallback; /* +78: 1 */
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t unicodeMask;            /* +79: 1  bit 0: has supplementary  bit 1: has single surrogates */
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t subChar1;               /* +80: 1  single-byte substitution character for IBM MBCS (0 if none) */
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t reserved[19];           /* +81: 19 to round out the structure */
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    /* total size: 100 */
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} UConverterStaticData;
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Defines the UConverterSharedData struct,
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the immutable, shared part of UConverter.
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct UConverterSharedData {
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t structSize;            /* Size of this structure */
96c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    uint32_t referenceCounter;      /* used to count number of clients, unused for static/immutable SharedData */
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *dataMemory;         /* from udata_openChoice() - for cleanup */
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    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 */
103c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    /** If FALSE, then referenceCounter is not used. Must not change after initialization. */
104c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    UBool isReferenceCounted;
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UConverterImpl *impl;     /* vtable-style struct of mostly function pointers */
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*initial values of some members of the mutable part of object */
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t toUnicodeStatus;
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Shared data structures currently come in two flavors:
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - readonly for built-in algorithmic converters
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - allocated for MBCS, with a pointer to an allocated UConverterTable
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   which always has a UConverterMBCSTable
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * To eliminate one allocation, I am making the UConverterMBCSTable
118c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert     * a member of the shared data.
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * markus 2003-nov-07
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterMBCSTable mbcs;
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
125c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert/** UConverterSharedData initializer for static, non-reference-counted converters. */
126c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert#define UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(pStaticData, pImpl) \
127c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    { \
128c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert        sizeof(UConverterSharedData), ~((uint32_t)0), \
129c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert        NULL, pStaticData, FALSE, FALSE, pImpl, \
130c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert        0, UCNV_MBCS_TABLE_INITIALIZER \
131c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    }
132c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Defines a UConverter, the lightweight mutable part the user sees */
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct UConverter {
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Error function pointer called when conversion issues
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * occur during a ucnv_fromUnicode call
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void (U_EXPORT2 *fromUCharErrorBehaviour) (const void *context,
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UConverterFromUnicodeArgs *args,
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     const UChar *codeUnits,
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     int32_t length,
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UChar32 codePoint,
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UConverterCallbackReason reason,
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UErrorCode *);
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Error function pointer called when conversion issues
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * occur during a ucnv_toUnicode call
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void (U_EXPORT2 *fromCharErrorBehaviour) (const void *context,
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    UConverterToUnicodeArgs *args,
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    const char *codeUnits,
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    int32_t length,
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    UConverterCallbackReason reason,
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                    UErrorCode *);
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Pointer to additional data that depends on the converter type.
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Used by ISO 2022, SCSU, GB 18030 converters, possibly more.
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void *extraInfo;
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *fromUContext;
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *toUContext;
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Pointer to charset bytes for substitution string if subCharLen>0,
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * or pointer to Unicode string (UChar *) if subCharLen<0.
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * subCharLen==0 is equivalent to using a skip callback.
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * If the pointer is !=subUChars then it is allocated with
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR bytes.
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * The subUChars field is declared as UChar[] not uint8_t[] to
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * guarantee alignment for UChars.
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *subChars;
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterSharedData *sharedData;   /* Pointer to the shared immutable part of the converter object */
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t options; /* options flags from UConverterOpen, may contain additional bits */
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    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 */
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool isCopyLocal;  /* TRUE if UConverter is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool isExtraLocal; /* TRUE if extraInfo is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool  useFallback;
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t toULength;                   /* number of bytes in toUBytes */
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t toUBytes[UCNV_MAX_CHAR_LEN-1];/* more "toU status"; keeps the bytes of the current character */
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t toUnicodeStatus;           /* Used to internalize stream status information */
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t mode;
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t fromUnicodeStatus;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * More fromUnicode() status. Serves 3 purposes:
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - keeps a lead surrogate between buffers (similar to toUBytes[])
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - keeps a lead surrogate at the end of the stream,
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   which the framework handles as truncated input
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - if the fromUnicode() implementation returns to the framework
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   (ucnv.c ucnv_fromUnicode()), then the framework calls the callback
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   for this code point
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 fromUChar32;
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * value for ucnv_getMaxCharSize()
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * usually simply copied from the static data, but ucnvmbcs.c modifies
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * the value depending on the converter type and options
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t maxBytesPerUChar;
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t subCharLen;                  /* length of the codepage specific character sequence */
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t invalidCharLength;
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t charErrorBufferLength;       /* number of valid bytes in charErrorBuffer */
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t invalidUCharLength;
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t UCharErrorBufferLength;      /* number of valid UChars in charErrorBuffer */
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t subChar1;                                   /* single-byte substitution character if different from subChar */
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool useSubChar1;
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char invalidCharBuffer[UCNV_MAX_CHAR_LEN];          /* bytes from last error/callback situation */
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t charErrorBuffer[UCNV_ERROR_BUFFER_LENGTH];  /* codepage output from Error functions */
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar subUChars[UCNV_MAX_SUBCHAR_LEN/U_SIZEOF_UCHAR]; /* see subChars documentation */
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar invalidUCharBuffer[U16_MAX_LENGTH];           /* UChars from last error/callback situation */
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar UCharErrorBuffer[UCNV_ERROR_BUFFER_LENGTH];   /* unicode output from Error functions */
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* fields for conversion extension */
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* store previous UChars/chars to continue partial matches */
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 preFromUFirstCP;                /* >=0: partial match */
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar preFromU[UCNV_EXT_MAX_UCHARS];
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char preToU[UCNV_EXT_MAX_BYTES];
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t preFromULength, preToULength;    /* negative: replay */
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int8_t preToUFirstLength;               /* length of first character */
23685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
23785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* new fields for ICU 4.0 */
23885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UConverterCallbackReason toUCallbackReason; /* (*fromCharErrorBehaviour) reason, set when error is detected */
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_END /* end of UConverter */
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CONVERTER_FILE_EXTENSION ".cnv"
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return the number of all converter names.
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param pErrorCode The error code
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the number of all converter names
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC uint16_t
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_bld_countAvailableConverters(UErrorCode *pErrorCode);
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return the (n)th converter name in mixed case, or NULL
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * if there is none (typically, if the data cannot be loaded).
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 0<=index<ucnv_io_countAvailableConverters().
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param n The number specifies which converter name to get
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param pErrorCode The error code
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the (n)th converter name in mixed case, or NULL if there is none.
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC const char *
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_bld_getAvailableConverter(uint16_t n, UErrorCode *pErrorCode);
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Load a non-algorithmic converter.
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If pkg==NULL, then this function must be called inside umtx_lock(&cnvCacheMutex).
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
26983a171d1a62abf406f7f44ae671823d5ec20db7dCraig CorneliusU_CAPI UConverterSharedData *
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_load(UConverterLoadArgs *pArgs, UErrorCode *err);
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Unload a non-algorithmic converter.
274c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert * It must be sharedData->isReferenceCounted
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and this function must be called inside umtx_lock(&cnvCacheMutex).
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
27783a171d1a62abf406f7f44ae671823d5ec20db7dCraig CorneliusU_CAPI void
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_unload(UConverterSharedData *sharedData);
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Swap ICU .cnv conversion tables. See udataswp.h.
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @internal
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_swap(const UDataSwapper *ds,
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          const void *inData, int32_t length, void *outData,
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          UErrorCode *pErrorCode);
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* _UCNV_BLD */
292