1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2012-08-08 00:50:16 +00:00
|
|
|
* Copyright (C) 1999-2012, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
|
|
|
*
|
2011-05-26 20:05:39 +00:00
|
|
|
* ucnv_io.cpp:
|
2005-08-30 20:37:50 +00:00
|
|
|
* initializes global variables and defines functions pertaining to converter
|
|
|
|
* name resolution aspect of the conversion code.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
|
|
|
* new implementation:
|
|
|
|
*
|
|
|
|
* created on: 1999nov22
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
2002-07-03 16:46:21 +00:00
|
|
|
* Use the binary cnvalias.icu (created from convrtrs.txt) to work
|
1999-11-23 23:02:55 +00:00
|
|
|
* with aliases for converter names.
|
2002-07-03 16:46:21 +00:00
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 11/22/1999 markus Created
|
|
|
|
* 06/28/2002 grhoten Major overhaul of the converter alias design.
|
|
|
|
* Now an alias can map to different converters
|
|
|
|
* depending on the specified standard.
|
2001-03-21 20:44:20 +00:00
|
|
|
*******************************************************************************
|
1999-11-23 23:02:55 +00:00
|
|
|
*/
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_CONVERSION
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
#include "unicode/ucnv.h"
|
2002-07-03 16:46:21 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "umutex.h"
|
2003-08-12 00:26:07 +00:00
|
|
|
#include "uarrsort.h"
|
|
|
|
#include "udataswp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cstring.h"
|
1999-12-04 00:55:54 +00:00
|
|
|
#include "cmemory.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "ucnv_io.h"
|
2002-07-13 16:32:16 +00:00
|
|
|
#include "uenumimp.h"
|
2001-08-29 22:07:27 +00:00
|
|
|
#include "ucln_cmn.h"
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
/* Format of cnvalias.icu -----------------------------------------------------
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2002-07-03 16:46:21 +00:00
|
|
|
* cnvalias.icu is a binary, memory-mappable form of convrtrs.txt.
|
2002-06-28 23:13:30 +00:00
|
|
|
* This binary form contains several tables. All indexes are to uint16_t
|
|
|
|
* units, and not to the bytes (uint8_t units). Addressing everything on
|
|
|
|
* 16-bit boundaries allows us to store more information with small index
|
|
|
|
* numbers, which are also 16-bit in size. The majority of the table (except
|
|
|
|
* the string table) are 16-bit numbers.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* First there is the size of the Table of Contents (TOC). The TOC
|
|
|
|
* entries contain the size of each section. In order to find the offset
|
|
|
|
* you just need to sum up the previous offsets.
|
2003-08-12 00:26:07 +00:00
|
|
|
* The TOC length and entries are an array of uint32_t values.
|
|
|
|
* The first section after the TOC starts immediately after the TOC.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* 1) This section contains a list of converters. This list contains indexes
|
|
|
|
* into the string table for the converter name. The index of this list is
|
|
|
|
* also used by other sections, which are mentioned later on.
|
2003-08-12 00:26:07 +00:00
|
|
|
* This list is not sorted.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* 2) This section contains a list of tags. This list contains indexes
|
|
|
|
* into the string table for the tag name. The index of this list is
|
|
|
|
* also used by other sections, which are mentioned later on.
|
2003-08-12 00:26:07 +00:00
|
|
|
* This list is in priority order of standards.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2002-08-02 21:59:23 +00:00
|
|
|
* 3) This section contains a list of sorted unique aliases. This
|
2002-06-28 23:13:30 +00:00
|
|
|
* list contains indexes into the string table for the alias name. The
|
2002-08-02 21:59:23 +00:00
|
|
|
* index of this list is also used by other sections, like the 4th section.
|
2002-08-08 22:46:05 +00:00
|
|
|
* The index for the 3rd and 4th section is used to get the
|
|
|
|
* alias -> converter name mapping. Section 3 and 4 form a two column table.
|
2006-06-12 10:05:08 +00:00
|
|
|
* Some of the most significant bits of each index may contain other
|
|
|
|
* information (see findConverter for details).
|
2002-06-28 23:13:30 +00:00
|
|
|
*
|
|
|
|
* 4) This section contains a list of mapped converter names. Consider this
|
|
|
|
* as a table that maps the 3rd section to the 1st section. This list contains
|
|
|
|
* indexes into the 1st section. The index of this list is the same index in
|
|
|
|
* the 3rd section. There is also some extra information in the high bits of
|
|
|
|
* each converter index in this table. Currently it's only used to say that
|
|
|
|
* an alias mapped to this converter is ambiguous. See UCNV_CONVERTER_INDEX_MASK
|
|
|
|
* and UCNV_AMBIGUOUS_ALIAS_MAP_BIT for more information. This section is
|
|
|
|
* the predigested form of the 5th section so that an alias lookup can be fast.
|
2004-11-11 23:34:58 +00:00
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* 5) This section contains a 2D array with indexes to the 6th section. This
|
|
|
|
* section is the full form of all alias mappings. The column index is the
|
|
|
|
* index into the converter list (column header). The row index is the index
|
|
|
|
* to tag list (row header). This 2D array is the top part a 3D array. The
|
|
|
|
* third dimension is in the 6th section.
|
|
|
|
*
|
|
|
|
* 6) This is blob of variable length arrays. Each array starts with a size,
|
|
|
|
* and is followed by indexes to alias names in the string table. This is
|
|
|
|
* the third dimension to the section 5. No other section should be referencing
|
|
|
|
* this section.
|
|
|
|
*
|
2006-06-11 16:57:02 +00:00
|
|
|
* 7) Starting in ICU 3.6, this can be a UConverterAliasOptions struct. Its
|
|
|
|
* presence indicates that a section 9 exists. UConverterAliasOptions specifies
|
|
|
|
* what type of string normalization is used among other potential things in the
|
|
|
|
* future.
|
2002-06-28 23:13:30 +00:00
|
|
|
*
|
|
|
|
* 8) This is the string table. All strings are indexed on an even address.
|
|
|
|
* There are two reasons for this. First many chip architectures locate strings
|
|
|
|
* faster on even address boundaries. Second, since all indexes are 16-bit
|
|
|
|
* numbers, this string table can be 128KB in size instead of 64KB when we
|
|
|
|
* only have strings starting on an even address.
|
|
|
|
*
|
2006-06-11 16:57:02 +00:00
|
|
|
* 9) When present this is a set of prenormalized strings from section 8. This
|
|
|
|
* table contains normalized strings with the dashes and spaces stripped out,
|
|
|
|
* and all strings lowercased. In the future, the options in section 7 may state
|
|
|
|
* other types of normalization.
|
2002-06-28 23:13:30 +00:00
|
|
|
*
|
|
|
|
* Here is the concept of section 5 and 6. It's a 3D cube. Each tag
|
|
|
|
* has a unique alias among all converters. That same alias can
|
|
|
|
* be mentioned in other standards on different converters,
|
|
|
|
* but only one alias per tag can be unique.
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* Converter Names (Usually in TR22 form)
|
|
|
|
* -------------------------------------------.
|
|
|
|
* T / /|
|
|
|
|
* a / / |
|
|
|
|
* g / / |
|
|
|
|
* s / / |
|
|
|
|
* / / |
|
|
|
|
* ------------------------------------------/ |
|
|
|
|
* A | | |
|
|
|
|
* l | | |
|
|
|
|
* i | | /
|
|
|
|
* a | | /
|
|
|
|
* s | | /
|
|
|
|
* e | | /
|
|
|
|
* s | |/
|
|
|
|
* -------------------------------------------
|
1999-11-23 23:02:55 +00:00
|
|
|
*
|
2000-08-10 01:32:29 +00:00
|
|
|
*
|
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* Here is what it really looks like. It's like swiss cheese.
|
|
|
|
* There are holes. Some converters aren't recognized by
|
|
|
|
* a standard, or they are really old converters that the
|
|
|
|
* standard doesn't recognize anymore.
|
2000-08-10 01:32:29 +00:00
|
|
|
*
|
2002-06-28 23:13:30 +00:00
|
|
|
* Converter Names (Usually in TR22 form)
|
|
|
|
* -------------------------------------------.
|
|
|
|
* T /##########################################/|
|
|
|
|
* a / # # /#
|
2004-11-11 23:34:58 +00:00
|
|
|
* g / # ## ## ### # ### ### ### #/
|
|
|
|
* s / # ##### #### ## ## #/#
|
|
|
|
* / ### # # ## # # # ### # # #/##
|
2002-06-28 23:13:30 +00:00
|
|
|
* ------------------------------------------/# #
|
|
|
|
* A |### # # ## # # # ### # # #|# #
|
|
|
|
* l |# # # # # ## # #|# #
|
|
|
|
* i |# # # # # # #|#
|
|
|
|
* a |# #|#
|
|
|
|
* s | #|#
|
2004-11-11 23:34:58 +00:00
|
|
|
* e
|
|
|
|
* s
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2002-08-02 21:59:23 +00:00
|
|
|
/**
|
|
|
|
* Used by the UEnumeration API
|
|
|
|
*/
|
2002-07-13 16:32:16 +00:00
|
|
|
typedef struct UAliasContext {
|
2002-08-08 22:46:05 +00:00
|
|
|
uint32_t listOffset;
|
2002-07-13 16:32:16 +00:00
|
|
|
uint32_t listIdx;
|
|
|
|
} UAliasContext;
|
|
|
|
|
2002-01-21 21:48:25 +00:00
|
|
|
static const char DATA_NAME[] = "cnvalias";
|
2002-06-28 23:13:30 +00:00
|
|
|
static const char DATA_TYPE[] = "icu";
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2002-08-08 22:46:05 +00:00
|
|
|
static UDataMemory *gAliasData=NULL;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2003-08-12 00:26:07 +00:00
|
|
|
enum {
|
|
|
|
tocLengthIndex=0,
|
|
|
|
converterListIndex=1,
|
|
|
|
tagListIndex=2,
|
|
|
|
aliasListIndex=3,
|
|
|
|
untaggedConvArrayIndex=4,
|
|
|
|
taggedAliasArrayIndex=5,
|
|
|
|
taggedAliasListsIndex=6,
|
2006-07-28 18:09:36 +00:00
|
|
|
tableOptionsIndex=7,
|
2003-08-12 00:26:07 +00:00
|
|
|
stringTableIndex=8,
|
2006-06-11 16:57:02 +00:00
|
|
|
normalizedStringTableIndex=9,
|
|
|
|
offsetsCount, /* length of the swapper's temporary offsets[] */
|
|
|
|
minTocLength=8 /* min. tocLength in the file, does not count the tocLengthIndex! */
|
2003-08-12 00:26:07 +00:00
|
|
|
};
|
|
|
|
|
2006-06-11 16:57:02 +00:00
|
|
|
static const UConverterAliasOptions defaultTableOptions = {
|
2006-06-12 10:05:08 +00:00
|
|
|
UCNV_IO_UNNORMALIZED,
|
|
|
|
0 /* containsCnvOptionInfo */
|
2006-06-11 16:57:02 +00:00
|
|
|
};
|
2005-08-30 20:37:50 +00:00
|
|
|
static UConverterAlias gMainTable;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
#define GET_STRING(idx) (const char *)(gMainTable.stringTable + (idx))
|
2006-06-11 16:57:02 +00:00
|
|
|
#define GET_NORMALIZED_STRING(idx) (const char *)(gMainTable.normalizedStringTable + (idx))
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2002-07-23 23:01:08 +00:00
|
|
|
static UBool U_CALLCONV
|
2011-05-26 20:05:39 +00:00
|
|
|
isAcceptable(void * /*context*/,
|
|
|
|
const char * /*type*/, const char * /*name*/,
|
2000-05-03 23:15:02 +00:00
|
|
|
const UDataInfo *pInfo) {
|
2000-08-10 02:08:49 +00:00
|
|
|
return (UBool)(
|
1999-11-23 23:02:55 +00:00
|
|
|
pInfo->size>=20 &&
|
|
|
|
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pInfo->charsetFamily==U_CHARSET_FAMILY &&
|
|
|
|
pInfo->dataFormat[0]==0x43 && /* dataFormat="CvAl" */
|
|
|
|
pInfo->dataFormat[1]==0x76 &&
|
|
|
|
pInfo->dataFormat[2]==0x41 &&
|
|
|
|
pInfo->dataFormat[3]==0x6c &&
|
2002-06-28 23:13:30 +00:00
|
|
|
pInfo->formatVersion[0]==3);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
static UBool U_CALLCONV ucnv_io_cleanup(void)
|
|
|
|
{
|
|
|
|
if (gAliasData) {
|
|
|
|
udata_close(gAliasData);
|
|
|
|
gAliasData = NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
uprv_memset(&gMainTable, 0, sizeof(gMainTable));
|
2004-10-06 23:10:53 +00:00
|
|
|
|
|
|
|
return TRUE; /* Everything was cleaned up */
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
1999-11-23 23:02:55 +00:00
|
|
|
haveAliasData(UErrorCode *pErrorCode) {
|
2005-05-08 07:56:44 +00:00
|
|
|
int needInit;
|
2003-05-07 00:53:32 +00:00
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
UMTX_CHECK(NULL, (gAliasData==NULL), needInit);
|
2003-05-07 00:53:32 +00:00
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
/* load converter alias data from file if necessary */
|
2005-05-08 07:56:44 +00:00
|
|
|
if (needInit) {
|
2007-07-24 23:27:14 +00:00
|
|
|
UDataMemory *data;
|
|
|
|
const uint16_t *table;
|
|
|
|
const uint32_t *sectionSizes;
|
2002-06-28 23:13:30 +00:00
|
|
|
uint32_t tableStart;
|
|
|
|
uint32_t currOffset;
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
data = udata_openChoice(NULL, DATA_TYPE, DATA_NAME, isAcceptable, NULL, pErrorCode);
|
1999-11-23 23:02:55 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-24 23:27:14 +00:00
|
|
|
sectionSizes = (const uint32_t *)udata_getMemory(data);
|
|
|
|
table = (const uint16_t *)sectionSizes;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2007-07-24 23:27:14 +00:00
|
|
|
tableStart = sectionSizes[0];
|
2003-08-12 00:26:07 +00:00
|
|
|
if (tableStart < minTocLength) {
|
2002-06-28 23:13:30 +00:00
|
|
|
*pErrorCode = U_INVALID_FORMAT_ERROR;
|
2002-08-02 21:59:23 +00:00
|
|
|
udata_close(data);
|
2002-06-28 23:13:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
|
|
|
|
umtx_lock(NULL);
|
2002-08-08 22:46:05 +00:00
|
|
|
if(gAliasData==NULL) {
|
2007-07-24 23:27:14 +00:00
|
|
|
gMainTable.converterListSize = sectionSizes[1];
|
|
|
|
gMainTable.tagListSize = sectionSizes[2];
|
|
|
|
gMainTable.aliasListSize = sectionSizes[3];
|
|
|
|
gMainTable.untaggedConvArraySize = sectionSizes[4];
|
|
|
|
gMainTable.taggedAliasArraySize = sectionSizes[5];
|
|
|
|
gMainTable.taggedAliasListsSize = sectionSizes[6];
|
|
|
|
gMainTable.optionTableSize = sectionSizes[7];
|
|
|
|
gMainTable.stringTableSize = sectionSizes[8];
|
|
|
|
|
|
|
|
if (tableStart > 8) {
|
|
|
|
gMainTable.normalizedStringTableSize = sectionSizes[9];
|
2006-06-11 16:57:02 +00:00
|
|
|
}
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
currOffset = tableStart * (sizeof(uint32_t)/sizeof(uint16_t)) + (sizeof(uint32_t)/sizeof(uint16_t));
|
2005-08-30 20:37:50 +00:00
|
|
|
gMainTable.converterList = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.converterListSize;
|
|
|
|
gMainTable.tagList = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.tagListSize;
|
|
|
|
gMainTable.aliasList = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.aliasListSize;
|
|
|
|
gMainTable.untaggedConvArray = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.untaggedConvArraySize;
|
|
|
|
gMainTable.taggedAliasArray = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
/* aliasLists is a 1's based array, but it has a padding character */
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.taggedAliasArraySize;
|
|
|
|
gMainTable.taggedAliasLists = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
currOffset += gMainTable.taggedAliasListsSize;
|
2006-06-11 16:57:02 +00:00
|
|
|
if (gMainTable.optionTableSize > 0
|
|
|
|
&& ((const UConverterAliasOptions *)(table + currOffset))->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
|
|
|
|
{
|
|
|
|
/* Faster table */
|
|
|
|
gMainTable.optionTable = (const UConverterAliasOptions *)(table + currOffset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Smaller table, or I can't handle this normalization mode!
|
|
|
|
Use the original slower table lookup. */
|
|
|
|
gMainTable.optionTable = &defaultTableOptions;
|
|
|
|
}
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2006-06-11 16:57:02 +00:00
|
|
|
currOffset += gMainTable.optionTableSize;
|
2005-08-30 20:37:50 +00:00
|
|
|
gMainTable.stringTable = table + currOffset;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2006-06-11 16:57:02 +00:00
|
|
|
currOffset += gMainTable.stringTableSize;
|
|
|
|
gMainTable.normalizedStringTable = ((gMainTable.optionTable->stringNormalizationType == UCNV_IO_UNNORMALIZED)
|
|
|
|
? gMainTable.stringTable : (table + currOffset));
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UCNV_IO, ucnv_io_cleanup);
|
2008-08-03 05:09:13 +00:00
|
|
|
|
|
|
|
gAliasData = data;
|
|
|
|
data=NULL;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
/* if a different thread set it first, then close the extra data */
|
|
|
|
if(data!=NULL) {
|
|
|
|
udata_close(data); /* NULL if it was set correctly */
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
return TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline UBool
|
1999-11-23 23:02:55 +00:00
|
|
|
isAlias(const char *alias, UErrorCode *pErrorCode) {
|
|
|
|
if(alias==NULL) {
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-08-30 20:37:50 +00:00
|
|
|
return (UBool)(*alias!=0);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
static uint32_t getTagNumber(const char *tagname) {
|
2005-08-30 20:37:50 +00:00
|
|
|
if (gMainTable.tagList) {
|
2002-06-28 23:13:30 +00:00
|
|
|
uint32_t tagNum;
|
2005-08-30 20:37:50 +00:00
|
|
|
for (tagNum = 0; tagNum < gMainTable.tagListSize; tagNum++) {
|
|
|
|
if (!uprv_stricmp(GET_STRING(gMainTable.tagList[tagNum]), tagname)) {
|
2002-06-28 23:13:30 +00:00
|
|
|
return tagNum;
|
2000-08-10 02:08:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-10 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
return UINT32_MAX;
|
2000-08-10 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 23:16:45 +00:00
|
|
|
/* character types relevant for ucnv_compareNames() */
|
|
|
|
enum {
|
|
|
|
IGNORE,
|
|
|
|
ZERO,
|
|
|
|
NONZERO,
|
|
|
|
MINLETTER /* any values from here on are lowercase letter mappings */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* character types for ASCII 00..7F */
|
|
|
|
static const uint8_t asciiTypes[128] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
ZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
|
|
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0, 0, 0, 0, 0,
|
|
|
|
0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
|
|
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0, 0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
2006-07-25 02:32:24 +00:00
|
|
|
#define GET_ASCII_TYPE(c) ((int8_t)(c) >= 0 ? asciiTypes[(uint8_t)c] : (uint8_t)IGNORE)
|
2006-06-28 23:16:45 +00:00
|
|
|
|
|
|
|
/* character types for EBCDIC 80..FF */
|
|
|
|
static const uint8_t ebcdicTypes[128] = {
|
|
|
|
0, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0, 0, 0, 0, 0, 0,
|
|
|
|
ZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, 0, 0, 0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_EBCDIC_TYPE(c) ((int8_t)(c) < 0 ? ebcdicTypes[(c)&0x7f] : (uint8_t)IGNORE)
|
|
|
|
|
|
|
|
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
|
|
|
|
# define GET_CHAR_TYPE(c) GET_ASCII_TYPE(c)
|
|
|
|
#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
|
|
|
|
# define GET_CHAR_TYPE(c) GET_EBCDIC_TYPE(c)
|
|
|
|
#else
|
|
|
|
# error U_CHARSET_FAMILY is not valid
|
|
|
|
#endif
|
|
|
|
|
2002-09-06 00:48:35 +00:00
|
|
|
/* @see ucnv_compareNames */
|
|
|
|
U_CFUNC char * U_EXPORT2
|
2003-08-08 23:39:34 +00:00
|
|
|
ucnv_io_stripASCIIForCompare(char *dst, const char *name) {
|
2002-09-06 00:48:35 +00:00
|
|
|
char *dstItr = dst;
|
2006-06-28 23:16:45 +00:00
|
|
|
uint8_t type, nextType;
|
|
|
|
char c1;
|
|
|
|
UBool afterDigit = FALSE;
|
|
|
|
|
|
|
|
while ((c1 = *name++) != 0) {
|
|
|
|
type = GET_ASCII_TYPE(c1);
|
|
|
|
switch (type) {
|
|
|
|
case IGNORE:
|
|
|
|
afterDigit = FALSE;
|
|
|
|
continue; /* ignore all but letters and digits */
|
|
|
|
case ZERO:
|
|
|
|
if (!afterDigit) {
|
|
|
|
nextType = GET_ASCII_TYPE(*name);
|
|
|
|
if (nextType == ZERO || nextType == NONZERO) {
|
|
|
|
continue; /* ignore leading zero before another digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NONZERO:
|
|
|
|
afterDigit = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c1 = (char)type; /* lowercased letter */
|
|
|
|
afterDigit = FALSE;
|
|
|
|
break;
|
2002-09-06 00:48:35 +00:00
|
|
|
}
|
2006-06-28 23:16:45 +00:00
|
|
|
*dstItr++ = c1;
|
2003-08-08 23:39:34 +00:00
|
|
|
}
|
2006-06-28 23:16:45 +00:00
|
|
|
*dstItr = 0;
|
2003-08-08 23:39:34 +00:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC char * U_EXPORT2
|
|
|
|
ucnv_io_stripEBCDICForCompare(char *dst, const char *name) {
|
|
|
|
char *dstItr = dst;
|
2006-06-28 23:16:45 +00:00
|
|
|
uint8_t type, nextType;
|
|
|
|
char c1;
|
|
|
|
UBool afterDigit = FALSE;
|
|
|
|
|
|
|
|
while ((c1 = *name++) != 0) {
|
|
|
|
type = GET_EBCDIC_TYPE(c1);
|
|
|
|
switch (type) {
|
|
|
|
case IGNORE:
|
|
|
|
afterDigit = FALSE;
|
|
|
|
continue; /* ignore all but letters and digits */
|
|
|
|
case ZERO:
|
|
|
|
if (!afterDigit) {
|
|
|
|
nextType = GET_EBCDIC_TYPE(*name);
|
|
|
|
if (nextType == ZERO || nextType == NONZERO) {
|
|
|
|
continue; /* ignore leading zero before another digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NONZERO:
|
|
|
|
afterDigit = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c1 = (char)type; /* lowercased letter */
|
|
|
|
afterDigit = FALSE;
|
|
|
|
break;
|
2003-08-08 23:39:34 +00:00
|
|
|
}
|
2006-06-28 23:16:45 +00:00
|
|
|
*dstItr++ = c1;
|
2002-09-06 00:48:35 +00:00
|
|
|
}
|
2006-06-28 23:16:45 +00:00
|
|
|
*dstItr = 0;
|
2002-09-06 00:48:35 +00:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2000-07-19 22:18:43 +00:00
|
|
|
/**
|
2006-06-28 23:16:45 +00:00
|
|
|
* Do a fuzzy compare of two converter/alias names.
|
|
|
|
* The comparison is case-insensitive, ignores leading zeroes if they are not
|
|
|
|
* followed by further digits, and ignores all but letters and digits.
|
|
|
|
* Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
|
|
|
|
* See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
|
|
|
|
* at http://www.unicode.org/reports/tr22/
|
2004-11-11 23:34:58 +00:00
|
|
|
*
|
2000-07-19 22:18:43 +00:00
|
|
|
* This is a symmetrical (commutative) operation; order of arguments
|
|
|
|
* is insignificant. This is an important property for sorting the
|
|
|
|
* list (when the list is preprocessed into binary form) and for
|
|
|
|
* performing binary searches on it at run time.
|
2004-11-11 23:34:58 +00:00
|
|
|
*
|
2000-07-19 22:18:43 +00:00
|
|
|
* @param name1 a converter name or alias, zero-terminated
|
|
|
|
* @param name2 a converter name or alias, zero-terminated
|
|
|
|
* @return 0 if the names match, or a negative value if the name1
|
|
|
|
* lexically precedes name2, or a positive value if the name1
|
|
|
|
* lexically follows name2.
|
2002-09-06 00:48:35 +00:00
|
|
|
*
|
|
|
|
* @see ucnv_io_stripForCompare
|
2000-07-19 22:18:43 +00:00
|
|
|
*/
|
2000-11-17 05:02:31 +00:00
|
|
|
U_CAPI int U_EXPORT2
|
2000-11-17 06:07:31 +00:00
|
|
|
ucnv_compareNames(const char *name1, const char *name2) {
|
1999-11-23 23:02:55 +00:00
|
|
|
int rc;
|
2006-06-28 23:16:45 +00:00
|
|
|
uint8_t type, nextType;
|
2002-06-28 23:13:30 +00:00
|
|
|
char c1, c2;
|
2006-06-28 23:16:45 +00:00
|
|
|
UBool afterDigit1 = FALSE, afterDigit2 = FALSE;
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2000-06-30 21:35:03 +00:00
|
|
|
for (;;) {
|
2006-06-28 23:16:45 +00:00
|
|
|
while ((c1 = *name1++) != 0) {
|
|
|
|
type = GET_CHAR_TYPE(c1);
|
|
|
|
switch (type) {
|
|
|
|
case IGNORE:
|
|
|
|
afterDigit1 = FALSE;
|
|
|
|
continue; /* ignore all but letters and digits */
|
|
|
|
case ZERO:
|
|
|
|
if (!afterDigit1) {
|
|
|
|
nextType = GET_CHAR_TYPE(*name1);
|
|
|
|
if (nextType == ZERO || nextType == NONZERO) {
|
|
|
|
continue; /* ignore leading zero before another digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NONZERO:
|
|
|
|
afterDigit1 = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c1 = (char)type; /* lowercased letter */
|
|
|
|
afterDigit1 = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break; /* deliver c1 */
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
2006-06-28 23:16:45 +00:00
|
|
|
while ((c2 = *name2++) != 0) {
|
|
|
|
type = GET_CHAR_TYPE(c2);
|
|
|
|
switch (type) {
|
|
|
|
case IGNORE:
|
|
|
|
afterDigit2 = FALSE;
|
|
|
|
continue; /* ignore all but letters and digits */
|
|
|
|
case ZERO:
|
|
|
|
if (!afterDigit2) {
|
|
|
|
nextType = GET_CHAR_TYPE(*name2);
|
|
|
|
if (nextType == ZERO || nextType == NONZERO) {
|
|
|
|
continue; /* ignore leading zero before another digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NONZERO:
|
|
|
|
afterDigit2 = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c2 = (char)type; /* lowercased letter */
|
|
|
|
afterDigit2 = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break; /* deliver c2 */
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
2000-07-19 22:18:43 +00:00
|
|
|
|
|
|
|
/* If we reach the ends of both strings then they match */
|
|
|
|
if ((c1|c2)==0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2000-07-19 22:18:43 +00:00
|
|
|
/* Case-insensitive comparison */
|
2006-06-28 23:16:45 +00:00
|
|
|
rc = (int)(unsigned char)c1 - (int)(unsigned char)c2;
|
2002-06-28 23:13:30 +00:00
|
|
|
if (rc != 0) {
|
2000-07-19 22:18:43 +00:00
|
|
|
return rc;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
/*
|
|
|
|
* search for an alias
|
2002-08-08 22:46:05 +00:00
|
|
|
* return the converter number index for gConverterList
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline uint32_t
|
2006-06-12 10:05:08 +00:00
|
|
|
findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) {
|
2002-06-28 23:13:30 +00:00
|
|
|
uint32_t mid, start, limit;
|
2004-11-11 23:34:58 +00:00
|
|
|
uint32_t lastMid;
|
2002-06-28 23:13:30 +00:00
|
|
|
int result;
|
2006-06-12 07:00:57 +00:00
|
|
|
int isUnnormalized = (gMainTable.optionTable->stringNormalizationType == UCNV_IO_UNNORMALIZED);
|
2006-06-11 16:57:02 +00:00
|
|
|
char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
|
|
|
|
2006-06-12 07:00:57 +00:00
|
|
|
if (!isUnnormalized) {
|
|
|
|
if (uprv_strlen(alias) >= UCNV_MAX_CONVERTER_NAME_LENGTH) {
|
|
|
|
*pErrorCode = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2006-06-11 16:57:02 +00:00
|
|
|
|
2006-06-12 07:00:57 +00:00
|
|
|
/* Lower case and remove ignoreable characters. */
|
|
|
|
ucnv_io_stripForCompare(strippedName, alias);
|
|
|
|
alias = strippedName;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
|
|
|
|
/* do a binary search for the alias */
|
2002-06-28 23:13:30 +00:00
|
|
|
start = 0;
|
2005-08-30 20:37:50 +00:00
|
|
|
limit = gMainTable.untaggedConvArraySize;
|
2002-06-28 23:13:30 +00:00
|
|
|
mid = limit;
|
2004-11-11 23:34:58 +00:00
|
|
|
lastMid = UINT32_MAX;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
2002-09-04 00:36:40 +00:00
|
|
|
for (;;) {
|
|
|
|
mid = (uint32_t)((start + limit) / 2);
|
2004-11-11 23:34:58 +00:00
|
|
|
if (lastMid == mid) { /* Have we moved? */
|
|
|
|
break; /* We haven't moved, and it wasn't found. */
|
|
|
|
}
|
|
|
|
lastMid = mid;
|
2006-06-12 07:00:57 +00:00
|
|
|
if (isUnnormalized) {
|
|
|
|
result = ucnv_compareNames(alias, GET_STRING(gMainTable.aliasList[mid]));
|
2006-06-11 16:57:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-06-12 07:00:57 +00:00
|
|
|
result = uprv_strcmp(alias, GET_NORMALIZED_STRING(gMainTable.aliasList[mid]));
|
2006-06-11 16:57:02 +00:00
|
|
|
}
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
if (result < 0) {
|
2002-09-04 00:36:40 +00:00
|
|
|
limit = mid;
|
2002-06-28 23:13:30 +00:00
|
|
|
} else if (result > 0) {
|
2002-09-04 00:36:40 +00:00
|
|
|
start = mid;
|
1999-11-23 23:02:55 +00:00
|
|
|
} else {
|
2002-06-28 23:13:30 +00:00
|
|
|
/* Since the gencnval tool folds duplicates into one entry,
|
2002-08-08 22:46:05 +00:00
|
|
|
* this alias in gAliasList is unique, but different standards
|
2002-06-28 23:13:30 +00:00
|
|
|
* may map an alias to different converters.
|
|
|
|
*/
|
2005-08-30 20:37:50 +00:00
|
|
|
if (gMainTable.untaggedConvArray[mid] & UCNV_AMBIGUOUS_ALIAS_MAP_BIT) {
|
2002-06-28 23:13:30 +00:00
|
|
|
*pErrorCode = U_AMBIGUOUS_ALIAS_WARNING;
|
|
|
|
}
|
2006-06-12 10:05:08 +00:00
|
|
|
/* State whether the canonical converter name contains an option.
|
|
|
|
This information is contained in this list in order to maintain backward & forward compatibility. */
|
|
|
|
if (containsOption) {
|
|
|
|
UBool containsCnvOptionInfo = (UBool)gMainTable.optionTable->containsCnvOptionInfo;
|
|
|
|
*containsOption = (UBool)((containsCnvOptionInfo
|
|
|
|
&& ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0))
|
|
|
|
|| !containsCnvOptionInfo);
|
|
|
|
}
|
2005-08-30 20:37:50 +00:00
|
|
|
return gMainTable.untaggedConvArray[mid] & UCNV_CONVERTER_INDEX_MASK;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
return UINT32_MAX;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-30 22:52:08 +00:00
|
|
|
/*
|
|
|
|
* Is this alias in this list?
|
|
|
|
* alias and listOffset should be non-NULL.
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline UBool
|
2002-10-30 22:52:08 +00:00
|
|
|
isAliasInList(const char *alias, uint32_t listOffset) {
|
|
|
|
if (listOffset) {
|
|
|
|
uint32_t currAlias;
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
|
2002-10-30 22:52:08 +00:00
|
|
|
/* +1 to skip listCount */
|
2005-08-30 20:37:50 +00:00
|
|
|
const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
|
2002-10-30 22:52:08 +00:00
|
|
|
for (currAlias = 0; currAlias < listCount; currAlias++) {
|
|
|
|
if (currList[currAlias]
|
|
|
|
&& ucnv_compareNames(alias, GET_STRING(currList[currAlias]))==0)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-08 22:46:05 +00:00
|
|
|
/*
|
|
|
|
* Search for an standard name of an alias (what is the default name
|
|
|
|
* that this standard uses?)
|
|
|
|
* return the listOffset for gTaggedAliasLists. If it's 0,
|
|
|
|
* the it couldn't be found, but the parameters are valid.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
findTaggedAliasListsOffset(const char *alias, const char *standard, UErrorCode *pErrorCode) {
|
|
|
|
uint32_t idx;
|
|
|
|
uint32_t listOffset;
|
|
|
|
uint32_t convNum;
|
|
|
|
UErrorCode myErr = U_ZERO_ERROR;
|
|
|
|
uint32_t tagNum = getTagNumber(standard);
|
|
|
|
|
|
|
|
/* Make a quick guess. Hopefully they used a TR22 canonical alias. */
|
2006-06-12 10:05:08 +00:00
|
|
|
convNum = findConverter(alias, NULL, &myErr);
|
2002-08-08 22:46:05 +00:00
|
|
|
if (myErr != U_ZERO_ERROR) {
|
|
|
|
*pErrorCode = myErr;
|
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
|
|
|
|
listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum];
|
|
|
|
if (listOffset && gMainTable.taggedAliasLists[listOffset + 1]) {
|
2002-08-08 22:46:05 +00:00
|
|
|
return listOffset;
|
|
|
|
}
|
|
|
|
if (myErr == U_AMBIGUOUS_ALIAS_WARNING) {
|
|
|
|
/* Uh Oh! They used an ambiguous alias.
|
|
|
|
We have to search the whole swiss cheese starting
|
|
|
|
at the highest standard affinity.
|
|
|
|
This may take a while.
|
|
|
|
*/
|
2005-08-30 20:37:50 +00:00
|
|
|
for (idx = 0; idx < gMainTable.taggedAliasArraySize; idx++) {
|
|
|
|
listOffset = gMainTable.taggedAliasArray[idx];
|
2002-10-30 22:52:08 +00:00
|
|
|
if (listOffset && isAliasInList(alias, listOffset)) {
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t currTagNum = idx/gMainTable.converterListSize;
|
|
|
|
uint32_t currConvNum = (idx - currTagNum*gMainTable.converterListSize);
|
|
|
|
uint32_t tempListOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + currConvNum];
|
|
|
|
if (tempListOffset && gMainTable.taggedAliasLists[tempListOffset + 1]) {
|
2002-10-30 22:52:08 +00:00
|
|
|
return tempListOffset;
|
2002-08-08 22:46:05 +00:00
|
|
|
}
|
2002-10-30 22:52:08 +00:00
|
|
|
/* else keep on looking */
|
|
|
|
/* We could speed this up by starting on the next row
|
|
|
|
because an alias is unique per row, right now.
|
|
|
|
This would change if alias versioning appears. */
|
2002-08-08 22:46:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* The standard doesn't know about the alias */
|
|
|
|
}
|
|
|
|
/* else no default name */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* else converter or tag not found */
|
|
|
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2002-10-30 22:52:08 +00:00
|
|
|
/* Return the canonical name */
|
|
|
|
static uint32_t
|
|
|
|
findTaggedConverterNum(const char *alias, const char *standard, UErrorCode *pErrorCode) {
|
|
|
|
uint32_t idx;
|
|
|
|
uint32_t listOffset;
|
|
|
|
uint32_t convNum;
|
|
|
|
UErrorCode myErr = U_ZERO_ERROR;
|
|
|
|
uint32_t tagNum = getTagNumber(standard);
|
|
|
|
|
|
|
|
/* Make a quick guess. Hopefully they used a TR22 canonical alias. */
|
2006-06-12 10:05:08 +00:00
|
|
|
convNum = findConverter(alias, NULL, &myErr);
|
2002-10-30 22:52:08 +00:00
|
|
|
if (myErr != U_ZERO_ERROR) {
|
|
|
|
*pErrorCode = myErr;
|
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
|
|
|
|
listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum];
|
2002-10-30 22:52:08 +00:00
|
|
|
if (listOffset && isAliasInList(alias, listOffset)) {
|
|
|
|
return convNum;
|
|
|
|
}
|
|
|
|
if (myErr == U_AMBIGUOUS_ALIAS_WARNING) {
|
|
|
|
/* Uh Oh! They used an ambiguous alias.
|
|
|
|
We have to search one slice of the swiss cheese.
|
|
|
|
We search only in the requested tag, not the whole thing.
|
|
|
|
This may take a while.
|
|
|
|
*/
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t convStart = (tagNum)*gMainTable.converterListSize;
|
|
|
|
uint32_t convLimit = (tagNum+1)*gMainTable.converterListSize;
|
2002-10-30 22:52:08 +00:00
|
|
|
for (idx = convStart; idx < convLimit; idx++) {
|
2005-08-30 20:37:50 +00:00
|
|
|
listOffset = gMainTable.taggedAliasArray[idx];
|
2002-10-30 22:52:08 +00:00
|
|
|
if (listOffset && isAliasInList(alias, listOffset)) {
|
2002-11-21 19:24:53 +00:00
|
|
|
return idx-convStart;
|
2002-10-30 22:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* The standard doesn't know about the alias */
|
|
|
|
}
|
|
|
|
/* else no canonical name */
|
|
|
|
}
|
|
|
|
/* else converter or tag not found */
|
|
|
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
U_CFUNC const char *
|
2006-06-12 10:05:08 +00:00
|
|
|
ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) {
|
2011-09-13 21:13:14 +00:00
|
|
|
const char *aliasTmp = alias;
|
|
|
|
int32_t i = 0;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (i == 1) {
|
|
|
|
/*
|
|
|
|
* After the first unsuccess converter lookup, check to see if
|
|
|
|
* the name begins with 'x-'. If it does, strip it off and try
|
|
|
|
* again. This behaviour is similar to how ICU4J does it.
|
|
|
|
*/
|
|
|
|
if (aliasTmp[0] == 'x' || aliasTmp[1] == '-') {
|
|
|
|
aliasTmp = aliasTmp+2;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(haveAliasData(pErrorCode) && isAlias(aliasTmp, pErrorCode)) {
|
|
|
|
uint32_t convNum = findConverter(aliasTmp, containsOption, pErrorCode);
|
|
|
|
if (convNum < gMainTable.converterListSize) {
|
|
|
|
return GET_STRING(gMainTable.converterList[convNum]);
|
|
|
|
}
|
|
|
|
/* else converter not found */
|
|
|
|
} else {
|
|
|
|
break;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
}
|
2011-09-13 21:13:14 +00:00
|
|
|
|
2002-07-13 16:32:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t U_CALLCONV
|
2011-05-26 20:05:39 +00:00
|
|
|
ucnv_io_countStandardAliases(UEnumeration *enumerator, UErrorCode * /*pErrorCode*/) {
|
2002-07-22 21:06:41 +00:00
|
|
|
int32_t value = 0;
|
|
|
|
UAliasContext *myContext = (UAliasContext *)(enumerator->context);
|
2002-08-08 22:46:05 +00:00
|
|
|
uint32_t listOffset = myContext->listOffset;
|
2002-07-13 16:32:16 +00:00
|
|
|
|
2002-07-22 21:06:41 +00:00
|
|
|
if (listOffset) {
|
2005-08-30 20:37:50 +00:00
|
|
|
value = gMainTable.taggedAliasLists[listOffset];
|
2002-07-13 16:32:16 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* U_CALLCONV
|
|
|
|
ucnv_io_nextStandardAliases(UEnumeration *enumerator,
|
|
|
|
int32_t* resultLength,
|
2011-05-26 20:05:39 +00:00
|
|
|
UErrorCode * /*pErrorCode*/)
|
2002-07-13 16:32:16 +00:00
|
|
|
{
|
2002-07-22 21:06:41 +00:00
|
|
|
UAliasContext *myContext = (UAliasContext *)(enumerator->context);
|
2002-08-08 22:46:05 +00:00
|
|
|
uint32_t listOffset = myContext->listOffset;
|
2002-07-13 16:32:16 +00:00
|
|
|
|
2002-07-22 21:06:41 +00:00
|
|
|
if (listOffset) {
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
|
|
|
|
const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
|
2002-07-13 16:32:16 +00:00
|
|
|
|
2002-07-22 21:06:41 +00:00
|
|
|
if (myContext->listIdx < listCount) {
|
2002-08-02 23:01:10 +00:00
|
|
|
const char *myStr = GET_STRING(currList[myContext->listIdx++]);
|
|
|
|
if (resultLength) {
|
2003-12-12 06:59:38 +00:00
|
|
|
*resultLength = (int32_t)uprv_strlen(myStr);
|
2002-08-02 23:01:10 +00:00
|
|
|
}
|
|
|
|
return myStr;
|
2002-07-13 16:32:16 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-07-22 21:06:41 +00:00
|
|
|
/* Either we accessed a zero length list, or we enumerated too far. */
|
2006-08-06 22:38:31 +00:00
|
|
|
if (resultLength) {
|
|
|
|
*resultLength = 0;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-07-13 16:32:16 +00:00
|
|
|
static void U_CALLCONV
|
2011-05-26 20:05:39 +00:00
|
|
|
ucnv_io_resetStandardAliases(UEnumeration *enumerator, UErrorCode * /*pErrorCode*/) {
|
2002-07-22 21:06:41 +00:00
|
|
|
((UAliasContext *)(enumerator->context))->listIdx = 0;
|
2002-07-13 16:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void U_CALLCONV
|
|
|
|
ucnv_io_closeUEnumeration(UEnumeration *enumerator) {
|
|
|
|
uprv_free(enumerator->context);
|
|
|
|
uprv_free(enumerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enumerate the aliases for the specified converter and standard tag */
|
|
|
|
static const UEnumeration gEnumAliases = {
|
2002-08-02 23:01:10 +00:00
|
|
|
NULL,
|
2002-07-13 16:32:16 +00:00
|
|
|
NULL,
|
|
|
|
ucnv_io_closeUEnumeration,
|
|
|
|
ucnv_io_countStandardAliases,
|
2002-08-02 23:01:10 +00:00
|
|
|
uenum_unextDefault,
|
2002-07-13 16:32:16 +00:00
|
|
|
ucnv_io_nextStandardAliases,
|
|
|
|
ucnv_io_resetStandardAliases
|
|
|
|
};
|
|
|
|
|
2003-01-29 01:17:11 +00:00
|
|
|
U_CAPI UEnumeration * U_EXPORT2
|
2002-07-13 16:32:16 +00:00
|
|
|
ucnv_openStandardNames(const char *convName,
|
2003-01-29 01:17:11 +00:00
|
|
|
const char *standard,
|
|
|
|
UErrorCode *pErrorCode)
|
2002-07-13 16:32:16 +00:00
|
|
|
{
|
|
|
|
UEnumeration *myEnum = NULL;
|
|
|
|
if (haveAliasData(pErrorCode) && isAlias(convName, pErrorCode)) {
|
2002-08-08 22:46:05 +00:00
|
|
|
uint32_t listOffset = findTaggedAliasListsOffset(convName, standard, pErrorCode);
|
|
|
|
|
2002-08-09 01:48:58 +00:00
|
|
|
/* When listOffset == 0, we want to acknowledge that the
|
|
|
|
converter name and standard are okay, but there
|
|
|
|
is nothing to enumerate. */
|
2005-08-30 20:37:50 +00:00
|
|
|
if (listOffset < gMainTable.taggedAliasListsSize) {
|
2002-07-13 16:32:16 +00:00
|
|
|
UAliasContext *myContext;
|
|
|
|
|
2012-08-08 00:50:16 +00:00
|
|
|
myEnum = static_cast<UEnumeration *>(uprv_malloc(sizeof(UEnumeration)));
|
2002-07-13 16:32:16 +00:00
|
|
|
if (myEnum == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memcpy(myEnum, &gEnumAliases, sizeof(UEnumeration));
|
2012-08-08 00:50:16 +00:00
|
|
|
myContext = static_cast<UAliasContext *>(uprv_malloc(sizeof(UAliasContext)));
|
2002-07-13 16:32:16 +00:00
|
|
|
if (myContext == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(myEnum);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 22:46:05 +00:00
|
|
|
myContext->listOffset = listOffset;
|
2002-07-13 16:32:16 +00:00
|
|
|
myContext->listIdx = 0;
|
2002-10-30 22:52:08 +00:00
|
|
|
myEnum->context = myContext;
|
2002-07-13 16:32:16 +00:00
|
|
|
}
|
|
|
|
/* else converter or tag not found */
|
|
|
|
}
|
|
|
|
return myEnum;
|
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
static uint16_t
|
2002-06-28 23:13:30 +00:00
|
|
|
ucnv_io_countAliases(const char *alias, UErrorCode *pErrorCode) {
|
1999-11-23 23:02:55 +00:00
|
|
|
if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
|
2006-06-12 10:05:08 +00:00
|
|
|
uint32_t convNum = findConverter(alias, NULL, pErrorCode);
|
2005-08-30 20:37:50 +00:00
|
|
|
if (convNum < gMainTable.converterListSize) {
|
2002-06-28 23:13:30 +00:00
|
|
|
/* tagListNum - 1 is the ALL tag */
|
2005-08-30 20:37:50 +00:00
|
|
|
int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
if (listOffset) {
|
2005-08-30 20:37:50 +00:00
|
|
|
return gMainTable.taggedAliasLists[listOffset];
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else this shouldn't happen. internal program error */
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else converter not found */
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
static uint16_t
|
2002-06-28 23:13:30 +00:00
|
|
|
ucnv_io_getAliases(const char *alias, uint16_t start, const char **aliases, UErrorCode *pErrorCode) {
|
|
|
|
if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
|
|
|
|
uint32_t currAlias;
|
2006-06-12 10:05:08 +00:00
|
|
|
uint32_t convNum = findConverter(alias, NULL, pErrorCode);
|
2005-08-30 20:37:50 +00:00
|
|
|
if (convNum < gMainTable.converterListSize) {
|
2002-06-28 23:13:30 +00:00
|
|
|
/* tagListNum - 1 is the ALL tag */
|
2005-08-30 20:37:50 +00:00
|
|
|
int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
if (listOffset) {
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
|
2002-06-28 23:13:30 +00:00
|
|
|
/* +1 to skip listCount */
|
2005-08-30 20:37:50 +00:00
|
|
|
const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
for (currAlias = start; currAlias < listCount; currAlias++) {
|
|
|
|
aliases[currAlias] = GET_STRING(currList[currAlias]);
|
|
|
|
}
|
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else this shouldn't happen. internal program error */
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else converter not found */
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
static const char *
|
2000-04-14 05:22:29 +00:00
|
|
|
ucnv_io_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode) {
|
1999-11-23 23:02:55 +00:00
|
|
|
if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
|
2006-06-12 10:05:08 +00:00
|
|
|
uint32_t convNum = findConverter(alias, NULL, pErrorCode);
|
2005-08-30 20:37:50 +00:00
|
|
|
if (convNum < gMainTable.converterListSize) {
|
2002-06-28 23:13:30 +00:00
|
|
|
/* tagListNum - 1 is the ALL tag */
|
2005-08-30 20:37:50 +00:00
|
|
|
int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
if (listOffset) {
|
2005-08-30 20:37:50 +00:00
|
|
|
uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
|
2002-06-28 23:13:30 +00:00
|
|
|
/* +1 to skip listCount */
|
2005-08-30 20:37:50 +00:00
|
|
|
const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
|
2002-06-28 23:13:30 +00:00
|
|
|
|
|
|
|
if (n < listCount) {
|
|
|
|
return GET_STRING(currList[n]);
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
2002-06-28 23:13:30 +00:00
|
|
|
*pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else this shouldn't happen. internal program error */
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
2002-07-13 16:32:16 +00:00
|
|
|
/* else converter not found */
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
static uint16_t
|
2000-11-17 19:28:31 +00:00
|
|
|
ucnv_io_countStandards(UErrorCode *pErrorCode) {
|
2000-11-17 05:49:58 +00:00
|
|
|
if (haveAliasData(pErrorCode)) {
|
2002-06-28 23:13:30 +00:00
|
|
|
/* Don't include the empty list */
|
2005-08-30 20:37:50 +00:00
|
|
|
return (uint16_t)(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
|
2000-08-10 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-17 02:02:11 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
|
|
|
ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode) {
|
2002-06-28 23:13:30 +00:00
|
|
|
if (haveAliasData(pErrorCode)) {
|
2005-08-30 20:37:50 +00:00
|
|
|
if (n < gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) {
|
|
|
|
return GET_STRING(gMainTable.tagList[n]);
|
2000-08-10 02:08:49 +00:00
|
|
|
}
|
2002-06-28 23:13:30 +00:00
|
|
|
*pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
|
2000-08-10 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-13 16:32:16 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
2000-11-17 02:02:11 +00:00
|
|
|
ucnv_getStandardName(const char *alias, const char *standard, UErrorCode *pErrorCode) {
|
2000-08-10 02:08:49 +00:00
|
|
|
if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
|
2002-08-08 22:46:05 +00:00
|
|
|
uint32_t listOffset = findTaggedAliasListsOffset(alias, standard, pErrorCode);
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
if (0 < listOffset && listOffset < gMainTable.taggedAliasListsSize) {
|
|
|
|
const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
|
2002-08-08 22:46:05 +00:00
|
|
|
|
|
|
|
/* Get the preferred name from this list */
|
|
|
|
if (currList[0]) {
|
|
|
|
return GET_STRING(currList[0]);
|
2002-06-28 23:13:30 +00:00
|
|
|
}
|
2002-08-08 22:46:05 +00:00
|
|
|
/* else someone screwed up the alias table. */
|
|
|
|
/* *pErrorCode = U_INVALID_FORMAT_ERROR */
|
2000-08-10 02:08:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-10 01:32:29 +00:00
|
|
|
|
2002-06-28 23:13:30 +00:00
|
|
|
return NULL;
|
2000-08-10 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
U_CAPI uint16_t U_EXPORT2
|
|
|
|
ucnv_countAliases(const char *alias, UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
return ucnv_io_countAliases(alias, pErrorCode);
|
|
|
|
}
|
2002-10-30 22:52:08 +00:00
|
|
|
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
return ucnv_io_getAlias(alias, n, pErrorCode);
|
2002-10-30 22:52:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
ucnv_io_getAliases(alias, 0, aliases, pErrorCode);
|
2002-06-13 16:43:41 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
U_CAPI uint16_t U_EXPORT2
|
|
|
|
ucnv_countStandards(void)
|
|
|
|
{
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
return ucnv_io_countStandards(&err);
|
2002-05-13 21:21:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
|
|
|
ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode) {
|
|
|
|
if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
|
|
|
|
uint32_t convNum = findTaggedConverterNum(alias, standard, pErrorCode);
|
1999-12-14 00:37:27 +00:00
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
if (convNum < gMainTable.converterListSize) {
|
|
|
|
return GET_STRING(gMainTable.converterList[convNum]);
|
1999-12-14 00:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-08 07:56:44 +00:00
|
|
|
|
1999-12-14 00:37:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-30 22:52:08 +00:00
|
|
|
static int32_t U_CALLCONV
|
2011-05-26 20:05:39 +00:00
|
|
|
ucnv_io_countAllConverters(UEnumeration * /*enumerator*/, UErrorCode * /*pErrorCode*/) {
|
2005-08-30 20:37:50 +00:00
|
|
|
return gMainTable.converterListSize;
|
2002-10-30 22:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* U_CALLCONV
|
|
|
|
ucnv_io_nextAllConverters(UEnumeration *enumerator,
|
|
|
|
int32_t* resultLength,
|
2011-05-26 20:05:39 +00:00
|
|
|
UErrorCode * /*pErrorCode*/)
|
2002-10-30 22:52:08 +00:00
|
|
|
{
|
|
|
|
uint16_t *myContext = (uint16_t *)(enumerator->context);
|
|
|
|
|
2005-08-30 20:37:50 +00:00
|
|
|
if (*myContext < gMainTable.converterListSize) {
|
|
|
|
const char *myStr = GET_STRING(gMainTable.converterList[(*myContext)++]);
|
2002-10-30 22:52:08 +00:00
|
|
|
if (resultLength) {
|
2003-12-12 06:59:38 +00:00
|
|
|
*resultLength = (int32_t)uprv_strlen(myStr);
|
2002-10-30 22:52:08 +00:00
|
|
|
}
|
|
|
|
return myStr;
|
|
|
|
}
|
|
|
|
/* Either we accessed a zero length list, or we enumerated too far. */
|
2006-08-06 22:38:31 +00:00
|
|
|
if (resultLength) {
|
|
|
|
*resultLength = 0;
|
|
|
|
}
|
2002-10-30 22:52:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void U_CALLCONV
|
2011-05-26 20:05:39 +00:00
|
|
|
ucnv_io_resetAllConverters(UEnumeration *enumerator, UErrorCode * /*pErrorCode*/) {
|
2002-10-30 22:52:08 +00:00
|
|
|
*((uint16_t *)(enumerator->context)) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UEnumeration gEnumAllConverters = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
ucnv_io_closeUEnumeration,
|
|
|
|
ucnv_io_countAllConverters,
|
|
|
|
uenum_unextDefault,
|
|
|
|
ucnv_io_nextAllConverters,
|
|
|
|
ucnv_io_resetAllConverters
|
|
|
|
};
|
|
|
|
|
|
|
|
U_CAPI UEnumeration * U_EXPORT2
|
|
|
|
ucnv_openAllNames(UErrorCode *pErrorCode) {
|
|
|
|
UEnumeration *myEnum = NULL;
|
|
|
|
if (haveAliasData(pErrorCode)) {
|
|
|
|
uint16_t *myContext;
|
|
|
|
|
2012-08-08 00:50:16 +00:00
|
|
|
myEnum = static_cast<UEnumeration *>(uprv_malloc(sizeof(UEnumeration)));
|
2002-10-30 22:52:08 +00:00
|
|
|
if (myEnum == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memcpy(myEnum, &gEnumAllConverters, sizeof(UEnumeration));
|
2012-08-08 00:50:16 +00:00
|
|
|
myContext = static_cast<uint16_t *>(uprv_malloc(sizeof(uint16_t)));
|
2002-10-30 22:52:08 +00:00
|
|
|
if (myContext == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(myEnum);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*myContext = 0;
|
|
|
|
myEnum->context = myContext;
|
|
|
|
}
|
|
|
|
return myEnum;
|
|
|
|
}
|
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
U_CFUNC uint16_t
|
2006-09-30 22:35:25 +00:00
|
|
|
ucnv_io_countKnownConverters(UErrorCode *pErrorCode) {
|
2002-06-28 23:13:30 +00:00
|
|
|
if (haveAliasData(pErrorCode)) {
|
2006-09-30 22:35:25 +00:00
|
|
|
return (uint16_t)gMainTable.converterListSize;
|
1999-11-23 23:02:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-12 00:26:07 +00:00
|
|
|
/* alias table swapping ----------------------------------------------------- */
|
|
|
|
|
|
|
|
typedef char * U_CALLCONV StripForCompareFn(char *dst, const char *name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* row of a temporary array
|
|
|
|
*
|
|
|
|
* gets platform-endian charset string indexes and sorting indexes;
|
|
|
|
* after sorting this array by strings, the actual arrays are permutated
|
|
|
|
* according to the sorting indexes
|
|
|
|
*/
|
2004-04-08 22:49:40 +00:00
|
|
|
typedef struct TempRow {
|
2003-08-12 00:26:07 +00:00
|
|
|
uint16_t strIndex, sortIndex;
|
2004-04-08 22:49:40 +00:00
|
|
|
} TempRow;
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2004-04-08 22:49:40 +00:00
|
|
|
typedef struct TempAliasTable {
|
2003-08-12 00:26:07 +00:00
|
|
|
const char *chars;
|
2004-04-08 22:49:40 +00:00
|
|
|
TempRow *rows;
|
2003-08-12 00:26:07 +00:00
|
|
|
uint16_t *resort;
|
|
|
|
StripForCompareFn *stripForCompare;
|
2004-04-08 22:49:40 +00:00
|
|
|
} TempAliasTable;
|
2003-08-12 00:26:07 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
STACK_ROW_CAPACITY=500
|
|
|
|
};
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
io_compareRows(const void *context, const void *left, const void *right) {
|
|
|
|
char strippedLeft[UCNV_MAX_CONVERTER_NAME_LENGTH],
|
|
|
|
strippedRight[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
|
|
|
|
2004-04-08 22:49:40 +00:00
|
|
|
TempAliasTable *tempTable=(TempAliasTable *)context;
|
2003-08-12 00:26:07 +00:00
|
|
|
const char *chars=tempTable->chars;
|
|
|
|
|
2004-04-08 22:49:40 +00:00
|
|
|
return (int32_t)uprv_strcmp(tempTable->stripForCompare(strippedLeft, chars+2*((const TempRow *)left)->strIndex),
|
|
|
|
tempTable->stripForCompare(strippedRight, chars+2*((const TempRow *)right)->strIndex));
|
2003-08-12 00:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucnv_swapAliases(const UDataSwapper *ds,
|
|
|
|
const void *inData, int32_t length, void *outData,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
const UDataInfo *pInfo;
|
|
|
|
int32_t headerSize;
|
|
|
|
|
|
|
|
const uint16_t *inTable;
|
2007-07-24 23:27:14 +00:00
|
|
|
const uint32_t *inSectionSizes;
|
2003-12-29 03:00:56 +00:00
|
|
|
uint32_t toc[offsetsCount];
|
|
|
|
uint32_t offsets[offsetsCount]; /* 16-bit-addressed offsets from inTable/outTable */
|
2003-08-12 00:26:07 +00:00
|
|
|
uint32_t i, count, tocLength, topOffset;
|
|
|
|
|
2004-04-08 22:49:40 +00:00
|
|
|
TempRow rows[STACK_ROW_CAPACITY];
|
2003-08-12 00:26:07 +00:00
|
|
|
uint16_t resort[STACK_ROW_CAPACITY];
|
2004-04-08 22:49:40 +00:00
|
|
|
TempAliasTable tempTable;
|
2003-08-12 00:26:07 +00:00
|
|
|
|
|
|
|
/* udata_swapDataHeader checks the arguments */
|
|
|
|
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check data format and format version */
|
|
|
|
pInfo=(const UDataInfo *)((const char *)inData+4);
|
|
|
|
if(!(
|
|
|
|
pInfo->dataFormat[0]==0x43 && /* dataFormat="CvAl" */
|
|
|
|
pInfo->dataFormat[1]==0x76 &&
|
|
|
|
pInfo->dataFormat[2]==0x41 &&
|
|
|
|
pInfo->dataFormat[3]==0x6c &&
|
|
|
|
pInfo->formatVersion[0]==3
|
|
|
|
)) {
|
|
|
|
udata_printError(ds, "ucnv_swapAliases(): data format %02x.%02x.%02x.%02x (format version %02x) is not an alias table\n",
|
|
|
|
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
|
|
|
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
|
|
|
pInfo->formatVersion[0]);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* an alias table must contain at least the table of contents array */
|
2003-08-12 12:21:24 +00:00
|
|
|
if(length>=0 && (length-headerSize)<4*(1+minTocLength)) {
|
2003-08-12 00:26:07 +00:00
|
|
|
udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
|
|
|
|
length-headerSize);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-24 23:27:14 +00:00
|
|
|
inSectionSizes=(const uint32_t *)((const char *)inData+headerSize);
|
|
|
|
inTable=(const uint16_t *)inSectionSizes;
|
2006-06-11 16:57:02 +00:00
|
|
|
uprv_memset(toc, 0, sizeof(toc));
|
2007-07-24 23:27:14 +00:00
|
|
|
toc[tocLengthIndex]=tocLength=ds->readUInt32(inSectionSizes[tocLengthIndex]);
|
2006-06-11 16:57:02 +00:00
|
|
|
if(tocLength<minTocLength || offsetsCount<=tocLength) {
|
|
|
|
udata_printError(ds, "ucnv_swapAliases(): table of contents contains unsupported number of sections (%u sections)\n", tocLength);
|
2003-08-12 00:26:07 +00:00
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the known part of the table of contents */
|
2006-06-11 16:57:02 +00:00
|
|
|
for(i=converterListIndex; i<=tocLength; ++i) {
|
2007-07-24 23:27:14 +00:00
|
|
|
toc[i]=ds->readUInt32(inSectionSizes[i]);
|
2003-08-12 00:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compute offsets */
|
2006-06-11 16:57:02 +00:00
|
|
|
uprv_memset(offsets, 0, sizeof(offsets));
|
2003-08-12 00:26:07 +00:00
|
|
|
offsets[converterListIndex]=2*(1+tocLength); /* count two 16-bit units per toc entry */
|
2006-06-11 16:57:02 +00:00
|
|
|
for(i=tagListIndex; i<=tocLength; ++i) {
|
2003-08-12 00:26:07 +00:00
|
|
|
offsets[i]=offsets[i-1]+toc[i-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute the overall size of the after-header data, in numbers of 16-bit units */
|
2003-12-29 03:00:56 +00:00
|
|
|
topOffset=offsets[i-1]+toc[i-1];
|
2003-08-12 00:26:07 +00:00
|
|
|
|
|
|
|
if(length>=0) {
|
|
|
|
uint16_t *outTable;
|
|
|
|
const uint16_t *p, *p2;
|
|
|
|
uint16_t *q, *q2;
|
|
|
|
uint16_t oldIndex;
|
|
|
|
|
2003-08-12 12:21:24 +00:00
|
|
|
if((length-headerSize)<(2*(int32_t)topOffset)) {
|
|
|
|
udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
|
|
|
|
length-headerSize);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-12 00:26:07 +00:00
|
|
|
outTable=(uint16_t *)((char *)outData+headerSize);
|
|
|
|
|
|
|
|
/* swap the entire table of contents */
|
|
|
|
ds->swapArray32(ds, inTable, 4*(1+tocLength), outTable, pErrorCode);
|
|
|
|
|
2006-07-28 18:09:36 +00:00
|
|
|
/* swap unormalized strings & normalized strings */
|
|
|
|
ds->swapInvChars(ds, inTable+offsets[stringTableIndex], 2*(int32_t)(toc[stringTableIndex]+toc[normalizedStringTableIndex]),
|
2003-08-12 00:26:07 +00:00
|
|
|
outTable+offsets[stringTableIndex], pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2004-12-05 05:38:50 +00:00
|
|
|
udata_printError(ds, "ucnv_swapAliases().swapInvChars(charset names) failed\n");
|
2003-08-12 00:26:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
if(ds->inCharset==ds->outCharset) {
|
|
|
|
/* no need to sort, just swap all 16-bit values together */
|
2003-08-12 00:26:07 +00:00
|
|
|
ds->swapArray16(ds,
|
|
|
|
inTable+offsets[converterListIndex],
|
|
|
|
2*(int32_t)(offsets[stringTableIndex]-offsets[converterListIndex]),
|
|
|
|
outTable+offsets[converterListIndex],
|
|
|
|
pErrorCode);
|
2003-09-25 04:17:12 +00:00
|
|
|
} else {
|
|
|
|
/* allocate the temporary table for sorting */
|
|
|
|
count=toc[aliasListIndex];
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
tempTable.chars=(const char *)(outTable+offsets[stringTableIndex]); /* sort by outCharset */
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
if(count<=STACK_ROW_CAPACITY) {
|
|
|
|
tempTable.rows=rows;
|
|
|
|
tempTable.resort=resort;
|
|
|
|
} else {
|
2004-04-08 22:49:40 +00:00
|
|
|
tempTable.rows=(TempRow *)uprv_malloc(count*sizeof(TempRow)+count*2);
|
2003-09-25 04:17:12 +00:00
|
|
|
if(tempTable.rows==NULL) {
|
|
|
|
udata_printError(ds, "ucnv_swapAliases(): unable to allocate memory for sorting tables (max length: %u)\n",
|
|
|
|
count);
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tempTable.resort=(uint16_t *)(tempTable.rows+count);
|
|
|
|
}
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
if(ds->outCharset==U_ASCII_FAMILY) {
|
|
|
|
tempTable.stripForCompare=ucnv_io_stripASCIIForCompare;
|
|
|
|
} else /* U_EBCDIC_FAMILY */ {
|
|
|
|
tempTable.stripForCompare=ucnv_io_stripEBCDICForCompare;
|
2003-08-12 00:26:07 +00:00
|
|
|
}
|
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
/*
|
|
|
|
* Sort unique aliases+mapped names.
|
|
|
|
*
|
|
|
|
* We need to sort the list again by outCharset strings because they
|
|
|
|
* sort differently for different charset families.
|
|
|
|
* First we set up a temporary table with the string indexes and
|
|
|
|
* sorting indexes and sort that.
|
|
|
|
* Then we permutate and copy/swap the actual values.
|
|
|
|
*/
|
|
|
|
p=inTable+offsets[aliasListIndex];
|
|
|
|
q=outTable+offsets[aliasListIndex];
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
p2=inTable+offsets[untaggedConvArrayIndex];
|
|
|
|
q2=outTable+offsets[untaggedConvArrayIndex];
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
for(i=0; i<count; ++i) {
|
|
|
|
tempTable.rows[i].strIndex=ds->readUInt16(p[i]);
|
|
|
|
tempTable.rows[i].sortIndex=(uint16_t)i;
|
|
|
|
}
|
|
|
|
|
2004-04-08 22:49:40 +00:00
|
|
|
uprv_sortArray(tempTable.rows, (int32_t)count, sizeof(TempRow),
|
2003-09-25 04:17:12 +00:00
|
|
|
io_compareRows, &tempTable,
|
|
|
|
FALSE, pErrorCode);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*pErrorCode)) {
|
|
|
|
/* copy/swap/permutate items */
|
|
|
|
if(p!=q) {
|
|
|
|
for(i=0; i<count; ++i) {
|
|
|
|
oldIndex=tempTable.rows[i].sortIndex;
|
|
|
|
ds->swapArray16(ds, p+oldIndex, 2, q+i, pErrorCode);
|
|
|
|
ds->swapArray16(ds, p2+oldIndex, 2, q2+i, pErrorCode);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we swap in-place, then the permutation must use another
|
|
|
|
* temporary array (tempTable.resort)
|
|
|
|
* before the results are copied to the outBundle.
|
|
|
|
*/
|
|
|
|
uint16_t *r=tempTable.resort;
|
|
|
|
|
|
|
|
for(i=0; i<count; ++i) {
|
|
|
|
oldIndex=tempTable.rows[i].sortIndex;
|
|
|
|
ds->swapArray16(ds, p+oldIndex, 2, r+i, pErrorCode);
|
|
|
|
}
|
|
|
|
uprv_memcpy(q, r, 2*count);
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
for(i=0; i<count; ++i) {
|
|
|
|
oldIndex=tempTable.rows[i].sortIndex;
|
|
|
|
ds->swapArray16(ds, p2+oldIndex, 2, r+i, pErrorCode);
|
|
|
|
}
|
|
|
|
uprv_memcpy(q2, r, 2*count);
|
2003-08-12 00:26:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
if(tempTable.rows!=rows) {
|
|
|
|
uprv_free(tempTable.rows);
|
|
|
|
}
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2004-12-05 05:38:50 +00:00
|
|
|
udata_printError(ds, "ucnv_swapAliases().uprv_sortArray(%u items) failed\n",
|
|
|
|
count);
|
2003-09-25 04:17:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-12 00:26:07 +00:00
|
|
|
|
2003-09-25 04:17:12 +00:00
|
|
|
/* swap remaining 16-bit values */
|
|
|
|
ds->swapArray16(ds,
|
|
|
|
inTable+offsets[converterListIndex],
|
|
|
|
2*(int32_t)(offsets[aliasListIndex]-offsets[converterListIndex]),
|
|
|
|
outTable+offsets[converterListIndex],
|
|
|
|
pErrorCode);
|
|
|
|
ds->swapArray16(ds,
|
|
|
|
inTable+offsets[taggedAliasArrayIndex],
|
|
|
|
2*(int32_t)(offsets[stringTableIndex]-offsets[taggedAliasArrayIndex]),
|
|
|
|
outTable+offsets[taggedAliasArrayIndex],
|
|
|
|
pErrorCode);
|
|
|
|
}
|
2003-08-12 00:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return headerSize+2*(int32_t)topOffset;
|
|
|
|
}
|
|
|
|
|
2004-08-26 22:51:40 +00:00
|
|
|
#endif
|
|
|
|
|
2000-08-10 01:32:29 +00:00
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|