1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-12-04 02:31:40 +00:00
|
|
|
********************************************************************
|
2004-11-11 23:34:58 +00:00
|
|
|
* COPYRIGHT:
|
2005-05-08 07:56:44 +00:00
|
|
|
* Copyright (c) 1996-2005, International Business Machines Corporation and
|
1999-12-04 02:31:40 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* uconv_bld.c:
|
|
|
|
*
|
|
|
|
* Defines functions that are used in the creation/initialization/deletion
|
|
|
|
* of converters and related structures.
|
|
|
|
* uses uconv_io.h routines to access disk information
|
|
|
|
* is used by ucnv.h to implement public API create/delete/flushCache routines
|
2000-06-20 23:42:20 +00:00
|
|
|
* Modification History:
|
2004-11-11 23:34:58 +00:00
|
|
|
*
|
2000-06-20 23:42:20 +00:00
|
|
|
* Date Name Description
|
2004-11-11 23:34:58 +00:00
|
|
|
*
|
2000-06-20 23:42:20 +00:00
|
|
|
* 06/20/2000 helena OS/400 port changes; mostly typecast.
|
2000-06-27 20:47:56 +00:00
|
|
|
* 06/29/2000 helena Major rewrite of the callback interface.
|
2000-06-20 23:42:20 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-08-26 22:51:40 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_CONVERSION
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
#include "unicode/putil.h"
|
2002-07-02 19:21:35 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "unicode/uloc.h"
|
2003-11-21 23:24:11 +00:00
|
|
|
#include "utracimp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "ucnv_io.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "ucnv_bld.h"
|
2003-10-30 03:16:04 +00:00
|
|
|
#include "ucnvmbcs.h"
|
|
|
|
#include "ucnv_ext.h"
|
2000-02-05 00:19:15 +00:00
|
|
|
#include "ucnv_cnv.h"
|
1999-10-18 22:48:32 +00:00
|
|
|
#include "ucnv_imp.h"
|
2002-07-02 19:21:35 +00:00
|
|
|
#include "uhash.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "umutex.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "cmemory.h"
|
2001-08-11 00:29:58 +00:00
|
|
|
#include "ucln_cmn.h"
|
2004-08-27 17:56:01 +00:00
|
|
|
#include "ustr_cnv.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-04 02:31:40 +00:00
|
|
|
|
2003-05-07 00:53:32 +00:00
|
|
|
|
2000-08-14 23:11:00 +00:00
|
|
|
#if 0
|
2001-02-06 22:26:52 +00:00
|
|
|
#include <stdio.h>
|
2000-08-14 23:11:00 +00:00
|
|
|
extern void UCNV_DEBUG_LOG(char *what, char *who, void *p, int l);
|
|
|
|
#define UCNV_DEBUG_LOG(x,y,z) UCNV_DEBUG_LOG(x,y,z,__LINE__)
|
|
|
|
#else
|
|
|
|
# define UCNV_DEBUG_LOG(x,y,z)
|
|
|
|
#endif
|
|
|
|
|
2001-08-24 00:22:07 +00:00
|
|
|
static const UConverterSharedData * const
|
2000-02-05 00:19:15 +00:00
|
|
|
converterData[UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES]={
|
2002-09-20 01:54:48 +00:00
|
|
|
NULL, NULL,
|
|
|
|
|
|
|
|
#if UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
NULL,
|
|
|
|
#else
|
|
|
|
&_MBCSData,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
&_Latin1Data,
|
2000-11-16 17:20:03 +00:00
|
|
|
&_UTF8Data, &_UTF16BEData, &_UTF16LEData, &_UTF32BEData, &_UTF32LEData,
|
2002-09-20 01:54:48 +00:00
|
|
|
NULL,
|
|
|
|
|
|
|
|
#if UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
#else
|
|
|
|
&_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,
|
2002-09-20 01:54:48 +00:00
|
|
|
&_HZData,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
&_SCSUData,
|
|
|
|
|
|
|
|
#if UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
NULL,
|
|
|
|
#else
|
|
|
|
&_ISCIIData,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
&_ASCIIData,
|
2002-11-07 21:02:24 +00:00
|
|
|
&_UTF7Data, &_Bocu1Data, &_UTF16Data, &_UTF32Data, &_CESU8Data, &_IMAPData
|
2000-02-05 00:19:15 +00:00
|
|
|
};
|
|
|
|
|
2002-09-06 00:48:35 +00:00
|
|
|
/* Please keep this in binary sorted order for getAlgorithmicTypeFromName.
|
|
|
|
Also the name should be in lower case and all spaces, dashes and underscores
|
|
|
|
removed
|
|
|
|
*/
|
2000-02-05 00:19:15 +00:00
|
|
|
static struct {
|
|
|
|
const char *name;
|
2001-08-24 00:22:07 +00:00
|
|
|
const UConverterType type;
|
|
|
|
} const cnvNameType[] = {
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "bocu1", UCNV_BOCU1 },
|
|
|
|
{ "cesu8", UCNV_CESU8 },
|
2002-09-20 01:54:48 +00:00
|
|
|
#if !UCONFIG_NO_LEGACY_CONVERSION
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "hz",UCNV_HZ },
|
2003-08-05 23:39:49 +00:00
|
|
|
#endif
|
2002-11-07 21:02:24 +00:00
|
|
|
{ "imapmailboxname", UCNV_IMAP_MAILBOX },
|
2003-08-05 23:39:49 +00:00
|
|
|
#if !UCONFIG_NO_LEGACY_CONVERSION
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "iscii", UCNV_ISCII },
|
|
|
|
{ "iso2022", UCNV_ISO_2022 },
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "iso88591", UCNV_LATIN_1 },
|
2002-09-20 01:54:48 +00:00
|
|
|
#if !UCONFIG_NO_LEGACY_CONVERSION
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "lmbcs1", UCNV_LMBCS_1 },
|
|
|
|
{ "lmbcs11",UCNV_LMBCS_11 },
|
|
|
|
{ "lmbcs16",UCNV_LMBCS_16 },
|
|
|
|
{ "lmbcs17",UCNV_LMBCS_17 },
|
|
|
|
{ "lmbcs18",UCNV_LMBCS_18 },
|
|
|
|
{ "lmbcs19",UCNV_LMBCS_19 },
|
|
|
|
{ "lmbcs2", UCNV_LMBCS_2 },
|
|
|
|
{ "lmbcs3", UCNV_LMBCS_3 },
|
|
|
|
{ "lmbcs4", UCNV_LMBCS_4 },
|
|
|
|
{ "lmbcs5", UCNV_LMBCS_5 },
|
|
|
|
{ "lmbcs6", UCNV_LMBCS_6 },
|
|
|
|
{ "lmbcs8", UCNV_LMBCS_8 },
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "scsu", UCNV_SCSU },
|
|
|
|
{ "usascii", UCNV_US_ASCII },
|
|
|
|
{ "utf16", UCNV_UTF16 },
|
|
|
|
{ "utf16be", UCNV_UTF16_BigEndian },
|
|
|
|
{ "utf16le", UCNV_UTF16_LittleEndian },
|
2000-02-05 00:19:15 +00:00
|
|
|
#if U_IS_BIG_ENDIAN
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf16oppositeendian", UCNV_UTF16_LittleEndian },
|
|
|
|
{ "utf16platformendian", UCNV_UTF16_BigEndian },
|
2000-02-05 00:19:15 +00:00
|
|
|
#else
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf16oppositeendian", UCNV_UTF16_BigEndian},
|
|
|
|
{ "utf16platformendian", UCNV_UTF16_LittleEndian },
|
2000-11-16 17:20:03 +00:00
|
|
|
#endif
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf32", UCNV_UTF32 },
|
|
|
|
{ "utf32be", UCNV_UTF32_BigEndian },
|
|
|
|
{ "utf32le", UCNV_UTF32_LittleEndian },
|
2000-11-16 17:20:03 +00:00
|
|
|
#if U_IS_BIG_ENDIAN
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf32oppositeendian", UCNV_UTF32_LittleEndian },
|
|
|
|
{ "utf32platformendian", UCNV_UTF32_BigEndian },
|
2000-11-16 17:20:03 +00:00
|
|
|
#else
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf32oppositeendian", UCNV_UTF32_BigEndian },
|
|
|
|
{ "utf32platformendian", UCNV_UTF32_LittleEndian },
|
2000-02-05 00:19:15 +00:00
|
|
|
#endif
|
2002-09-06 00:48:35 +00:00
|
|
|
{ "utf7", UCNV_UTF7 },
|
|
|
|
{ "utf8", UCNV_UTF8 }
|
1999-10-18 22:48:32 +00:00
|
|
|
};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-31 16:53:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*initializes some global variables */
|
2001-10-04 01:04:28 +00:00
|
|
|
static UHashtable *SHARED_DATA_HASHTABLE = NULL;
|
2002-03-27 17:36:15 +00:00
|
|
|
static UMTX cnvCacheMutex = NULL; /* Mutex for synchronizing cnv cache access. */
|
2002-03-12 21:54:23 +00:00
|
|
|
/* Note: the global mutex is used for */
|
|
|
|
/* reference count updates. */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
static const char **gAvailableConverters = NULL;
|
|
|
|
static uint16_t gAvailableConverterCount = 0;
|
|
|
|
|
|
|
|
static char gDefaultConverterNameBuffer[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; /* +1 for NULL */
|
|
|
|
static const char *gDefaultConverterName = NULL;
|
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
|
2003-05-08 01:32:27 +00:00
|
|
|
static const char DATA_TYPE[] = "cnv";
|
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
/* ucnv_cleanup - delete all storage held by the converter cache, except any in use */
|
|
|
|
/* by open converters. */
|
|
|
|
/* Not thread safe. */
|
2002-03-13 18:34:45 +00:00
|
|
|
/* Not supported API. Marked U_CAPI only for use by test programs. */
|
2004-10-06 23:10:53 +00:00
|
|
|
static UBool U_CALLCONV ucnv_cleanup(void) {
|
2001-08-11 00:29:58 +00:00
|
|
|
if (SHARED_DATA_HASHTABLE != NULL) {
|
|
|
|
ucnv_flushCache();
|
|
|
|
if (SHARED_DATA_HASHTABLE != NULL && uhash_count(SHARED_DATA_HASHTABLE) == 0) {
|
|
|
|
uhash_close(SHARED_DATA_HASHTABLE);
|
|
|
|
SHARED_DATA_HASHTABLE = NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-03-12 21:54:23 +00:00
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
/* Called from ucnv_flushCache because it allocates the hashtable */
|
|
|
|
/*ucnv_flushAvailableConverterCache();*/
|
|
|
|
|
|
|
|
gDefaultConverterName = NULL;
|
|
|
|
gDefaultConverterNameBuffer[0] = 0;
|
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
umtx_destroy(&cnvCacheMutex); /* Don't worry about destroying the mutex even */
|
|
|
|
/* if the hash table still exists. The mutex */
|
|
|
|
/* will lazily re-init itself if needed. */
|
2001-08-11 00:29:58 +00:00
|
|
|
return (SHARED_DATA_HASHTABLE == NULL);
|
2000-08-14 23:11:00 +00:00
|
|
|
}
|
|
|
|
|
2002-07-23 23:01:08 +00:00
|
|
|
static UBool U_CALLCONV
|
1999-12-04 02:31:40 +00:00
|
|
|
isCnvAcceptable(void *context,
|
|
|
|
const char *type, const char *name,
|
2000-05-03 23:15:02 +00:00
|
|
|
const UDataInfo *pInfo) {
|
2000-08-10 01:59:18 +00:00
|
|
|
return (UBool)(
|
1999-12-04 02:31:40 +00:00
|
|
|
pInfo->size>=20 &&
|
|
|
|
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pInfo->charsetFamily==U_CHARSET_FAMILY &&
|
|
|
|
pInfo->sizeofUChar==U_SIZEOF_UCHAR &&
|
|
|
|
pInfo->dataFormat[0]==0x63 && /* dataFormat="cnvt" */
|
|
|
|
pInfo->dataFormat[1]==0x6e &&
|
|
|
|
pInfo->dataFormat[2]==0x76 &&
|
|
|
|
pInfo->dataFormat[3]==0x74 &&
|
2002-07-17 02:34:50 +00:00
|
|
|
pInfo->formatVersion[0]==6); /* Everything will be version 6 */
|
1999-12-04 02:31:40 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 01:32:27 +00:00
|
|
|
/**
|
|
|
|
* Un flatten shared data from a UDATA..
|
|
|
|
*/
|
|
|
|
static UConverterSharedData*
|
2003-11-12 02:04:55 +00:00
|
|
|
ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCode *status)
|
2003-05-08 01:32:27 +00:00
|
|
|
{
|
|
|
|
/* UDataInfo info; -- necessary only if some converters have different formatVersion */
|
|
|
|
const uint8_t *raw = (const uint8_t *)udata_getMemory(pData);
|
|
|
|
const UConverterStaticData *source = (const UConverterStaticData *) raw;
|
|
|
|
UConverterSharedData *data;
|
|
|
|
UConverterType type = (UConverterType)source->conversionType;
|
|
|
|
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if( (uint16_t)type >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES ||
|
|
|
|
converterData[type] == NULL ||
|
|
|
|
converterData[type]->referenceCounter != 1 ||
|
|
|
|
source->structSize != sizeof(UConverterStaticData))
|
|
|
|
{
|
|
|
|
*status = U_INVALID_TABLE_FORMAT;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = (UConverterSharedData *)uprv_malloc(sizeof(UConverterSharedData));
|
|
|
|
if(data == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy initial values from the static structure for this type */
|
|
|
|
uprv_memcpy(data, converterData[type], sizeof(UConverterSharedData));
|
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
#if 0 /* made UConverterMBCSTable part of UConverterSharedData -- markus 20031107 */
|
2003-05-08 01:32:27 +00:00
|
|
|
/*
|
|
|
|
* It would be much more efficient if the table were a direct member, not a pointer.
|
|
|
|
* However, that would add to the size of all UConverterSharedData objects
|
|
|
|
* even if they do not use this table (especially algorithmic ones).
|
|
|
|
* If this changes, then the static templates from converterData[type]
|
|
|
|
* need more entries.
|
2003-11-08 00:09:50 +00:00
|
|
|
*
|
|
|
|
* In principle, it would be cleaner if the load() function below
|
|
|
|
* allocated the table.
|
2003-05-08 01:32:27 +00:00
|
|
|
*/
|
|
|
|
data->table = (UConverterTable *)uprv_malloc(sizeof(UConverterTable));
|
|
|
|
if(data->table == NULL) {
|
|
|
|
uprv_free(data);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memset(data->table, 0, sizeof(UConverterTable));
|
2003-11-08 00:09:50 +00:00
|
|
|
#endif
|
|
|
|
|
2003-05-08 01:32:27 +00:00
|
|
|
data->staticData = source;
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2003-05-08 01:32:27 +00:00
|
|
|
data->sharedDataCached = FALSE;
|
|
|
|
|
|
|
|
/* fill in fields from the loaded data */
|
|
|
|
data->dataMemory = (void*)pData; /* for future use */
|
|
|
|
|
|
|
|
if(data->impl->load != NULL) {
|
2003-11-12 02:04:55 +00:00
|
|
|
data->impl->load(data, pArgs, raw + source->structSize, status);
|
2003-05-08 01:32:27 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
uprv_free(data->table);
|
|
|
|
uprv_free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
1999-12-04 02:31:40 +00:00
|
|
|
|
2003-05-08 01:32:27 +00:00
|
|
|
/*Takes an alias name gets an actual converter file name
|
|
|
|
*goes to disk and opens it.
|
|
|
|
*allocates the memory and returns a new UConverter object
|
|
|
|
*/
|
2003-11-12 02:04:55 +00:00
|
|
|
static UConverterSharedData *createConverterFromFile(UConverterLoadArgs *pArgs, UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
UDataMemory *data;
|
|
|
|
UConverterSharedData *sharedData;
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_LOAD);
|
|
|
|
|
2005-08-02 18:12:39 +00:00
|
|
|
if (U_FAILURE (*err)) {
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2001-08-11 00:29:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "load converter %s from package %s", pArgs->name, pArgs->pkg);
|
|
|
|
|
2003-11-12 02:04:55 +00:00
|
|
|
data = udata_openChoice(pArgs->pkg, DATA_TYPE, pArgs->name, isCnvAcceptable, NULL, err);
|
2001-08-11 00:29:58 +00:00
|
|
|
if(U_FAILURE(*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2001-08-11 00:29:58 +00:00
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-11-12 02:04:55 +00:00
|
|
|
sharedData = ucnv_data_unFlattenClone(pArgs, data, err);
|
2001-08-11 00:29:58 +00:00
|
|
|
if(U_FAILURE(*err))
|
1999-12-04 02:31:40 +00:00
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
udata_close(data);
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2001-08-11 00:29:58 +00:00
|
|
|
return NULL;
|
1999-12-04 02:31:40 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
/*
|
|
|
|
* TODO Store pkg in a field in the shared data so that delta-only converters
|
|
|
|
* can load base converters from the same package.
|
|
|
|
* If the pkg name is longer than the field, then either do not load the converter
|
|
|
|
* in the first place, or just set the pkg field to "".
|
|
|
|
*/
|
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_PTR_STATUS(sharedData, *err);
|
2001-08-11 00:29:58 +00:00
|
|
|
return sharedData;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*returns a converter type from a string
|
|
|
|
*/
|
2000-08-11 01:27:17 +00:00
|
|
|
static const UConverterSharedData *
|
2001-08-11 00:29:58 +00:00
|
|
|
getAlgorithmicTypeFromName(const char *realName)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-09-04 00:36:40 +00:00
|
|
|
uint32_t mid, start, limit;
|
2004-11-11 23:34:58 +00:00
|
|
|
uint32_t lastMid;
|
2002-09-04 00:36:40 +00:00
|
|
|
int result;
|
2002-09-06 00:48:35 +00:00
|
|
|
char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
|
|
|
|
|
|
|
/* Lower case and remove ignoreable characters. */
|
|
|
|
ucnv_io_stripForCompare(strippedName, realName);
|
2002-09-04 00:36:40 +00:00
|
|
|
|
|
|
|
/* do a binary search for the alias */
|
|
|
|
start = 0;
|
|
|
|
limit = sizeof(cnvNameType)/sizeof(cnvNameType[0]);
|
|
|
|
mid = limit;
|
2004-11-11 23:34:58 +00:00
|
|
|
lastMid = UINT32_MAX;
|
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;
|
2002-09-06 00:48:35 +00:00
|
|
|
result = uprv_strcmp(strippedName, cnvNameType[mid].name);
|
2002-09-04 00:36:40 +00:00
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
limit = mid;
|
|
|
|
} else if (result > 0) {
|
|
|
|
start = mid;
|
|
|
|
} else {
|
|
|
|
return converterData[cnvNameType[mid].type];
|
2001-08-11 00:29:58 +00:00
|
|
|
}
|
2000-02-05 00:19:15 +00:00
|
|
|
}
|
2002-09-04 00:36:40 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
/* Puts the shared data in the static hashtable SHARED_DATA_HASHTABLE */
|
|
|
|
/* Will always be called with the cnvCacheMutex alrady being held */
|
|
|
|
/* by the calling function. */
|
2003-05-08 01:32:27 +00:00
|
|
|
/* Stores the shared data in the SHARED_DATA_HASHTABLE
|
|
|
|
* @param data The shared data
|
|
|
|
*/
|
2003-05-07 00:53:32 +00:00
|
|
|
static void
|
2001-10-04 01:14:52 +00:00
|
|
|
ucnv_shareConverterData(UConverterSharedData * data)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
/*Lazy evaluates the Hashtable itself */
|
|
|
|
/*void *sanity = NULL;*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-08-06 15:59:27 +00:00
|
|
|
if (SHARED_DATA_HASHTABLE == NULL)
|
|
|
|
{
|
2005-11-11 19:23:09 +00:00
|
|
|
SHARED_DATA_HASHTABLE = uhash_openSize(uhash_hashChars, uhash_compareChars, NULL,
|
2005-05-08 07:56:44 +00:00
|
|
|
ucnv_io_countTotalAliases(&err),
|
2001-08-11 00:29:58 +00:00
|
|
|
&err);
|
2004-10-06 23:10:53 +00:00
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
|
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
if (U_FAILURE(err))
|
2001-08-11 00:29:58 +00:00
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-03-12 21:54:23 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* ### check to see if the element is not already there! */
|
2000-08-14 23:11:00 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/*
|
2001-10-04 01:14:52 +00:00
|
|
|
sanity = ucnv_getSharedConverterData (data->staticData->name);
|
2000-08-14 23:11:00 +00:00
|
|
|
if(sanity != NULL)
|
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
UCNV_DEBUG_LOG("put:overwrite!",data->staticData->name,sanity);
|
2000-08-14 23:11:00 +00:00
|
|
|
}
|
|
|
|
UCNV_DEBUG_LOG("put:chk",data->staticData->name,sanity);
|
2001-08-11 00:29:58 +00:00
|
|
|
*/
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
/* Mark it shared */
|
|
|
|
data->sharedDataCached = TRUE;
|
2000-08-14 23:11:00 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
uhash_put(SHARED_DATA_HASHTABLE,
|
|
|
|
(void*) data->staticData->name, /* Okay to cast away const as long as
|
|
|
|
keyDeleter == NULL */
|
1999-12-04 00:55:54 +00:00
|
|
|
data,
|
|
|
|
&err);
|
2001-08-11 00:29:58 +00:00
|
|
|
UCNV_DEBUG_LOG("put", data->staticData->name,data);
|
2002-03-12 21:54:23 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
/* Look up a converter name in the shared data cache. */
|
|
|
|
/* cnvCacheMutex must be held by the caller to protect the hash table. */
|
2003-05-08 01:32:27 +00:00
|
|
|
/* gets the shared data from the SHARED_DATA_HASHTABLE (might return NULL if it isn't there)
|
|
|
|
* @param name The name of the shared data
|
|
|
|
* @return the shared data from the SHARED_DATA_HASHTABLE
|
|
|
|
*/
|
2003-05-07 00:53:32 +00:00
|
|
|
static UConverterSharedData *
|
2001-10-04 01:14:52 +00:00
|
|
|
ucnv_getSharedConverterData(const char *name)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
/*special case when no Table has yet been created we return NULL */
|
|
|
|
if (SHARED_DATA_HASHTABLE == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-08-11 00:29:58 +00:00
|
|
|
UConverterSharedData *rc;
|
2000-08-14 23:11:00 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
rc = (UConverterSharedData*)uhash_get(SHARED_DATA_HASHTABLE, name);
|
|
|
|
UCNV_DEBUG_LOG("get",name,rc);
|
|
|
|
return rc;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*frees the string of memory blocks associates with a sharedConverter
|
|
|
|
*if and only if the referenceCounter == 0
|
|
|
|
*/
|
2003-05-08 01:32:27 +00:00
|
|
|
/* Deletes (frees) the Shared data it's passed. first it checks the referenceCounter to
|
|
|
|
* see if anyone is using it, if not it frees all the memory stemming from sharedConverterData and
|
|
|
|
* returns TRUE,
|
|
|
|
* otherwise returns FALSE
|
|
|
|
* @param sharedConverterData The shared data
|
|
|
|
* @return if not it frees all the memory stemming from sharedConverterData and
|
|
|
|
* returns TRUE, otherwise returns FALSE
|
|
|
|
*/
|
2003-05-07 00:53:32 +00:00
|
|
|
static UBool
|
2001-10-04 01:14:52 +00:00
|
|
|
ucnv_deleteSharedConverterData(UConverterSharedData * deadSharedData)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_UNLOAD);
|
|
|
|
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "unload converter %s shared data %p", deadSharedData->staticData->name, deadSharedData);
|
|
|
|
|
|
|
|
if (deadSharedData->referenceCounter > 0) {
|
|
|
|
UTRACE_EXIT_VALUE((int32_t)FALSE);
|
1999-12-04 02:31:40 +00:00
|
|
|
return FALSE;
|
2003-11-21 23:24:11 +00:00
|
|
|
}
|
2002-07-17 02:34:50 +00:00
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
if (deadSharedData->impl->unload != NULL) {
|
|
|
|
deadSharedData->impl->unload(deadSharedData);
|
|
|
|
}
|
2004-11-11 23:34:58 +00:00
|
|
|
|
1999-12-04 02:31:40 +00:00
|
|
|
if(deadSharedData->dataMemory != NULL)
|
|
|
|
{
|
|
|
|
UDataMemory *data = (UDataMemory*)deadSharedData->dataMemory;
|
|
|
|
udata_close(data);
|
|
|
|
}
|
|
|
|
|
2000-08-14 23:11:00 +00:00
|
|
|
if(deadSharedData->table != NULL)
|
|
|
|
{
|
|
|
|
uprv_free(deadSharedData->table);
|
|
|
|
}
|
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
#if 0
|
|
|
|
/* if the static data is actually owned by the shared data */
|
|
|
|
/* enable if we ever have this situation. */
|
|
|
|
if(deadSharedData->staticDataOwned == TRUE) /* see ucnv_bld.h */
|
|
|
|
{
|
|
|
|
uprv_free((void*)deadSharedData->staticData);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Zap it ! */
|
|
|
|
uprv_memset(deadSharedData->0, sizeof(*deadSharedData));
|
|
|
|
#endif
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
uprv_free(deadSharedData);
|
2003-11-21 23:24:11 +00:00
|
|
|
|
|
|
|
UTRACE_EXIT_VALUE((int32_t)TRUE);
|
1999-12-04 02:31:40 +00:00
|
|
|
return TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
/**
|
|
|
|
* Load a non-algorithmic converter.
|
|
|
|
* If pkg==NULL, then this function must be called inside umtx_lock(&cnvCacheMutex).
|
|
|
|
*/
|
|
|
|
UConverterSharedData *
|
2003-11-12 02:04:55 +00:00
|
|
|
ucnv_load(UConverterLoadArgs *pArgs, UErrorCode *err) {
|
2003-11-08 00:09:50 +00:00
|
|
|
UConverterSharedData *mySharedConverterData;
|
|
|
|
|
|
|
|
if(err == NULL || U_FAILURE(*err)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-12 02:04:55 +00:00
|
|
|
if(pArgs->pkg != NULL && *pArgs->pkg != 0) {
|
2003-11-08 00:09:50 +00:00
|
|
|
/* application-provided converters are not currently cached */
|
2003-11-12 02:04:55 +00:00
|
|
|
return createConverterFromFile(pArgs, err);
|
2003-11-08 00:09:50 +00:00
|
|
|
}
|
|
|
|
|
2003-11-12 02:04:55 +00:00
|
|
|
mySharedConverterData = ucnv_getSharedConverterData(pArgs->name);
|
2003-11-08 00:09:50 +00:00
|
|
|
if (mySharedConverterData == NULL)
|
|
|
|
{
|
|
|
|
/*Not cached, we need to stream it in from file */
|
2003-11-12 02:04:55 +00:00
|
|
|
mySharedConverterData = createConverterFromFile(pArgs, err);
|
2003-11-08 00:09:50 +00:00
|
|
|
if (U_FAILURE (*err) || (mySharedConverterData == NULL))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* share it with other library clients */
|
|
|
|
ucnv_shareConverterData(mySharedConverterData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The data for this converter was already in the cache. */
|
|
|
|
/* Update the reference counter on the shared data: one more client */
|
|
|
|
mySharedConverterData->referenceCounter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mySharedConverterData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unload a non-algorithmic converter.
|
|
|
|
* It must be sharedData->referenceCounter != ~0
|
|
|
|
* and this function must be called inside umtx_lock(&cnvCacheMutex).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ucnv_unload(UConverterSharedData *sharedData) {
|
|
|
|
if(sharedData != NULL) {
|
|
|
|
if (sharedData->referenceCounter > 0) {
|
|
|
|
sharedData->referenceCounter--;
|
|
|
|
}
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
if((sharedData->referenceCounter <= 0)&&(sharedData->sharedDataCached == FALSE)) {
|
|
|
|
ucnv_deleteSharedConverterData(sharedData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-07 00:53:32 +00:00
|
|
|
void
|
|
|
|
ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData)
|
|
|
|
{
|
|
|
|
/*
|
2003-12-16 05:16:55 +00:00
|
|
|
Checking whether it's an algorithic converter is okay
|
|
|
|
in multithreaded applications because the value never changes.
|
|
|
|
Don't check referenceCounter for any other value.
|
2003-05-07 00:53:32 +00:00
|
|
|
*/
|
2003-12-16 05:16:55 +00:00
|
|
|
if(sharedData != NULL && sharedData->referenceCounter != ~0) {
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
2003-11-08 00:09:50 +00:00
|
|
|
ucnv_unload(sharedData);
|
2003-12-16 05:16:55 +00:00
|
|
|
umtx_unlock(&cnvCacheMutex);
|
2003-05-07 00:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ucnv_incrementRefCount(UConverterSharedData *sharedData)
|
|
|
|
{
|
2003-12-16 05:16:55 +00:00
|
|
|
if(sharedData != NULL && sharedData->referenceCounter != ~0) {
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
2003-05-07 00:53:32 +00:00
|
|
|
sharedData->referenceCounter++;
|
2003-12-16 05:16:55 +00:00
|
|
|
umtx_unlock(&cnvCacheMutex);
|
2003-05-07 00:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-22 20:15:09 +00:00
|
|
|
static void
|
|
|
|
parseConverterOptions(const char *inName,
|
2002-07-02 19:21:35 +00:00
|
|
|
char *cnvName,
|
|
|
|
char *locale,
|
|
|
|
uint32_t *pFlags,
|
|
|
|
UErrorCode *err)
|
|
|
|
{
|
2000-05-22 20:15:09 +00:00
|
|
|
char c;
|
2002-07-02 19:21:35 +00:00
|
|
|
int32_t len = 0;
|
2000-05-22 20:15:09 +00:00
|
|
|
|
|
|
|
/* copy the converter name itself to cnvName */
|
|
|
|
while((c=*inName)!=0 && c!=UCNV_OPTION_SEP_CHAR) {
|
2002-07-02 19:21:35 +00:00
|
|
|
if (++len>=UCNV_MAX_CONVERTER_NAME_LENGTH) {
|
2002-07-03 20:18:36 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR; /* bad name */
|
2002-07-02 21:42:29 +00:00
|
|
|
*cnvName=0;
|
2002-07-02 19:21:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-05-22 20:15:09 +00:00
|
|
|
*cnvName++=c;
|
2002-07-02 19:21:35 +00:00
|
|
|
inName++;
|
2000-05-22 20:15:09 +00:00
|
|
|
}
|
|
|
|
*cnvName=0;
|
|
|
|
|
2002-07-02 19:21:35 +00:00
|
|
|
/* parse options. No more name copying should occur. */
|
2002-09-18 01:42:32 +00:00
|
|
|
while((c=*inName)!=0) {
|
|
|
|
if(c==UCNV_OPTION_SEP_CHAR) {
|
|
|
|
++inName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inName is behind an option separator */
|
|
|
|
if(uprv_strncmp(inName, "locale=", 7)==0) {
|
|
|
|
/* do not modify locale itself in case we have multiple locale options */
|
|
|
|
char *dest=locale;
|
|
|
|
|
|
|
|
/* copy the locale option value */
|
|
|
|
inName+=7;
|
|
|
|
len=0;
|
|
|
|
while((c=*inName)!=0 && c!=UCNV_OPTION_SEP_CHAR) {
|
|
|
|
++inName;
|
|
|
|
|
|
|
|
if(++len>=ULOC_FULLNAME_CAPACITY) {
|
|
|
|
*err=U_ILLEGAL_ARGUMENT_ERROR; /* bad name */
|
|
|
|
*locale=0;
|
|
|
|
return;
|
2000-05-22 20:15:09 +00:00
|
|
|
}
|
2002-09-18 01:42:32 +00:00
|
|
|
|
|
|
|
*dest++=c;
|
|
|
|
}
|
|
|
|
*dest=0;
|
|
|
|
} else if(uprv_strncmp(inName, "version=", 8)==0) {
|
|
|
|
/* copy the version option value into bits 3..0 of *pFlags */
|
|
|
|
inName+=8;
|
|
|
|
c=*inName;
|
|
|
|
if(c==0) {
|
|
|
|
*pFlags&=~UCNV_OPTION_VERSION;
|
|
|
|
return;
|
|
|
|
} else if((uint8_t)(c-'0')<10) {
|
|
|
|
*pFlags=(*pFlags&~UCNV_OPTION_VERSION)|(uint32_t)(c-'0');
|
|
|
|
++inName;
|
|
|
|
}
|
|
|
|
} else if(uprv_strncmp(inName, "swaplfnl", 8)==0) {
|
|
|
|
inName+=8;
|
|
|
|
*pFlags|=UCNV_OPTION_SWAP_LFNL;
|
|
|
|
/* add processing for new options here with another } else if(uprv_strncmp(inName, "option-name=", XX)==0) { */
|
|
|
|
} else {
|
|
|
|
/* ignore any other options until we define some */
|
2003-05-08 01:32:27 +00:00
|
|
|
while(((c = *inName++) != 0) && (c != UCNV_OPTION_SEP_CHAR)) {
|
|
|
|
}
|
|
|
|
if(c==0) {
|
|
|
|
return;
|
|
|
|
}
|
2000-05-22 20:15:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*Logic determines if the converter is Algorithmic AND/OR cached
|
|
|
|
*depending on that:
|
|
|
|
* -we either go to get data from disk and cache it (Data=TRUE, Cached=False)
|
|
|
|
* -Get it from a Hashtable (Data=X, Cached=TRUE)
|
|
|
|
* -Call dataConverter initializer (Data=TRUE, Cached=TRUE)
|
|
|
|
* -Call AlgorithmicConverter initializer (Data=FALSE, Cached=TRUE)
|
|
|
|
*/
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverterSharedData *
|
|
|
|
ucnv_loadSharedData(const char *converterName, UConverterLookupData *lookup, UErrorCode * err) {
|
|
|
|
UConverterLookupData stackLookup;
|
2001-08-11 00:29:58 +00:00
|
|
|
UConverterSharedData *mySharedConverterData = NULL;
|
|
|
|
UErrorCode internalErrorCode = U_ZERO_ERROR;
|
2003-11-21 23:24:11 +00:00
|
|
|
|
|
|
|
if (U_FAILURE (*err)) {
|
2003-12-16 05:16:55 +00:00
|
|
|
return NULL;
|
2003-11-21 23:24:11 +00:00
|
|
|
}
|
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
if(lookup == NULL) {
|
|
|
|
lookup = &stackLookup;
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
lookup->locale[0] = 0;
|
|
|
|
lookup->options = 0;
|
2001-08-11 00:29:58 +00:00
|
|
|
|
|
|
|
/* In case "name" is NULL we want to open the default converter. */
|
|
|
|
if (converterName == NULL) {
|
2005-05-08 07:56:44 +00:00
|
|
|
lookup->realName = ucnv_getDefaultName();
|
2003-12-16 05:16:55 +00:00
|
|
|
if (lookup->realName == NULL) {
|
2001-08-11 00:29:58 +00:00
|
|
|
*err = U_MISSING_RESOURCE_ERROR;
|
2003-12-16 05:16:55 +00:00
|
|
|
return NULL;
|
2001-08-11 00:29:58 +00:00
|
|
|
}
|
|
|
|
/* the default converter name is already canonical */
|
|
|
|
} else {
|
|
|
|
/* separate the converter name from the options */
|
2003-12-16 05:16:55 +00:00
|
|
|
parseConverterOptions(converterName, lookup->cnvName, lookup->locale, &lookup->options, err);
|
2002-07-02 21:42:29 +00:00
|
|
|
if (U_FAILURE(*err)) {
|
|
|
|
/* Very bad name used. */
|
2003-12-16 05:16:55 +00:00
|
|
|
return NULL;
|
2002-07-02 21:42:29 +00:00
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
|
|
|
/* get the canonical converter name */
|
2003-12-16 05:16:55 +00:00
|
|
|
lookup->realName = ucnv_io_getConverterName(lookup->cnvName, &internalErrorCode);
|
|
|
|
if (U_FAILURE(internalErrorCode) || lookup->realName == NULL) {
|
2001-08-11 00:29:58 +00:00
|
|
|
/*
|
|
|
|
* set the input name in case the converter was added
|
|
|
|
* without updating the alias table, or when there is no alias table
|
|
|
|
*/
|
2003-12-16 05:16:55 +00:00
|
|
|
lookup->realName = lookup->cnvName;
|
2001-08-11 00:29:58 +00:00
|
|
|
}
|
1999-12-04 00:55:54 +00:00
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2000-05-22 20:15:09 +00:00
|
|
|
/* separate the converter name from the options */
|
2003-12-16 05:16:55 +00:00
|
|
|
if(lookup->realName != lookup->cnvName) {
|
|
|
|
parseConverterOptions(lookup->realName, lookup->cnvName, lookup->locale, &lookup->options, err);
|
|
|
|
lookup->realName = lookup->cnvName;
|
1999-12-04 00:55:54 +00:00
|
|
|
}
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* get the shared data for an algorithmic converter, if it is one */
|
2003-12-16 05:16:55 +00:00
|
|
|
mySharedConverterData = (UConverterSharedData *)getAlgorithmicTypeFromName(lookup->realName);
|
2001-08-11 00:29:58 +00:00
|
|
|
if (mySharedConverterData == NULL)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-03-12 21:54:23 +00:00
|
|
|
/* it is a data-based converter, get its shared data. */
|
|
|
|
/* Hold the cnvCacheMutex through the whole process of checking the */
|
|
|
|
/* converter data cache, and adding new entries to the cache */
|
|
|
|
/* to prevent other threads from modifying the cache during the */
|
|
|
|
/* process. */
|
2003-11-12 02:04:55 +00:00
|
|
|
UConverterLoadArgs args={ 0 };
|
|
|
|
|
|
|
|
args.size=sizeof(UConverterLoadArgs);
|
|
|
|
args.nestedLoads=1;
|
2003-12-16 05:16:55 +00:00
|
|
|
args.options=lookup->options;
|
2003-11-12 02:04:55 +00:00
|
|
|
args.pkg=NULL;
|
2003-12-16 05:16:55 +00:00
|
|
|
args.name=lookup->realName;
|
2003-11-12 02:04:55 +00:00
|
|
|
|
2002-03-12 21:54:23 +00:00
|
|
|
umtx_lock(&cnvCacheMutex);
|
2003-11-12 02:04:55 +00:00
|
|
|
mySharedConverterData = ucnv_load(&args, err);
|
2003-11-08 00:09:50 +00:00
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
if (U_FAILURE (*err) || (mySharedConverterData == NULL))
|
1999-12-04 00:55:54 +00:00
|
|
|
{
|
2003-12-16 05:16:55 +00:00
|
|
|
return NULL;
|
1999-12-04 00:55:54 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
return mySharedConverterData;
|
|
|
|
}
|
2002-07-17 02:34:50 +00:00
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
UConverter *
|
|
|
|
ucnv_createConverter(UConverter *myUConverter, const char *converterName, UErrorCode * err)
|
|
|
|
{
|
|
|
|
UConverterLookupData stackLookup;
|
|
|
|
UConverterSharedData *mySharedConverterData;
|
|
|
|
|
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*err)) {
|
|
|
|
UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open converter %s", converterName);
|
|
|
|
|
|
|
|
mySharedConverterData = ucnv_loadSharedData(converterName, &stackLookup, err);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*err)) {
|
|
|
|
myUConverter = ucnv_createConverterFromSharedData(
|
|
|
|
myUConverter, mySharedConverterData,
|
|
|
|
stackLookup.realName, stackLookup.locale, stackLookup.options,
|
|
|
|
err);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*err)) {
|
|
|
|
UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
|
|
|
|
return myUConverter;
|
|
|
|
} else {
|
|
|
|
ucnv_unloadSharedDataIfReady(mySharedConverterData);
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-12-16 05:16:55 +00:00
|
|
|
/* exit with error */
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
|
|
|
return NULL;
|
2002-07-17 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
2003-04-21 02:12:46 +00:00
|
|
|
UConverter *
|
|
|
|
ucnv_createAlgorithmicConverter(UConverter *myUConverter,
|
|
|
|
UConverterType type,
|
|
|
|
const char *locale, uint32_t options,
|
|
|
|
UErrorCode *err) {
|
2003-11-21 23:24:11 +00:00
|
|
|
UConverter *cnv;
|
2003-04-21 02:12:46 +00:00
|
|
|
const UConverterSharedData *sharedData;
|
2003-05-08 01:32:27 +00:00
|
|
|
UBool isAlgorithmicConverter;
|
2003-04-21 02:12:46 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_ALGORITHMIC);
|
|
|
|
UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open algorithmic converter type %d", (int32_t)type);
|
|
|
|
|
2003-04-21 02:12:46 +00:00
|
|
|
if(type<0 || UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES<=type) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
|
2003-04-21 02:12:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sharedData = converterData[type];
|
2003-05-08 01:32:27 +00:00
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
isAlgorithmicConverter = (UBool)(sharedData == NULL || sharedData->referenceCounter != ~0);
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
if (isAlgorithmicConverter) {
|
2003-04-21 02:12:46 +00:00
|
|
|
/* not a valid type, or not an algorithmic converter */
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
|
2003-04-21 02:12:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
cnv = ucnv_createConverterFromSharedData(myUConverter, (UConverterSharedData *)sharedData, "",
|
2003-04-21 02:12:46 +00:00
|
|
|
locale != NULL ? locale : "", options, err);
|
2003-11-21 23:24:11 +00:00
|
|
|
|
|
|
|
UTRACE_EXIT_PTR_STATUS(cnv, *err);
|
|
|
|
return cnv;
|
2003-04-21 02:12:46 +00:00
|
|
|
}
|
2002-07-17 02:34:50 +00:00
|
|
|
|
|
|
|
UConverter*
|
|
|
|
ucnv_createConverterFromPackage(const char *packageName, const char *converterName, UErrorCode * err)
|
|
|
|
{
|
|
|
|
char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH], locale[ULOC_FULLNAME_CAPACITY];
|
|
|
|
UConverter *myUConverter;
|
2003-11-12 02:04:55 +00:00
|
|
|
UConverterSharedData *mySharedConverterData;
|
|
|
|
|
|
|
|
UConverterLoadArgs args={ 0 };
|
2002-07-17 02:34:50 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_PACKAGE);
|
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
if(U_FAILURE(*err)) {
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2004-11-11 23:34:58 +00:00
|
|
|
return NULL;
|
2002-07-17 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "open converter %s from package %s", converterName, packageName);
|
|
|
|
|
2003-11-12 02:04:55 +00:00
|
|
|
args.size=sizeof(UConverterLoadArgs);
|
|
|
|
args.nestedLoads=1;
|
|
|
|
args.pkg=packageName;
|
|
|
|
|
|
|
|
/* first, get the options out of the converterName string */
|
|
|
|
parseConverterOptions(converterName, cnvName, locale, &args.options, err);
|
2002-07-17 02:34:50 +00:00
|
|
|
if (U_FAILURE(*err)) {
|
|
|
|
/* Very bad name used. */
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2002-07-17 02:34:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-11-12 02:04:55 +00:00
|
|
|
args.name=cnvName;
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
/* open the data, unflatten the shared structure */
|
2003-11-12 02:04:55 +00:00
|
|
|
mySharedConverterData = createConverterFromFile(&args, err);
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
if (U_FAILURE(*err)) {
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2004-11-11 23:34:58 +00:00
|
|
|
return NULL;
|
2002-07-17 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create the actual converter */
|
2003-11-12 02:04:55 +00:00
|
|
|
myUConverter = ucnv_createConverterFromSharedData(NULL, mySharedConverterData, cnvName, locale, args.options, err);
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2002-07-17 02:34:50 +00:00
|
|
|
if (U_FAILURE(*err)) {
|
|
|
|
ucnv_close(myUConverter);
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_STATUS(*err);
|
2004-11-11 23:34:58 +00:00
|
|
|
return NULL;
|
2002-07-17 02:34:50 +00:00
|
|
|
}
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
|
2002-07-17 02:34:50 +00:00
|
|
|
return myUConverter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UConverter*
|
2003-04-21 02:12:46 +00:00
|
|
|
ucnv_createConverterFromSharedData(UConverter *myUConverter,
|
|
|
|
UConverterSharedData *mySharedConverterData,
|
|
|
|
const char *realName, const char *locale, uint32_t options,
|
|
|
|
UErrorCode *err)
|
2002-07-17 02:34:50 +00:00
|
|
|
{
|
2003-04-21 02:12:46 +00:00
|
|
|
UBool isCopyLocal;
|
2002-07-17 02:34:50 +00:00
|
|
|
|
|
|
|
if(myUConverter == NULL)
|
|
|
|
{
|
2003-04-21 02:12:46 +00:00
|
|
|
myUConverter = (UConverter *) uprv_malloc (sizeof (UConverter));
|
|
|
|
if(myUConverter == NULL)
|
|
|
|
{
|
|
|
|
*err = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
isCopyLocal = FALSE;
|
|
|
|
} else {
|
|
|
|
isCopyLocal = TRUE;
|
2002-07-17 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* initialize the converter */
|
|
|
|
uprv_memset(myUConverter, 0, sizeof(UConverter));
|
2003-04-21 02:12:46 +00:00
|
|
|
myUConverter->isCopyLocal = isCopyLocal;
|
2003-05-13 21:05:05 +00:00
|
|
|
myUConverter->isExtraLocal = FALSE;
|
2001-08-11 00:29:58 +00:00
|
|
|
myUConverter->sharedData = mySharedConverterData;
|
2002-09-18 01:42:32 +00:00
|
|
|
myUConverter->options = options;
|
2001-08-11 00:29:58 +00:00
|
|
|
myUConverter->fromCharErrorBehaviour = (UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE;
|
|
|
|
myUConverter->fromUCharErrorBehaviour = (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE;
|
|
|
|
myUConverter->toUnicodeStatus = myUConverter->sharedData->toUnicodeStatus;
|
2003-10-30 22:54:18 +00:00
|
|
|
myUConverter->maxBytesPerUChar = myUConverter->sharedData->staticData->maxBytesPerChar;
|
2001-08-11 00:29:58 +00:00
|
|
|
myUConverter->subChar1 = myUConverter->sharedData->staticData->subChar1;
|
|
|
|
myUConverter->subCharLen = myUConverter->sharedData->staticData->subCharLen;
|
|
|
|
uprv_memcpy (myUConverter->subChar, myUConverter->sharedData->staticData->subChar, myUConverter->subCharLen);
|
2003-10-25 00:29:13 +00:00
|
|
|
myUConverter->preFromUFirstCP = U_SENTINEL;
|
2001-08-11 00:29:58 +00:00
|
|
|
|
|
|
|
if(myUConverter != NULL && myUConverter->sharedData->impl->open != NULL) {
|
|
|
|
myUConverter->sharedData->impl->open(myUConverter, realName, locale,options, err);
|
|
|
|
if(U_FAILURE(*err)) {
|
|
|
|
ucnv_close(myUConverter);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-02-09 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
return myUConverter;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
static void
|
|
|
|
ucnv_flushAvailableConverterCache() {
|
|
|
|
if (gAvailableConverters) {
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
gAvailableConverterCount = 0;
|
|
|
|
uprv_free((char **)gAvailableConverters);
|
|
|
|
gAvailableConverters = NULL;
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-04 01:04:28 +00:00
|
|
|
/*Frees all shared immutable objects that aren't referred to (reference count = 0)
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-10-04 01:04:28 +00:00
|
|
|
ucnv_flushCache ()
|
|
|
|
{
|
|
|
|
UConverterSharedData *mySharedData = NULL;
|
2003-11-08 00:09:50 +00:00
|
|
|
int32_t pos;
|
2001-10-04 01:04:28 +00:00
|
|
|
int32_t tableDeletedNum = 0;
|
|
|
|
const UHashElement *e;
|
2003-04-18 20:31:45 +00:00
|
|
|
UErrorCode status = U_ILLEGAL_ARGUMENT_ERROR;
|
2003-11-08 00:09:50 +00:00
|
|
|
int32_t i, remaining;
|
2003-04-18 20:31:45 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_UCNV_FLUSH_CACHE);
|
|
|
|
|
2003-04-18 20:31:45 +00:00
|
|
|
/* Close the default converter without creating a new one so that everything will be flushed. */
|
|
|
|
ucnv_close(u_getDefaultConverter(&status));
|
2001-10-04 01:04:28 +00:00
|
|
|
|
|
|
|
/*if shared data hasn't even been lazy evaluated yet
|
|
|
|
* return 0
|
|
|
|
*/
|
2003-11-21 23:24:11 +00:00
|
|
|
if (SHARED_DATA_HASHTABLE == NULL) {
|
|
|
|
UTRACE_EXIT_VALUE((int32_t)0);
|
2001-10-04 01:04:28 +00:00
|
|
|
return 0;
|
2003-11-21 23:24:11 +00:00
|
|
|
}
|
2001-10-04 01:04:28 +00:00
|
|
|
|
|
|
|
/*creates an enumeration to iterate through every element in the
|
2002-03-12 21:54:23 +00:00
|
|
|
* table
|
|
|
|
*
|
|
|
|
* Synchronization: holding cnvCacheMutex will prevent any other thread from
|
|
|
|
* accessing or modifying the hash table during the iteration.
|
|
|
|
* The reference count of an entry may be decremented by
|
|
|
|
* ucnv_close while the iteration is in process, but this is
|
|
|
|
* benign. It can't be incremented (in ucnv_createConverter())
|
|
|
|
* because the sequence of looking up in the cache + incrementing
|
|
|
|
* is protected by cnvCacheMutex.
|
2001-10-04 01:04:28 +00:00
|
|
|
*/
|
2003-05-07 00:53:32 +00:00
|
|
|
umtx_lock(&cnvCacheMutex);
|
2003-11-08 00:09:50 +00:00
|
|
|
/*
|
|
|
|
* double loop: A delta/extension-only converter has a pointer to its base table's
|
|
|
|
* shared data; the first iteration of the outer loop may see the delta converter
|
|
|
|
* before the base converter, and unloading the delta converter may get the base
|
|
|
|
* converter's reference counter down to 0.
|
|
|
|
*/
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
remaining = 0;
|
|
|
|
pos = -1;
|
|
|
|
while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL)
|
2001-10-04 01:04:28 +00:00
|
|
|
{
|
2003-11-08 00:09:50 +00:00
|
|
|
mySharedData = (UConverterSharedData *) e->value.pointer;
|
|
|
|
/*deletes only if reference counter == 0 */
|
|
|
|
if (mySharedData->referenceCounter == 0)
|
|
|
|
{
|
|
|
|
tableDeletedNum++;
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
UCNV_DEBUG_LOG("del",mySharedData->staticData->name,mySharedData);
|
2004-11-11 23:34:58 +00:00
|
|
|
|
2003-11-08 00:09:50 +00:00
|
|
|
uhash_removeElement(SHARED_DATA_HASHTABLE, e);
|
|
|
|
mySharedData->sharedDataCached = FALSE;
|
|
|
|
ucnv_deleteSharedConverterData (mySharedData);
|
|
|
|
} else {
|
|
|
|
++remaining;
|
|
|
|
}
|
2001-10-04 01:04:28 +00:00
|
|
|
}
|
2003-11-08 00:09:50 +00:00
|
|
|
} while(++i == 1 && remaining > 0);
|
2003-05-07 00:53:32 +00:00
|
|
|
umtx_unlock(&cnvCacheMutex);
|
2001-10-04 01:04:28 +00:00
|
|
|
|
2004-01-08 21:44:54 +00:00
|
|
|
UTRACE_DATA1(UTRACE_INFO, "ucnv_flushCache() exits with %d converters remaining", remaining);
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
ucnv_flushAvailableConverterCache();
|
2002-06-13 16:43:41 +00:00
|
|
|
|
2003-11-21 23:24:11 +00:00
|
|
|
UTRACE_EXIT_VALUE(tableDeletedNum);
|
2001-10-04 01:04:28 +00:00
|
|
|
return tableDeletedNum;
|
|
|
|
}
|
|
|
|
|
2005-05-08 07:56:44 +00:00
|
|
|
/* available converters list --------------------------------------------------- */
|
|
|
|
|
|
|
|
static UBool haveAvailableConverterList(UErrorCode *pErrorCode) {
|
|
|
|
int needInit;
|
|
|
|
UMTX_CHECK(&cnvCacheMutex, (gAvailableConverters == NULL), needInit);
|
|
|
|
if (needInit) {
|
|
|
|
UConverter tempConverter;
|
|
|
|
UEnumeration *allConvEnum = NULL;
|
|
|
|
uint16_t idx;
|
|
|
|
uint16_t localConverterCount;
|
|
|
|
uint16_t allConverterCount;
|
|
|
|
UErrorCode localStatus;
|
|
|
|
const char *converterName;
|
|
|
|
const char **localConverterList;
|
|
|
|
|
|
|
|
allConvEnum = ucnv_openAllNames(pErrorCode);
|
|
|
|
allConverterCount = uenum_count(allConvEnum, pErrorCode);
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't have more than "*converterTable" converters to open */
|
|
|
|
localConverterList = (const char **) uprv_malloc(allConverterCount * sizeof(char*));
|
|
|
|
if (!localConverterList) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
localConverterCount = 0;
|
|
|
|
|
|
|
|
for (idx = 0; idx < allConverterCount; idx++) {
|
|
|
|
localStatus = U_ZERO_ERROR;
|
|
|
|
converterName = uenum_next(allConvEnum, NULL, &localStatus);
|
|
|
|
ucnv_close(ucnv_createConverter(&tempConverter, converterName, &localStatus));
|
|
|
|
if (U_SUCCESS(localStatus)) {
|
|
|
|
localConverterList[localConverterCount++] = converterName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uenum_close(allConvEnum);
|
|
|
|
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
if (gAvailableConverters == NULL) {
|
|
|
|
gAvailableConverters = localConverterList;
|
|
|
|
gAvailableConverterCount = localConverterCount;
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uprv_free((char **)localConverterList);
|
|
|
|
}
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC uint16_t
|
|
|
|
ucnv_bld_countAvailableConverters(UErrorCode *pErrorCode) {
|
|
|
|
if (haveAvailableConverterList(pErrorCode)) {
|
|
|
|
return gAvailableConverterCount;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC const char *
|
|
|
|
ucnv_bld_getAvailableConverter(uint16_t n, UErrorCode *pErrorCode) {
|
|
|
|
if (haveAvailableConverterList(pErrorCode)) {
|
|
|
|
if (n < gAvailableConverterCount) {
|
|
|
|
return gAvailableConverters[n];
|
|
|
|
}
|
|
|
|
*pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default converter name --------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to be really thread-safe, the get function would have to take
|
|
|
|
* a buffer parameter and copy the current string inside a mutex block.
|
|
|
|
* This implementation only tries to be really thread-safe while
|
|
|
|
* setting the name.
|
|
|
|
* It assumes that setting a pointer is atomic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ucnv_getDefaultName() {
|
|
|
|
/* local variable to be thread-safe */
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
UMTX_CHECK(&cnvCacheMutex, gDefaultConverterName, name);
|
|
|
|
if(name==NULL) {
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
UConverter *cnv = NULL;
|
|
|
|
int32_t length = 0;
|
|
|
|
|
|
|
|
name = uprv_getDefaultCodepage();
|
|
|
|
|
|
|
|
/* if the name is there, test it out and get the canonical name with options */
|
|
|
|
if(name != NULL) {
|
|
|
|
cnv = ucnv_open(name, &errorCode);
|
|
|
|
if(U_SUCCESS(errorCode) && cnv != NULL) {
|
|
|
|
name = ucnv_getName(cnv, &errorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name == NULL || name[0] == 0
|
|
|
|
|| U_FAILURE(errorCode) || cnv == NULL
|
|
|
|
|| length>=sizeof(gDefaultConverterNameBuffer))
|
|
|
|
{
|
|
|
|
/* Panic time, let's use a fallback. */
|
|
|
|
#if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
|
|
|
|
name = "US-ASCII";
|
|
|
|
/* there is no 'algorithmic' converter for EBCDIC */
|
|
|
|
#elif defined(OS390)
|
|
|
|
name = "ibm-1047_P100-1995" UCNV_SWAP_LFNL_OPTION_STRING;
|
|
|
|
#else
|
|
|
|
name = "ibm-37_P100-1995";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
length=(int32_t)(uprv_strlen(name));
|
|
|
|
|
|
|
|
/* Copy the name before we close the converter. */
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
uprv_memcpy(gDefaultConverterNameBuffer, name, length);
|
|
|
|
gDefaultConverterNameBuffer[length]=0;
|
|
|
|
gDefaultConverterName = gDefaultConverterNameBuffer;
|
|
|
|
name = gDefaultConverterName;
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
|
|
|
|
/* The close may make the current name go away. */
|
|
|
|
ucnv_close(cnv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucnv_setDefaultName(const char *converterName) {
|
|
|
|
if(converterName==NULL) {
|
|
|
|
/* reset to the default codepage */
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
gDefaultConverterName=NULL;
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
} else {
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const char *name=ucnv_io_getConverterName(converterName, &errorCode);
|
|
|
|
|
|
|
|
umtx_lock(&cnvCacheMutex);
|
|
|
|
|
|
|
|
if(U_SUCCESS(errorCode) && name!=NULL) {
|
|
|
|
gDefaultConverterName=name;
|
|
|
|
} else {
|
|
|
|
/* do not set the name if the alias lookup failed and it is too long */
|
|
|
|
int32_t length=(int32_t)(uprv_strlen(converterName));
|
|
|
|
if(length<sizeof(gDefaultConverterNameBuffer)) {
|
|
|
|
/* it was not found as an alias, so copy it - accept an empty name */
|
|
|
|
uprv_memcpy(gDefaultConverterNameBuffer, converterName, length);
|
|
|
|
gDefaultConverterNameBuffer[length]=0;
|
|
|
|
gDefaultConverterName=gDefaultConverterNameBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
umtx_unlock(&cnvCacheMutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-22 13:57:19 +00:00
|
|
|
/* data swapping ------------------------------------------------------------ */
|
|
|
|
|
|
|
|
/* most of this might belong more properly into ucnvmbcs.c, but that is so large */
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucnv_swap(const UDataSwapper *ds,
|
|
|
|
const void *inData, int32_t length, void *outData,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
const UDataInfo *pInfo;
|
|
|
|
int32_t headerSize;
|
|
|
|
|
|
|
|
const uint8_t *inBytes;
|
|
|
|
uint8_t *outBytes;
|
|
|
|
|
|
|
|
uint32_t offset, count, staticDataSize;
|
|
|
|
int32_t size;
|
|
|
|
|
|
|
|
const UConverterStaticData *inStaticData;
|
|
|
|
UConverterStaticData *outStaticData;
|
|
|
|
|
|
|
|
const _MBCSHeader *inMBCSHeader;
|
|
|
|
_MBCSHeader *outMBCSHeader;
|
|
|
|
_MBCSHeader mbcsHeader;
|
|
|
|
uint8_t outputType;
|
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
const int32_t *inExtIndexes;
|
|
|
|
int32_t extOffset;
|
|
|
|
|
2003-09-22 13:57:19 +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]==0x63 && /* dataFormat="cnvt" */
|
|
|
|
pInfo->dataFormat[1]==0x6e &&
|
|
|
|
pInfo->dataFormat[2]==0x76 &&
|
|
|
|
pInfo->dataFormat[3]==0x74 &&
|
|
|
|
pInfo->formatVersion[0]==6 &&
|
|
|
|
pInfo->formatVersion[1]>=2
|
|
|
|
)) {
|
|
|
|
udata_printError(ds, "ucnv_swap(): data format %02x.%02x.%02x.%02x (format version %02x.%02x) is not recognized as an ICU .cnv conversion table\n",
|
|
|
|
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
|
|
|
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
|
|
|
pInfo->formatVersion[0], pInfo->formatVersion[1]);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inBytes=(const uint8_t *)inData+headerSize;
|
|
|
|
outBytes=(uint8_t *)outData+headerSize;
|
|
|
|
|
|
|
|
/* read the initial UConverterStaticData structure after the UDataInfo header */
|
|
|
|
inStaticData=(const UConverterStaticData *)inBytes;
|
|
|
|
outStaticData=(UConverterStaticData *)outBytes;
|
|
|
|
|
|
|
|
if(length<0) {
|
|
|
|
staticDataSize=ds->readUInt32(inStaticData->structSize);
|
|
|
|
} else {
|
|
|
|
length-=headerSize;
|
|
|
|
if( length<sizeof(UConverterStaticData) ||
|
|
|
|
(uint32_t)length<(staticDataSize=ds->readUInt32(inStaticData->structSize))
|
|
|
|
) {
|
|
|
|
udata_printError(ds, "ucnv_swap(): too few bytes (%d after header) for an ICU .cnv conversion table\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(length>=0) {
|
|
|
|
/* swap the static data */
|
|
|
|
if(inStaticData!=outStaticData) {
|
|
|
|
uprv_memcpy(outStaticData, inStaticData, staticDataSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->swapArray32(ds, &inStaticData->structSize, 4,
|
|
|
|
&outStaticData->structSize, pErrorCode);
|
|
|
|
ds->swapArray32(ds, &inStaticData->codepage, 4,
|
|
|
|
&outStaticData->codepage, pErrorCode);
|
|
|
|
|
2004-12-08 01:05:40 +00:00
|
|
|
ds->swapInvChars(ds, inStaticData->name, (int32_t)uprv_strlen(inStaticData->name),
|
2003-09-22 13:57:19 +00:00
|
|
|
outStaticData->name, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2004-12-05 05:38:50 +00:00
|
|
|
udata_printError(ds, "ucnv_swap(): error swapping converter name\n");
|
2003-09-22 13:57:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inBytes+=staticDataSize;
|
|
|
|
outBytes+=staticDataSize;
|
|
|
|
if(length>=0) {
|
|
|
|
length-=(int32_t)staticDataSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for supported conversionType values */
|
|
|
|
if(inStaticData->conversionType==UCNV_MBCS) {
|
|
|
|
/* swap MBCS data */
|
|
|
|
inMBCSHeader=(const _MBCSHeader *)inBytes;
|
|
|
|
outMBCSHeader=(_MBCSHeader *)outBytes;
|
|
|
|
|
2005-09-20 18:59:05 +00:00
|
|
|
if(0<=length && length<sizeof(_MBCSHeader)) {
|
|
|
|
udata_printError(ds, "ucnv_swap(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!(inMBCSHeader->version[0]==4 && inMBCSHeader->version[1]>=1)) {
|
2003-09-22 13:57:19 +00:00
|
|
|
udata_printError(ds, "ucnv_swap(): unsupported _MBCSHeader.version %d.%d\n",
|
|
|
|
inMBCSHeader->version[0], inMBCSHeader->version[1]);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_memcpy(mbcsHeader.version, inMBCSHeader->version, 4);
|
|
|
|
mbcsHeader.countStates= ds->readUInt32(inMBCSHeader->countStates);
|
|
|
|
mbcsHeader.countToUFallbacks= ds->readUInt32(inMBCSHeader->countToUFallbacks);
|
|
|
|
mbcsHeader.offsetToUCodeUnits= ds->readUInt32(inMBCSHeader->offsetToUCodeUnits);
|
|
|
|
mbcsHeader.offsetFromUTable= ds->readUInt32(inMBCSHeader->offsetFromUTable);
|
|
|
|
mbcsHeader.offsetFromUBytes= ds->readUInt32(inMBCSHeader->offsetFromUBytes);
|
|
|
|
mbcsHeader.flags= ds->readUInt32(inMBCSHeader->flags);
|
|
|
|
mbcsHeader.fromUBytesLength= ds->readUInt32(inMBCSHeader->fromUBytesLength);
|
|
|
|
|
2005-09-20 18:59:05 +00:00
|
|
|
extOffset=(int32_t)(mbcsHeader.flags>>8);
|
2003-09-22 13:57:19 +00:00
|
|
|
outputType=(uint8_t)mbcsHeader.flags;
|
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* make sure that the output type is known */
|
|
|
|
switch(outputType) {
|
|
|
|
case MBCS_OUTPUT_1:
|
|
|
|
case MBCS_OUTPUT_2:
|
|
|
|
case MBCS_OUTPUT_3:
|
|
|
|
case MBCS_OUTPUT_4:
|
|
|
|
case MBCS_OUTPUT_3_EUC:
|
|
|
|
case MBCS_OUTPUT_4_EUC:
|
|
|
|
case MBCS_OUTPUT_2_SISO:
|
|
|
|
case MBCS_OUTPUT_EXT_ONLY:
|
|
|
|
/* OK */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
udata_printError(ds, "ucnv_swap(): unsupported MBCS output type 0x%x\n",
|
|
|
|
outputType);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-22 13:57:19 +00:00
|
|
|
/* calculate the length of the MBCS data */
|
2003-10-30 03:16:04 +00:00
|
|
|
if(extOffset==0) {
|
|
|
|
size=(int32_t)(mbcsHeader.offsetFromUBytes+mbcsHeader.fromUBytesLength);
|
2003-12-04 00:34:51 +00:00
|
|
|
|
|
|
|
/* avoid compiler warnings - not otherwise necessary, and the value does not matter */
|
|
|
|
inExtIndexes=NULL;
|
2003-10-30 03:16:04 +00:00
|
|
|
} else {
|
|
|
|
/* there is extension data after the base data, see ucnv_ext.h */
|
2003-11-19 00:58:12 +00:00
|
|
|
if(length>=0 && length<(extOffset+UCNV_EXT_INDEXES_MIN_LENGTH*4)) {
|
2003-10-30 03:16:04 +00:00
|
|
|
udata_printError(ds, "ucnv_swap(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table with extension data\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inExtIndexes=(const int32_t *)(inBytes+extOffset);
|
|
|
|
size=extOffset+udata_readInt32(ds, inExtIndexes[UCNV_EXT_SIZE]);
|
|
|
|
}
|
2003-09-22 13:57:19 +00:00
|
|
|
|
|
|
|
if(length>=0) {
|
|
|
|
if(length<size) {
|
|
|
|
udata_printError(ds, "ucnv_swap(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the data for inaccessible bytes */
|
|
|
|
if(inBytes!=outBytes) {
|
|
|
|
uprv_memcpy(outBytes, inBytes, size);
|
|
|
|
}
|
|
|
|
|
2004-09-16 04:00:12 +00:00
|
|
|
/* swap the MBCSHeader */
|
2003-09-22 13:57:19 +00:00
|
|
|
ds->swapArray32(ds, &inMBCSHeader->countStates, 7*4,
|
|
|
|
&outMBCSHeader->countStates, pErrorCode);
|
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
if(outputType==MBCS_OUTPUT_EXT_ONLY) {
|
|
|
|
/*
|
|
|
|
* extension-only file,
|
|
|
|
* contains a base name instead of normal base table data
|
|
|
|
*/
|
2003-09-22 13:57:19 +00:00
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* swap the base name, between the header and the extension data */
|
2004-12-08 01:05:40 +00:00
|
|
|
ds->swapInvChars(ds, inMBCSHeader+1, (int32_t)uprv_strlen((const char *)(inMBCSHeader+1)),
|
2003-10-30 03:16:04 +00:00
|
|
|
outMBCSHeader+1, pErrorCode);
|
|
|
|
} else {
|
|
|
|
/* normal file with base table data */
|
2003-09-22 13:57:19 +00:00
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* swap the state table, 1kB per state */
|
|
|
|
ds->swapArray32(ds, inMBCSHeader+1, (int32_t)(mbcsHeader.countStates*1024),
|
|
|
|
outMBCSHeader+1, pErrorCode);
|
2003-09-22 13:57:19 +00:00
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* swap the toUFallbacks[] */
|
|
|
|
offset=sizeof(_MBCSHeader)+mbcsHeader.countStates*1024;
|
|
|
|
ds->swapArray32(ds, inBytes+offset, (int32_t)(mbcsHeader.countToUFallbacks*8),
|
2003-09-22 13:57:19 +00:00
|
|
|
outBytes+offset, pErrorCode);
|
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* swap the unicodeCodeUnits[] */
|
|
|
|
offset=mbcsHeader.offsetToUCodeUnits;
|
|
|
|
count=mbcsHeader.offsetFromUTable-offset;
|
2003-09-22 13:57:19 +00:00
|
|
|
ds->swapArray16(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
/* offset to the stage 1 table, independent of the outputType */
|
|
|
|
offset=mbcsHeader.offsetFromUTable;
|
2003-09-22 13:57:19 +00:00
|
|
|
|
2003-10-30 03:16:04 +00:00
|
|
|
if(outputType==MBCS_OUTPUT_1) {
|
|
|
|
/* SBCS: swap the fromU tables, all 16 bits wide */
|
|
|
|
count=(mbcsHeader.offsetFromUBytes-offset)+mbcsHeader.fromUBytesLength;
|
2003-09-22 13:57:19 +00:00
|
|
|
ds->swapArray16(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
2003-10-30 03:16:04 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise: swap the stage tables separately */
|
|
|
|
|
|
|
|
/* stage 1 table: uint16_t[0x440 or 0x40] */
|
|
|
|
if(inStaticData->unicodeMask&UCNV_HAS_SUPPLEMENTARY) {
|
|
|
|
count=0x440*2; /* for all of Unicode */
|
|
|
|
} else {
|
|
|
|
count=0x40*2; /* only BMP */
|
|
|
|
}
|
|
|
|
ds->swapArray16(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* stage 2 table: uint32_t[] */
|
|
|
|
offset+=count;
|
|
|
|
count=mbcsHeader.offsetFromUBytes-offset;
|
2003-09-22 13:57:19 +00:00
|
|
|
ds->swapArray32(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
2003-10-30 03:16:04 +00:00
|
|
|
|
|
|
|
/* stage 3/result bytes: sometimes uint16_t[] or uint32_t[] */
|
|
|
|
offset=mbcsHeader.offsetFromUBytes;
|
|
|
|
count=mbcsHeader.fromUBytesLength;
|
|
|
|
switch(outputType) {
|
|
|
|
case MBCS_OUTPUT_2:
|
|
|
|
case MBCS_OUTPUT_3_EUC:
|
|
|
|
case MBCS_OUTPUT_2_SISO:
|
|
|
|
ds->swapArray16(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
|
|
|
break;
|
|
|
|
case MBCS_OUTPUT_4:
|
|
|
|
ds->swapArray32(ds, inBytes+offset, (int32_t)count,
|
|
|
|
outBytes+offset, pErrorCode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* just uint8_t[], nothing to swap */
|
|
|
|
break;
|
|
|
|
}
|
2003-09-22 13:57:19 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-30 03:16:04 +00:00
|
|
|
|
|
|
|
if(extOffset!=0) {
|
|
|
|
/* swap the extension data */
|
|
|
|
inBytes+=extOffset;
|
|
|
|
outBytes+=extOffset;
|
|
|
|
|
|
|
|
/* swap toUTable[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_LENGTH]);
|
|
|
|
ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap toUUChars[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_UCHARS_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_UCHARS_LENGTH]);
|
|
|
|
ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap fromUTableUChars[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_UCHARS_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_LENGTH]);
|
|
|
|
ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap fromUTableValues[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_VALUES_INDEX]);
|
|
|
|
/* same length as for fromUTableUChars[] */
|
|
|
|
ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* no need to swap fromUBytes[] */
|
|
|
|
|
|
|
|
/* swap fromUStage12[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_12_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_12_LENGTH]);
|
|
|
|
ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap fromUStage3[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3_LENGTH]);
|
|
|
|
ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap fromUStage3b[] */
|
|
|
|
offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3B_INDEX]);
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3B_LENGTH]);
|
|
|
|
ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
|
|
|
|
|
|
|
|
/* swap indexes[] */
|
|
|
|
length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_INDEXES_LENGTH]);
|
|
|
|
ds->swapArray32(ds, inBytes, length*4, outBytes, pErrorCode);
|
|
|
|
}
|
2003-09-22 13:57:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
udata_printError(ds, "ucnv_swap(): unknown conversionType=%d!=UCNV_MBCS\n",
|
|
|
|
inStaticData->conversionType);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return headerSize+(int32_t)staticDataSize+size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
#endif
|