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