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
|
|
|
#include "ucmp8.h"
|
|
|
|
#include "ucmp16.h"
|
|
|
|
|
|
|
|
/*Table Node Definitions */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UChar *toUnicode; /* [256]; */
|
|
|
|
CompactByteArray fromUnicode;
|
2000-05-12 19:59:03 +00:00
|
|
|
UChar *toUnicodeFallback;
|
|
|
|
CompactByteArray fromUnicodeFallback;
|
2000-04-19 23:05:27 +00:00
|
|
|
}
|
|
|
|
UConverterSBCSTable;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CompactShortArray toUnicode;
|
|
|
|
CompactShortArray fromUnicode;
|
2000-05-12 19:59:03 +00:00
|
|
|
CompactShortArray toUnicodeFallback;
|
|
|
|
CompactShortArray fromUnicodeFallback;
|
2000-04-19 23:05:27 +00:00
|
|
|
}
|
|
|
|
UConverterDBCSTable;
|
|
|
|
|
|
|
|
union UConverterTable
|
|
|
|
{
|
|
|
|
UConverterSBCSTable sbcs;
|
|
|
|
UConverterDBCSTable dbcs;
|
|
|
|
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);
|
|
|
|
|
|
|
|
typedef void (*UConverterOpen) (UConverter *cnv, const char *name, const char *locale, UErrorCode *pErrorCode);
|
|
|
|
typedef void (*UConverterClose) (UConverter *cnv);
|
|
|
|
|
|
|
|
typedef void (*UConverterReset) (UConverter *cnv);
|
|
|
|
|
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-02-09 19:15:17 +00:00
|
|
|
|
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-02-05 00:19:15 +00:00
|
|
|
};
|
|
|
|
|
2000-02-09 19:15:17 +00:00
|
|
|
extern const UConverterSharedData
|
2000-02-05 00:19:15 +00:00
|
|
|
_SBCSData, _DBCSData, _MBCSData, _Latin1Data,
|
|
|
|
_UTF8Data, _UTF16BEData, _UTF16LEData, _EBCDICStatefulData,
|
2000-10-17 08:03:36 +00:00
|
|
|
_ISO2022Data,
|
2000-03-31 16:53:09 +00:00
|
|
|
_LMBCSData1,_LMBCSData2, _LMBCSData3, _LMBCSData4, _LMBCSData5, _LMBCSData6,
|
2000-10-17 08:03:36 +00:00
|
|
|
_LMBCSData8,_LMBCSData11,_LMBCSData16,_LMBCSData17,_LMBCSData18,_LMBCSData19,_HZData;
|
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);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif /* UCNV_CNV */
|