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 */
|
|
|
|
const char **UnicodeConverterCPP::availableConverterNames=NULL;
|
|
|
|
int32_t UnicodeConverterCPP::availableConverterNamesCount=0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeConverterCPP::UnicodeConverterCPP()
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
UnicodeConverterCPP::UnicodeConverterCPP(const char* name, UErrorCode& err)
|
|
|
|
{
|
|
|
|
myUnicodeConverter = ucnv_open(name, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeConverterCPP::UnicodeConverterCPP(const UnicodeString& name, UErrorCode& err)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UnicodeConverterCPP::UnicodeConverterCPP(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeConverterCPP& UnicodeConverterCPP::operator=(const UnicodeConverterCPP& that)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*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-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeConverterCPP::operator==(const UnicodeConverterCPP& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if ((myUnicodeConverter->sharedData == that.myUnicodeConverter->sharedData) &&
|
|
|
|
(myUnicodeConverter->fromCharErrorBehaviour == that.myUnicodeConverter->fromCharErrorBehaviour) &&
|
|
|
|
(myUnicodeConverter->toUnicodeStatus == that.myUnicodeConverter->toUnicodeStatus) &&
|
|
|
|
(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) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
(myUnicodeConverter->fromUCharErrorBehaviour == that.myUnicodeConverter->fromUCharErrorBehaviour))
|
|
|
|
return TRUE;
|
|
|
|
else return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeConverterCPP::operator!=(const UnicodeConverterCPP& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return !(*this == that);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeConverterCPP::UnicodeConverterCPP(const UnicodeConverterCPP& that)
|
|
|
|
{
|
|
|
|
/*increments the referenceCounter to let the static table know
|
|
|
|
*it has one more client
|
|
|
|
*/
|
|
|
|
myUnicodeConverter = new UConverter;
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UnicodeConverterCPP::~UnicodeConverterCPP()
|
|
|
|
{
|
|
|
|
ucnv_close(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnicodeConverterCPP::fromUnicodeString(char* target,
|
|
|
|
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
|
|
|
|
UnicodeConverterCPP::toUnicodeString(UnicodeString& target,
|
|
|
|
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;
|
|
|
|
} while (err == U_INDEX_OUTOFBOUNDS_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
|
|
|
|
UnicodeConverterCPP::fromUnicode(char*& target,
|
|
|
|
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
|
|
|
|
UnicodeConverterCPP::toUnicode(UChar*& target,
|
|
|
|
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*
|
|
|
|
UnicodeConverterCPP::getName(UErrorCode& err) const
|
|
|
|
{
|
|
|
|
return ucnv_getName(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
|
|
|
UnicodeConverterCPP::getMaxBytesPerChar() const
|
|
|
|
{
|
|
|
|
return ucnv_getMaxCharSize(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
|
|
|
UnicodeConverterCPP::getMinBytesPerChar() const
|
|
|
|
{
|
|
|
|
return ucnv_getMinCharSize(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnicodeConverterCPP::getSubstitutionChars(char* subChars,
|
|
|
|
int8_t& len,
|
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
ucnv_getSubstChars(myUnicodeConverter,
|
|
|
|
subChars,
|
|
|
|
&len,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnicodeConverterCPP::setSubstitutionChars(const char* subChars,
|
|
|
|
int8_t len,
|
|
|
|
UErrorCode& err)
|
|
|
|
{
|
|
|
|
ucnv_setSubstChars(myUnicodeConverter,
|
|
|
|
subChars,
|
|
|
|
len,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UnicodeConverterCPP::resetState()
|
|
|
|
{
|
|
|
|
ucnv_reset(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
UnicodeConverterCPP::getCodepage(UErrorCode& err) const
|
|
|
|
{
|
|
|
|
return ucnv_getCCSID(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterToUCallback
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeConverterCPP::getMissingCharAction() const
|
|
|
|
{
|
|
|
|
return ucnv_getToUCallBack(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterFromUCallback
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeConverterCPP::getMissingUnicodeAction() const
|
|
|
|
{
|
|
|
|
return ucnv_getFromUCallBack(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-06-27 20:47:56 +00:00
|
|
|
UnicodeConverterCPP::setMissingCharAction(UConverterToUCallback newAction,
|
|
|
|
void *newContext,
|
|
|
|
UConverterToUCallback oldAction,
|
|
|
|
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-06-27 20:47:56 +00:00
|
|
|
UnicodeConverterCPP::setMissingUnicodeAction(UConverterFromUCallback newAction,
|
|
|
|
void* newContext,
|
|
|
|
UConverterFromUCallback oldAction,
|
|
|
|
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
|
|
|
|
UnicodeConverterCPP::getDisplayName(const Locale& displayLocale,
|
|
|
|
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
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeConverterCPP::getCodepagePlatform(UErrorCode &err) const
|
|
|
|
{
|
|
|
|
return ucnv_getPlatform(myUnicodeConverter, &err);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
UConverterType UnicodeConverterCPP::getType() const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
return ucnv_getType(myUnicodeConverter);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
void UnicodeConverterCPP::getStarters(UBool starters[256],
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode& err) const
|
|
|
|
{
|
|
|
|
ucnv_getStarters(myUnicodeConverter,
|
|
|
|
starters,
|
|
|
|
&err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const*
|
|
|
|
UnicodeConverterCPP::getAvailableNames(int32_t& num, UErrorCode& err)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int32_t UnicodeConverterCPP::flushCache()
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
void UnicodeConverterCPP::fixFileSeparator(UnicodeString& source) const
|
|
|
|
{
|
|
|
|
int32_t i = 0;
|
|
|
|
int32_t index = 0;
|
|
|
|
int32_t ccsid = 0;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
if (source.length() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ccsid = getCodepage(status);
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < UCNV_MAX_AMBIGUOUSCCSIDS; i++) {
|
|
|
|
if (ccsid == UCNV_AMBIGUOUSCONVERTERS[i].ccsid)
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
for (i = 0; i < source.length(); i++)
|
|
|
|
{
|
|
|
|
if (source[i] == UCNV_AMBIGUOUSCONVERTERS[index].mismapped)
|
|
|
|
{
|
|
|
|
source[i] = UCNV_AMBIGUOUSCONVERTERS[index].replacement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeConverterCPP::isAmbiguous(void) const
|
2000-01-08 00:51:44 +00:00
|
|
|
{
|
|
|
|
return ucnv_isAmbiguous(myUnicodeConverter);
|
2000-01-13 21:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|