1999-12-09 23:27:55 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 1998-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
/* C++ wrappers for the ICUs Codeset Conversion Routines*/
|
|
|
|
|
|
|
|
class Locale;
|
|
|
|
class UnicodeString;
|
|
|
|
class Mutex;
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/resbund.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "mutex.h"
|
|
|
|
extern "C" {
|
|
|
|
#include "ucnv_io.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
|
|
|
#include "ucnv_bld.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/convert.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-11-23 23:02:55 +00:00
|
|
|
/* list of converter and alias names */
|
2000-08-01 00:44:15 +00:00
|
|
|
const char **UnicodeConverter::availableConverterNames=NULL;
|
|
|
|
int32_t UnicodeConverter::availableConverterNamesCount=0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::UnicodeConverter()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
myUnicodeConverter = ucnv_open(NULL, &err);
|
|
|
|
}
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::UnicodeConverter(const char* name, UErrorCode& err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
myUnicodeConverter = ucnv_open(name, &err);
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::UnicodeConverter(const UnicodeString& name, 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
|
|
|
int i;
|
1999-12-08 02:11:04 +00:00
|
|
|
name.extract(0, i = name.length(), myName);
|
1999-08-16 21:50:52 +00:00
|
|
|
myName[i]='\0';
|
|
|
|
myUnicodeConverter = ucnv_open(myName, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::UnicodeConverter(int32_t codepageNumber,
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterPlatform platform,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err)
|
|
|
|
{
|
|
|
|
myUnicodeConverter = ucnv_openCCSID(codepageNumber,
|
|
|
|
platform,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter& UnicodeConverter::operator=(const UnicodeConverter& that)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
/*Decrements the overwritten converter's ref count
|
|
|
|
*Increments the assigner converter's ref count
|
|
|
|
*/
|
|
|
|
Mutex updateReferenceCounters;
|
2000-04-13 23:00:43 +00:00
|
|
|
if (myUnicodeConverter->sharedData->referenceCounter != 0 && myUnicodeConverter->sharedData->referenceCounter != (uint32_t) ~0) {
|
2000-02-05 00:19:15 +00:00
|
|
|
myUnicodeConverter->sharedData->referenceCounter--;
|
|
|
|
}
|
2000-04-13 23:00:43 +00:00
|
|
|
if (that.myUnicodeConverter->sharedData->referenceCounter != (uint32_t) ~0) {
|
2000-02-05 00:19:15 +00:00
|
|
|
that.myUnicodeConverter->sharedData->referenceCounter++;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*myUnicodeConverter = *(that.myUnicodeConverter);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UBool UnicodeConverter::operator==(const UnicodeConverter& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-15 22:03:20 +00:00
|
|
|
return
|
|
|
|
(myUnicodeConverter->sharedData == that.myUnicodeConverter->sharedData) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
(myUnicodeConverter->fromCharErrorBehaviour == that.myUnicodeConverter->fromCharErrorBehaviour) &&
|
2000-07-15 22:03:20 +00:00
|
|
|
(myUnicodeConverter->toUContext == that.myUnicodeConverter->toUContext) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
(myUnicodeConverter->toUnicodeStatus == that.myUnicodeConverter->toUnicodeStatus) &&
|
2001-02-26 19:51:20 +00:00
|
|
|
(myUnicodeConverter->subChar1 == that.myUnicodeConverter->subChar1) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
(myUnicodeConverter->subCharLen == that.myUnicodeConverter->subCharLen) &&
|
1999-12-28 23:39:02 +00:00
|
|
|
(uprv_memcmp(myUnicodeConverter->subChar, that.myUnicodeConverter->subChar, myUnicodeConverter->subCharLen) == 0) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
(myUnicodeConverter->UCharErrorBufferLength == that.myUnicodeConverter->UCharErrorBufferLength) &&
|
|
|
|
(myUnicodeConverter->charErrorBufferLength == that.myUnicodeConverter->charErrorBufferLength) &&
|
1999-12-28 23:39:02 +00:00
|
|
|
(uprv_memcmp(myUnicodeConverter->UCharErrorBuffer, that.myUnicodeConverter->UCharErrorBuffer, myUnicodeConverter->UCharErrorBufferLength) == 0) &&
|
|
|
|
(uprv_memcmp(myUnicodeConverter->charErrorBuffer, that.myUnicodeConverter->charErrorBuffer, myUnicodeConverter->charErrorBufferLength) == 0) &&
|
2000-07-15 22:03:20 +00:00
|
|
|
(myUnicodeConverter->fromUCharErrorBehaviour == that.myUnicodeConverter->fromUCharErrorBehaviour) &&
|
|
|
|
(myUnicodeConverter->fromUContext == that.myUnicodeConverter->fromUContext);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UBool UnicodeConverter::operator!=(const UnicodeConverter& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return !(*this == that);
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::UnicodeConverter(const UnicodeConverter& that)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/*increments the referenceCounter to let the static table know
|
|
|
|
*it has one more client
|
|
|
|
*/
|
2000-08-01 19:41:44 +00:00
|
|
|
myUnicodeConverter = (UConverter *)uprv_malloc(sizeof(UConverter)); //new UConverter;
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
Mutex updateReferenceCounter;
|
2000-04-13 23:00:43 +00:00
|
|
|
if (that.myUnicodeConverter->sharedData->referenceCounter != (uint32_t) ~0) {
|
2000-02-05 00:19:15 +00:00
|
|
|
that.myUnicodeConverter->sharedData->referenceCounter++;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
*myUnicodeConverter = *(that.myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::~UnicodeConverter()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
ucnv_close(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::fromUnicodeString(char* target,
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t& targetSize,
|
|
|
|
const UnicodeString& source,
|
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
const UChar* mySource = NULL;
|
|
|
|
int32_t mySourceLength = 0;
|
|
|
|
UConverter myConverter;
|
|
|
|
char *myTarget = NULL;
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(err)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if ((myUnicodeConverter == NULL) || source.isBogus() || (targetSize <= 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*makes a local copy of the UnicodeConverter*/
|
|
|
|
myConverter = *myUnicodeConverter;
|
|
|
|
|
|
|
|
/*Removes all state info on the UnicodeConverter*/
|
|
|
|
ucnv_reset(&myConverter);
|
|
|
|
|
|
|
|
|
1999-12-08 02:11:04 +00:00
|
|
|
mySourceLength = source.length();
|
2000-03-29 01:13:49 +00:00
|
|
|
mySource = source.getArrayStart();
|
1999-08-16 21:50:52 +00:00
|
|
|
myTarget = target;
|
|
|
|
ucnv_fromUnicode(&myConverter,
|
|
|
|
&myTarget,
|
|
|
|
target + targetSize,
|
|
|
|
&mySource,
|
|
|
|
mySource + mySourceLength,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
&err);
|
|
|
|
targetSize = myTarget - target;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::toUnicodeString(UnicodeString& target,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* source,
|
|
|
|
int32_t sourceSize,
|
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
const char* mySource = source;
|
|
|
|
const char* mySourceLimit = source + sourceSize;
|
|
|
|
UChar* myTargetUChars = NULL;
|
|
|
|
UChar* myTargetUCharsAlias = NULL;
|
|
|
|
int32_t myTargetUCharsLength = 0;
|
|
|
|
UConverter myConverter;
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(err)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
if ((myUnicodeConverter == NULL) || target.isBogus() || (sourceSize <= 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
err = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*makes a local bitwise copy of the UnicodeConverter*/
|
|
|
|
myConverter = *myUnicodeConverter;
|
|
|
|
|
|
|
|
/*Removes all state info on the UnicodeConverter*/
|
|
|
|
ucnv_reset(&myConverter);
|
|
|
|
/*Allocates the theoritically (Not counting added bytes from the error functions) max buffer
|
|
|
|
*on a "normal" call, only one iteration will be necessary.
|
|
|
|
*/
|
|
|
|
myTargetUChars =
|
1999-12-28 23:39:02 +00:00
|
|
|
(UChar*)uprv_malloc(sizeof(UChar)*(myTargetUCharsLength = (sourceSize/(int32_t)getMinBytesPerChar())));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (myTargetUChars == NULL)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
err = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*renders the target clean*/
|
|
|
|
target.remove();
|
|
|
|
|
|
|
|
/*Will loop until (re-use the same buffer) until no more memory is requested
|
|
|
|
*or an error (other than INDEX_OUTOF_BOUNDS) is encountered
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
err = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
myTargetUCharsAlias = myTargetUChars;
|
|
|
|
ucnv_toUnicode(&myConverter,
|
|
|
|
&myTargetUCharsAlias,
|
|
|
|
myTargetUChars + myTargetUCharsLength,
|
|
|
|
&mySource,
|
|
|
|
mySourceLimit,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
&err);
|
|
|
|
|
|
|
|
/*appends what we got thus far to the UnicodeString*/
|
1999-12-08 02:11:04 +00:00
|
|
|
target.replace((UTextOffset)target.length(),
|
1999-08-16 21:50:52 +00:00
|
|
|
myTargetUCharsAlias - myTargetUChars,
|
|
|
|
myTargetUChars,
|
|
|
|
myTargetUCharsAlias - myTargetUChars);
|
|
|
|
/*Checks for the integrity of target (UnicodeString) as it adds data to it*/
|
1999-10-07 00:07:53 +00:00
|
|
|
if (target.isBogus()) err = U_MEMORY_ALLOCATION_ERROR;
|
2000-08-11 19:23:50 +00:00
|
|
|
} while (err == U_BUFFER_OVERFLOW_ERROR);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_free(myTargetUChars);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::fromUnicode(char*& target,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* targetLimit,
|
|
|
|
const UChar*& source,
|
|
|
|
const UChar* sourceLimit,
|
|
|
|
int32_t *offsets,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool flush,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err)
|
|
|
|
{
|
|
|
|
ucnv_fromUnicode(myUnicodeConverter,
|
|
|
|
&target,
|
|
|
|
targetLimit,
|
|
|
|
&source,
|
|
|
|
sourceLimit,
|
|
|
|
offsets,
|
|
|
|
flush,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::toUnicode(UChar*& target,
|
1999-08-16 21:50:52 +00:00
|
|
|
const UChar* targetLimit,
|
|
|
|
const char*& source,
|
|
|
|
const char* sourceLimit,
|
|
|
|
int32_t* offsets,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool flush,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err)
|
|
|
|
{
|
|
|
|
ucnv_toUnicode(myUnicodeConverter,
|
|
|
|
&target,
|
|
|
|
targetLimit,
|
|
|
|
&source,
|
|
|
|
sourceLimit,
|
|
|
|
offsets,
|
|
|
|
flush,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getName(UErrorCode& err) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getName(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getMaxBytesPerChar() const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getMaxCharSize(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getMinBytesPerChar() const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getMinCharSize(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getSubstitutionChars(char* subChars,
|
1999-08-16 21:50:52 +00:00
|
|
|
int8_t& len,
|
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
ucnv_getSubstChars(myUnicodeConverter,
|
|
|
|
subChars,
|
|
|
|
&len,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::setSubstitutionChars(const char* subChars,
|
1999-08-16 21:50:52 +00:00
|
|
|
int8_t len,
|
|
|
|
UErrorCode& err)
|
|
|
|
{
|
|
|
|
ucnv_setSubstChars(myUnicodeConverter,
|
|
|
|
subChars,
|
|
|
|
len,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::resetState()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
ucnv_reset(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getCodepage(UErrorCode& err) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getCCSID(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
2000-07-14 01:00:59 +00:00
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getMissingCharAction(UConverterToUCallback *action,
|
2000-07-14 01:00:59 +00:00
|
|
|
void **context) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-14 01:00:59 +00:00
|
|
|
ucnv_getToUCallBack(myUnicodeConverter, action, context);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-14 01:00:59 +00:00
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getMissingUnicodeAction(UConverterFromUCallback *action,
|
2000-07-14 01:00:59 +00:00
|
|
|
void **context) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-14 01:00:59 +00:00
|
|
|
ucnv_getFromUCallBack(myUnicodeConverter, action, context);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::setMissingCharAction(UConverterToUCallback newAction,
|
2000-06-27 20:47:56 +00:00
|
|
|
void *newContext,
|
2000-07-05 20:56:42 +00:00
|
|
|
UConverterToUCallback *oldAction,
|
2000-06-27 20:47:56 +00:00
|
|
|
void **oldContext,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err)
|
|
|
|
{
|
2000-06-27 20:47:56 +00:00
|
|
|
ucnv_setToUCallBack(myUnicodeConverter, newAction, newContext, oldAction, oldContext, &err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::setMissingUnicodeAction(UConverterFromUCallback newAction,
|
2000-06-27 20:47:56 +00:00
|
|
|
void* newContext,
|
2000-07-05 20:56:42 +00:00
|
|
|
UConverterFromUCallback *oldAction,
|
2000-06-27 20:47:56 +00:00
|
|
|
void** oldContext,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err)
|
|
|
|
{
|
2000-06-27 20:47:56 +00:00
|
|
|
ucnv_setFromUCallBack(myUnicodeConverter, newAction, newContext, oldAction, oldContext, &err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getDisplayName(const Locale& displayLocale,
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString& displayName) const
|
|
|
|
{
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
1999-12-01 21:27:44 +00:00
|
|
|
UChar name[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
|
|
|
int32_t length = ucnv_getDisplayName(myUnicodeConverter, displayLocale.getName(), name, sizeof(name), &err);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(err))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-12-01 21:27:44 +00:00
|
|
|
displayName.replace(0, 0x7fffffff, name, length);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-12-01 21:27:44 +00:00
|
|
|
else
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/*Error While creating the resource bundle use the internal name instead*/
|
|
|
|
displayName.remove();
|
|
|
|
displayName = getName(err); /*Get the raw ASCII name*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterPlatform
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getCodepagePlatform(UErrorCode &err) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getPlatform(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UConverterType UnicodeConverter::getType() const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getType(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
void UnicodeConverter::getStarters(UBool starters[256],
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
ucnv_getStarters(myUnicodeConverter,
|
|
|
|
starters,
|
|
|
|
&err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const*
|
2000-08-01 00:44:15 +00:00
|
|
|
UnicodeConverter::getAvailableNames(int32_t& num, UErrorCode& err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-12-07 19:06:51 +00:00
|
|
|
if(U_FAILURE(err)) {
|
|
|
|
num = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
if (availableConverterNames==NULL) {
|
1999-12-14 00:37:27 +00:00
|
|
|
int32_t count = ucnv_io_countAvailableConverters(&err);
|
1999-12-07 19:06:51 +00:00
|
|
|
if (count > 0) {
|
|
|
|
const char **names = new const char *[count];
|
|
|
|
if (names != NULL) {
|
1999-12-14 00:37:27 +00:00
|
|
|
ucnv_io_fillAvailableConverters(names, &err);
|
1999-12-07 19:06:51 +00:00
|
|
|
|
|
|
|
/* in the mutex block, set the data for this process */
|
|
|
|
umtx_lock(0);
|
|
|
|
if (availableConverterNames == NULL) {
|
|
|
|
availableConverterNamesCount = count;
|
|
|
|
availableConverterNames = names;
|
|
|
|
names = 0;
|
|
|
|
}
|
|
|
|
umtx_unlock(0);
|
|
|
|
|
|
|
|
/* if a different thread set it first, then delete the extra data */
|
|
|
|
if (names != 0) {
|
|
|
|
delete [] names;
|
|
|
|
}
|
1999-11-23 23:02:55 +00:00
|
|
|
} else {
|
|
|
|
num = 0;
|
|
|
|
err = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num = availableConverterNamesCount;
|
|
|
|
return availableConverterNames;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
int32_t UnicodeConverter::flushCache()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_flushCache();
|
|
|
|
}
|
2000-01-08 00:51:44 +00:00
|
|
|
|
|
|
|
/* HSYS: To be cleaned up. The usage of UChar* and UnicodeString in
|
|
|
|
the C++ APIs need to be revisited. */
|
2001-03-16 20:49:41 +00:00
|
|
|
void UnicodeConverter::fixFileSeparator(UnicodeString& source) const {
|
|
|
|
if(this==NULL || &source==NULL || source.length()<=0) {
|
2000-01-08 00:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-16 20:49:41 +00:00
|
|
|
|
|
|
|
ucnv_fixFileSeparator(myUnicodeConverter, source.getArrayStart(), source.length());
|
2000-01-08 00:51:44 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 00:44:15 +00:00
|
|
|
UBool UnicodeConverter::isAmbiguous(void) const
|
2000-01-08 00:51:44 +00:00
|
|
|
{
|
|
|
|
return ucnv_isAmbiguous(myUnicodeConverter);
|
2000-01-13 21:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|