2001-08-15 19:06:40 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2006-02-09 08:59:20 +00:00
|
|
|
* Copyright (c) 2001-2006, International Business Machines
|
2001-08-15 19:06:40 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 08/10/2001 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2002-06-27 01:19:20 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
#include "unicode/translit.h"
|
2005-04-05 20:44:00 +00:00
|
|
|
#include "unicode/resbund.h"
|
2001-10-10 19:29:45 +00:00
|
|
|
#include "unicode/uniset.h"
|
2001-08-15 19:06:40 +00:00
|
|
|
#include "unicode/uscript.h"
|
2003-02-14 01:44:49 +00:00
|
|
|
#include "rbt.h"
|
|
|
|
#include "cpdtrans.h"
|
|
|
|
#include "nultrans.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "transreg.h"
|
|
|
|
#include "rbt_data.h"
|
|
|
|
#include "rbt_pars.h"
|
|
|
|
#include "tridpars.h"
|
2001-11-19 21:25:34 +00:00
|
|
|
#include "charstr.h"
|
2004-06-04 00:52:39 +00:00
|
|
|
#include "uassert.h"
|
2005-03-28 05:12:13 +00:00
|
|
|
#include "locutil.h"
|
2001-08-15 19:06:40 +00:00
|
|
|
|
2002-03-20 18:29:10 +00:00
|
|
|
// Enable the following symbol to add debugging code that tracks the
|
|
|
|
// allocation, deletion, and use of Entry objects. BoundsChecker has
|
|
|
|
// reported dangling pointer errors with these objects, but I have
|
|
|
|
// been unable to confirm them. I suspect BoundsChecker is getting
|
|
|
|
// confused with pointers going into and coming out of a UHashtable,
|
|
|
|
// despite the hinting code that is designed to help it.
|
|
|
|
// #define DEBUG_MEM
|
|
|
|
#ifdef DEBUG_MEM
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
// UChar constants
|
|
|
|
static const UChar LOCALE_SEP = 95; // '_'
|
2006-02-09 08:59:20 +00:00
|
|
|
//static const UChar ID_SEP = 0x002D; /*-*/
|
|
|
|
//static const UChar VARIANT_SEP = 0x002F; // '/'
|
2001-08-15 19:06:40 +00:00
|
|
|
|
|
|
|
// String constants
|
|
|
|
static const UChar NO_VARIANT[] = { 0 }; // empty string
|
|
|
|
static const UChar ANY[] = { 65, 110, 121, 0 }; // Any
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resource bundle key for the RuleBasedTransliterator rule.
|
|
|
|
*/
|
2006-02-09 08:59:20 +00:00
|
|
|
//static const char RB_RULE[] = "Rule";
|
2001-08-15 19:06:40 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-10-04 21:22:17 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Alias
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2005-06-09 17:30:48 +00:00
|
|
|
TransliteratorAlias::TransliteratorAlias(const UnicodeString& theAliasID,
|
|
|
|
const UnicodeSet* cpdFilter) :
|
2001-10-04 21:22:17 +00:00
|
|
|
ID(),
|
2005-06-09 17:30:48 +00:00
|
|
|
aliasesOrRules(theAliasID),
|
|
|
|
transes(0),
|
|
|
|
compoundFilter(cpdFilter),
|
|
|
|
direction(UTRANS_FORWARD),
|
2004-06-04 00:52:39 +00:00
|
|
|
type(TransliteratorAlias::SIMPLE) {
|
2001-10-04 21:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
|
2005-06-09 17:30:48 +00:00
|
|
|
const UnicodeString& idBlocks,
|
|
|
|
UVector* adoptedTransliterators,
|
2001-10-10 19:29:45 +00:00
|
|
|
const UnicodeSet* cpdFilter) :
|
2001-10-04 21:22:17 +00:00
|
|
|
ID(theID),
|
2005-06-09 17:30:48 +00:00
|
|
|
aliasesOrRules(idBlocks),
|
|
|
|
transes(adoptedTransliterators),
|
2001-11-16 21:58:05 +00:00
|
|
|
compoundFilter(cpdFilter),
|
2005-06-09 17:30:48 +00:00
|
|
|
direction(UTRANS_FORWARD),
|
2004-06-04 00:52:39 +00:00
|
|
|
type(TransliteratorAlias::COMPOUND) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
|
|
|
|
const UnicodeString& rules,
|
|
|
|
UTransDirection dir) :
|
|
|
|
ID(theID),
|
2005-06-09 17:30:48 +00:00
|
|
|
aliasesOrRules(rules),
|
|
|
|
transes(0),
|
2004-06-04 00:52:39 +00:00
|
|
|
compoundFilter(0),
|
2005-06-09 17:30:48 +00:00
|
|
|
direction(dir),
|
2004-06-04 00:52:39 +00:00
|
|
|
type(TransliteratorAlias::RULES) {
|
2001-10-04 21:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransliteratorAlias::~TransliteratorAlias() {
|
2005-06-09 17:30:48 +00:00
|
|
|
delete transes;
|
2001-10-04 21:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Transliterator* TransliteratorAlias::create(UParseError& pe,
|
2001-10-10 19:29:45 +00:00
|
|
|
UErrorCode& ec) {
|
2004-06-04 00:52:39 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-07 17:44:28 +00:00
|
|
|
Transliterator *t = NULL;
|
2004-06-04 00:52:39 +00:00
|
|
|
switch (type) {
|
|
|
|
case SIMPLE:
|
2005-06-09 17:30:48 +00:00
|
|
|
t = Transliterator::createInstance(aliasesOrRules, UTRANS_FORWARD, pe, ec);
|
|
|
|
if (compoundFilter != 0)
|
|
|
|
t->adoptFilter((UnicodeSet*)compoundFilter->clone());
|
2004-06-04 00:52:39 +00:00
|
|
|
break;
|
|
|
|
case COMPOUND:
|
2005-06-09 17:30:48 +00:00
|
|
|
{
|
|
|
|
// the total number of transliterators in the compound is the total number of anonymous transliterators
|
|
|
|
// plus the total number of ID blocks-- we start by assuming the list begins and ends with an ID
|
|
|
|
// block and that each pair anonymous transliterators has an ID block between them. Then we go back
|
|
|
|
// to see whether there really are ID blocks at the beginning and end (by looking for U+FFFF, which
|
|
|
|
// marks the position where an anonymous transliterator goes) and adjust accordingly
|
|
|
|
int32_t anonymousRBTs = transes->size();
|
|
|
|
int32_t transCount = anonymousRBTs * 2 + 1;
|
|
|
|
if (!aliasesOrRules.isEmpty() && aliasesOrRules[0] == (UChar)(0xffff))
|
|
|
|
--transCount;
|
|
|
|
if (aliasesOrRules.length() >= 2 && aliasesOrRules[aliasesOrRules.length() - 1] == (UChar)(0xffff))
|
|
|
|
--transCount;
|
|
|
|
UnicodeString noIDBlock((UChar)(0xffff));
|
|
|
|
noIDBlock += ((UChar)(0xffff));
|
|
|
|
int32_t pos = aliasesOrRules.indexOf(noIDBlock);
|
|
|
|
while (pos >= 0) {
|
|
|
|
--transCount;
|
|
|
|
pos = aliasesOrRules.indexOf(noIDBlock, pos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
UVector transliterators(ec);
|
|
|
|
UnicodeString idBlock;
|
|
|
|
int32_t blockSeparatorPos = aliasesOrRules.indexOf((UChar)(0xffff));
|
|
|
|
while (blockSeparatorPos >= 0) {
|
|
|
|
aliasesOrRules.extract(0, blockSeparatorPos, idBlock);
|
|
|
|
aliasesOrRules.remove(0, blockSeparatorPos + 1);
|
|
|
|
if (!idBlock.isEmpty())
|
|
|
|
transliterators.addElement(Transliterator::createInstance(idBlock, UTRANS_FORWARD, pe, ec), ec);
|
|
|
|
if (!transes->isEmpty())
|
|
|
|
transliterators.addElement(transes->orphanElementAt(0), ec);
|
|
|
|
blockSeparatorPos = aliasesOrRules.indexOf((UChar)(0xffff));
|
|
|
|
}
|
|
|
|
if (!aliasesOrRules.isEmpty())
|
|
|
|
transliterators.addElement(Transliterator::createInstance(aliasesOrRules, UTRANS_FORWARD, pe, ec), ec);
|
|
|
|
while (!transes->isEmpty())
|
|
|
|
transliterators.addElement(transes->orphanElementAt(0), ec);
|
|
|
|
|
|
|
|
if (U_SUCCESS(ec)) {
|
|
|
|
t = new CompoundTransliterator(ID, transliterators,
|
|
|
|
(compoundFilter ? (UnicodeSet*)(compoundFilter->clone()) : 0),
|
|
|
|
anonymousRBTs, pe, ec);
|
|
|
|
if (t == 0) {
|
|
|
|
ec = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int32_t i = 0; i < transliterators.size(); i++)
|
|
|
|
delete (Transliterator*)(transliterators.elementAt(i));
|
|
|
|
}
|
2001-10-10 19:29:45 +00:00
|
|
|
}
|
2004-06-04 00:52:39 +00:00
|
|
|
break;
|
|
|
|
case RULES:
|
|
|
|
U_ASSERT(FALSE); // don't call create() if isRuleBased() returns TRUE!
|
|
|
|
break;
|
2001-10-04 21:22:17 +00:00
|
|
|
}
|
2001-10-10 19:29:45 +00:00
|
|
|
return t;
|
2001-10-04 21:22:17 +00:00
|
|
|
}
|
|
|
|
|
2004-06-04 00:52:39 +00:00
|
|
|
UBool TransliteratorAlias::isRuleBased() const {
|
|
|
|
return type == RULES;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransliteratorAlias::parse(TransliteratorParser& parser,
|
|
|
|
UParseError& pe, UErrorCode& ec) const {
|
|
|
|
U_ASSERT(type == RULES);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-09 17:30:48 +00:00
|
|
|
parser.parse(aliasesOrRules, direction, pe, ec);
|
2004-06-04 00:52:39 +00:00
|
|
|
}
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Spec
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Spec is a string specifying either a source or a target. In more
|
|
|
|
* general terms, it may also specify a variant, but we only use the
|
|
|
|
* Spec class for sources and targets.
|
|
|
|
*
|
|
|
|
* A Spec may be a locale or a script. If it is a locale, it has a
|
|
|
|
* fallback chain that goes xx_YY_ZZZ -> xx_YY -> xx -> ssss, where
|
|
|
|
* ssss is the script mapping of xx_YY_ZZZ. The Spec API methods
|
|
|
|
* hasFallback(), next(), and reset() iterate over this fallback
|
|
|
|
* sequence.
|
|
|
|
*
|
|
|
|
* The Spec class canonicalizes itself, so the locale is put into
|
|
|
|
* canonical form, or the script is transformed from an abbreviation
|
|
|
|
* to a full name.
|
|
|
|
*/
|
2002-10-04 18:17:35 +00:00
|
|
|
class Spec : public UMemory {
|
2001-08-15 19:06:40 +00:00
|
|
|
public:
|
|
|
|
Spec(const UnicodeString& spec);
|
|
|
|
~Spec();
|
|
|
|
|
|
|
|
const UnicodeString& get() const;
|
|
|
|
UBool hasFallback() const;
|
|
|
|
const UnicodeString& next();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
UBool isLocale() const;
|
|
|
|
ResourceBundle& getBundle() const;
|
|
|
|
|
|
|
|
operator const UnicodeString&() const { return get(); }
|
|
|
|
const UnicodeString& getTop() const { return top; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupNext();
|
|
|
|
|
|
|
|
UnicodeString top;
|
|
|
|
UnicodeString spec;
|
|
|
|
UnicodeString nextSpec;
|
|
|
|
UnicodeString scriptName;
|
|
|
|
UBool isSpecLocale; // TRUE if spec is a locale
|
|
|
|
UBool isNextLocale; // TRUE if nextSpec is a locale
|
|
|
|
ResourceBundle* res;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2002-10-04 18:17:35 +00:00
|
|
|
Spec(const Spec &other); // forbid copying of this class
|
|
|
|
Spec &operator=(const Spec &other); // forbid copying of this class
|
2001-08-15 19:06:40 +00:00
|
|
|
};
|
|
|
|
|
2005-03-26 15:55:57 +00:00
|
|
|
Spec::Spec(const UnicodeString& theSpec)
|
|
|
|
: top(theSpec),
|
|
|
|
res(0)
|
|
|
|
{
|
2001-08-15 19:06:40 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2005-03-26 15:55:57 +00:00
|
|
|
CharString topch(theSpec);
|
|
|
|
Locale topLoc("");
|
|
|
|
LocaleUtility::initLocaleFromName(theSpec, topLoc);
|
|
|
|
if (!topLoc.isBogus()) {
|
|
|
|
res = new ResourceBundle(U_ICUDATA_TRANSLIT, topLoc, status);
|
|
|
|
/* test for NULL */
|
|
|
|
if (res == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
|
|
|
|
delete res;
|
|
|
|
res = 0;
|
|
|
|
}
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Canonicalize script name -or- do locale->script mapping
|
|
|
|
status = U_ZERO_ERROR;
|
2005-03-26 15:55:57 +00:00
|
|
|
static const int32_t capacity = 10;
|
2001-10-23 02:00:50 +00:00
|
|
|
UScriptCode script[capacity]={USCRIPT_INVALID_CODE};
|
2001-11-16 21:58:05 +00:00
|
|
|
int32_t num = uscript_getCode(topch,script,capacity, &status);
|
2001-10-31 00:29:15 +00:00
|
|
|
if (num > 0 && script[0] != USCRIPT_INVALID_CODE) {
|
2004-12-04 07:22:23 +00:00
|
|
|
scriptName = UnicodeString(uscript_getName(script[0]), -1, US_INV);
|
2001-10-31 00:29:15 +00:00
|
|
|
}
|
2001-08-15 19:06:40 +00:00
|
|
|
|
|
|
|
// Canonicalize top
|
|
|
|
if (res != 0) {
|
|
|
|
// Canonicalize locale name
|
2005-03-26 15:55:57 +00:00
|
|
|
UnicodeString locStr;
|
|
|
|
LocaleUtility::initNameFromLocale(topLoc, locStr);
|
|
|
|
if (!locStr.isBogus()) {
|
|
|
|
top = locStr;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
} else if (scriptName.length() != 0) {
|
|
|
|
// We are a script; use canonical name
|
|
|
|
top = scriptName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assert(spec != top);
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
Spec::~Spec() {
|
|
|
|
delete res;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool Spec::hasFallback() const {
|
|
|
|
return nextSpec.length() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spec::reset() {
|
|
|
|
if (spec != top) {
|
|
|
|
spec = top;
|
|
|
|
isSpecLocale = (res != 0);
|
|
|
|
setupNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spec::setupNext() {
|
|
|
|
isNextLocale = FALSE;
|
|
|
|
if (isSpecLocale) {
|
|
|
|
nextSpec = spec;
|
|
|
|
int32_t i = nextSpec.lastIndexOf(LOCALE_SEP);
|
|
|
|
// If i == 0 then we have _FOO, so we fall through
|
|
|
|
// to the scriptName.
|
|
|
|
if (i > 0) {
|
|
|
|
nextSpec.truncate(i);
|
|
|
|
isNextLocale = TRUE;
|
|
|
|
} else {
|
|
|
|
nextSpec = scriptName; // scriptName may be empty
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// spec is a script, so we are at the end
|
|
|
|
nextSpec.truncate(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocol:
|
|
|
|
// for(const UnicodeString& s(spec.get());
|
|
|
|
// spec.hasFallback(); s(spec.next())) { ...
|
|
|
|
|
|
|
|
const UnicodeString& Spec::next() {
|
|
|
|
spec = nextSpec;
|
|
|
|
isSpecLocale = isNextLocale;
|
|
|
|
setupNext();
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString& Spec::get() const {
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool Spec::isLocale() const {
|
|
|
|
return isSpecLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundle& Spec::getBundle() const {
|
|
|
|
return *res;
|
|
|
|
}
|
|
|
|
|
2002-03-20 18:29:10 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef DEBUG_MEM
|
|
|
|
|
|
|
|
// Vector of Entry pointers currently in use
|
|
|
|
static UVector* DEBUG_entries = NULL;
|
|
|
|
|
|
|
|
static void DEBUG_setup() {
|
|
|
|
if (DEBUG_entries == NULL) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
DEBUG_entries = new UVector(ec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Caller must call DEBUG_setup first. Return index of given Entry,
|
|
|
|
// if it is in use (not deleted yet), or -1 if not found.
|
|
|
|
static int DEBUG_findEntry(Entry* e) {
|
|
|
|
for (int i=0; i<DEBUG_entries->size(); ++i) {
|
|
|
|
if (e == (Entry*) DEBUG_entries->elementAt(i)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track object creation
|
|
|
|
static void DEBUG_newEntry(Entry* e) {
|
|
|
|
DEBUG_setup();
|
|
|
|
if (DEBUG_findEntry(e) >= 0) {
|
|
|
|
// This should really never happen unless the heap is broken
|
|
|
|
printf("ERROR DEBUG_newEntry duplicate new pointer %08X\n", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
DEBUG_entries->addElement(e, ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track object deletion
|
|
|
|
static void DEBUG_delEntry(Entry* e) {
|
|
|
|
DEBUG_setup();
|
|
|
|
int i = DEBUG_findEntry(e);
|
|
|
|
if (i < 0) {
|
|
|
|
printf("ERROR DEBUG_delEntry possible double deletion %08X\n", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DEBUG_entries->removeElementAt(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track object usage
|
|
|
|
static void DEBUG_useEntry(Entry* e) {
|
|
|
|
if (e == NULL) return;
|
|
|
|
DEBUG_setup();
|
|
|
|
int i = DEBUG_findEntry(e);
|
|
|
|
if (i < 0) {
|
|
|
|
printf("ERROR DEBUG_useEntry possible dangling pointer %08X\n", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
// If we're not debugging then make these macros into NOPs
|
|
|
|
#define DEBUG_newEntry(x)
|
|
|
|
#define DEBUG_delEntry(x)
|
|
|
|
#define DEBUG_useEntry(x)
|
|
|
|
#endif
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Entry
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Entry object stores objects of different types and
|
|
|
|
* singleton objects as placeholders for rule-based transliterators to
|
|
|
|
* be built as needed. Instances of this struct can be placeholders,
|
|
|
|
* can represent prototype transliterators to be cloned, or can
|
|
|
|
* represent TransliteratorData objects. We don't support storing
|
|
|
|
* classes in the registry because we don't have the rtti infrastructure
|
|
|
|
* for it. We could easily add this if there is a need for it in the
|
|
|
|
* future.
|
|
|
|
*/
|
2002-10-04 18:17:35 +00:00
|
|
|
class Entry : public UMemory {
|
2001-08-15 19:06:40 +00:00
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
RULES_FORWARD,
|
|
|
|
RULES_REVERSE,
|
|
|
|
LOCALE_RULES,
|
|
|
|
PROTOTYPE,
|
|
|
|
RBT_DATA,
|
|
|
|
COMPOUND_RBT,
|
|
|
|
ALIAS,
|
|
|
|
FACTORY,
|
|
|
|
NONE // Only used for uninitialized entries
|
|
|
|
} entryType;
|
|
|
|
// NOTE: stringArg cannot go inside the union because
|
|
|
|
// it has a copy constructor
|
|
|
|
UnicodeString stringArg; // For RULES_*, ALIAS, COMPOUND_RBT
|
2001-11-03 02:03:33 +00:00
|
|
|
int32_t intArg; // For COMPOUND_RBT, LOCALE_RULES
|
2001-10-10 19:29:45 +00:00
|
|
|
UnicodeSet* compoundFilter; // For COMPOUND_RBT
|
2001-08-15 19:06:40 +00:00
|
|
|
union {
|
|
|
|
Transliterator* prototype; // For PROTOTYPE
|
2005-06-09 17:30:48 +00:00
|
|
|
TransliterationRuleData* data; // For RBT_DATA
|
|
|
|
UVector* dataVector; // For COMPOUND_RBT
|
2001-10-17 17:29:34 +00:00
|
|
|
struct {
|
|
|
|
Transliterator::Factory function;
|
|
|
|
Transliterator::Token context;
|
|
|
|
} factory; // For FACTORY
|
2001-08-15 19:06:40 +00:00
|
|
|
} u;
|
|
|
|
Entry();
|
|
|
|
~Entry();
|
|
|
|
void adoptPrototype(Transliterator* adopted);
|
2001-10-17 17:29:34 +00:00
|
|
|
void setFactory(Transliterator::Factory factory,
|
|
|
|
Transliterator::Token context);
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2002-10-04 18:17:35 +00:00
|
|
|
Entry(const Entry &other); // forbid copying of this class
|
|
|
|
Entry &operator=(const Entry &other); // forbid copying of this class
|
2001-08-15 19:06:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Entry::Entry() {
|
|
|
|
u.prototype = 0;
|
2001-10-10 19:29:45 +00:00
|
|
|
compoundFilter = NULL;
|
2001-08-15 19:06:40 +00:00
|
|
|
entryType = NONE;
|
2002-03-20 18:29:10 +00:00
|
|
|
DEBUG_newEntry(this);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Entry::~Entry() {
|
2002-03-20 18:29:10 +00:00
|
|
|
DEBUG_delEntry(this);
|
2001-08-15 19:06:40 +00:00
|
|
|
if (entryType == PROTOTYPE) {
|
|
|
|
delete u.prototype;
|
2005-06-09 17:30:48 +00:00
|
|
|
} else if (entryType == RBT_DATA) {
|
2001-10-01 20:07:29 +00:00
|
|
|
// The data object is shared between instances of RBT. The
|
|
|
|
// entry object owns it. It should only be deleted when the
|
|
|
|
// transliterator component is being cleaned up. Doing so
|
|
|
|
// invalidates any RBTs that the user has instantiated.
|
|
|
|
delete u.data;
|
2005-06-09 17:30:48 +00:00
|
|
|
} else if (entryType == COMPOUND_RBT) {
|
|
|
|
while (u.dataVector != NULL && !u.dataVector->isEmpty())
|
|
|
|
delete (TransliterationRuleData*)u.dataVector->orphanElementAt(0);
|
|
|
|
delete u.dataVector;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
2001-10-10 19:29:45 +00:00
|
|
|
delete compoundFilter;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::adoptPrototype(Transliterator* adopted) {
|
|
|
|
if (entryType == PROTOTYPE) {
|
|
|
|
delete u.prototype;
|
|
|
|
}
|
|
|
|
entryType = PROTOTYPE;
|
|
|
|
u.prototype = adopted;
|
|
|
|
}
|
|
|
|
|
2001-10-17 17:29:34 +00:00
|
|
|
void Entry::setFactory(Transliterator::Factory factory,
|
|
|
|
Transliterator::Token context) {
|
2001-08-15 19:06:40 +00:00
|
|
|
if (entryType == PROTOTYPE) {
|
|
|
|
delete u.prototype;
|
|
|
|
}
|
|
|
|
entryType = FACTORY;
|
2001-10-17 17:29:34 +00:00
|
|
|
u.factory.function = factory;
|
|
|
|
u.factory.context = context;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UObjectDeleter for Hashtable::setValueDeleter
|
2001-10-05 16:50:59 +00:00
|
|
|
U_CDECL_BEGIN
|
2005-07-07 18:09:09 +00:00
|
|
|
static void U_CALLCONV
|
2001-10-05 16:50:59 +00:00
|
|
|
deleteEntry(void* obj) {
|
2001-08-15 19:06:40 +00:00
|
|
|
delete (Entry*) obj;
|
|
|
|
}
|
2001-10-05 16:50:59 +00:00
|
|
|
U_CDECL_END
|
2001-08-15 19:06:40 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class TransliteratorRegistry: Basic public API
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-08-23 01:06:08 +00:00
|
|
|
TransliteratorRegistry::TransliteratorRegistry(UErrorCode& status) :
|
2004-10-08 01:52:53 +00:00
|
|
|
registry(TRUE, status),
|
|
|
|
specDAG(TRUE, status),
|
2001-08-23 01:06:08 +00:00
|
|
|
availableIDs(status)
|
|
|
|
{
|
2001-08-15 19:06:40 +00:00
|
|
|
registry.setValueDeleter(deleteEntry);
|
|
|
|
availableIDs.setDeleter(uhash_deleteUnicodeString);
|
|
|
|
availableIDs.setComparer(uhash_compareCaselessUnicodeString);
|
|
|
|
specDAG.setValueDeleter(uhash_deleteHashtable);
|
|
|
|
}
|
|
|
|
|
|
|
|
TransliteratorRegistry::~TransliteratorRegistry() {
|
|
|
|
// Through the magic of C++, everything cleans itself up
|
|
|
|
}
|
|
|
|
|
|
|
|
Transliterator* TransliteratorRegistry::get(const UnicodeString& ID,
|
2001-10-04 21:22:17 +00:00
|
|
|
TransliteratorAlias*& aliasReturn,
|
2001-08-31 03:23:39 +00:00
|
|
|
UErrorCode& status) {
|
2004-06-04 00:52:39 +00:00
|
|
|
U_ASSERT(aliasReturn == NULL);
|
2001-08-15 19:06:40 +00:00
|
|
|
Entry *entry = find(ID);
|
|
|
|
return (entry == 0) ? 0
|
2004-11-05 05:12:29 +00:00
|
|
|
: instantiateEntry(ID, entry, aliasReturn, status);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-04 00:52:39 +00:00
|
|
|
Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
|
|
|
|
TransliteratorParser& parser,
|
|
|
|
TransliteratorAlias*& aliasReturn,
|
|
|
|
UErrorCode& status) {
|
|
|
|
U_ASSERT(aliasReturn == NULL);
|
|
|
|
Entry *entry = find(ID);
|
|
|
|
|
|
|
|
if (entry == 0) {
|
|
|
|
// We get to this point if there are two threads, one of which
|
|
|
|
// is instantiating an ID, and another of which is removing
|
|
|
|
// the same ID from the registry, and the timing is just right.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The usage model for the caller is that they will first call
|
|
|
|
// reg->get() inside the mutex, they'll get back an alias, they call
|
|
|
|
// alias->isRuleBased(), and if they get TRUE, they call alias->parse()
|
|
|
|
// outside the mutex, then reg->reget() inside the mutex again. A real
|
|
|
|
// mess, but it gets things working for ICU 3.0. [alan].
|
|
|
|
|
|
|
|
// Note: It's possible that in between the caller calling
|
|
|
|
// alias->parse() and reg->reget(), that another thread will have
|
|
|
|
// called reg->reget(), and the entry will already have been fixed up.
|
|
|
|
// We have to detect this so we don't stomp over existing entry
|
|
|
|
// data members and potentially leak memory (u.data and compoundFilter).
|
|
|
|
|
|
|
|
if (entry->entryType == Entry::RULES_FORWARD ||
|
|
|
|
entry->entryType == Entry::RULES_REVERSE ||
|
|
|
|
entry->entryType == Entry::LOCALE_RULES) {
|
|
|
|
|
2005-06-09 17:30:48 +00:00
|
|
|
if (parser.idBlockVector->isEmpty() && parser.dataVector->isEmpty()) {
|
|
|
|
entry->u.data = 0;
|
|
|
|
entry->entryType = Entry::ALIAS;
|
|
|
|
entry->stringArg = UNICODE_STRING_SIMPLE("Any-NULL");
|
|
|
|
}
|
|
|
|
else if (parser.idBlockVector->isEmpty() && parser.dataVector->size() == 1) {
|
|
|
|
entry->u.data = (TransliterationRuleData*)parser.dataVector->orphanElementAt(0);
|
|
|
|
entry->entryType = Entry::RBT_DATA;
|
|
|
|
}
|
|
|
|
else if (parser.idBlockVector->size() == 1 && parser.dataVector->isEmpty()) {
|
|
|
|
entry->stringArg = *(UnicodeString*)(parser.idBlockVector->elementAt(0));
|
|
|
|
entry->compoundFilter = parser.orphanCompoundFilter();
|
|
|
|
entry->entryType = Entry::ALIAS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
entry->entryType = Entry::COMPOUND_RBT;
|
|
|
|
entry->compoundFilter = parser.orphanCompoundFilter();
|
|
|
|
entry->u.dataVector = new UVector(status);
|
|
|
|
entry->stringArg.remove();
|
|
|
|
|
|
|
|
int32_t limit = parser.idBlockVector->size();
|
|
|
|
if (parser.dataVector->size() > limit)
|
|
|
|
limit = parser.dataVector->size();
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < limit; i++) {
|
|
|
|
if (i < parser.idBlockVector->size()) {
|
|
|
|
UnicodeString* idBlock = (UnicodeString*)parser.idBlockVector->elementAt(i);
|
|
|
|
if (!idBlock->isEmpty())
|
|
|
|
entry->stringArg += *idBlock;
|
|
|
|
}
|
|
|
|
if (!parser.dataVector->isEmpty()) {
|
|
|
|
TransliterationRuleData* data = (TransliterationRuleData*)parser.dataVector->orphanElementAt(0);
|
|
|
|
entry->u.dataVector->addElement(data, status);
|
|
|
|
entry->stringArg += (UChar)0xffff; // use U+FFFF to mark position of RBTs in ID block
|
|
|
|
}
|
2004-06-04 00:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Transliterator *t =
|
2004-11-05 05:12:29 +00:00
|
|
|
instantiateEntry(ID, entry, aliasReturn, status);
|
2004-06-04 00:52:39 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
void TransliteratorRegistry::put(Transliterator* adoptedProto,
|
|
|
|
UBool visible) {
|
|
|
|
Entry *entry = new Entry();
|
|
|
|
entry->adoptPrototype(adoptedProto);
|
|
|
|
registerEntry(adoptedProto->getID(), entry, visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransliteratorRegistry::put(const UnicodeString& ID,
|
|
|
|
Transliterator::Factory factory,
|
2001-10-17 17:29:34 +00:00
|
|
|
Transliterator::Token context,
|
2001-08-15 19:06:40 +00:00
|
|
|
UBool visible) {
|
|
|
|
Entry *entry = new Entry();
|
2001-10-17 17:29:34 +00:00
|
|
|
entry->setFactory(factory, context);
|
2001-08-15 19:06:40 +00:00
|
|
|
registerEntry(ID, entry, visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransliteratorRegistry::put(const UnicodeString& ID,
|
|
|
|
const UnicodeString& resourceName,
|
|
|
|
UTransDirection dir,
|
|
|
|
UBool visible) {
|
|
|
|
Entry *entry = new Entry();
|
|
|
|
entry->entryType = (dir == UTRANS_FORWARD) ? Entry::RULES_FORWARD
|
|
|
|
: Entry::RULES_REVERSE;
|
|
|
|
entry->stringArg = resourceName;
|
|
|
|
registerEntry(ID, entry, visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransliteratorRegistry::put(const UnicodeString& ID,
|
|
|
|
const UnicodeString& alias,
|
|
|
|
UBool visible) {
|
|
|
|
Entry *entry = new Entry();
|
|
|
|
entry->entryType = Entry::ALIAS;
|
|
|
|
entry->stringArg = alias;
|
|
|
|
registerEntry(ID, entry, visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransliteratorRegistry::remove(const UnicodeString& ID) {
|
|
|
|
UnicodeString source, target, variant;
|
2002-02-07 01:07:55 +00:00
|
|
|
UBool sawSource;
|
|
|
|
TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
|
2001-09-14 21:49:26 +00:00
|
|
|
// Only need to do this if ID.indexOf('-') < 0
|
|
|
|
UnicodeString id;
|
2002-06-11 22:36:11 +00:00
|
|
|
TransliteratorIDParser::STVtoID(source, target, variant, id);
|
2001-09-14 21:49:26 +00:00
|
|
|
registry.remove(id);
|
2001-08-15 19:06:40 +00:00
|
|
|
removeSTV(source, target, variant);
|
2001-09-14 21:49:26 +00:00
|
|
|
availableIDs.removeElement((void*) &id);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class TransliteratorRegistry: Public ID and spec management
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2004-02-20 03:25:18 +00:00
|
|
|
* == OBSOLETE - remove in ICU 3.4 ==
|
2001-08-15 19:06:40 +00:00
|
|
|
* Return the number of IDs currently registered with the system.
|
|
|
|
* To retrieve the actual IDs, call getAvailableID(i) with
|
|
|
|
* i from 0 to countAvailableIDs() - 1.
|
|
|
|
*/
|
2004-03-27 16:26:29 +00:00
|
|
|
int32_t TransliteratorRegistry::countAvailableIDs(void) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
return availableIDs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-02-20 03:25:18 +00:00
|
|
|
* == OBSOLETE - remove in ICU 3.4 ==
|
2001-08-15 19:06:40 +00:00
|
|
|
* Return the index-th available ID. index must be between 0
|
|
|
|
* and countAvailableIDs() - 1, inclusive. If index is out of
|
|
|
|
* range, the result of getAvailableID(0) is returned.
|
|
|
|
*/
|
2004-03-27 16:26:29 +00:00
|
|
|
const UnicodeString& TransliteratorRegistry::getAvailableID(int32_t index) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
if (index < 0 || index >= availableIDs.size()) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
return *(const UnicodeString*) availableIDs[index];
|
|
|
|
}
|
|
|
|
|
2004-03-27 16:26:29 +00:00
|
|
|
StringEnumeration* TransliteratorRegistry::getAvailableIDs() const {
|
2004-02-20 03:25:18 +00:00
|
|
|
return new Enumeration(*this);
|
|
|
|
}
|
|
|
|
|
2004-03-27 16:26:29 +00:00
|
|
|
int32_t TransliteratorRegistry::countAvailableSources(void) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
return specDAG.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString& TransliteratorRegistry::getAvailableSource(int32_t index,
|
2004-03-27 16:26:29 +00:00
|
|
|
UnicodeString& result) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
int32_t pos = -1;
|
|
|
|
const UHashElement *e = 0;
|
|
|
|
while (index-- >= 0) {
|
|
|
|
e = specDAG.nextElement(pos);
|
|
|
|
if (e == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e == 0) {
|
|
|
|
result.truncate(0);
|
|
|
|
} else {
|
|
|
|
result = *(UnicodeString*) e->key.pointer;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-03-27 16:26:29 +00:00
|
|
|
int32_t TransliteratorRegistry::countAvailableTargets(const UnicodeString& source) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
return (targets == 0) ? 0 : targets->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString& TransliteratorRegistry::getAvailableTarget(int32_t index,
|
|
|
|
const UnicodeString& source,
|
2004-03-27 16:26:29 +00:00
|
|
|
UnicodeString& result) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
if (targets == 0) {
|
|
|
|
result.truncate(0); // invalid source
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
int32_t pos = -1;
|
|
|
|
const UHashElement *e = 0;
|
|
|
|
while (index-- >= 0) {
|
|
|
|
e = targets->nextElement(pos);
|
|
|
|
if (e == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e == 0) {
|
|
|
|
result.truncate(0); // invalid index
|
|
|
|
} else {
|
|
|
|
result = *(UnicodeString*) e->key.pointer;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t TransliteratorRegistry::countAvailableVariants(const UnicodeString& source,
|
2004-03-27 16:26:29 +00:00
|
|
|
const UnicodeString& target) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
if (targets == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UVector *variants = (UVector*) targets->get(target);
|
2001-09-14 21:49:26 +00:00
|
|
|
// variants may be 0 if the source/target are invalid
|
|
|
|
return (variants == 0) ? 0 : variants->size();
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString& TransliteratorRegistry::getAvailableVariant(int32_t index,
|
|
|
|
const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
2004-03-27 16:26:29 +00:00
|
|
|
UnicodeString& result) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
if (targets == 0) {
|
|
|
|
result.truncate(0); // invalid source
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
UVector *variants = (UVector*) targets->get(target);
|
|
|
|
if (variants == 0) {
|
|
|
|
result.truncate(0); // invalid target
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
UnicodeString *v = (UnicodeString*) variants->elementAt(index);
|
|
|
|
if (v == 0) {
|
|
|
|
result.truncate(0); // invalid index
|
|
|
|
} else {
|
|
|
|
result = *v;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-02-20 03:25:18 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class TransliteratorRegistry::Enumeration
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-03-27 16:26:29 +00:00
|
|
|
TransliteratorRegistry::Enumeration::Enumeration(const TransliteratorRegistry& _reg) :
|
2004-04-29 18:54:22 +00:00
|
|
|
index(0), reg(_reg) {
|
2004-02-20 03:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransliteratorRegistry::Enumeration::~Enumeration() {
|
|
|
|
}
|
|
|
|
|
2004-04-29 18:54:22 +00:00
|
|
|
int32_t TransliteratorRegistry::Enumeration::count(UErrorCode& /*status*/) const {
|
2004-02-20 03:25:18 +00:00
|
|
|
return reg.availableIDs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString* TransliteratorRegistry::Enumeration::snext(UErrorCode& status) {
|
|
|
|
// This is sloppy but safe -- if we get out of sync with the underlying
|
|
|
|
// registry, we will still return legal strings, but they might not
|
|
|
|
// correspond to the snapshot at construction time. So there could be
|
|
|
|
// duplicate IDs or omitted IDs if insertions or deletions occur in one
|
|
|
|
// thread while another is iterating. To be more rigorous, add a timestamp,
|
|
|
|
// which is incremented with any modification, and validate this iterator
|
|
|
|
// against the timestamp at construction time. This probably isn't worth
|
|
|
|
// doing as long as there is some possibility of removing this code in favor
|
|
|
|
// of some new code based on Doug's service framework.
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int32_t n = reg.availableIDs.size();
|
|
|
|
if (index > n) {
|
|
|
|
status = U_ENUM_OUT_OF_SYNC_ERROR;
|
|
|
|
}
|
|
|
|
// index == n is okay -- this means we've reached the end
|
|
|
|
if (index < n) {
|
|
|
|
// Copy the string! This avoids lifetime problems.
|
|
|
|
unistr = *(const UnicodeString*)reg.availableIDs[index++];
|
|
|
|
return &unistr;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-29 18:54:22 +00:00
|
|
|
void TransliteratorRegistry::Enumeration::reset(UErrorCode& /*status*/) {
|
2004-02-20 03:25:18 +00:00
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TransliteratorRegistry::Enumeration)
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class TransliteratorRegistry: internal
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method. Calls 6-arg registerEntry().
|
|
|
|
*/
|
|
|
|
void TransliteratorRegistry::registerEntry(const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
|
|
|
const UnicodeString& variant,
|
|
|
|
Entry* adopted,
|
|
|
|
UBool visible) {
|
|
|
|
UnicodeString ID;
|
2001-09-14 21:49:26 +00:00
|
|
|
UnicodeString s(source);
|
|
|
|
if (s.length() == 0) {
|
2001-11-16 21:58:05 +00:00
|
|
|
s = ANY;
|
2001-09-14 21:49:26 +00:00
|
|
|
}
|
2002-06-11 22:36:11 +00:00
|
|
|
TransliteratorIDParser::STVtoID(source, target, variant, ID);
|
2001-09-14 21:49:26 +00:00
|
|
|
registerEntry(ID, s, target, variant, adopted, visible);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method. Calls 6-arg registerEntry().
|
|
|
|
*/
|
|
|
|
void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
|
|
|
|
Entry* adopted,
|
|
|
|
UBool visible) {
|
|
|
|
UnicodeString source, target, variant;
|
2002-02-07 01:07:55 +00:00
|
|
|
UBool sawSource;
|
|
|
|
TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
|
2001-09-14 21:49:26 +00:00
|
|
|
// Only need to do this if ID.indexOf('-') < 0
|
|
|
|
UnicodeString id;
|
2002-06-11 22:36:11 +00:00
|
|
|
TransliteratorIDParser::STVtoID(source, target, variant, id);
|
2001-09-14 21:49:26 +00:00
|
|
|
registerEntry(id, source, target, variant, adopted, visible);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register an entry object (adopted) with the given ID, source,
|
|
|
|
* target, and variant strings.
|
|
|
|
*/
|
|
|
|
void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
|
|
|
|
const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
|
|
|
const UnicodeString& variant,
|
|
|
|
Entry* adopted,
|
|
|
|
UBool visible) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
registry.put(ID, adopted, status);
|
|
|
|
if (visible) {
|
|
|
|
registerSTV(source, target, variant);
|
|
|
|
if (!availableIDs.contains((void*) &ID)) {
|
2003-07-02 21:23:39 +00:00
|
|
|
UnicodeString *newID = (UnicodeString *)ID.clone();
|
|
|
|
// NUL-terminate the ID string
|
|
|
|
newID->getTerminatedBuffer();
|
|
|
|
availableIDs.addElement(newID, status);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
removeSTV(source, target, variant);
|
|
|
|
availableIDs.removeElement((void*) &ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a source-target/variant in the specDAG. Variant may be
|
|
|
|
* empty, but source and target must not be. If variant is empty then
|
|
|
|
* the special variant NO_VARIANT is stored in slot zero of the
|
|
|
|
* UVector of variants.
|
|
|
|
*/
|
|
|
|
void TransliteratorRegistry::registerSTV(const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
|
|
|
const UnicodeString& variant) {
|
|
|
|
// assert(source.length() > 0);
|
|
|
|
// assert(target.length() > 0);
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
if (targets == 0) {
|
2004-10-08 01:52:53 +00:00
|
|
|
targets = new Hashtable(TRUE, status);
|
|
|
|
if (U_FAILURE(status) || targets == 0) {
|
2001-08-15 19:06:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
targets->setValueDeleter(uhash_deleteUVector);
|
|
|
|
specDAG.put(source, targets, status);
|
|
|
|
}
|
|
|
|
UVector *variants = (UVector*) targets->get(target);
|
|
|
|
if (variants == 0) {
|
|
|
|
variants = new UVector(uhash_deleteUnicodeString,
|
2001-08-23 01:06:08 +00:00
|
|
|
uhash_compareCaselessUnicodeString, status);
|
2001-08-15 19:06:40 +00:00
|
|
|
if (variants == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
targets->put(target, variants, status);
|
|
|
|
}
|
|
|
|
// assert(NO_VARIANT == "");
|
|
|
|
// We add the variant string. If it is the special "no variant"
|
|
|
|
// string, that is, the empty string, we add it at position zero.
|
|
|
|
if (!variants->contains((void*) &variant)) {
|
|
|
|
if (variant.length() > 0) {
|
2001-08-23 01:06:08 +00:00
|
|
|
variants->addElement(new UnicodeString(variant), status);
|
2001-08-15 19:06:40 +00:00
|
|
|
} else {
|
2001-08-23 01:06:08 +00:00
|
|
|
variants->insertElementAt(new UnicodeString(NO_VARIANT), 0, status);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a source-target/variant from the specDAG.
|
|
|
|
*/
|
|
|
|
void TransliteratorRegistry::removeSTV(const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
|
|
|
const UnicodeString& variant) {
|
|
|
|
// assert(source.length() > 0);
|
|
|
|
// assert(target.length() > 0);
|
2001-08-23 01:06:08 +00:00
|
|
|
// UErrorCode status = U_ZERO_ERROR;
|
2001-08-15 19:06:40 +00:00
|
|
|
Hashtable *targets = (Hashtable*) specDAG.get(source);
|
|
|
|
if (targets == 0) {
|
|
|
|
return; // should never happen for valid s-t/v
|
|
|
|
}
|
|
|
|
UVector *variants = (UVector*) targets->get(target);
|
|
|
|
if (variants == 0) {
|
|
|
|
return; // should never happen for valid s-t/v
|
|
|
|
}
|
|
|
|
variants->removeElement((void*) &variant);
|
|
|
|
if (variants->size() == 0) {
|
|
|
|
targets->remove(target); // should delete variants
|
|
|
|
if (targets->count() == 0) {
|
|
|
|
specDAG.remove(source); // should delete targets
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to find a source-target/variant in the dynamic registry
|
|
|
|
* store. Return 0 on failure.
|
|
|
|
*
|
|
|
|
* Caller does NOT own returned object.
|
|
|
|
*/
|
|
|
|
Entry* TransliteratorRegistry::findInDynamicStore(const Spec& src,
|
|
|
|
const Spec& trg,
|
2004-03-27 16:26:29 +00:00
|
|
|
const UnicodeString& variant) const {
|
2001-08-15 19:06:40 +00:00
|
|
|
UnicodeString ID;
|
2002-06-11 22:36:11 +00:00
|
|
|
TransliteratorIDParser::STVtoID(src, trg, variant, ID);
|
2002-03-20 18:29:10 +00:00
|
|
|
Entry *e = (Entry*) registry.get(ID);
|
|
|
|
DEBUG_useEntry(e);
|
|
|
|
return e;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to find a source-target/variant in the static locale
|
|
|
|
* resource store. Do not perform fallback. Return 0 on failure.
|
|
|
|
*
|
|
|
|
* On success, create a new entry object, register it in the dynamic
|
|
|
|
* store, and return a pointer to it, but do not make it public --
|
|
|
|
* just because someone requested something, we do not expand the
|
|
|
|
* available ID list (or spec DAG).
|
|
|
|
*
|
|
|
|
* Caller does NOT own returned object.
|
|
|
|
*/
|
|
|
|
Entry* TransliteratorRegistry::findInStaticStore(const Spec& src,
|
|
|
|
const Spec& trg,
|
|
|
|
const UnicodeString& variant) {
|
|
|
|
Entry* entry = 0;
|
|
|
|
if (src.isLocale()) {
|
2001-11-03 02:03:33 +00:00
|
|
|
entry = findInBundle(src, trg, variant, UTRANS_FORWARD);
|
2001-08-15 19:06:40 +00:00
|
|
|
} else if (trg.isLocale()) {
|
2001-11-03 02:03:33 +00:00
|
|
|
entry = findInBundle(trg, src, variant, UTRANS_REVERSE);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we found an entry, store it in the Hashtable for next
|
|
|
|
// time.
|
|
|
|
if (entry != 0) {
|
|
|
|
registerEntry(src.getTop(), trg.getTop(), variant, entry, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2001-11-03 02:03:33 +00:00
|
|
|
// As of 2.0, resource bundle keys cannot contain '_'
|
|
|
|
static const UChar TRANSLITERATE_TO[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,84,111,0}; // "TransliterateTo"
|
|
|
|
|
|
|
|
static const UChar TRANSLITERATE_FROM[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,70,114,111,109,0}; // "TransliterateFrom"
|
|
|
|
|
|
|
|
static const UChar TRANSLITERATE[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,0}; // "Transliterate"
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
/**
|
|
|
|
* Attempt to find an entry in a single resource bundle. This is
|
|
|
|
* a one-sided lookup. findInStaticStore() performs up to two such
|
|
|
|
* lookups, one for the source, and one for the target.
|
|
|
|
*
|
|
|
|
* Do not perform fallback. Return 0 on failure.
|
|
|
|
*
|
|
|
|
* On success, create a new Entry object, populate it, and return it.
|
|
|
|
* The caller owns the returned object.
|
|
|
|
*/
|
|
|
|
Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
|
|
|
|
const Spec& specToFind,
|
|
|
|
const UnicodeString& variant,
|
2002-02-28 01:42:40 +00:00
|
|
|
UTransDirection direction)
|
|
|
|
{
|
2001-11-03 02:03:33 +00:00
|
|
|
UnicodeString utag;
|
2001-08-15 19:06:40 +00:00
|
|
|
UnicodeString resStr;
|
2002-02-28 01:42:40 +00:00
|
|
|
int32_t pass;
|
2001-11-03 02:03:33 +00:00
|
|
|
|
|
|
|
for (pass=0; pass<2; ++pass) {
|
|
|
|
utag.truncate(0);
|
|
|
|
// First try either TransliteratorTo_xxx or
|
|
|
|
// TransliterateFrom_xxx, then try the bidirectional
|
|
|
|
// Transliterate_xxx. This precedence order is arbitrary
|
|
|
|
// but must be consistent and documented.
|
|
|
|
if (pass == 0) {
|
|
|
|
utag.append(direction == UTRANS_FORWARD ?
|
|
|
|
TRANSLITERATE_TO : TRANSLITERATE_FROM);
|
|
|
|
} else {
|
|
|
|
utag.append(TRANSLITERATE);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
2001-11-03 02:03:33 +00:00
|
|
|
UnicodeString s(specToFind.get());
|
2004-12-22 19:40:16 +00:00
|
|
|
utag.append(s.toUpper(""));
|
2001-11-03 02:03:33 +00:00
|
|
|
CharString tag(utag);
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
ResourceBundle subres(specToOpen.getBundle().get(tag, status));
|
2002-08-21 19:12:24 +00:00
|
|
|
if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
|
2001-11-03 02:03:33 +00:00
|
|
|
continue;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
2001-11-03 02:03:33 +00:00
|
|
|
|
2005-03-26 15:55:57 +00:00
|
|
|
s.truncate(0);
|
|
|
|
if (specToOpen.get() != LocaleUtility::initNameFromLocale(subres.getLocale(), s)) {
|
2001-11-03 02:03:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variant.length() != 0) {
|
|
|
|
CharString var(variant);
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
resStr = subres.getStringEx(var, status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// Exit loop successfully
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
// Variant is empty, which means match the first variant listed.
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
resStr = subres.getStringEx(1, status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// Exit loop successfully
|
|
|
|
break;
|
|
|
|
}
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-03 02:03:33 +00:00
|
|
|
if (pass==2) {
|
|
|
|
// Failed
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
// We have succeeded in loading a string from the locale
|
|
|
|
// resources. Create a new registry entry to hold it and return it.
|
|
|
|
Entry *entry = new Entry();
|
|
|
|
if (entry != 0) {
|
2001-11-03 02:03:33 +00:00
|
|
|
// The direction is always forward for the
|
|
|
|
// TransliterateTo_xxx and TransliterateFrom_xxx
|
|
|
|
// items; those are unidirectional forward rules.
|
|
|
|
// For the bidirectional Transliterate_xxx items,
|
|
|
|
// the direction is the value passed in to this
|
|
|
|
// function.
|
|
|
|
int32_t dir = (pass == 0) ? UTRANS_FORWARD : direction;
|
2001-08-15 19:06:40 +00:00
|
|
|
entry->entryType = Entry::LOCALE_RULES;
|
|
|
|
entry->stringArg = resStr;
|
2001-11-03 02:03:33 +00:00
|
|
|
entry->intArg = dir;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method. Calls 3-arg find().
|
|
|
|
*/
|
|
|
|
Entry* TransliteratorRegistry::find(const UnicodeString& ID) {
|
|
|
|
UnicodeString source, target, variant;
|
2002-02-07 01:07:55 +00:00
|
|
|
UBool sawSource;
|
|
|
|
TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
|
2001-08-15 19:06:40 +00:00
|
|
|
return find(source, target, variant);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Top-level find method. Attempt to find a source-target/variant in
|
|
|
|
* either the dynamic or the static (locale resource) store. Perform
|
|
|
|
* fallback.
|
|
|
|
*
|
|
|
|
* Lookup sequence for ss_SS_SSS-tt_TT_TTT/v:
|
|
|
|
*
|
|
|
|
* ss_SS_SSS-tt_TT_TTT/v -- in hashtable
|
|
|
|
* ss_SS_SSS-tt_TT_TTT/v -- in ss_SS_SSS (no fallback)
|
|
|
|
*
|
|
|
|
* repeat with t = tt_TT_TTT, tt_TT, tt, and tscript
|
|
|
|
*
|
2001-10-05 16:50:59 +00:00
|
|
|
* ss_SS_SSS-t/ *
|
|
|
|
* ss_SS-t/ *
|
|
|
|
* ss-t/ *
|
|
|
|
* sscript-t/ *
|
2001-08-15 19:06:40 +00:00
|
|
|
*
|
|
|
|
* Here * matches the first variant listed.
|
|
|
|
*
|
|
|
|
* Caller does NOT own returned object. Return 0 on failure.
|
|
|
|
*/
|
|
|
|
Entry* TransliteratorRegistry::find(UnicodeString& source,
|
|
|
|
UnicodeString& target,
|
|
|
|
UnicodeString& variant) {
|
|
|
|
|
|
|
|
Spec src(source);
|
|
|
|
Spec trg(target);
|
|
|
|
Entry* entry;
|
|
|
|
|
|
|
|
if (variant.length() != 0) {
|
|
|
|
|
|
|
|
// Seek exact match in hashtable
|
|
|
|
entry = findInDynamicStore(src, trg, variant);
|
|
|
|
if (entry != 0) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek exact match in locale resources
|
|
|
|
entry = findInStaticStore(src, trg, variant);
|
|
|
|
if (entry != 0) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
src.reset();
|
|
|
|
for (;;) {
|
|
|
|
// Seek match in hashtable
|
|
|
|
entry = findInDynamicStore(src, trg, NO_VARIANT);
|
|
|
|
if (entry != 0) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek match in locale resources
|
|
|
|
entry = findInStaticStore(src, trg, NO_VARIANT);
|
|
|
|
if (entry != 0) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
if (!src.hasFallback()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
src.next();
|
|
|
|
}
|
|
|
|
if (!trg.hasFallback()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
trg.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an Entry object, instantiate it. Caller owns result. Return
|
|
|
|
* 0 on failure.
|
|
|
|
*
|
|
|
|
* Return a non-empty aliasReturn value if the ID points to an alias.
|
|
|
|
* We cannot instantiate it ourselves because the alias may contain
|
|
|
|
* filters or compounds, which we do not understand. Caller should
|
|
|
|
* make aliasReturn empty before calling.
|
|
|
|
*
|
|
|
|
* The entry object is assumed to reside in the dynamic store. It may be
|
|
|
|
* modified.
|
|
|
|
*/
|
|
|
|
Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID,
|
|
|
|
Entry *entry,
|
2001-10-04 21:22:17 +00:00
|
|
|
TransliteratorAlias* &aliasReturn,
|
2001-08-31 03:23:39 +00:00
|
|
|
UErrorCode& status) {
|
2004-06-04 00:52:39 +00:00
|
|
|
Transliterator *t = 0;
|
|
|
|
U_ASSERT(aliasReturn == 0);
|
2001-08-15 19:06:40 +00:00
|
|
|
|
2004-06-04 00:52:39 +00:00
|
|
|
switch (entry->entryType) {
|
|
|
|
case Entry::RBT_DATA:
|
|
|
|
t = new RuleBasedTransliterator(ID, entry->u.data);
|
|
|
|
if (t == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
case Entry::PROTOTYPE:
|
|
|
|
t = entry->u.prototype->clone();
|
|
|
|
if (t == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
case Entry::ALIAS:
|
2005-06-09 17:30:48 +00:00
|
|
|
aliasReturn = new TransliteratorAlias(entry->stringArg, entry->compoundFilter);
|
2004-06-04 00:52:39 +00:00
|
|
|
if (aliasReturn == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case Entry::FACTORY:
|
|
|
|
t = entry->u.factory.function(ID, entry->u.factory.context);
|
|
|
|
if (t == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
case Entry::COMPOUND_RBT:
|
|
|
|
{
|
2005-06-09 17:30:48 +00:00
|
|
|
UVector* rbts = new UVector(status);
|
|
|
|
int32_t passNumber = 1;
|
|
|
|
for (int32_t i = 0; U_SUCCESS(status) && i < entry->u.dataVector->size(); i++) {
|
2005-06-21 16:55:19 +00:00
|
|
|
Transliterator* t = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + (passNumber++),
|
2005-06-09 17:30:48 +00:00
|
|
|
(TransliterationRuleData*)(entry->u.dataVector->elementAt(i)), FALSE);
|
|
|
|
if (t == 0)
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
else
|
|
|
|
rbts->addElement(t, status);
|
2002-06-29 09:31:05 +00:00
|
|
|
}
|
2005-06-09 17:30:48 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return 0;
|
|
|
|
aliasReturn = new TransliteratorAlias(ID, entry->stringArg, rbts, entry->compoundFilter);
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
2004-06-04 00:52:39 +00:00
|
|
|
if (aliasReturn == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case Entry::LOCALE_RULES:
|
|
|
|
aliasReturn = new TransliteratorAlias(ID, entry->stringArg,
|
|
|
|
(UTransDirection) entry->intArg);
|
|
|
|
if (aliasReturn == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case Entry::RULES_FORWARD:
|
|
|
|
case Entry::RULES_REVERSE:
|
|
|
|
// Process the rule data into a TransliteratorRuleData object,
|
|
|
|
// and possibly also into an ::id header and/or footer. Then
|
|
|
|
// we modify the registry with the parsed data and retry.
|
|
|
|
{
|
|
|
|
TransliteratorParser parser;
|
2001-11-03 02:03:33 +00:00
|
|
|
|
|
|
|
// We use the file name, taken from another resource bundle
|
|
|
|
// 2-d array at static init time, as a locale language. We're
|
|
|
|
// just using the locale mechanism to map through to a file
|
|
|
|
// name; this in no way represents an actual locale.
|
2004-08-02 20:06:55 +00:00
|
|
|
//CharString ch(entry->stringArg);
|
|
|
|
//UResourceBundle *bundle = ures_openDirect(0, ch, &status);
|
|
|
|
UnicodeString rules = entry->stringArg;
|
|
|
|
//ures_close(bundle);
|
2001-11-03 02:03:33 +00:00
|
|
|
|
2004-11-05 05:12:29 +00:00
|
|
|
//if (U_FAILURE(status)) {
|
2004-06-04 00:52:39 +00:00
|
|
|
// We have a failure of some kind. Remove the ID from the
|
|
|
|
// registry so we don't keep trying. NOTE: This will throw off
|
|
|
|
// anyone who is, at the moment, trying to iterate over the
|
|
|
|
// available IDs. That's acceptable since we should never
|
|
|
|
// really get here except under installation, configuration,
|
|
|
|
// or unrecoverable run time memory failures.
|
2004-11-05 05:12:29 +00:00
|
|
|
// remove(ID);
|
|
|
|
//} else {
|
2004-06-04 00:52:39 +00:00
|
|
|
|
|
|
|
// If the status indicates a failure, then we don't have any
|
|
|
|
// rules -- there is probably an installation error. The list
|
|
|
|
// in the root locale should correspond to all the installed
|
|
|
|
// transliterators; if it lists something that's not
|
|
|
|
// installed, we'll get an error from ResourceBundle.
|
|
|
|
aliasReturn = new TransliteratorAlias(ID, rules,
|
|
|
|
((entry->entryType == Entry::RULES_REVERSE) ?
|
|
|
|
UTRANS_REVERSE : UTRANS_FORWARD));
|
|
|
|
if (aliasReturn == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2004-11-05 05:12:29 +00:00
|
|
|
//}
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
2004-06-04 00:52:39 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
U_ASSERT(FALSE); // can't get here
|
|
|
|
return 0;
|
2001-08-15 19:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
2001-08-15 19:06:40 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|
|
|
|
|
2001-08-15 19:06:40 +00:00
|
|
|
//eof
|