1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-12-09 23:27:55 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
2000-05-12 19:59:03 +00:00
|
|
|
*
|
|
|
|
* uconv_cnv.h:
|
|
|
|
* defines all the low level conversion functions
|
|
|
|
* T_UnicodeConverter_{to,from}Unicode_$ConversionType
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 05/09/00 helena Added implementation to handle fallback mappings.
|
2000-06-27 20:47:56 +00:00
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
2000-05-12 19:59:03 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#ifndef UCNV_CNV_H
|
|
|
|
#define UCNV_CNV_H
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
|
|
|
#include "ucnv_bld.h"
|
2000-07-13 00:10:29 +00:00
|
|
|
#include "ucnvmbcs.h"
|
2000-04-19 23:05:27 +00:00
|
|
|
|
|
|
|
union UConverterTable
|
|
|
|
{
|
|
|
|
UConverterMBCSTable mbcs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
U_CDECL_BEGIN
|
|
|
|
|
2000-07-13 23:55:33 +00:00
|
|
|
/* this is used in fromUnicode DBCS tables as an "unassigned" marker */
|
2000-02-05 00:19:15 +00:00
|
|
|
#define missingCharMarker 0xFFFF
|
2000-07-13 23:55:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* #define missingUCharMarker 0xfffe
|
|
|
|
*
|
|
|
|
* there are actually two values used in toUnicode tables:
|
|
|
|
* U+fffe "unassigned"
|
|
|
|
* U+ffff "illegal"
|
|
|
|
*/
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
#define FromU_CALLBACK_MACRO(context, args, codeUnits, length, codePoint, reason, err) \
|
2000-02-05 00:19:15 +00:00
|
|
|
{ \
|
|
|
|
/*copies current values for the ErrorFunctor to update */ \
|
|
|
|
/*Calls the ErrorFunctor */ \
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->fromUCharErrorBehaviour ( context, \
|
|
|
|
args, \
|
2000-06-27 20:47:56 +00:00
|
|
|
codeUnits, \
|
|
|
|
length, \
|
|
|
|
codePoint, \
|
|
|
|
reason, \
|
2000-02-05 00:19:15 +00:00
|
|
|
err); \
|
2000-07-10 20:51:54 +00:00
|
|
|
myTargetIndex = args->target - (char*)myTarget; \
|
|
|
|
mySourceIndex = args->source - mySource; \
|
2000-02-05 00:19:15 +00:00
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
/*
|
|
|
|
*/
|
2000-06-27 20:47:56 +00:00
|
|
|
#define ToU_CALLBACK_MACRO(context, args, codePoints, length, reason, err) \
|
2000-02-05 00:19:15 +00:00
|
|
|
{ \
|
|
|
|
/*Calls the ErrorFunctor */ \
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->fromCharErrorBehaviour ( \
|
2000-06-27 20:47:56 +00:00
|
|
|
context, \
|
2000-07-10 20:51:54 +00:00
|
|
|
args, \
|
2000-06-27 20:47:56 +00:00
|
|
|
codePoints, \
|
|
|
|
length, \
|
|
|
|
reason, \
|
2000-02-05 00:19:15 +00:00
|
|
|
err); \
|
2000-07-10 20:51:54 +00:00
|
|
|
myTargetIndex = args->target - myTarget; \
|
|
|
|
mySourceIndex = args->source - (const char*)mySource; \
|
2000-06-30 17:38:47 +00:00
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
/*
|
|
|
|
*/
|
2000-06-30 17:38:47 +00:00
|
|
|
#define FromU_CALLBACK_OFFSETS_LOGIC_MACRO(context, args, codeUnits, length, codePoint, reason, err) \
|
|
|
|
{ \
|
|
|
|
int32_t My_i = myTargetIndex; \
|
|
|
|
/*copies current values for the ErrorFunctor to update */ \
|
|
|
|
/*Calls the ErrorFunctor */ \
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->fromUCharErrorBehaviour ( \
|
2000-06-30 17:38:47 +00:00
|
|
|
context, \
|
2000-07-10 20:51:54 +00:00
|
|
|
args, \
|
2000-06-30 17:38:47 +00:00
|
|
|
codeUnits, \
|
|
|
|
length, \
|
|
|
|
codePoint, \
|
|
|
|
reason, \
|
|
|
|
err); \
|
|
|
|
/*Update the local Indexes so that the conversion can restart at the right points */ \
|
2000-07-10 20:51:54 +00:00
|
|
|
myTargetIndex = args->target - (char*)myTarget; \
|
|
|
|
mySourceIndex = args->source - mySource; \
|
|
|
|
args->offsets = saveOffsets; \
|
2000-07-24 20:33:23 +00:00
|
|
|
for (;My_i < myTargetIndex;My_i++) args->offsets[My_i] += currentOffset; \
|
2000-06-30 17:38:47 +00:00
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
/*
|
|
|
|
*/
|
2000-06-30 17:38:47 +00:00
|
|
|
#define ToU_CALLBACK_OFFSETS_LOGIC_MACRO(context, args, codePoints, length, reason, err) \
|
|
|
|
{ \
|
2000-07-10 20:51:54 +00:00
|
|
|
args->converter->fromCharErrorBehaviour ( \
|
2000-06-30 17:38:47 +00:00
|
|
|
context, \
|
2000-07-10 20:51:54 +00:00
|
|
|
args, \
|
2000-06-30 17:38:47 +00:00
|
|
|
codePoints, \
|
|
|
|
length, \
|
|
|
|
reason, \
|
|
|
|
err); \
|
|
|
|
/*Update the local Indexes so that the conversion can restart at the right points */ \
|
2000-07-10 20:51:54 +00:00
|
|
|
myTargetIndex = args->target - myTarget; \
|
|
|
|
mySourceIndex = args->source - (const char*)mySource; \
|
|
|
|
args->offsets = saveOffsets; \
|
2000-07-24 20:33:23 +00:00
|
|
|
for (;My_i < myTargetIndex;My_i++) {args->offsets[My_i] += currentOffset;} \
|
2000-02-05 00:19:15 +00:00
|
|
|
}
|
2000-07-13 00:10:29 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
typedef void (*UConverterLoad) (UConverterSharedData *sharedData, const uint8_t *raw, UErrorCode *pErrorCode);
|
|
|
|
typedef void (*UConverterUnload) (UConverterSharedData *sharedData);
|
|
|
|
|
2000-11-29 01:04:03 +00:00
|
|
|
typedef void (*UConverterOpen) (UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *pErrorCode);
|
2000-02-08 23:41:16 +00:00
|
|
|
typedef void (*UConverterClose) (UConverter *cnv);
|
|
|
|
|
2000-12-20 21:18:46 +00:00
|
|
|
typedef enum UConverterResetChoice {
|
|
|
|
UCNV_RESET_BOTH,
|
|
|
|
UCNV_RESET_TO_UNICODE,
|
|
|
|
UCNV_RESET_FROM_UNICODE
|
|
|
|
} UConverterResetChoice;
|
|
|
|
|
|
|
|
typedef void (*UConverterReset) (UConverter *cnv, UConverterResetChoice choice);
|
2000-02-08 23:41:16 +00:00
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
typedef void (*T_ToUnicodeFunction) (UConverterToUnicodeArgs *, UErrorCode *);
|
|
|
|
|
|
|
|
typedef void (*T_FromUnicodeFunction) (UConverterFromUnicodeArgs *, UErrorCode *);
|
|
|
|
|
|
|
|
typedef UChar32 (*T_GetNextUCharFunction) (UConverterToUnicodeArgs *, UErrorCode *);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
typedef void (*UConverterGetStarters)(const UConverter* converter,
|
2000-07-24 20:33:23 +00:00
|
|
|
UBool starters[256],
|
|
|
|
UErrorCode *pErrorCode);
|
2000-12-20 22:54:51 +00:00
|
|
|
|
2000-11-22 02:05:29 +00:00
|
|
|
/* If this function pointer is null or if the function returns null
|
|
|
|
* the name field in static data struct should be returned by
|
|
|
|
* ucnv_getName() API function
|
|
|
|
*/
|
2000-11-27 17:40:41 +00:00
|
|
|
typedef const char * (*UConverterGetName) (const UConverter *cnv);
|
2000-02-09 19:15:17 +00:00
|
|
|
|
2000-12-20 22:54:51 +00:00
|
|
|
/**
|
|
|
|
* Write the codepage substitution character.
|
|
|
|
* If this function is not set, then ucnv_cbFromUWriteSub() writes
|
|
|
|
* the substitution character from UConverter.
|
|
|
|
* For stateful converters, it is typically necessary to handle this
|
|
|
|
* specificially for the converter in order to properly maintain the state.
|
|
|
|
*/
|
|
|
|
typedef void (*UConverterWriteSub) (UConverterFromUnicodeArgs *pArgs, int32_t offsetIndex, UErrorCode *pErrorCode);
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool CONVERSION_U_SUCCESS (UErrorCode err);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
void flushInternalUnicodeBuffer (UConverter * _this,
|
2000-07-24 20:33:23 +00:00
|
|
|
UChar * myTarget,
|
|
|
|
int32_t * myTargetIndex,
|
|
|
|
int32_t targetLength,
|
|
|
|
int32_t** offsets,
|
|
|
|
UErrorCode * err);
|
2000-02-05 00:19:15 +00:00
|
|
|
|
|
|
|
void flushInternalCharBuffer (UConverter * _this,
|
2000-07-24 20:33:23 +00:00
|
|
|
char *myTarget,
|
|
|
|
int32_t * myTargetIndex,
|
|
|
|
int32_t targetLength,
|
|
|
|
int32_t** offsets,
|
|
|
|
UErrorCode * err);
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
/**
|
|
|
|
* UConverterImpl contains all the data and functions for a converter type.
|
|
|
|
* Its function pointers work much like a C++ vtable.
|
|
|
|
* Many converter types need to define only a subset of the functions;
|
|
|
|
* when a function pointer is NULL, then a default action will be performed.
|
|
|
|
*
|
|
|
|
* Every converter type must implement toUnicode, fromUnicode, and getNextUChar,
|
|
|
|
* otherwise the converter may crash.
|
|
|
|
* Every converter type that has variable-length codepage sequences should
|
|
|
|
* also implement toUnicodeWithOffsets and fromUnicodeWithOffsets for
|
|
|
|
* correct offset handling.
|
|
|
|
* All other functions may or may not be implemented - it depends only on
|
|
|
|
* whether the converter type needs them.
|
|
|
|
*
|
|
|
|
* When open() fails, then close() will be called, if present.
|
|
|
|
*/
|
2000-02-05 00:19:15 +00:00
|
|
|
struct UConverterImpl {
|
|
|
|
UConverterType type;
|
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
UConverterLoad load;
|
|
|
|
UConverterUnload unload;
|
|
|
|
|
|
|
|
UConverterOpen open;
|
|
|
|
UConverterClose close;
|
|
|
|
UConverterReset reset;
|
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
T_ToUnicodeFunction toUnicode;
|
|
|
|
T_ToUnicodeFunction toUnicodeWithOffsets;
|
|
|
|
T_FromUnicodeFunction fromUnicode;
|
|
|
|
T_FromUnicodeFunction fromUnicodeWithOffsets;
|
|
|
|
T_GetNextUCharFunction getNextUChar;
|
2000-02-09 19:15:17 +00:00
|
|
|
|
|
|
|
UConverterGetStarters getStarters;
|
2000-11-22 02:05:29 +00:00
|
|
|
UConverterGetName getName;
|
2000-12-20 22:54:51 +00:00
|
|
|
UConverterWriteSub writeSub;
|
2000-02-05 00:19:15 +00:00
|
|
|
};
|
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
extern const UConverterSharedData
|
2001-01-02 23:09:45 +00:00
|
|
|
_MBCSData, _Latin1Data,
|
2000-11-16 17:20:03 +00:00
|
|
|
_UTF8Data, _UTF16BEData, _UTF16LEData, _UTF32BEData, _UTF32LEData,
|
2001-01-02 23:09:45 +00:00
|
|
|
_ISO2022Data,
|
2000-03-31 16:53:09 +00:00
|
|
|
_LMBCSData1,_LMBCSData2, _LMBCSData3, _LMBCSData4, _LMBCSData5, _LMBCSData6,
|
2000-12-19 01:24:45 +00:00
|
|
|
_LMBCSData8,_LMBCSData11,_LMBCSData16,_LMBCSData17,_LMBCSData18,_LMBCSData19,
|
2000-12-20 02:08:39 +00:00
|
|
|
_HZData, _SCSUData, _ASCIIData;
|
2000-02-05 00:19:15 +00:00
|
|
|
|
|
|
|
U_CDECL_END
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-17 21:30:13 +00:00
|
|
|
/**
|
|
|
|
* This function is useful for implementations of getNextUChar().
|
|
|
|
* After a call to a callback function or to toUnicode(), an output buffer
|
|
|
|
* begins with a Unicode code point that needs to be returned as UChar32,
|
|
|
|
* and all following code units must be prepended to the - potentially
|
|
|
|
* prefilled - overflow buffer in the UConverter.
|
|
|
|
* The buffer should be at least of capacity UTF_MAX_CHAR_LENGTH so that a
|
|
|
|
* complete UChar32's UChars fit into it.
|
|
|
|
*
|
|
|
|
* @param cnv The converter that will get remaining UChars copied to its overflow area.
|
|
|
|
* @param buffer An array of UChars that was passed into a callback function
|
|
|
|
* or a toUnicode() function.
|
|
|
|
* @param length The number of code units (UChars) that are actually in the buffer.
|
|
|
|
* This must be >0.
|
|
|
|
* @return The code point from the first UChars in the buffer.
|
|
|
|
*/
|
|
|
|
U_CFUNC UChar32
|
|
|
|
ucnv_getUChar32KeepOverflow(UConverter *cnv, const UChar *buffer, int32_t length);
|
|
|
|
|
2000-11-07 22:37:01 +00:00
|
|
|
/**
|
|
|
|
* This helper function updates the offsets array after a callback function call.
|
|
|
|
* It adds the sourceIndex to each offsets item, or sets each of them to -1 if
|
|
|
|
* sourceIndex==-1.
|
|
|
|
*
|
|
|
|
* @param offsets The pointer to offsets entry that corresponds to the first target
|
|
|
|
* unit that the callback wrote.
|
|
|
|
* @param length The number of output units that the callback wrote.
|
|
|
|
* @param sourceIndex The sourceIndex of the input sequence that the callback
|
|
|
|
* function was called for.
|
|
|
|
* @return offsets+length if offsets!=NULL, otherwise NULL
|
|
|
|
*/
|
|
|
|
U_CFUNC int32_t *
|
|
|
|
ucnv_updateCallbackOffsets(int32_t *offsets, int32_t length, int32_t sourceIndex);
|
|
|
|
|
|
|
|
/** Always use fallbacks from codepage to Unicode */
|
|
|
|
#define TO_U_USE_FALLBACK(useFallback) TRUE
|
|
|
|
#define UCNV_TO_U_USE_FALLBACK(cnv) TRUE
|
|
|
|
|
|
|
|
/** Use fallbacks from Unicode to codepage when cnv->useFallback or for private-use code points */
|
|
|
|
#define FROM_U_USE_FALLBACK(useFallback, c) ((useFallback) || (uint32_t)((c)-0xe000)<0x1900 || (uint32_t)((c)-0xf0000)<0x20000)
|
|
|
|
#define UCNV_FROM_U_USE_FALLBACK(cnv, c) FROM_U_USE_FALLBACK((cnv)->useFallback, c)
|
|
|
|
|
2000-12-19 00:29:27 +00:00
|
|
|
/**
|
|
|
|
* This is a simple implementation of ucnv_getNextUChar() that uses the
|
|
|
|
* converter's toUnicode() function.
|
|
|
|
*
|
|
|
|
* \par
|
|
|
|
* A surrogate pair from a single byte sequence is always
|
|
|
|
* combined to a supplementary code point.
|
|
|
|
* A surrogate pair from consecutive byte sequences is only combined
|
|
|
|
* if collectPairs is set. This is necessary for SCSU
|
|
|
|
* but not allowed for most legacy codepages.
|
|
|
|
*
|
|
|
|
* @param pArgs The argument structure supplied by ucnv_getNextUChar()
|
|
|
|
* @param toU A function pointer to the converter's toUnicode() function
|
|
|
|
* @param collectPairs indicates whether separate surrogate results from
|
|
|
|
* consecutive byte sequences should be combined into
|
|
|
|
* a single code point
|
|
|
|
* @param pErrorCode An ICU error code parameter
|
|
|
|
* @return The Unicode code point as a result of a conversion of a minimal
|
|
|
|
* number of input bytes
|
|
|
|
*/
|
|
|
|
U_CFUNC UChar32
|
|
|
|
ucnv_getNextUCharFromToUImpl(UConverterToUnicodeArgs *pArgs,
|
2000-12-19 01:24:45 +00:00
|
|
|
T_ToUnicodeFunction toU,
|
|
|
|
UBool collectPairs,
|
|
|
|
UErrorCode *pErrorCode);
|
2000-12-19 00:29:27 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif /* UCNV_CNV */
|