os/textandloc/fontservices/textshaperplugin/IcuSource/common/udataswp.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
*
sl@0
     4
*   Copyright (C) 2003-2005, International Business Machines
sl@0
     5
*   Corporation and others.  All Rights Reserved.
sl@0
     6
*
sl@0
     7
*******************************************************************************
sl@0
     8
*   file name:  udataswp.h
sl@0
     9
*   encoding:   US-ASCII
sl@0
    10
*   tab size:   8 (not used)
sl@0
    11
*   indentation:4
sl@0
    12
*
sl@0
    13
*   created on: 2003jun05
sl@0
    14
*   created by: Markus W. Scherer
sl@0
    15
*
sl@0
    16
*   Definitions for ICU data transformations for different platforms,
sl@0
    17
*   changing between big- and little-endian data and/or between
sl@0
    18
*   charset families (ASCII<->EBCDIC).
sl@0
    19
*/
sl@0
    20
sl@0
    21
#ifndef __UDATASWP_H__
sl@0
    22
#define __UDATASWP_H__
sl@0
    23
sl@0
    24
#include <stdarg.h>
sl@0
    25
#include "unicode/utypes.h"
sl@0
    26
sl@0
    27
/* forward declaration */
sl@0
    28
sl@0
    29
U_CDECL_BEGIN
sl@0
    30
sl@0
    31
struct UDataSwapper;
sl@0
    32
typedef struct UDataSwapper UDataSwapper;
sl@0
    33
sl@0
    34
/**
sl@0
    35
 * Function type for data transformation.
sl@0
    36
 * Transforms data, or just returns the length of the data if
sl@0
    37
 * the input length is -1.
sl@0
    38
 * Swap functions assume that their data pointers are aligned properly.
sl@0
    39
 *
sl@0
    40
 * Quick implementation outline:
sl@0
    41
 * (best to copy and adapt and existing swapper implementation)
sl@0
    42
 * check that the data looks like the expected format
sl@0
    43
 * if(length<0) {
sl@0
    44
 *   preflight:
sl@0
    45
 *   never dereference outData
sl@0
    46
 *   read inData and determine the data size
sl@0
    47
 *   assume that inData is long enough for this
sl@0
    48
 * } else {
sl@0
    49
 *   outData can be NULL if length==0
sl@0
    50
 *   inData==outData (in-place swapping) possible but not required!
sl@0
    51
 *   verify that length>=(actual size)
sl@0
    52
 *   if there is a chance that not every byte up to size is reached
sl@0
    53
 *     due to padding etc.:
sl@0
    54
 *   if(inData!=outData) {
sl@0
    55
 *     memcpy(outData, inData, actual size);
sl@0
    56
 *   }
sl@0
    57
 *   swap contents
sl@0
    58
 * }
sl@0
    59
 * return actual size
sl@0
    60
 *
sl@0
    61
 * Further implementation notes:
sl@0
    62
 * - read integers from inData before swapping them
sl@0
    63
 *   because in-place swapping can make them unreadable
sl@0
    64
 * - compareInvChars compares a local Unicode string with already-swapped
sl@0
    65
 *   output charset strings
sl@0
    66
 *
sl@0
    67
 * @param ds Pointer to UDataSwapper containing global data about the
sl@0
    68
 *           transformation and function pointers for handling primitive
sl@0
    69
 *           types.
sl@0
    70
 * @param inData Pointer to the input data to be transformed or examined.
sl@0
    71
 * @param length Length of the data, counting bytes. May be -1 for preflighting.
sl@0
    72
 *               If length>=0, then transform the data.
sl@0
    73
 *               If length==-1, then only determine the length of the data.
sl@0
    74
 *               The length cannot be determined from the data itself for all
sl@0
    75
 *               types of data (e.g., not for simple arrays of integers).
sl@0
    76
 * @param outData Pointer to the output data buffer.
sl@0
    77
 *                If length>=0 (transformation), then the output buffer must
sl@0
    78
 *                have a capacity of at least length.
sl@0
    79
 *                If length==-1, then outData will not be used and can be NULL.
sl@0
    80
 * @param pErrorCode ICU UErrorCode parameter, must not be NULL and must
sl@0
    81
 *                   fulfill U_SUCCESS on input.
sl@0
    82
 * @return The actual length of the data.
sl@0
    83
 *
sl@0
    84
 * @see UDataSwapper
sl@0
    85
 * @internal ICU 2.8
sl@0
    86
 */
sl@0
    87
typedef int32_t U_CALLCONV
sl@0
    88
UDataSwapFn(const UDataSwapper *ds,
sl@0
    89
            const void *inData, int32_t length, void *outData,
sl@0
    90
            UErrorCode *pErrorCode);
sl@0
    91
sl@0
    92
/**
sl@0
    93
 * Convert one uint16_t from input to platform endianness.
sl@0
    94
 * @internal ICU 2.8
sl@0
    95
 */
sl@0
    96
typedef uint16_t U_CALLCONV
sl@0
    97
UDataReadUInt16(uint16_t x);
sl@0
    98
sl@0
    99
/**
sl@0
   100
 * Convert one uint32_t from input to platform endianness.
sl@0
   101
 * @internal ICU 2.8
sl@0
   102
 */
sl@0
   103
typedef uint32_t U_CALLCONV
sl@0
   104
UDataReadUInt32(uint32_t x);
sl@0
   105
sl@0
   106
/**
sl@0
   107
 * Convert one uint16_t from platform to input endianness.
sl@0
   108
 * @internal ICU 2.8
sl@0
   109
 */
sl@0
   110
typedef void U_CALLCONV
sl@0
   111
UDataWriteUInt16(uint16_t *p, uint16_t x);
sl@0
   112
sl@0
   113
/**
sl@0
   114
 * Convert one uint32_t from platform to input endianness.
sl@0
   115
 * @internal ICU 2.8
sl@0
   116
 */
sl@0
   117
typedef void U_CALLCONV
sl@0
   118
UDataWriteUInt32(uint32_t *p, uint32_t x);
sl@0
   119
sl@0
   120
/**
sl@0
   121
 * Compare invariant-character strings, one in the output data and the
sl@0
   122
 * other one caller-provided in Unicode.
sl@0
   123
 * An output data string is compared because strings are usually swapped
sl@0
   124
 * before the rest of the data, to allow for sorting of string tables
sl@0
   125
 * according to the output charset.
sl@0
   126
 * You can use -1 for the length parameters of NUL-terminated strings as usual.
sl@0
   127
 * Returns Unicode code point order for invariant characters.
sl@0
   128
 * @internal ICU 2.8
sl@0
   129
 */
sl@0
   130
typedef int32_t U_CALLCONV
sl@0
   131
UDataCompareInvChars(const UDataSwapper *ds,
sl@0
   132
                     const char *outString, int32_t outLength,
sl@0
   133
                     const UChar *localString, int32_t localLength);
sl@0
   134
sl@0
   135
/**
sl@0
   136
 * Function for message output when an error occurs during data swapping.
sl@0
   137
 * A format string and variable number of arguments are passed
sl@0
   138
 * like for vprintf().
sl@0
   139
 *
sl@0
   140
 * @param context A function-specific context pointer.
sl@0
   141
 * @param fmt The format string.
sl@0
   142
 * @param args The arguments for format string inserts.
sl@0
   143
 *
sl@0
   144
 * @internal ICU 2.8
sl@0
   145
 */
sl@0
   146
typedef void U_CALLCONV
sl@0
   147
UDataPrintError(void *context, const char *fmt, va_list args);
sl@0
   148
sl@0
   149
struct UDataSwapper {
sl@0
   150
    /** Input endianness. @internal ICU 2.8 */
sl@0
   151
    UBool inIsBigEndian;
sl@0
   152
    /** Input charset family. @see U_CHARSET_FAMILY @internal ICU 2.8 */
sl@0
   153
    uint8_t inCharset;
sl@0
   154
    /** Output endianness. @internal ICU 2.8 */
sl@0
   155
    UBool outIsBigEndian;
sl@0
   156
    /** Output charset family. @see U_CHARSET_FAMILY @internal ICU 2.8 */
sl@0
   157
    uint8_t outCharset;
sl@0
   158
sl@0
   159
    /* basic functions for reading data values */
sl@0
   160
sl@0
   161
    /** Convert one uint16_t from input to platform endianness. @internal ICU 2.8 */
sl@0
   162
    UDataReadUInt16 *readUInt16;
sl@0
   163
    /** Convert one uint32_t from input to platform endianness. @internal ICU 2.8 */
sl@0
   164
    UDataReadUInt32 *readUInt32;
sl@0
   165
    /** Compare an invariant-character output string with a local one. @internal ICU 2.8 */
sl@0
   166
    UDataCompareInvChars *compareInvChars;
sl@0
   167
sl@0
   168
    /* basic functions for writing data values */
sl@0
   169
sl@0
   170
    /** Convert one uint16_t from platform to input endianness. @internal ICU 2.8 */
sl@0
   171
    UDataWriteUInt16 *writeUInt16;
sl@0
   172
    /** Convert one uint32_t from platform to input endianness. @internal ICU 2.8 */
sl@0
   173
    UDataWriteUInt32 *writeUInt32;
sl@0
   174
sl@0
   175
    /* basic functions for data transformations */
sl@0
   176
sl@0
   177
    /** Transform an array of 16-bit integers. @internal ICU 2.8 */
sl@0
   178
    UDataSwapFn *swapArray16;
sl@0
   179
    /** Transform an array of 32-bit integers. @internal ICU 2.8 */
sl@0
   180
    UDataSwapFn *swapArray32;
sl@0
   181
    /** Transform an invariant-character string. @internal ICU 2.8 */
sl@0
   182
    UDataSwapFn *swapInvChars;
sl@0
   183
sl@0
   184
    /**
sl@0
   185
     * Function for message output when an error occurs during data swapping.
sl@0
   186
     * Can be NULL.
sl@0
   187
     * @internal ICU 2.8
sl@0
   188
     */
sl@0
   189
    UDataPrintError *printError;
sl@0
   190
    /** Context pointer for printError. @internal ICU 2.8 */
sl@0
   191
    void *printErrorContext;
sl@0
   192
};
sl@0
   193
sl@0
   194
U_CDECL_END
sl@0
   195
sl@0
   196
U_CAPI UDataSwapper * U_EXPORT2
sl@0
   197
udata_openSwapper(UBool inIsBigEndian, uint8_t inCharset,
sl@0
   198
                  UBool outIsBigEndian, uint8_t outCharset,
sl@0
   199
                  UErrorCode *pErrorCode);
sl@0
   200
sl@0
   201
/**
sl@0
   202
 * Open a UDataSwapper for the given input data and the specified output
sl@0
   203
 * characteristics.
sl@0
   204
 * Values of -1 for any of the characteristics mean the local platform's
sl@0
   205
 * characteristics.
sl@0
   206
 *
sl@0
   207
 * @see udata_swap
sl@0
   208
 * @internal ICU 2.8
sl@0
   209
 */
sl@0
   210
U_CAPI UDataSwapper * U_EXPORT2
sl@0
   211
udata_openSwapperForInputData(const void *data, int32_t length,
sl@0
   212
                              UBool outIsBigEndian, uint8_t outCharset,
sl@0
   213
                              UErrorCode *pErrorCode);
sl@0
   214
sl@0
   215
U_CAPI void U_EXPORT2
sl@0
   216
udata_closeSwapper(UDataSwapper *ds);
sl@0
   217
sl@0
   218
/**
sl@0
   219
 * Read the beginning of an ICU data piece, recognize magic bytes,
sl@0
   220
 * swap the structure.
sl@0
   221
 * Set a U_UNSUPPORTED_ERROR if it does not look like an ICU data piece.
sl@0
   222
 *
sl@0
   223
 * @return The size of the data header, in bytes.
sl@0
   224
 *
sl@0
   225
 * @internal ICU 2.8
sl@0
   226
 */
sl@0
   227
U_CAPI int32_t U_EXPORT2
sl@0
   228
udata_swapDataHeader(const UDataSwapper *ds,
sl@0
   229
                     const void *inData, int32_t length, void *outData,
sl@0
   230
                     UErrorCode *pErrorCode);
sl@0
   231
sl@0
   232
/**
sl@0
   233
 * Convert one int16_t from input to platform endianness.
sl@0
   234
 * @internal ICU 2.8
sl@0
   235
 */
sl@0
   236
U_CAPI int16_t U_EXPORT2
sl@0
   237
udata_readInt16(const UDataSwapper *ds, int16_t x);
sl@0
   238
sl@0
   239
/**
sl@0
   240
 * Convert one int32_t from input to platform endianness.
sl@0
   241
 * @internal ICU 2.8
sl@0
   242
 */
sl@0
   243
U_CAPI int32_t U_EXPORT2
sl@0
   244
udata_readInt32(const UDataSwapper *ds, int32_t x);
sl@0
   245
sl@0
   246
/**
sl@0
   247
 * Swap a block of invariant, NUL-terminated strings, but not padding
sl@0
   248
 * bytes after the last string.
sl@0
   249
 * @internal
sl@0
   250
 */
sl@0
   251
U_CAPI int32_t U_EXPORT2
sl@0
   252
udata_swapInvStringBlock(const UDataSwapper *ds,
sl@0
   253
                         const void *inData, int32_t length, void *outData,
sl@0
   254
                         UErrorCode *pErrorCode);
sl@0
   255
sl@0
   256
U_CAPI void U_EXPORT2
sl@0
   257
udata_printError(const UDataSwapper *ds,
sl@0
   258
                 const char *fmt,
sl@0
   259
                 ...);
sl@0
   260
sl@0
   261
/* internal exports from putil.c -------------------------------------------- */
sl@0
   262
sl@0
   263
/* declared here to keep them out of the public putil.h */
sl@0
   264
sl@0
   265
/**
sl@0
   266
 * Swap invariant char * strings ASCII->EBCDIC.
sl@0
   267
 * @internal
sl@0
   268
 */
sl@0
   269
U_CFUNC int32_t
sl@0
   270
uprv_ebcdicFromAscii(const UDataSwapper *ds,
sl@0
   271
                     const void *inData, int32_t length, void *outData,
sl@0
   272
                     UErrorCode *pErrorCode);
sl@0
   273
sl@0
   274
/**
sl@0
   275
 * Copy invariant ASCII char * strings and verify they are invariant.
sl@0
   276
 * @internal
sl@0
   277
 */
sl@0
   278
U_CFUNC int32_t
sl@0
   279
uprv_copyAscii(const UDataSwapper *ds,
sl@0
   280
               const void *inData, int32_t length, void *outData,
sl@0
   281
               UErrorCode *pErrorCode);
sl@0
   282
sl@0
   283
/**
sl@0
   284
 * Swap invariant char * strings EBCDIC->ASCII.
sl@0
   285
 * @internal
sl@0
   286
 */
sl@0
   287
U_CFUNC int32_t
sl@0
   288
uprv_asciiFromEbcdic(const UDataSwapper *ds,
sl@0
   289
                     const void *inData, int32_t length, void *outData,
sl@0
   290
                     UErrorCode *pErrorCode);
sl@0
   291
sl@0
   292
/**
sl@0
   293
 * Copy invariant EBCDIC char * strings and verify they are invariant.
sl@0
   294
 * @internal
sl@0
   295
 */
sl@0
   296
U_CFUNC int32_t
sl@0
   297
uprv_copyEbcdic(const UDataSwapper *ds,
sl@0
   298
                const void *inData, int32_t length, void *outData,
sl@0
   299
                UErrorCode *pErrorCode);
sl@0
   300
sl@0
   301
/**
sl@0
   302
 * Compare ASCII invariant char * with Unicode invariant UChar *
sl@0
   303
 * @internal
sl@0
   304
 */
sl@0
   305
U_CFUNC int32_t
sl@0
   306
uprv_compareInvAscii(const UDataSwapper *ds,
sl@0
   307
                     const char *outString, int32_t outLength,
sl@0
   308
                     const UChar *localString, int32_t localLength);
sl@0
   309
sl@0
   310
/**
sl@0
   311
 * Compare EBCDIC invariant char * with Unicode invariant UChar *
sl@0
   312
 * @internal
sl@0
   313
 */
sl@0
   314
U_CFUNC int32_t
sl@0
   315
uprv_compareInvEbcdic(const UDataSwapper *ds,
sl@0
   316
                      const char *outString, int32_t outLength,
sl@0
   317
                      const UChar *localString, int32_t localLength);
sl@0
   318
sl@0
   319
/* material... -------------------------------------------------------------- */
sl@0
   320
sl@0
   321
#if 0
sl@0
   322
sl@0
   323
/* udata.h */
sl@0
   324
sl@0
   325
/**
sl@0
   326
 * Public API function in udata.c
sl@0
   327
 *
sl@0
   328
 * Same as udata_openChoice() but automatically swaps the data.
sl@0
   329
 * isAcceptable, if not NULL, may accept data with endianness and charset family
sl@0
   330
 * different from the current platform's properties.
sl@0
   331
 * If the data is acceptable and the platform properties do not match, then
sl@0
   332
 * the swap function is called to swap an allocated version of the data.
sl@0
   333
 * Preflighting may or may not be performed depending on whether the size of
sl@0
   334
 * the loaded data item is known.
sl@0
   335
 *
sl@0
   336
 * @param isAcceptable Same as for udata_openChoice(). May be NULL.
sl@0
   337
 *
sl@0
   338
 * @internal ICU 2.8
sl@0
   339
 */
sl@0
   340
U_CAPI UDataMemory * U_EXPORT2
sl@0
   341
udata_openSwap(const char *path, const char *type, const char *name,
sl@0
   342
               UDataMemoryIsAcceptable *isAcceptable, void *isAcceptableContext,
sl@0
   343
               UDataSwapFn *swap,
sl@0
   344
               UDataPrintError *printError, void *printErrorContext,
sl@0
   345
               UErrorCode *pErrorCode);
sl@0
   346
sl@0
   347
#endif
sl@0
   348
sl@0
   349
#endif