1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
* Copyright (C) 1998-2001, 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
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
|
|
|
* ucnv.c:
|
2001-03-17 22:13:27 +00:00
|
|
|
* Implements APIs for the ICU's codeset conversion library;
|
|
|
|
* mostly calls through internal functions;
|
|
|
|
* created by Bertrand A. Damiba
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/04/99 helena Fixed internal header inclusion.
|
2000-05-12 19:59:03 +00:00
|
|
|
* 05/09/00 helena Added implementation to handle fallback mappings.
|
2000-06-20 23:42:20 +00:00
|
|
|
* 06/20/2000 helena OS/400 port changes; mostly typecast.
|
2000-01-13 23:54:23 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "umutex.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ures.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "uhash.h"
|
|
|
|
#include "ucnv_io.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "ucnv_cnv.h"
|
1999-10-18 22:48:32 +00:00
|
|
|
#include "ucnv_imp.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/uloc.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "ucnv_bld.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-14 23:11:00 +00:00
|
|
|
#if 0
|
|
|
|
/* debugging for converters */
|
|
|
|
# include <stdio.h>
|
|
|
|
void UCNV_DEBUG_LOG(char *what, char *who, void *p, int l)
|
|
|
|
{
|
|
|
|
static FILE *f = NULL;
|
|
|
|
if(f==NULL)
|
|
|
|
{
|
|
|
|
f = fopen("c:\\UCNV_DEBUG_LOG.txt", "w");
|
|
|
|
}
|
|
|
|
fprintf(f, "%-20s %-10s %p@%d\n",
|
|
|
|
who,what,p,l);
|
|
|
|
fflush(f);
|
|
|
|
}
|
|
|
|
# define UCNV_DEBUG_LOG(x,y,z) UCNV_DEBUG_LOG(x,y,z,__LINE__)
|
|
|
|
#else
|
|
|
|
# define UCNV_DEBUG_LOG(x,y,z)
|
|
|
|
#endif
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/* size of intermediate and preflighting buffers in ucnv_convert() */
|
1999-08-16 21:50:52 +00:00
|
|
|
#define CHUNK_SIZE 5*1024
|
|
|
|
|
2001-03-16 20:49:41 +00:00
|
|
|
typedef struct UAmbiguousConverter {
|
|
|
|
const char *name;
|
|
|
|
UChar variant5c;
|
|
|
|
} UAmbiguousConverter;
|
|
|
|
|
|
|
|
static const UAmbiguousConverter ambiguousConverters[]={
|
|
|
|
{ "ibm-942_P120-2000", 0xa5 },
|
|
|
|
{ "ibm-943_P130-2000", 0xa5 },
|
|
|
|
{ "ibm-33722", 0xa5 },
|
|
|
|
{ "ibm-949_P110-2000", 0x20a9 },
|
|
|
|
{ "ibm-1363_P110-2000", 0x20a9 },
|
|
|
|
{ "ISO_2022,locale=ko,version=0", 0x20a9 }
|
2001-01-23 18:10:46 +00:00
|
|
|
};
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* ucnv_getDefaultName ()
|
|
|
|
{
|
1999-12-04 00:55:54 +00:00
|
|
|
return ucnv_io_getDefaultConverterName();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ucnv_setDefaultName (const char *converterName)
|
|
|
|
{
|
1999-12-04 00:55:54 +00:00
|
|
|
ucnv_io_setDefaultConverterName(converterName);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
/*Calls through createConverter */
|
|
|
|
UConverter* ucnv_open (const char *name,
|
2000-08-11 01:27:17 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-12-04 00:55:54 +00:00
|
|
|
if (err == NULL || U_FAILURE (*err)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
1999-12-04 00:55:54 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-04 00:55:54 +00:00
|
|
|
return createConverter (name, err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Extracts the UChar* to a char* and calls through createConverter */
|
|
|
|
UConverter* ucnv_openU (const UChar * name,
|
2000-08-11 01:27:17 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
char asciiName[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
if (name == NULL)
|
|
|
|
return ucnv_open (NULL, err);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (u_strlen (name) > UCNV_MAX_CONVERTER_NAME_LENGTH)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ucnv_open (u_austrcpy (asciiName, name), err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Assumes a $platform-#codepage.$CONVERTER_FILE_EXTENSION scheme and calls
|
|
|
|
*through createConverter*/
|
|
|
|
UConverter* ucnv_openCCSID (int32_t codepage,
|
2000-08-11 01:27:17 +00:00
|
|
|
UConverterPlatform platform,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
char myName[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
copyPlatformString (myName, platform);
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_strcat (myName, "-");
|
|
|
|
T_CString_integerToString (myName + uprv_strlen (myName), codepage, 10);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
return createConverter (myName, err);
|
|
|
|
}
|
|
|
|
|
2001-02-16 22:22:40 +00:00
|
|
|
/* Creating a temporary stack-based object that can be used in one thread,
|
|
|
|
and created from a converter that is shared across threads.
|
|
|
|
*/
|
|
|
|
|
|
|
|
UConverter *ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status)
|
|
|
|
{
|
|
|
|
UConverter * localConverter;
|
|
|
|
int32_t bufferSizeNeeded;
|
|
|
|
|
|
|
|
if (status == NULL || U_FAILURE(*status)){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!pBufferSize || !cnv){
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
if (cnv->sharedData->impl->safeClone != NULL) {
|
|
|
|
/* call the custom safeClone function for sizing */
|
|
|
|
bufferSizeNeeded = 0;
|
|
|
|
cnv->sharedData->impl->safeClone(cnv, stackBuffer, &bufferSizeNeeded, status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufferSizeNeeded = sizeof(UConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pBufferSize == 0){ /* 'preflighting' request - set needed size into *pBufferSize */
|
|
|
|
*pBufferSize = bufferSizeNeeded;
|
|
|
|
return 0;
|
2001-02-16 22:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*pBufferSize < bufferSizeNeeded || stackBuffer == NULL)
|
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
/* allocate one here...*/
|
|
|
|
localConverter = createConverter (ucnv_getName (cnv, status), status);
|
|
|
|
if (U_SUCCESS(*status))
|
|
|
|
{
|
|
|
|
*status = U_SAFECLONE_ALLOCATED_ERROR;
|
|
|
|
}
|
2001-02-16 22:22:40 +00:00
|
|
|
} else {
|
2001-03-21 20:44:20 +00:00
|
|
|
if (cnv->sharedData->impl->safeClone != NULL) {
|
|
|
|
/* call the custom safeClone function */
|
|
|
|
localConverter = cnv->sharedData->impl->safeClone(cnv, stackBuffer, pBufferSize, status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
localConverter = (UConverter *)stackBuffer;
|
|
|
|
memcpy(localConverter, cnv, sizeof(UConverter));
|
|
|
|
localConverter->isCopyLocal = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localConverter;
|
2001-02-16 22:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*Decreases the reference counter in the shared immutable section of the object
|
|
|
|
*and frees the mutable part*/
|
|
|
|
|
|
|
|
void ucnv_close (UConverter * converter)
|
|
|
|
{
|
2000-07-15 20:47:31 +00:00
|
|
|
/* first, notify the callback functions that the converter is closed */
|
|
|
|
UConverterToUnicodeArgs toUArgs = {
|
|
|
|
sizeof(UConverterToUnicodeArgs),
|
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
UConverterFromUnicodeArgs fromUArgs = {
|
|
|
|
sizeof(UConverterFromUnicodeArgs),
|
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
UErrorCode errorCode;
|
|
|
|
|
2001-02-16 22:22:40 +00:00
|
|
|
if (converter == NULL || converter->isCopyLocal)
|
2000-07-15 20:47:31 +00:00
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
2000-07-15 20:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toUArgs.converter = fromUArgs.converter = converter;
|
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_CLOSE, &errorCode);
|
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLOSE, &errorCode);
|
2000-02-08 23:41:16 +00:00
|
|
|
|
|
|
|
if (converter->sharedData->impl->close != NULL) {
|
|
|
|
converter->sharedData->impl->close(converter);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-02-05 00:19:15 +00:00
|
|
|
if (converter->sharedData->referenceCounter != ~0) {
|
|
|
|
umtx_lock (NULL);
|
|
|
|
if (converter->sharedData->referenceCounter != 0) {
|
|
|
|
converter->sharedData->referenceCounter--;
|
|
|
|
}
|
|
|
|
umtx_unlock (NULL);
|
|
|
|
}
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_free (converter);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Frees all shared immutable objects that aren't referred to (reference count = 0)
|
|
|
|
*/
|
|
|
|
int32_t ucnv_flushCache ()
|
|
|
|
{
|
|
|
|
UConverterSharedData *mySharedData = NULL;
|
|
|
|
int32_t pos = -1;
|
|
|
|
int32_t tableDeletedNum = 0;
|
2000-03-30 04:17:27 +00:00
|
|
|
const UHashElement *e;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*if shared data hasn't even been lazy evaluated yet
|
|
|
|
* return 0
|
|
|
|
*/
|
|
|
|
if (SHARED_DATA_HASHTABLE == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*creates an enumeration to iterate through every element in the
|
|
|
|
*table
|
|
|
|
*/
|
1999-09-30 23:47:52 +00:00
|
|
|
umtx_lock (NULL);
|
2000-03-28 22:04:39 +00:00
|
|
|
while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-03-28 22:04:39 +00:00
|
|
|
mySharedData = (UConverterSharedData *) e->value;
|
1999-08-16 21:50:52 +00:00
|
|
|
/*deletes only if reference counter == 0 */
|
|
|
|
if (mySharedData->referenceCounter == 0)
|
2000-03-28 22:04:39 +00:00
|
|
|
{
|
|
|
|
tableDeletedNum++;
|
1999-09-30 23:47:52 +00:00
|
|
|
|
2000-08-14 23:11:00 +00:00
|
|
|
UCNV_DEBUG_LOG("del",mySharedData->staticData->name,mySharedData);
|
|
|
|
|
2000-03-28 22:04:39 +00:00
|
|
|
uhash_removeElement(SHARED_DATA_HASHTABLE, e);
|
|
|
|
deleteSharedConverterData (mySharedData);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-09-30 23:47:52 +00:00
|
|
|
umtx_unlock (NULL);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return tableDeletedNum;
|
|
|
|
}
|
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
/*returns a single Name from the list, will return NULL if out of bounds
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2000-04-14 05:22:29 +00:00
|
|
|
const char* ucnv_getAvailableName (int32_t n)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-14 05:22:29 +00:00
|
|
|
if (0 <= n && n <= 0xffff) {
|
1999-11-23 23:02:55 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2000-04-14 05:22:29 +00:00
|
|
|
const char *name = ucnv_io_getAvailableConverter((uint16_t)n, &err);
|
1999-11-23 23:02:55 +00:00
|
|
|
if (U_SUCCESS(err)) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ucnv_countAvailable ()
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
1999-12-14 00:37:27 +00:00
|
|
|
return ucnv_io_countAvailableConverters(&err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 23:29:01 +00:00
|
|
|
U_CAPI uint16_t
|
|
|
|
ucnv_countAliases(const char *alias, UErrorCode *pErrorCode) {
|
|
|
|
const char *p;
|
|
|
|
return ucnv_io_getAliases(alias, &p, pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI const char *
|
2000-04-14 05:22:29 +00:00
|
|
|
ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode) {
|
|
|
|
return ucnv_io_getAlias(alias, n, pErrorCode);
|
2000-01-14 23:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode) {
|
2000-01-20 00:33:18 +00:00
|
|
|
const char *p;
|
2000-01-14 23:29:01 +00:00
|
|
|
uint16_t count=ucnv_io_getAliases(alias, &p, pErrorCode);
|
|
|
|
while(count>0) {
|
2000-01-20 00:33:18 +00:00
|
|
|
*aliases++=p;
|
2000-01-14 23:29:01 +00:00
|
|
|
/* skip a name, first the canonical converter name */
|
2000-01-20 00:33:18 +00:00
|
|
|
p+=uprv_strlen(p)+1;
|
2000-01-14 23:29:01 +00:00
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-17 19:28:31 +00:00
|
|
|
U_CAPI uint16_t
|
|
|
|
ucnv_countStandards(void) {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
return ucnv_io_countStandards(&err);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void ucnv_getSubstChars (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
char *mySubChar,
|
|
|
|
int8_t * len,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
if (*len < converter->subCharLen) /*not enough space in subChars */
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_INDEX_OUTOFBOUNDS_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
uprv_memcpy (mySubChar, converter->subChar, converter->subCharLen); /*fills in the subchars */
|
|
|
|
*len = converter->subCharLen; /*store # of bytes copied to buffer */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ucnv_setSubstChars (UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
const char *mySubChar,
|
|
|
|
int8_t len,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*Makes sure that the subChar is within the codepages char length boundaries */
|
2000-04-19 23:05:27 +00:00
|
|
|
if ((len > converter->sharedData->staticData->maxBytesPerChar)
|
|
|
|
|| (len < converter->sharedData->staticData->minBytesPerChar))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
uprv_memcpy (converter->subChar, mySubChar, len); /*copies the subchars */
|
|
|
|
converter->subCharLen = len; /*sets the new len */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-02-26 19:51:20 +00:00
|
|
|
/*
|
|
|
|
* There is currently (2001Feb) no separate API to set/get subChar1.
|
|
|
|
* In order to always have subChar written after it is explicitly set,
|
|
|
|
* we set subChar1 to 0.
|
|
|
|
*/
|
|
|
|
converter->subChar1 = 0;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t ucnv_getDisplayName (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
const char *displayLocale,
|
|
|
|
UChar * displayName,
|
|
|
|
int32_t displayNameCapacity,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
UChar stringToWriteBuffer[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar const *stringToWrite;
|
|
|
|
int32_t stringToWriteLength;
|
|
|
|
UResourceBundle *rb = NULL;
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*create an RB, init the fill-in string, gets it from the RB */
|
|
|
|
rb = ures_open (NULL, displayLocale, err);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
stringToWrite = ures_getStringByKey(rb,
|
2000-08-11 01:27:17 +00:00
|
|
|
converter->sharedData->staticData->name,
|
2000-05-15 18:39:17 +00:00
|
|
|
&stringToWriteLength,
|
2000-08-11 01:27:17 +00:00
|
|
|
err);
|
1999-08-16 21:50:52 +00:00
|
|
|
if (rb)
|
|
|
|
ures_close (rb);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/*Error While creating or getting resource from the resource bundle
|
|
|
|
*use the internal name instead
|
|
|
|
*
|
|
|
|
*sets stringToWriteLength (which accounts for a NULL terminator)
|
|
|
|
*and stringToWrite
|
|
|
|
*/
|
2000-04-19 23:05:27 +00:00
|
|
|
stringToWriteLength = uprv_strlen (converter->sharedData->staticData->name) + 1;
|
|
|
|
stringToWrite = u_uastrcpy (stringToWriteBuffer, converter->sharedData->staticData->name);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*Hides the fallback to the internal name from the user */
|
1999-10-07 00:07:53 +00:00
|
|
|
if (*err == U_MISSING_RESOURCE_ERROR)
|
2000-08-11 01:27:17 +00:00
|
|
|
*err = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*At this point we have a displayName and its length
|
|
|
|
*we want to see if it fits in the user provided params
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (stringToWriteLength <= displayNameCapacity)
|
|
|
|
{
|
|
|
|
/*it fits */
|
|
|
|
u_strcpy (displayName, stringToWrite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*it doesn't fit */
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-11 01:27:17 +00:00
|
|
|
u_strncpy (displayName, stringToWrite, displayNameCapacity);
|
1999-08-16 21:50:52 +00:00
|
|
|
/*Zero terminates the string */
|
|
|
|
if (displayNameCapacity > 0)
|
2000-08-11 01:27:17 +00:00
|
|
|
displayName[displayNameCapacity - 1] = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*if the user provided us with a with an outputLength
|
|
|
|
*buffer we'll store in it the theoretical size of the
|
|
|
|
*displayString
|
|
|
|
*/
|
|
|
|
return stringToWriteLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*resets the internal states of a converter
|
|
|
|
*goal : have the same behaviour than a freshly created converter
|
|
|
|
*/
|
2000-12-20 21:18:46 +00:00
|
|
|
static void _reset(UConverter *converter, UConverterResetChoice choice) {
|
2000-07-15 20:47:31 +00:00
|
|
|
/* first, notify the callback functions that the converter is reset */
|
|
|
|
UConverterToUnicodeArgs toUArgs = {
|
|
|
|
sizeof(UConverterToUnicodeArgs),
|
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
UConverterFromUnicodeArgs fromUArgs = {
|
|
|
|
sizeof(UConverterFromUnicodeArgs),
|
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
UErrorCode errorCode;
|
|
|
|
|
2000-07-21 23:58:31 +00:00
|
|
|
if(converter == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2000-12-20 21:18:46 +00:00
|
|
|
|
2000-07-15 20:47:31 +00:00
|
|
|
toUArgs.converter = fromUArgs.converter = converter;
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_RESET, &errorCode);
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_RESET, &errorCode);
|
|
|
|
}
|
2000-07-15 20:47:31 +00:00
|
|
|
|
|
|
|
/* now reset the converter itself */
|
2000-12-20 21:18:46 +00:00
|
|
|
if(choice<=UCNV_RESET_TO_UNICODE) {
|
|
|
|
converter->toUnicodeStatus = converter->sharedData->toUnicodeStatus;
|
|
|
|
converter->UCharErrorBufferLength = 0;
|
|
|
|
}
|
|
|
|
if(choice!=UCNV_RESET_TO_UNICODE) {
|
|
|
|
converter->fromUnicodeStatus = 0;
|
|
|
|
converter->charErrorBufferLength = 0;
|
|
|
|
}
|
|
|
|
|
2000-02-08 23:41:16 +00:00
|
|
|
if (converter->sharedData->impl->reset != NULL) {
|
2000-07-15 20:47:31 +00:00
|
|
|
/* call the custom reset function */
|
2000-12-20 21:18:46 +00:00
|
|
|
converter->sharedData->impl->reset(converter, choice);
|
|
|
|
} else if(choice<=UCNV_RESET_TO_UNICODE) {
|
2000-02-08 23:41:16 +00:00
|
|
|
converter->mode = UCNV_SI;
|
|
|
|
}
|
2000-11-17 02:40:07 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-12-20 21:18:46 +00:00
|
|
|
void ucnv_reset(UConverter *converter) {
|
|
|
|
_reset(converter, UCNV_RESET_BOTH);
|
2000-11-17 02:40:07 +00:00
|
|
|
}
|
|
|
|
|
2000-12-20 21:18:46 +00:00
|
|
|
void ucnv_resetToUnicode(UConverter *converter) {
|
|
|
|
_reset(converter, UCNV_RESET_TO_UNICODE);
|
|
|
|
}
|
2000-11-17 02:40:07 +00:00
|
|
|
|
2000-12-20 21:18:46 +00:00
|
|
|
void ucnv_resetFromUnicode(UConverter *converter) {
|
|
|
|
_reset(converter, UCNV_RESET_FROM_UNICODE);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int8_t ucnv_getMaxCharSize (const UConverter * converter)
|
|
|
|
{
|
2000-04-19 23:05:27 +00:00
|
|
|
return converter->sharedData->staticData->maxBytesPerChar;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int8_t ucnv_getMinCharSize (const UConverter * converter)
|
|
|
|
{
|
2000-04-19 23:05:27 +00:00
|
|
|
return converter->sharedData->staticData->minBytesPerChar;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* ucnv_getName (const UConverter * converter, UErrorCode * err)
|
|
|
|
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
2000-11-22 02:05:29 +00:00
|
|
|
if(converter->sharedData->impl->getName){
|
|
|
|
const char* temp= converter->sharedData->impl->getName(converter);
|
|
|
|
if(temp)
|
|
|
|
return temp;
|
|
|
|
}
|
2000-04-19 23:05:27 +00:00
|
|
|
return converter->sharedData->staticData->name;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ucnv_getCCSID (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return -1;
|
|
|
|
|
2000-04-19 23:05:27 +00:00
|
|
|
return converter->sharedData->staticData->codepage;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterPlatform ucnv_getPlatform (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
|
|
|
return UCNV_UNKNOWN;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-06-20 23:42:20 +00:00
|
|
|
return (UConverterPlatform)converter->sharedData->staticData->platform;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-14 01:01:14 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucnv_getToUCallBack (const UConverter * converter,
|
|
|
|
UConverterToUCallback *action,
|
|
|
|
void **context)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-14 01:01:14 +00:00
|
|
|
*action = converter->fromCharErrorBehaviour;
|
|
|
|
*context = converter->toUContext;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-14 01:01:14 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucnv_getFromUCallBack (const UConverter * converter,
|
|
|
|
UConverterFromUCallback *action,
|
|
|
|
void **context)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-14 01:01:14 +00:00
|
|
|
*action = converter->fromUCharErrorBehaviour;
|
|
|
|
*context = converter->fromUContext;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
void ucnv_setToUCallBack (UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UConverterToUCallback newAction,
|
|
|
|
void* newContext,
|
|
|
|
UConverterToUCallback *oldAction,
|
|
|
|
void** oldContext,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
2000-06-27 20:47:56 +00:00
|
|
|
return;
|
2000-07-14 01:01:14 +00:00
|
|
|
*oldAction = converter->fromCharErrorBehaviour;
|
2000-06-27 20:47:56 +00:00
|
|
|
converter->fromCharErrorBehaviour = newAction;
|
2000-07-14 01:01:14 +00:00
|
|
|
*oldContext = converter->toUContext;
|
2000-06-27 20:47:56 +00:00
|
|
|
converter->toUContext = newContext;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-11 01:27:17 +00:00
|
|
|
void ucnv_setFromUCallBack (UConverter * converter,
|
|
|
|
UConverterFromUCallback newAction,
|
|
|
|
void* newContext,
|
|
|
|
UConverterFromUCallback *oldAction,
|
|
|
|
void** oldContext,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
2000-06-27 20:47:56 +00:00
|
|
|
return;
|
2000-07-14 01:01:14 +00:00
|
|
|
*oldAction = converter->fromUCharErrorBehaviour;
|
2000-06-27 20:47:56 +00:00
|
|
|
converter->fromUCharErrorBehaviour = newAction;
|
2000-07-14 01:01:14 +00:00
|
|
|
*oldContext = converter->fromUContext;
|
2000-06-27 20:47:56 +00:00
|
|
|
converter->fromUContext = newContext;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-08-11 01:27:17 +00:00
|
|
|
|
|
|
|
void ucnv_fromUnicode (UConverter * _this,
|
|
|
|
char **target,
|
|
|
|
const char *targetLimit,
|
|
|
|
const UChar ** source,
|
|
|
|
const UChar * sourceLimit,
|
|
|
|
int32_t* offsets,
|
|
|
|
UBool flush,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
UConverterFromUnicodeArgs args;
|
2001-03-17 22:13:27 +00:00
|
|
|
const char *t;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
* Check parameters in for all conversions
|
|
|
|
*/
|
2001-03-17 22:13:27 +00:00
|
|
|
if (err == NULL || U_FAILURE (*err)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this == NULL || target == NULL || source == NULL) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = *target;
|
|
|
|
if (targetLimit < t || sourceLimit < *source) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that the target buffer size does not exceed the number range for int32_t
|
|
|
|
* because some functions use the size rather than comparing pointers.
|
2001-03-19 20:26:30 +00:00
|
|
|
* size_t is guaranteed to be unsigned.
|
2001-03-17 22:13:27 +00:00
|
|
|
*/
|
2001-03-19 20:26:30 +00:00
|
|
|
if((size_t)(targetLimit - t) > (size_t)0x7fffffff && targetLimit > t) {
|
2001-03-17 22:13:27 +00:00
|
|
|
targetLimit = t + 0x7fffffff;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with stored carry over data. This is done in the common location
|
|
|
|
* to avoid doing it for each conversion.
|
|
|
|
*/
|
|
|
|
if (_this->charErrorBufferLength > 0)
|
|
|
|
{
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
|
|
|
|
flushInternalCharBuffer (_this,
|
2001-03-17 22:13:27 +00:00
|
|
|
(char *)t,
|
2000-08-11 01:27:17 +00:00
|
|
|
&myTargetIndex,
|
|
|
|
targetLimit - *target,
|
|
|
|
offsets?&offsets:NULL,
|
|
|
|
err);
|
1999-08-16 21:50:52 +00:00
|
|
|
*target += myTargetIndex;
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter = _this;
|
|
|
|
args.flush = flush;
|
|
|
|
args.offsets = offsets;
|
|
|
|
args.source = *source;
|
|
|
|
args.sourceLimit = sourceLimit;
|
|
|
|
args.target = *target;
|
|
|
|
args.targetLimit = targetLimit;
|
|
|
|
args.size = sizeof(args);
|
2000-02-08 23:41:16 +00:00
|
|
|
if (offsets) {
|
|
|
|
if (_this->sharedData->impl->fromUnicodeWithOffsets != NULL) {
|
2000-08-11 01:27:17 +00:00
|
|
|
_this->sharedData->impl->fromUnicodeWithOffsets(&args, err);
|
2000-07-10 20:51:54 +00:00
|
|
|
*source = args.source;
|
|
|
|
*target = args.target;
|
2000-02-08 23:41:16 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2001-01-02 23:11:11 +00:00
|
|
|
/* there is no implementation that sets offsets, set them all to -1 */
|
|
|
|
int32_t i, targetSize = targetLimit - *target;
|
2000-02-08 23:41:16 +00:00
|
|
|
|
2001-01-02 23:11:11 +00:00
|
|
|
for (i=0; i<targetSize; i++) {
|
|
|
|
offsets[i] = -1;
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*calls the specific conversion routines */
|
2000-07-10 20:51:54 +00:00
|
|
|
_this->sharedData->impl->fromUnicode(&args, err);
|
|
|
|
*source = args.source;
|
|
|
|
*target = args.target;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ucnv_toUnicode (UConverter * _this,
|
2000-08-11 01:27:17 +00:00
|
|
|
UChar ** target,
|
|
|
|
const UChar * targetLimit,
|
|
|
|
const char **source,
|
|
|
|
const char *sourceLimit,
|
|
|
|
int32_t* offsets,
|
|
|
|
UBool flush,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
UConverterToUnicodeArgs args;
|
2001-03-17 22:13:27 +00:00
|
|
|
const UChar *t;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
* Check parameters in for all conversions
|
|
|
|
*/
|
2001-03-17 22:13:27 +00:00
|
|
|
if (err == NULL || U_FAILURE (*err)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this == NULL || target == NULL || source == NULL) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = *target;
|
|
|
|
if (targetLimit < t || sourceLimit < *source) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that the target buffer size does not exceed the number range for int32_t
|
|
|
|
* because some functions use the size rather than comparing pointers.
|
2001-03-19 20:26:30 +00:00
|
|
|
* size_t is guaranteed to be unsigned.
|
2001-03-17 22:13:27 +00:00
|
|
|
*/
|
2001-03-19 20:26:30 +00:00
|
|
|
if((size_t)(targetLimit - t) > (size_t)0x3fffffff && targetLimit > t) {
|
2001-03-17 22:13:27 +00:00
|
|
|
targetLimit = t + 0x3fffffff;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with stored carry over data. This is done in the common location
|
|
|
|
* to avoid doing it for each conversion.
|
|
|
|
*/
|
|
|
|
if (_this->UCharErrorBufferLength > 0)
|
|
|
|
{
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
|
|
|
|
flushInternalUnicodeBuffer (_this,
|
2001-03-17 22:13:27 +00:00
|
|
|
(UChar *)t,
|
2000-08-11 01:27:17 +00:00
|
|
|
&myTargetIndex,
|
|
|
|
targetLimit - *target,
|
|
|
|
offsets?&offsets:NULL,
|
|
|
|
err);
|
1999-08-16 21:50:52 +00:00
|
|
|
*target += myTargetIndex;
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
2000-08-11 01:27:17 +00:00
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter = _this;
|
|
|
|
args.flush = flush;
|
|
|
|
args.offsets = offsets;
|
|
|
|
args.source = (char *) *source;
|
|
|
|
args.sourceLimit = sourceLimit;
|
|
|
|
args.target = *target;
|
|
|
|
args.targetLimit = targetLimit;
|
|
|
|
args.size = sizeof(args);
|
2000-02-08 23:41:16 +00:00
|
|
|
if (offsets) {
|
|
|
|
if (_this->sharedData->impl->toUnicodeWithOffsets != NULL) {
|
2000-08-11 01:27:17 +00:00
|
|
|
_this->sharedData->impl->toUnicodeWithOffsets(&args, err);
|
2000-07-10 20:51:54 +00:00
|
|
|
*source = args.source;
|
|
|
|
*target = args.target;
|
2000-08-11 01:27:17 +00:00
|
|
|
return;
|
2000-02-08 23:41:16 +00:00
|
|
|
} else {
|
2001-01-02 23:11:11 +00:00
|
|
|
/* there is no implementation that sets offsets, set them all to -1 */
|
|
|
|
int32_t i, targetSize = targetLimit - *target;
|
2000-02-08 23:41:16 +00:00
|
|
|
|
2001-01-02 23:11:11 +00:00
|
|
|
for (i=0; i<targetSize; i++) {
|
|
|
|
offsets[i] = -1;
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-02-08 23:41:16 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*calls the specific conversion routines */
|
2000-07-10 20:51:54 +00:00
|
|
|
_this->sharedData->impl->toUnicode(&args, err);
|
2000-08-11 01:27:17 +00:00
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
*source = args.source;
|
|
|
|
*target = args.target;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ucnv_fromUChars (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
char *target,
|
|
|
|
int32_t targetSize,
|
|
|
|
const UChar * source,
|
|
|
|
int32_t sourceSize,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const UChar *mySource_limit;
|
2000-03-07 01:42:40 +00:00
|
|
|
int32_t mySourceLength = sourceSize;
|
1999-08-16 21:50:52 +00:00
|
|
|
UConverter myConverter;
|
1999-10-25 22:20:12 +00:00
|
|
|
char *myTarget_limit;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t targetCapacity = 0;
|
2000-07-10 20:51:54 +00:00
|
|
|
UConverterFromUnicodeArgs args;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((converter == NULL) || (targetSize < 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*makes a local copy of the UConverter */
|
|
|
|
myConverter = *converter;
|
|
|
|
|
|
|
|
|
|
|
|
/*Removes all state info on the UConverter */
|
|
|
|
ucnv_reset (&myConverter);
|
|
|
|
|
|
|
|
/*if the source is empty we return immediately */
|
2000-03-07 01:42:40 +00:00
|
|
|
if (sourceSize == -1) {
|
|
|
|
mySourceLength = u_strlen (source);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
if (mySourceLength == 0)
|
|
|
|
{
|
|
|
|
/*for consistency we still need to
|
|
|
|
*store 0 in the targetCapacity
|
|
|
|
*if the user requires it
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
mySource_limit = source + mySourceLength;
|
1999-10-25 22:20:12 +00:00
|
|
|
myTarget_limit = target + targetSize;
|
|
|
|
|
2000-03-07 01:26:15 +00:00
|
|
|
/* Pin the limit to U_MAX_PTR. NULL check is for AS/400. */
|
2000-12-15 19:29:55 +00:00
|
|
|
if((myTarget_limit < target) || ( (myTarget_limit == NULL) &&
|
|
|
|
(target != NULL))) {
|
2001-02-21 01:30:39 +00:00
|
|
|
myTarget_limit = (char *)U_MAX_PTR(target);
|
2000-03-07 01:26:15 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter = &myConverter;
|
|
|
|
args.flush = TRUE;
|
|
|
|
args.offsets = NULL;
|
|
|
|
args.source = source;
|
|
|
|
args.sourceLimit = mySource_limit;
|
|
|
|
args.target = target;
|
|
|
|
args.targetLimit = myTarget_limit;
|
|
|
|
args.size = sizeof(args);
|
1999-08-16 21:50:52 +00:00
|
|
|
if (targetSize > 0)
|
|
|
|
{
|
2001-02-24 02:41:29 +00:00
|
|
|
/*
|
|
|
|
* ISO-2022 converters contain state information
|
|
|
|
* as soon as they are opened so we need to
|
|
|
|
* deal with the stored carry over data
|
|
|
|
*/
|
|
|
|
if (args.converter->charErrorBufferLength > 0)
|
|
|
|
{
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
|
|
|
|
flushInternalCharBuffer (args.converter,
|
|
|
|
args.target,
|
|
|
|
&myTargetIndex,
|
|
|
|
targetSize,
|
|
|
|
NULL,
|
|
|
|
err);
|
|
|
|
args.target+=myTargetIndex;
|
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
/*calls the specific conversion routines */
|
|
|
|
args.converter->sharedData->impl->fromUnicode(&args, err);
|
|
|
|
|
|
|
|
targetCapacity = args.target - target;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Updates targetCapacity to contain the number of bytes written to target */
|
|
|
|
|
|
|
|
/* If the output buffer is exhausted, we need to stop writing
|
|
|
|
* to it but continue the conversion in order to store in targetSize
|
|
|
|
* the number of bytes that was required*/
|
2000-08-11 19:39:34 +00:00
|
|
|
if (*err == U_BUFFER_OVERFLOW_ERROR || targetSize == 0)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
char target2[CHUNK_SIZE];
|
|
|
|
const char *target2_limit = target2 + CHUNK_SIZE;
|
|
|
|
|
|
|
|
/*We use a stack allocated buffer around which we loop
|
|
|
|
*(in case the output is greater than CHUNK_SIZE)
|
|
|
|
*/
|
2000-08-11 19:39:34 +00:00
|
|
|
do
|
2000-08-11 01:27:17 +00:00
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
args.target = target2;
|
|
|
|
args.targetLimit = target2_limit;
|
|
|
|
args.converter->sharedData->impl->fromUnicode(&args, err);
|
|
|
|
/*updates the output parameter to contain the number of char required */
|
2000-08-11 19:39:34 +00:00
|
|
|
targetCapacity += (args.target - target2);
|
|
|
|
} while (*err == U_BUFFER_OVERFLOW_ERROR);
|
|
|
|
/*We will set the error code to U_BUFFER_OVERFLOW_ERROR only if
|
1999-08-16 21:50:52 +00:00
|
|
|
*nothing graver happened in the previous loop*/
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS (*err))
|
2000-08-11 01:27:17 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return targetCapacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ucnv_toUChars (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UChar * target,
|
|
|
|
int32_t targetSize,
|
|
|
|
const char *source,
|
|
|
|
int32_t sourceSize,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const char *mySource_limit = source + sourceSize;
|
|
|
|
UConverter myConverter;
|
1999-10-25 22:20:12 +00:00
|
|
|
UChar *myTarget_limit;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t targetCapacity;
|
2000-07-10 20:51:54 +00:00
|
|
|
UConverterToUnicodeArgs args;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (*err))
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((converter == NULL) || (targetSize < 0) || (sourceSize < 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*Means there is no work to be done */
|
|
|
|
if (sourceSize == 0)
|
|
|
|
{
|
|
|
|
/*for consistency we still need to
|
|
|
|
*store 0 in the targetCapacity
|
|
|
|
*if the user requires it
|
|
|
|
*/
|
|
|
|
if (targetSize >= 1)
|
2000-08-11 01:27:17 +00:00
|
|
|
{
|
|
|
|
target[0] = 0x0000;
|
|
|
|
return 1;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
else
|
2000-08-11 01:27:17 +00:00
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*makes a local copy of the UConverter */
|
|
|
|
myConverter = *converter;
|
|
|
|
|
|
|
|
/*Removes all state info on the UConverter */
|
|
|
|
ucnv_reset (&myConverter);
|
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter = &myConverter;
|
|
|
|
args.flush = TRUE;
|
|
|
|
args.offsets = NULL;
|
|
|
|
args.source = source;
|
|
|
|
args.sourceLimit = mySource_limit;
|
|
|
|
args.target = target;
|
|
|
|
args.size = sizeof(args);
|
1999-08-16 21:50:52 +00:00
|
|
|
if (targetSize > 0)
|
1999-12-23 18:40:27 +00:00
|
|
|
{
|
2001-02-21 01:30:39 +00:00
|
|
|
myTarget_limit = target + targetSize;
|
2000-03-07 01:26:15 +00:00
|
|
|
|
|
|
|
/* Pin the limit to U_MAX_PTR. NULL check is for AS/400. */
|
|
|
|
if ((myTarget_limit == NULL) || (myTarget_limit < target)) {
|
2001-02-21 01:30:39 +00:00
|
|
|
myTarget_limit = ((UChar*)U_MAX_PTR(target));
|
1999-12-23 18:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Not in pure pre-flight mode */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-10 20:51:54 +00:00
|
|
|
args.targetLimit = myTarget_limit;
|
2001-02-24 02:41:29 +00:00
|
|
|
/*
|
|
|
|
* Some converters have state immidiately after
|
|
|
|
* an open call so we need to deal with that
|
|
|
|
*/
|
|
|
|
if (args.converter->UCharErrorBufferLength > 0)
|
|
|
|
{
|
|
|
|
int32_t myTargetIndex = 0;
|
|
|
|
|
|
|
|
flushInternalUnicodeBuffer (args.converter,
|
|
|
|
args.target,
|
|
|
|
&myTargetIndex,
|
|
|
|
targetSize,
|
|
|
|
NULL,
|
|
|
|
err);
|
|
|
|
args.target += myTargetIndex;
|
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter->sharedData->impl->toUnicode(&args, err);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*Null terminates the string */
|
2000-07-10 20:51:54 +00:00
|
|
|
*(args.target) = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*Rigs targetCapacity to have at least one cell for zero termination */
|
|
|
|
/*Updates targetCapacity to contain the number of bytes written to target */
|
|
|
|
targetCapacity = 1;
|
2000-07-10 20:51:54 +00:00
|
|
|
targetCapacity += args.target - target;
|
2000-08-11 19:39:34 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* If the output buffer is exhausted, we need to stop writing
|
|
|
|
* to it but if the input buffer is not exhausted,
|
|
|
|
* we need to continue the conversion in order to store in targetSize
|
|
|
|
* the number of bytes that was required
|
|
|
|
*/
|
2000-08-11 19:39:34 +00:00
|
|
|
if (*err == U_BUFFER_OVERFLOW_ERROR || targetSize == 0)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UChar target2[CHUNK_SIZE];
|
|
|
|
const UChar *target2_limit = target2 + CHUNK_SIZE;
|
|
|
|
|
|
|
|
/*We use a stack allocated buffer around which we loop
|
|
|
|
(in case the output is greater than CHUNK_SIZE) */
|
2000-08-11 19:39:34 +00:00
|
|
|
do
|
2000-08-11 01:27:17 +00:00
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
args.target = target2;
|
|
|
|
args.targetLimit = target2_limit;
|
|
|
|
args.converter->sharedData->impl->toUnicode(&args, err);
|
|
|
|
/*updates the output parameter to contain the number of char required */
|
2000-08-11 19:39:34 +00:00
|
|
|
targetCapacity += args.target - target2;
|
|
|
|
} while (*err == U_BUFFER_OVERFLOW_ERROR);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS (*err))
|
2000-08-11 01:27:17 +00:00
|
|
|
*err = U_BUFFER_OVERFLOW_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return targetCapacity;
|
|
|
|
}
|
|
|
|
|
2000-08-11 01:27:17 +00:00
|
|
|
UChar32 ucnv_getNextUChar(UConverter * converter,
|
|
|
|
const char **source,
|
|
|
|
const char *sourceLimit,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-10 20:51:54 +00:00
|
|
|
UConverterToUnicodeArgs args;
|
|
|
|
UChar32 ch;
|
|
|
|
|
2000-07-21 23:58:31 +00:00
|
|
|
if(err == NULL || U_FAILURE(*err)) {
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
2001-03-17 22:13:27 +00:00
|
|
|
if(converter == NULL || source == NULL || sourceLimit < *source) {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* In case internal data had been stored
|
2000-04-13 17:27:35 +00:00
|
|
|
* we return the first UChar32 in the internal buffer,
|
1999-08-16 21:50:52 +00:00
|
|
|
* and update the internal state accordingly
|
|
|
|
*/
|
|
|
|
if (converter->UCharErrorBufferLength > 0)
|
|
|
|
{
|
2000-04-13 17:27:35 +00:00
|
|
|
UTextOffset i = 0;
|
|
|
|
UChar32 myUChar;
|
|
|
|
UTF_NEXT_CHAR(converter->UCharErrorBuffer, i, sizeof(converter->UCharErrorBuffer), myUChar);
|
1999-08-16 21:50:52 +00:00
|
|
|
/*In this memmove we update the internal buffer by
|
|
|
|
*popping the first character.
|
2000-12-19 00:29:27 +00:00
|
|
|
*Note that in the call itself we decrement
|
|
|
|
*UCharErrorBufferLength
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_memmove (converter->UCharErrorBuffer,
|
2000-08-11 01:27:17 +00:00
|
|
|
converter->UCharErrorBuffer + i,
|
|
|
|
(converter->UCharErrorBufferLength - i) * sizeof (UChar));
|
2000-04-13 17:27:35 +00:00
|
|
|
converter->UCharErrorBufferLength -= (int8_t)i;
|
1999-08-16 21:50:52 +00:00
|
|
|
return myUChar;
|
|
|
|
}
|
|
|
|
/*calls the specific conversion routines */
|
|
|
|
/*as dictated in a code review, avoids a switch statement */
|
2000-07-10 20:51:54 +00:00
|
|
|
args.converter = converter;
|
|
|
|
args.flush = TRUE;
|
|
|
|
args.offsets = NULL;
|
|
|
|
args.source = *source;
|
|
|
|
args.sourceLimit = sourceLimit;
|
|
|
|
args.target = NULL;
|
|
|
|
args.targetLimit = NULL;
|
|
|
|
args.size = sizeof(args);
|
2000-12-19 00:29:27 +00:00
|
|
|
if (converter->sharedData->impl->getNextUChar != NULL)
|
|
|
|
{
|
2000-12-19 01:21:32 +00:00
|
|
|
ch = converter->sharedData->impl->getNextUChar(&args, err);
|
2000-12-19 00:29:27 +00:00
|
|
|
} else {
|
2000-12-19 01:21:32 +00:00
|
|
|
/* default implementation */
|
|
|
|
ch = ucnv_getNextUCharFromToUImpl(&args, converter->sharedData->impl->toUnicode, FALSE, err);
|
2000-12-19 00:29:27 +00:00
|
|
|
}
|
2000-07-10 20:51:54 +00:00
|
|
|
*source = args.source;
|
|
|
|
return ch;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
int32_t
|
|
|
|
ucnv_convert(const char *toConverterName, const char *fromConverterName,
|
|
|
|
char *target, int32_t targetSize,
|
|
|
|
const char *source, int32_t sourceSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
UChar pivotBuffer[CHUNK_SIZE];
|
|
|
|
UChar *pivot, *pivot2;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
UConverter *inConverter, *outConverter;
|
2001-05-21 22:58:19 +00:00
|
|
|
const char *sourceLimit;
|
2001-05-19 00:55:13 +00:00
|
|
|
const char *targetLimit;
|
|
|
|
int32_t targetCapacity=0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-21 23:12:10 +00:00
|
|
|
if(sourceSize<0 || targetSize<0 || source==NULL
|
|
|
|
|| (targetSize>0 && target==NULL))
|
|
|
|
{
|
2001-05-19 00:55:13 +00:00
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/* if there is no input data, we're done */
|
|
|
|
if(sourceSize==0) {
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/* create the converters */
|
|
|
|
inConverter=ucnv_open(fromConverterName, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
outConverter=ucnv_open(toConverterName, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
ucnv_close(inConverter);
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/* set up the other variables */
|
|
|
|
sourceLimit=source+sourceSize;
|
|
|
|
pivot=pivot2=pivotBuffer;
|
|
|
|
targetCapacity=0;
|
|
|
|
|
|
|
|
if(targetSize>0) {
|
|
|
|
/* perform real conversion */
|
|
|
|
char *myTarget=target;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loops until the input buffer is completely consumed
|
|
|
|
* or an error is encountered;
|
|
|
|
* first we convert from inConverter codepage to Unicode
|
|
|
|
* then from Unicode to outConverter codepage
|
|
|
|
*/
|
|
|
|
targetLimit=target+targetSize;
|
|
|
|
do {
|
|
|
|
pivot=pivotBuffer;
|
|
|
|
ucnv_toUnicode(inConverter,
|
|
|
|
&pivot, pivotBuffer+CHUNK_SIZE,
|
|
|
|
&source, sourceLimit,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
pErrorCode);
|
|
|
|
|
|
|
|
/* U_BUFFER_OVERFLOW_ERROR only means that the pivot buffer is full */
|
|
|
|
if(U_SUCCESS(*pErrorCode) || *pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
*pErrorCode=U_ZERO_ERROR;
|
|
|
|
pivot2=pivotBuffer;
|
|
|
|
ucnv_fromUnicode(outConverter,
|
|
|
|
&myTarget, targetLimit,
|
2001-05-21 23:12:10 +00:00
|
|
|
(const UChar **)&pivot2, pivot,
|
2001-05-19 00:55:13 +00:00
|
|
|
NULL,
|
|
|
|
(UBool)(source==sourceLimit),
|
|
|
|
pErrorCode);
|
|
|
|
/*
|
|
|
|
* If this overflows the real target, then we must stop
|
|
|
|
* converting and preflight with the loop below.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
} while(U_SUCCESS(*pErrorCode) && source!=sourceLimit);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
targetCapacity=myTarget-target;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/*
|
|
|
|
* If the output buffer is exhausted (or we are only "preflighting"), we need to stop writing
|
|
|
|
* to it but continue the conversion in order to store in targetSize
|
|
|
|
* the number of bytes that was required.
|
|
|
|
*/
|
|
|
|
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR || targetSize==0) {
|
|
|
|
char targetBuffer[CHUNK_SIZE];
|
|
|
|
|
|
|
|
targetLimit=targetBuffer+CHUNK_SIZE;
|
|
|
|
do {
|
|
|
|
/* since the pivot buffer may still contain some characters, start with emptying it */
|
|
|
|
*pErrorCode=U_ZERO_ERROR;
|
|
|
|
while(pivot2!=pivot && U_SUCCESS(*pErrorCode)) {
|
|
|
|
target=targetBuffer;
|
|
|
|
ucnv_fromUnicode(outConverter,
|
|
|
|
&target, targetLimit,
|
2001-05-21 23:12:10 +00:00
|
|
|
(const UChar **)&pivot2, pivot,
|
2001-05-19 00:55:13 +00:00
|
|
|
NULL,
|
|
|
|
(UBool)(source==sourceLimit),
|
|
|
|
pErrorCode);
|
|
|
|
targetCapacity+=(target-targetBuffer);
|
|
|
|
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
*pErrorCode=U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
/* an error occurred: done */
|
|
|
|
break;
|
|
|
|
}
|
2000-08-11 01:27:17 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
if(source==sourceLimit) {
|
|
|
|
/*
|
|
|
|
* source is consumed:
|
|
|
|
* done, and set the buffer overflow error as
|
|
|
|
* the result for the entire function
|
|
|
|
*/
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-08-11 19:39:34 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
/* now convert from the source into the pivot buffer again */
|
|
|
|
pivot=pivot2=pivotBuffer;
|
|
|
|
ucnv_toUnicode(inConverter,
|
|
|
|
&pivot, pivotBuffer+CHUNK_SIZE,
|
|
|
|
&source, sourceLimit,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
pErrorCode);
|
|
|
|
} while(U_SUCCESS(*pErrorCode) || *pErrorCode==U_BUFFER_OVERFLOW_ERROR);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
ucnv_close (inConverter);
|
|
|
|
ucnv_close (outConverter);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-19 00:55:13 +00:00
|
|
|
return targetCapacity;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterType ucnv_getType(const UConverter* converter)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-12-20 20:34:23 +00:00
|
|
|
int8_t type = converter->sharedData->staticData->conversionType;
|
|
|
|
if(type == UCNV_MBCS) {
|
2001-01-02 23:11:11 +00:00
|
|
|
return _MBCSGetType(converter);
|
2000-12-20 20:34:23 +00:00
|
|
|
}
|
|
|
|
return (UConverterType)type;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ucnv_getStarters(const UConverter* converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UBool starters[256],
|
|
|
|
UErrorCode* err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-02-09 19:15:17 +00:00
|
|
|
if (err == NULL || U_FAILURE(*err)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(converter->sharedData->impl->getStarters != NULL) {
|
|
|
|
converter->sharedData->impl->getStarters(converter, starters, err);
|
|
|
|
} else {
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-08 00:51:44 +00:00
|
|
|
|
2001-03-16 20:49:41 +00:00
|
|
|
static const UAmbiguousConverter *ucnv_getAmbiguous(const UConverter *cnv) {
|
|
|
|
UErrorCode errorCode;
|
|
|
|
const char *name;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
if(cnv==NULL) {
|
|
|
|
return NULL;
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
2001-03-16 20:49:41 +00:00
|
|
|
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
name=ucnv_getName(cnv, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
return NULL;
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
2001-03-16 20:49:41 +00:00
|
|
|
|
|
|
|
for(i=0; i<(int32_t)(sizeof(ambiguousConverters)/sizeof(UAmbiguousConverter)); ++i) {
|
|
|
|
if(0==uprv_strcmp(name, ambiguousConverters[i].name)) {
|
|
|
|
return ambiguousConverters+i;
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-16 20:49:41 +00:00
|
|
|
|
|
|
|
return NULL;
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ucnv_fixFileSeparator(const UConverter *cnv,
|
|
|
|
UChar* source,
|
2001-03-16 20:49:41 +00:00
|
|
|
int32_t sourceLength) {
|
|
|
|
const UAmbiguousConverter *a;
|
|
|
|
int32_t i;
|
|
|
|
UChar variant5c;
|
|
|
|
|
|
|
|
if(cnv==NULL || source==NULL || sourceLength<=0 || (a=ucnv_getAmbiguous(cnv))==NULL) {
|
2000-01-08 00:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-16 20:49:41 +00:00
|
|
|
|
|
|
|
variant5c=a->variant5c;
|
|
|
|
for(i=0; i<sourceLength; ++i) {
|
|
|
|
if(source[i]==variant5c) {
|
|
|
|
source[i]=0x5c;
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-16 20:49:41 +00:00
|
|
|
UBool ucnv_isAmbiguous(const UConverter *cnv) {
|
|
|
|
return (UBool)(ucnv_getAmbiguous(cnv)!=NULL);
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
2000-05-12 19:59:03 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
void ucnv_setFallback(UConverter *cnv, UBool usesFallback)
|
2000-05-12 19:59:03 +00:00
|
|
|
{
|
|
|
|
cnv->useFallback = usesFallback;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool ucnv_usesFallback(const UConverter *cnv)
|
2000-05-12 19:59:03 +00:00
|
|
|
{
|
|
|
|
return cnv->useFallback;
|
|
|
|
}
|
2000-07-13 15:25:04 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ucnv_getInvalidChars (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
char *errBytes,
|
|
|
|
int8_t * len,
|
|
|
|
UErrorCode * err)
|
2000-07-13 15:25:04 +00:00
|
|
|
{
|
2000-07-15 01:11:05 +00:00
|
|
|
if (err == NULL || U_FAILURE(*err))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (len == NULL || errBytes == NULL || converter == NULL)
|
|
|
|
{
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-15 20:09:58 +00:00
|
|
|
if (*len < converter->invalidCharLength)
|
2000-07-15 01:11:05 +00:00
|
|
|
{
|
|
|
|
*err = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-15 20:09:58 +00:00
|
|
|
if ((*len = converter->invalidCharLength) > 0)
|
2000-07-15 01:11:05 +00:00
|
|
|
{
|
2000-07-15 20:09:58 +00:00
|
|
|
uprv_memcpy (errBytes, converter->invalidCharBuffer, *len);
|
2000-07-15 01:11:05 +00:00
|
|
|
}
|
2000-07-13 15:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ucnv_getInvalidUChars (const UConverter * converter,
|
2000-08-11 01:27:17 +00:00
|
|
|
UChar *errChars,
|
|
|
|
int8_t * len,
|
|
|
|
UErrorCode * err)
|
2000-07-13 15:25:04 +00:00
|
|
|
{
|
2000-07-15 01:11:05 +00:00
|
|
|
if (err == NULL || U_FAILURE(*err))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (len == NULL || errChars == NULL || converter == NULL)
|
|
|
|
{
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-15 20:09:58 +00:00
|
|
|
if (*len < converter->invalidUCharLength)
|
2000-07-15 01:11:05 +00:00
|
|
|
{
|
|
|
|
*err = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-15 20:09:58 +00:00
|
|
|
if ((*len = converter->invalidUCharLength) > 0)
|
2000-07-15 01:11:05 +00:00
|
|
|
{
|
2000-07-15 20:09:58 +00:00
|
|
|
uprv_memcpy (errChars, converter->invalidUCharBuffer, sizeof(UChar) * (*len));
|
2000-07-15 01:11:05 +00:00
|
|
|
}
|
2000-07-13 15:25:04 +00:00
|
|
|
}
|
2000-08-10 01:32:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|