ICU-1885 add swaplfnl converter option

X-SVN-Rev: 9878
This commit is contained in:
Markus Scherer 2002-09-18 01:27:37 +00:00
parent fa4c6ea32f
commit 3c802a478a
3 changed files with 55 additions and 7 deletions
icu4c/source/common

View file

@ -27,6 +27,11 @@
#define UCNV_MAX_SUBCHAR_LEN 4
/* converter options bits */
#define UCNV_OPTION_VERSION 0xf
#define UCNV_OPTION_SWAP_LFNL 0x10
U_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv
itself is compiled under C++, the linkage of the funcptrs will
work.
@ -117,8 +122,8 @@ struct UConverter {
UErrorCode *);
/*
* currently only used to point to a struct containing UConverter used by iso 2022;
* could be used by clients writing their own call back function to pass context to them
* Pointer to additional data that depends on the converter type.
* Used by ISO 2022, SCSU, GB 18030 converters, possibly more.
*/
void *extraInfo;
@ -126,6 +131,9 @@ struct UConverter {
const void *toUContext;
UConverterSharedData *sharedData; /* Pointer to the shared immutable part of the converter object */
uint32_t options; /* options flags from UConverterOpen, may contain additional bits */
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 */
UBool isCopyLocal; /* TRUE if created by safeClone with no allocation - Don't free cnv memory on ucnv_close. */

View file

@ -74,7 +74,8 @@ enum {
#define MBCS_SINGLE_RESULT_FROM_U(table, results, c) (results)[ (table)[ (table)[(c)>>10] +(((c)>>4)&0x3f) ] +((c)&0xf) ]
/* multi-byte fromUnicode: get the 32-bit stage 2 entry */
#define MBCS_STAGE_2_FROM_U(table, c) ((uint32_t *)(table))[ (table)[(c)>>10] +(((c)>>4)&0x3f) ]
#define MBCS_STAGE_2_FROM_U(table, c) ((const uint32_t *)(table))[ (table)[(c)>>10] +(((c)>>4)&0x3f) ]
#define MBCS_FROM_U_IS_ROUNDTRIP(stage2Entry, c) ( ((stage2Entry) & ((uint32_t)1<< (16+((c)&0xf)) )) !=0)
#define MBCS_VALUE_2_FROM_STAGE_2(bytes, stage2Entry, c) ((uint16_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
#define MBCS_VALUE_4_FROM_STAGE_2(bytes, stage2Entry, c) ((uint32_t *)(bytes))[16*(uint32_t)(uint16_t)(stage2Entry)+((c)&0xf)]
@ -119,13 +120,18 @@ typedef struct UConverterMBCSTable {
uint32_t countToUFallbacks;
const int32_t (*stateTable)/*[countStates]*/[256];
int32_t (*swapLFNLStateTable)/*[countStates]*/[256]; /* for swaplfnl */
const uint16_t *unicodeCodeUnits/*[countUnicodeResults]*/;
const _MBCSToUFallback *toUFallbacks;
/* fromUnicode */
const uint16_t *fromUnicodeTable;
const uint8_t *fromUnicodeBytes;
uint8_t *swapLFNLFromUnicodeBytes; /* for swaplfnl */
uint8_t outputType, unicodeMask;
/* converter name for swaplfnl */
char *swapLFNLName;
} UConverterMBCSTable;
/**
@ -171,6 +177,7 @@ typedef struct {
* This is a simple version of _MBCSGetNextUChar() that is used
* by other converter implementations.
* It does not use state from the converter, nor error codes.
* It does not handle the EBCDIC swaplfnl option (set in UConverter).
*
* Return value:
* U+fffe unassigned
@ -182,7 +189,10 @@ _MBCSSimpleGetNextUChar(UConverterSharedData *sharedData,
const char **pSource, const char *sourceLimit,
UBool useFallback);
/** This version of _MBCSSimpleGetNextUChar() is optimized for single-byte, single-state codepages. */
/**
* This version of _MBCSSimpleGetNextUChar() is optimized for single-byte, single-state codepages.
* It does not handle the EBCDIC swaplfnl option (set in UConverter).
*/
U_CFUNC UChar32
_MBCSSingleSimpleGetNextUChar(UConverterSharedData *sharedData,
uint8_t b, UBool useFallback);
@ -211,6 +221,8 @@ _MBCSIsLeadByte(UConverterSharedData *sharedData, char byte);
* This is another simple conversion function for internal use by other
* conversion implementations.
* It does not use the converter state nor call callbacks.
* It does not handle the EBCDIC swaplfnl option (set in UConverter).
*
* It converts one single Unicode code point into codepage bytes, encoded
* as one 32-bit value. The function returns the number of bytes in *pValue:
* 1..4 the number of bytes in *pValue
@ -228,6 +240,8 @@ _MBCSFromUChar32(UConverterSharedData *sharedData,
/**
* This version of _MBCSFromUChar32() is optimized for single-byte codepages.
* It does not handle the EBCDIC swaplfnl option (set in UConverter).
*
* It returns the codepage byte for the code point, or -1 if it is unassigned.
*/
U_CFUNC int32_t

View file

@ -197,11 +197,36 @@ U_CDECL_END
/**
* Converter option for specifying a locale.
* For example, ucnv_open("SCSU,locale=ja", &errorCode);
* See convrtrs.txt.
*
* @see ucnv_open
* @stable
*/
#define UCNV_LOCALE_OPTION_STRING ",locale="
/**
* Converter option for specifying a version selector (0..9) for some converters.
* For example, ucnv_open("UTF-7,version=1", &errorCode);
* See convrtrs.txt.
*
* @see ucnv_open
* @draft ICU 2.4
*/
#define UCNV_VERSION_OPTION_STRING ",version="
/**
* Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages.
* Swaps Unicode mappings for EBCDIC LF and NL codes, as used on
* S/390 (z/OS) Unix System Services (Open Edition).
* For example, ucnv_open("ibm-1047,swaplfnl", &errorCode);
* See convrtrs.txt.
*
* @see ucnv_open
* @draft ICU 2.4
*/
#define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl"
/**
* Do a fuzzy compare of a two converter/alias names. The comparison
* is case-insensitive. It also ignores the characters '-', '_', and
@ -311,11 +336,12 @@ ucnv_openU (const UChar * name,
* cnv=ucnv_open(name, &errorCode);
* \endcode
*
* In order to open a converter with the IBM S/390 Unix System Services variant of a Unicode/EBCDIC conversion table,
* you can use the prefix "ibm-" together with the suffix "-s390":
* In order to open a converter with the IBM S/390 Unix System Services variant
* of a Unicode/EBCDIC conversion table,
* you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING:
* \code
* char name[20];
* sprintf(name, "ibm-%hu-s390", ccsid);
* sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid);
* cnv=ucnv_open(name, &errorCode);
* \endcode
*