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