1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 2001-2014, International Business Machines 6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 8*0e209d39SAndroid Build Coastguard Worker * Date Name Description 9*0e209d39SAndroid Build Coastguard Worker * 08/10/2001 aliu Creation. 10*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 11*0e209d39SAndroid Build Coastguard Worker */ 12*0e209d39SAndroid Build Coastguard Worker #ifndef _TRANSREG_H 13*0e209d39SAndroid Build Coastguard Worker #define _TRANSREG_H 14*0e209d39SAndroid Build Coastguard Worker 15*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_TRANSLITERATION 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h" 20*0e209d39SAndroid Build Coastguard Worker #include "unicode/translit.h" 21*0e209d39SAndroid Build Coastguard Worker #include "hash.h" 22*0e209d39SAndroid Build Coastguard Worker #include "uvector.h" 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 25*0e209d39SAndroid Build Coastguard Worker 26*0e209d39SAndroid Build Coastguard Worker class TransliteratorEntry; 27*0e209d39SAndroid Build Coastguard Worker class TransliteratorSpec; 28*0e209d39SAndroid Build Coastguard Worker class UnicodeString; 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 31*0e209d39SAndroid Build Coastguard Worker // TransliteratorAlias 32*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 33*0e209d39SAndroid Build Coastguard Worker 34*0e209d39SAndroid Build Coastguard Worker /** 35*0e209d39SAndroid Build Coastguard Worker * A TransliteratorAlias object is returned by get() if the given ID 36*0e209d39SAndroid Build Coastguard Worker * actually translates into something else. The caller then invokes 37*0e209d39SAndroid Build Coastguard Worker * the create() method on the alias to create the actual 38*0e209d39SAndroid Build Coastguard Worker * transliterator, and deletes the alias. 39*0e209d39SAndroid Build Coastguard Worker * 40*0e209d39SAndroid Build Coastguard Worker * Why all the shenanigans? To prevent circular calls between 41*0e209d39SAndroid Build Coastguard Worker * the registry code and the transliterator code that deadlocks. 42*0e209d39SAndroid Build Coastguard Worker */ 43*0e209d39SAndroid Build Coastguard Worker class TransliteratorAlias : public UMemory { 44*0e209d39SAndroid Build Coastguard Worker public: 45*0e209d39SAndroid Build Coastguard Worker /** 46*0e209d39SAndroid Build Coastguard Worker * Construct a simple alias (type == SIMPLE) 47*0e209d39SAndroid Build Coastguard Worker * @param aliasID the given id. 48*0e209d39SAndroid Build Coastguard Worker */ 49*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias(const UnicodeString& aliasID, const UnicodeSet* compoundFilter); 50*0e209d39SAndroid Build Coastguard Worker 51*0e209d39SAndroid Build Coastguard Worker /** 52*0e209d39SAndroid Build Coastguard Worker * Construct a compound RBT alias (type == COMPOUND) 53*0e209d39SAndroid Build Coastguard Worker */ 54*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias(const UnicodeString& ID, const UnicodeString& idBlocks, 55*0e209d39SAndroid Build Coastguard Worker UVector* adoptedTransliterators, 56*0e209d39SAndroid Build Coastguard Worker const UnicodeSet* compoundFilter); 57*0e209d39SAndroid Build Coastguard Worker 58*0e209d39SAndroid Build Coastguard Worker /** 59*0e209d39SAndroid Build Coastguard Worker * Construct a rules alias (type = RULES) 60*0e209d39SAndroid Build Coastguard Worker */ 61*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias(const UnicodeString& theID, 62*0e209d39SAndroid Build Coastguard Worker const UnicodeString& rules, 63*0e209d39SAndroid Build Coastguard Worker UTransDirection dir); 64*0e209d39SAndroid Build Coastguard Worker 65*0e209d39SAndroid Build Coastguard Worker ~TransliteratorAlias(); 66*0e209d39SAndroid Build Coastguard Worker 67*0e209d39SAndroid Build Coastguard Worker /** 68*0e209d39SAndroid Build Coastguard Worker * The whole point of create() is that the caller must invoke 69*0e209d39SAndroid Build Coastguard Worker * it when the registry mutex is NOT held, to prevent deadlock. 70*0e209d39SAndroid Build Coastguard Worker * It may only be called once. 71*0e209d39SAndroid Build Coastguard Worker * 72*0e209d39SAndroid Build Coastguard Worker * Note: Only call create() if isRuleBased() returns false. 73*0e209d39SAndroid Build Coastguard Worker * 74*0e209d39SAndroid Build Coastguard Worker * This method must be called *outside* of the TransliteratorRegistry 75*0e209d39SAndroid Build Coastguard Worker * mutex. 76*0e209d39SAndroid Build Coastguard Worker */ 77*0e209d39SAndroid Build Coastguard Worker Transliterator* create(UParseError&, UErrorCode&); 78*0e209d39SAndroid Build Coastguard Worker 79*0e209d39SAndroid Build Coastguard Worker /** 80*0e209d39SAndroid Build Coastguard Worker * Return true if this alias is rule-based. If so, the caller 81*0e209d39SAndroid Build Coastguard Worker * must call parse() on it, then call TransliteratorRegistry::reget(). 82*0e209d39SAndroid Build Coastguard Worker */ 83*0e209d39SAndroid Build Coastguard Worker UBool isRuleBased() const; 84*0e209d39SAndroid Build Coastguard Worker 85*0e209d39SAndroid Build Coastguard Worker /** 86*0e209d39SAndroid Build Coastguard Worker * If isRuleBased() returns true, then the caller must call this 87*0e209d39SAndroid Build Coastguard Worker * method, followed by TransliteratorRegistry::reget(). The latter 88*0e209d39SAndroid Build Coastguard Worker * method must be called inside the TransliteratorRegistry mutex. 89*0e209d39SAndroid Build Coastguard Worker * 90*0e209d39SAndroid Build Coastguard Worker * Note: Only call parse() if isRuleBased() returns true. 91*0e209d39SAndroid Build Coastguard Worker * 92*0e209d39SAndroid Build Coastguard Worker * This method must be called *outside* of the TransliteratorRegistry 93*0e209d39SAndroid Build Coastguard Worker * mutex, because it can instantiate Transliterators embedded in 94*0e209d39SAndroid Build Coastguard Worker * the rules via the "&Latin-Arabic()" syntax. 95*0e209d39SAndroid Build Coastguard Worker */ 96*0e209d39SAndroid Build Coastguard Worker void parse(TransliteratorParser& parser, 97*0e209d39SAndroid Build Coastguard Worker UParseError& pe, UErrorCode& ec) const; 98*0e209d39SAndroid Build Coastguard Worker 99*0e209d39SAndroid Build Coastguard Worker private: 100*0e209d39SAndroid Build Coastguard Worker // We actually come in three flavors: 101*0e209d39SAndroid Build Coastguard Worker // 1. Simple alias 102*0e209d39SAndroid Build Coastguard Worker // Here aliasID is the alias string. Everything else is 103*0e209d39SAndroid Build Coastguard Worker // null, zero, empty. 104*0e209d39SAndroid Build Coastguard Worker // 2. CompoundRBT 105*0e209d39SAndroid Build Coastguard Worker // Here ID is the ID, aliasID is the idBlock, trans is the 106*0e209d39SAndroid Build Coastguard Worker // contained RBT, and idSplitPoint is the offset in aliasID 107*0e209d39SAndroid Build Coastguard Worker // where the contained RBT goes. compoundFilter is the 108*0e209d39SAndroid Build Coastguard Worker // compound filter, and it is _not_ owned. 109*0e209d39SAndroid Build Coastguard Worker // 3. Rules 110*0e209d39SAndroid Build Coastguard Worker // Here ID is the ID, aliasID is the rules string. 111*0e209d39SAndroid Build Coastguard Worker // idSplitPoint is the UTransDirection. 112*0e209d39SAndroid Build Coastguard Worker UnicodeString ID; 113*0e209d39SAndroid Build Coastguard Worker UnicodeString aliasesOrRules; 114*0e209d39SAndroid Build Coastguard Worker UVector* transes; // owned 115*0e209d39SAndroid Build Coastguard Worker const UnicodeSet* compoundFilter; // alias 116*0e209d39SAndroid Build Coastguard Worker UTransDirection direction; 117*0e209d39SAndroid Build Coastguard Worker enum { SIMPLE, COMPOUND, RULES } type; 118*0e209d39SAndroid Build Coastguard Worker 119*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias(const TransliteratorAlias &other); // forbid copying of this class 120*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias &operator=(const TransliteratorAlias &other); // forbid copying of this class 121*0e209d39SAndroid Build Coastguard Worker }; 122*0e209d39SAndroid Build Coastguard Worker 123*0e209d39SAndroid Build Coastguard Worker 124*0e209d39SAndroid Build Coastguard Worker /** 125*0e209d39SAndroid Build Coastguard Worker * A registry of system transliterators. This is the data structure 126*0e209d39SAndroid Build Coastguard Worker * that implements the mapping between transliterator IDs and the data 127*0e209d39SAndroid Build Coastguard Worker * or function pointers used to create the corresponding 128*0e209d39SAndroid Build Coastguard Worker * transliterators. There is one instance of the registry that is 129*0e209d39SAndroid Build Coastguard Worker * created statically. 130*0e209d39SAndroid Build Coastguard Worker * 131*0e209d39SAndroid Build Coastguard Worker * The registry consists of a dynamic component -- a hashtable -- and 132*0e209d39SAndroid Build Coastguard Worker * a static component -- locale resource bundles. The dynamic store 133*0e209d39SAndroid Build Coastguard Worker * is semantically overlaid on the static store, so the static mapping 134*0e209d39SAndroid Build Coastguard Worker * can be dynamically overridden. 135*0e209d39SAndroid Build Coastguard Worker * 136*0e209d39SAndroid Build Coastguard Worker * This is an internal class that is only used by Transliterator. 137*0e209d39SAndroid Build Coastguard Worker * Transliterator maintains one static instance of this class and 138*0e209d39SAndroid Build Coastguard Worker * delegates all registry-related operations to it. 139*0e209d39SAndroid Build Coastguard Worker * 140*0e209d39SAndroid Build Coastguard Worker * @author Alan Liu 141*0e209d39SAndroid Build Coastguard Worker */ 142*0e209d39SAndroid Build Coastguard Worker class TransliteratorRegistry : public UMemory { 143*0e209d39SAndroid Build Coastguard Worker 144*0e209d39SAndroid Build Coastguard Worker public: 145*0e209d39SAndroid Build Coastguard Worker 146*0e209d39SAndroid Build Coastguard Worker /** 147*0e209d39SAndroid Build Coastguard Worker * Constructor 148*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code. 149*0e209d39SAndroid Build Coastguard Worker */ 150*0e209d39SAndroid Build Coastguard Worker TransliteratorRegistry(UErrorCode& status); 151*0e209d39SAndroid Build Coastguard Worker 152*0e209d39SAndroid Build Coastguard Worker /** 153*0e209d39SAndroid Build Coastguard Worker * Nonvirtual destructor -- this class is not subclassable. 154*0e209d39SAndroid Build Coastguard Worker */ 155*0e209d39SAndroid Build Coastguard Worker ~TransliteratorRegistry(); 156*0e209d39SAndroid Build Coastguard Worker 157*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 158*0e209d39SAndroid Build Coastguard Worker // Basic public API 159*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 160*0e209d39SAndroid Build Coastguard Worker 161*0e209d39SAndroid Build Coastguard Worker /** 162*0e209d39SAndroid Build Coastguard Worker * Given a simple ID (forward direction, no inline filter, not 163*0e209d39SAndroid Build Coastguard Worker * compound) attempt to instantiate it from the registry. Return 164*0e209d39SAndroid Build Coastguard Worker * 0 on failure. 165*0e209d39SAndroid Build Coastguard Worker * 166*0e209d39SAndroid Build Coastguard Worker * Return a non-nullptr aliasReturn value if the ID points to an alias. 167*0e209d39SAndroid Build Coastguard Worker * We cannot instantiate it ourselves because the alias may contain 168*0e209d39SAndroid Build Coastguard Worker * filters or compounds, which we do not understand. Caller should 169*0e209d39SAndroid Build Coastguard Worker * make aliasReturn nullptr before calling. 170*0e209d39SAndroid Build Coastguard Worker * @param ID the given ID 171*0e209d39SAndroid Build Coastguard Worker * @param aliasReturn output param to receive TransliteratorAlias; 172*0e209d39SAndroid Build Coastguard Worker * should be nullptr on entry 173*0e209d39SAndroid Build Coastguard Worker * @param parseError Struct to receive information on position 174*0e209d39SAndroid Build Coastguard Worker * of error if an error is encountered 175*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code. 176*0e209d39SAndroid Build Coastguard Worker */ 177*0e209d39SAndroid Build Coastguard Worker Transliterator* get(const UnicodeString& ID, 178*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias*& aliasReturn, 179*0e209d39SAndroid Build Coastguard Worker UErrorCode& status); 180*0e209d39SAndroid Build Coastguard Worker 181*0e209d39SAndroid Build Coastguard Worker /** 182*0e209d39SAndroid Build Coastguard Worker * The caller must call this after calling get(), if [a] calling get() 183*0e209d39SAndroid Build Coastguard Worker * returns an alias, and [b] the alias is rule based. In that 184*0e209d39SAndroid Build Coastguard Worker * situation the caller must call alias->parse() to do the parsing 185*0e209d39SAndroid Build Coastguard Worker * OUTSIDE THE REGISTRY MUTEX, then call this method to retry 186*0e209d39SAndroid Build Coastguard Worker * instantiating the transliterator. 187*0e209d39SAndroid Build Coastguard Worker * 188*0e209d39SAndroid Build Coastguard Worker * Note: Another alias might be returned by this method. 189*0e209d39SAndroid Build Coastguard Worker * 190*0e209d39SAndroid Build Coastguard Worker * This method (like all public methods of this class) must be called 191*0e209d39SAndroid Build Coastguard Worker * from within the TransliteratorRegistry mutex. 192*0e209d39SAndroid Build Coastguard Worker * 193*0e209d39SAndroid Build Coastguard Worker * @param aliasReturn output param to receive TransliteratorAlias; 194*0e209d39SAndroid Build Coastguard Worker * should be nullptr on entry 195*0e209d39SAndroid Build Coastguard Worker */ 196*0e209d39SAndroid Build Coastguard Worker Transliterator* reget(const UnicodeString& ID, 197*0e209d39SAndroid Build Coastguard Worker TransliteratorParser& parser, 198*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias*& aliasReturn, 199*0e209d39SAndroid Build Coastguard Worker UErrorCode& status); 200*0e209d39SAndroid Build Coastguard Worker 201*0e209d39SAndroid Build Coastguard Worker /** 202*0e209d39SAndroid Build Coastguard Worker * Register a prototype (adopted). This adds an entry to the 203*0e209d39SAndroid Build Coastguard Worker * dynamic store, or replaces an existing entry. Any entry in the 204*0e209d39SAndroid Build Coastguard Worker * underlying static locale resource store is masked. 205*0e209d39SAndroid Build Coastguard Worker */ 206*0e209d39SAndroid Build Coastguard Worker void put(Transliterator* adoptedProto, 207*0e209d39SAndroid Build Coastguard Worker UBool visible, 208*0e209d39SAndroid Build Coastguard Worker UErrorCode& ec); 209*0e209d39SAndroid Build Coastguard Worker 210*0e209d39SAndroid Build Coastguard Worker /** 211*0e209d39SAndroid Build Coastguard Worker * Register an ID and a factory function pointer. This adds an 212*0e209d39SAndroid Build Coastguard Worker * entry to the dynamic store, or replaces an existing entry. Any 213*0e209d39SAndroid Build Coastguard Worker * entry in the underlying static locale resource store is masked. 214*0e209d39SAndroid Build Coastguard Worker */ 215*0e209d39SAndroid Build Coastguard Worker void put(const UnicodeString& ID, 216*0e209d39SAndroid Build Coastguard Worker Transliterator::Factory factory, 217*0e209d39SAndroid Build Coastguard Worker Transliterator::Token context, 218*0e209d39SAndroid Build Coastguard Worker UBool visible, 219*0e209d39SAndroid Build Coastguard Worker UErrorCode& ec); 220*0e209d39SAndroid Build Coastguard Worker 221*0e209d39SAndroid Build Coastguard Worker /** 222*0e209d39SAndroid Build Coastguard Worker * Register an ID and a resource name. This adds an entry to the 223*0e209d39SAndroid Build Coastguard Worker * dynamic store, or replaces an existing entry. Any entry in the 224*0e209d39SAndroid Build Coastguard Worker * underlying static locale resource store is masked. 225*0e209d39SAndroid Build Coastguard Worker */ 226*0e209d39SAndroid Build Coastguard Worker void put(const UnicodeString& ID, 227*0e209d39SAndroid Build Coastguard Worker const UnicodeString& resourceName, 228*0e209d39SAndroid Build Coastguard Worker UTransDirection dir, 229*0e209d39SAndroid Build Coastguard Worker UBool readonlyResourceAlias, 230*0e209d39SAndroid Build Coastguard Worker UBool visible, 231*0e209d39SAndroid Build Coastguard Worker UErrorCode& ec); 232*0e209d39SAndroid Build Coastguard Worker 233*0e209d39SAndroid Build Coastguard Worker /** 234*0e209d39SAndroid Build Coastguard Worker * Register an ID and an alias ID. This adds an entry to the 235*0e209d39SAndroid Build Coastguard Worker * dynamic store, or replaces an existing entry. Any entry in the 236*0e209d39SAndroid Build Coastguard Worker * underlying static locale resource store is masked. 237*0e209d39SAndroid Build Coastguard Worker */ 238*0e209d39SAndroid Build Coastguard Worker void put(const UnicodeString& ID, 239*0e209d39SAndroid Build Coastguard Worker const UnicodeString& alias, 240*0e209d39SAndroid Build Coastguard Worker UBool readonlyAliasAlias, 241*0e209d39SAndroid Build Coastguard Worker UBool visible, 242*0e209d39SAndroid Build Coastguard Worker UErrorCode& ec); 243*0e209d39SAndroid Build Coastguard Worker 244*0e209d39SAndroid Build Coastguard Worker /** 245*0e209d39SAndroid Build Coastguard Worker * Unregister an ID. This removes an entry from the dynamic store 246*0e209d39SAndroid Build Coastguard Worker * if there is one. The static locale resource store is 247*0e209d39SAndroid Build Coastguard Worker * unaffected. 248*0e209d39SAndroid Build Coastguard Worker * @param ID the given ID. 249*0e209d39SAndroid Build Coastguard Worker */ 250*0e209d39SAndroid Build Coastguard Worker void remove(const UnicodeString& ID); 251*0e209d39SAndroid Build Coastguard Worker 252*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 253*0e209d39SAndroid Build Coastguard Worker // Public ID and spec management 254*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------ 255*0e209d39SAndroid Build Coastguard Worker 256*0e209d39SAndroid Build Coastguard Worker /** 257*0e209d39SAndroid Build Coastguard Worker * Return a StringEnumeration over the IDs currently registered 258*0e209d39SAndroid Build Coastguard Worker * with the system. 259*0e209d39SAndroid Build Coastguard Worker * @internal 260*0e209d39SAndroid Build Coastguard Worker */ 261*0e209d39SAndroid Build Coastguard Worker StringEnumeration* getAvailableIDs() const; 262*0e209d39SAndroid Build Coastguard Worker 263*0e209d39SAndroid Build Coastguard Worker /** 264*0e209d39SAndroid Build Coastguard Worker * == OBSOLETE - remove in ICU 3.4 == 265*0e209d39SAndroid Build Coastguard Worker * Return the number of IDs currently registered with the system. 266*0e209d39SAndroid Build Coastguard Worker * To retrieve the actual IDs, call getAvailableID(i) with 267*0e209d39SAndroid Build Coastguard Worker * i from 0 to countAvailableIDs() - 1. 268*0e209d39SAndroid Build Coastguard Worker * @return the number of IDs currently registered with the system. 269*0e209d39SAndroid Build Coastguard Worker * @internal 270*0e209d39SAndroid Build Coastguard Worker */ 271*0e209d39SAndroid Build Coastguard Worker int32_t countAvailableIDs() const; 272*0e209d39SAndroid Build Coastguard Worker 273*0e209d39SAndroid Build Coastguard Worker /** 274*0e209d39SAndroid Build Coastguard Worker * == OBSOLETE - remove in ICU 3.4 == 275*0e209d39SAndroid Build Coastguard Worker * Return the index-th available ID. index must be between 0 276*0e209d39SAndroid Build Coastguard Worker * and countAvailableIDs() - 1, inclusive. If index is out of 277*0e209d39SAndroid Build Coastguard Worker * range, the result of getAvailableID(0) is returned. 278*0e209d39SAndroid Build Coastguard Worker * @param index the given index. 279*0e209d39SAndroid Build Coastguard Worker * @return the index-th available ID. index must be between 0 280*0e209d39SAndroid Build Coastguard Worker * and countAvailableIDs() - 1, inclusive. If index is out of 281*0e209d39SAndroid Build Coastguard Worker * range, the result of getAvailableID(0) is returned. 282*0e209d39SAndroid Build Coastguard Worker * @internal 283*0e209d39SAndroid Build Coastguard Worker */ 284*0e209d39SAndroid Build Coastguard Worker const UnicodeString& getAvailableID(int32_t index) const; 285*0e209d39SAndroid Build Coastguard Worker 286*0e209d39SAndroid Build Coastguard Worker /** 287*0e209d39SAndroid Build Coastguard Worker * Return the number of registered source specifiers. 288*0e209d39SAndroid Build Coastguard Worker * @return the number of registered source specifiers. 289*0e209d39SAndroid Build Coastguard Worker */ 290*0e209d39SAndroid Build Coastguard Worker int32_t countAvailableSources() const; 291*0e209d39SAndroid Build Coastguard Worker 292*0e209d39SAndroid Build Coastguard Worker /** 293*0e209d39SAndroid Build Coastguard Worker * Return a registered source specifier. 294*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where 295*0e209d39SAndroid Build Coastguard Worker * n = countAvailableSources() 296*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the source specifier. 297*0e209d39SAndroid Build Coastguard Worker * If index is out of range, result will be empty. 298*0e209d39SAndroid Build Coastguard Worker * @return reference to result 299*0e209d39SAndroid Build Coastguard Worker */ 300*0e209d39SAndroid Build Coastguard Worker UnicodeString& getAvailableSource(int32_t index, 301*0e209d39SAndroid Build Coastguard Worker UnicodeString& result) const; 302*0e209d39SAndroid Build Coastguard Worker 303*0e209d39SAndroid Build Coastguard Worker /** 304*0e209d39SAndroid Build Coastguard Worker * Return the number of registered target specifiers for a given 305*0e209d39SAndroid Build Coastguard Worker * source specifier. 306*0e209d39SAndroid Build Coastguard Worker * @param source the given source specifier. 307*0e209d39SAndroid Build Coastguard Worker * @return the number of registered target specifiers for a given 308*0e209d39SAndroid Build Coastguard Worker * source specifier. 309*0e209d39SAndroid Build Coastguard Worker */ 310*0e209d39SAndroid Build Coastguard Worker int32_t countAvailableTargets(const UnicodeString& source) const; 311*0e209d39SAndroid Build Coastguard Worker 312*0e209d39SAndroid Build Coastguard Worker /** 313*0e209d39SAndroid Build Coastguard Worker * Return a registered target specifier for a given source. 314*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where 315*0e209d39SAndroid Build Coastguard Worker * n = countAvailableTargets(source) 316*0e209d39SAndroid Build Coastguard Worker * @param source the source specifier 317*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the target specifier. 318*0e209d39SAndroid Build Coastguard Worker * If source is invalid or if index is out of range, result will 319*0e209d39SAndroid Build Coastguard Worker * be empty. 320*0e209d39SAndroid Build Coastguard Worker * @return reference to result 321*0e209d39SAndroid Build Coastguard Worker */ 322*0e209d39SAndroid Build Coastguard Worker UnicodeString& getAvailableTarget(int32_t index, 323*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source, 324*0e209d39SAndroid Build Coastguard Worker UnicodeString& result) const; 325*0e209d39SAndroid Build Coastguard Worker 326*0e209d39SAndroid Build Coastguard Worker /** 327*0e209d39SAndroid Build Coastguard Worker * Return the number of registered variant specifiers for a given 328*0e209d39SAndroid Build Coastguard Worker * source-target pair. There is always at least one variant: If 329*0e209d39SAndroid Build Coastguard Worker * just source-target is registered, then the single variant 330*0e209d39SAndroid Build Coastguard Worker * NO_VARIANT is returned. If source-target/variant is registered 331*0e209d39SAndroid Build Coastguard Worker * then that variant is returned. 332*0e209d39SAndroid Build Coastguard Worker * @param source the source specifiers 333*0e209d39SAndroid Build Coastguard Worker * @param target the target specifiers 334*0e209d39SAndroid Build Coastguard Worker * @return the number of registered variant specifiers for a given 335*0e209d39SAndroid Build Coastguard Worker * source-target pair. 336*0e209d39SAndroid Build Coastguard Worker */ 337*0e209d39SAndroid Build Coastguard Worker int32_t countAvailableVariants(const UnicodeString& source, 338*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target) const; 339*0e209d39SAndroid Build Coastguard Worker 340*0e209d39SAndroid Build Coastguard Worker /** 341*0e209d39SAndroid Build Coastguard Worker * Return a registered variant specifier for a given source-target 342*0e209d39SAndroid Build Coastguard Worker * pair. If NO_VARIANT is one of the variants, then it will be 343*0e209d39SAndroid Build Coastguard Worker * at index 0. 344*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where 345*0e209d39SAndroid Build Coastguard Worker * n = countAvailableVariants(source, target) 346*0e209d39SAndroid Build Coastguard Worker * @param source the source specifier 347*0e209d39SAndroid Build Coastguard Worker * @param target the target specifier 348*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the variant 349*0e209d39SAndroid Build Coastguard Worker * specifier. If source is invalid or if target is invalid or if 350*0e209d39SAndroid Build Coastguard Worker * index is out of range, result will be empty. 351*0e209d39SAndroid Build Coastguard Worker * @return reference to result 352*0e209d39SAndroid Build Coastguard Worker */ 353*0e209d39SAndroid Build Coastguard Worker UnicodeString& getAvailableVariant(int32_t index, 354*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source, 355*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target, 356*0e209d39SAndroid Build Coastguard Worker UnicodeString& result) const; 357*0e209d39SAndroid Build Coastguard Worker 358*0e209d39SAndroid Build Coastguard Worker private: 359*0e209d39SAndroid Build Coastguard Worker 360*0e209d39SAndroid Build Coastguard Worker //---------------------------------------------------------------- 361*0e209d39SAndroid Build Coastguard Worker // Private implementation 362*0e209d39SAndroid Build Coastguard Worker //---------------------------------------------------------------- 363*0e209d39SAndroid Build Coastguard Worker 364*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* find(const UnicodeString& ID); 365*0e209d39SAndroid Build Coastguard Worker 366*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* find(UnicodeString& source, 367*0e209d39SAndroid Build Coastguard Worker UnicodeString& target, 368*0e209d39SAndroid Build Coastguard Worker UnicodeString& variant); 369*0e209d39SAndroid Build Coastguard Worker 370*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* findInDynamicStore(const TransliteratorSpec& src, 371*0e209d39SAndroid Build Coastguard Worker const TransliteratorSpec& trg, 372*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant) const; 373*0e209d39SAndroid Build Coastguard Worker 374*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* findInStaticStore(const TransliteratorSpec& src, 375*0e209d39SAndroid Build Coastguard Worker const TransliteratorSpec& trg, 376*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant); 377*0e209d39SAndroid Build Coastguard Worker 378*0e209d39SAndroid Build Coastguard Worker static TransliteratorEntry* findInBundle(const TransliteratorSpec& specToOpen, 379*0e209d39SAndroid Build Coastguard Worker const TransliteratorSpec& specToFind, 380*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant, 381*0e209d39SAndroid Build Coastguard Worker UTransDirection direction); 382*0e209d39SAndroid Build Coastguard Worker 383*0e209d39SAndroid Build Coastguard Worker void registerEntry(const UnicodeString& source, 384*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target, 385*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant, 386*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* adopted, 387*0e209d39SAndroid Build Coastguard Worker UBool visible); 388*0e209d39SAndroid Build Coastguard Worker 389*0e209d39SAndroid Build Coastguard Worker void registerEntry(const UnicodeString& ID, 390*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* adopted, 391*0e209d39SAndroid Build Coastguard Worker UBool visible); 392*0e209d39SAndroid Build Coastguard Worker 393*0e209d39SAndroid Build Coastguard Worker void registerEntry(const UnicodeString& ID, 394*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source, 395*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target, 396*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant, 397*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry* adopted, 398*0e209d39SAndroid Build Coastguard Worker UBool visible); 399*0e209d39SAndroid Build Coastguard Worker 400*0e209d39SAndroid Build Coastguard Worker void registerSTV(const UnicodeString& source, 401*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target, 402*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant); 403*0e209d39SAndroid Build Coastguard Worker 404*0e209d39SAndroid Build Coastguard Worker void removeSTV(const UnicodeString& source, 405*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target, 406*0e209d39SAndroid Build Coastguard Worker const UnicodeString& variant); 407*0e209d39SAndroid Build Coastguard Worker 408*0e209d39SAndroid Build Coastguard Worker Transliterator* instantiateEntry(const UnicodeString& ID, 409*0e209d39SAndroid Build Coastguard Worker TransliteratorEntry *entry, 410*0e209d39SAndroid Build Coastguard Worker TransliteratorAlias*& aliasReturn, 411*0e209d39SAndroid Build Coastguard Worker UErrorCode& status); 412*0e209d39SAndroid Build Coastguard Worker 413*0e209d39SAndroid Build Coastguard Worker /** 414*0e209d39SAndroid Build Coastguard Worker * A StringEnumeration over the registered IDs in this object. 415*0e209d39SAndroid Build Coastguard Worker */ 416*0e209d39SAndroid Build Coastguard Worker class Enumeration : public StringEnumeration { 417*0e209d39SAndroid Build Coastguard Worker public: 418*0e209d39SAndroid Build Coastguard Worker Enumeration(const TransliteratorRegistry& reg); 419*0e209d39SAndroid Build Coastguard Worker virtual ~Enumeration(); 420*0e209d39SAndroid Build Coastguard Worker virtual int32_t count(UErrorCode& status) const override; 421*0e209d39SAndroid Build Coastguard Worker virtual const UnicodeString* snext(UErrorCode& status) override; 422*0e209d39SAndroid Build Coastguard Worker virtual void reset(UErrorCode& status) override; 423*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID(); 424*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override; 425*0e209d39SAndroid Build Coastguard Worker private: 426*0e209d39SAndroid Build Coastguard Worker int32_t pos; 427*0e209d39SAndroid Build Coastguard Worker int32_t size; 428*0e209d39SAndroid Build Coastguard Worker const TransliteratorRegistry& reg; 429*0e209d39SAndroid Build Coastguard Worker }; 430*0e209d39SAndroid Build Coastguard Worker friend class Enumeration; 431*0e209d39SAndroid Build Coastguard Worker 432*0e209d39SAndroid Build Coastguard Worker private: 433*0e209d39SAndroid Build Coastguard Worker 434*0e209d39SAndroid Build Coastguard Worker /** 435*0e209d39SAndroid Build Coastguard Worker * Dynamic registry mapping full IDs to Entry objects. This 436*0e209d39SAndroid Build Coastguard Worker * contains both public and internal entities. The visibility is 437*0e209d39SAndroid Build Coastguard Worker * controlled by whether an entry is listed in availableIDs and 438*0e209d39SAndroid Build Coastguard Worker * specDAG or not. 439*0e209d39SAndroid Build Coastguard Worker */ 440*0e209d39SAndroid Build Coastguard Worker Hashtable registry; 441*0e209d39SAndroid Build Coastguard Worker 442*0e209d39SAndroid Build Coastguard Worker /** 443*0e209d39SAndroid Build Coastguard Worker * DAG of visible IDs by spec. Hashtable: source => (Hashtable: 444*0e209d39SAndroid Build Coastguard Worker * target => variant bitmask) 445*0e209d39SAndroid Build Coastguard Worker */ 446*0e209d39SAndroid Build Coastguard Worker Hashtable specDAG; 447*0e209d39SAndroid Build Coastguard Worker 448*0e209d39SAndroid Build Coastguard Worker /** 449*0e209d39SAndroid Build Coastguard Worker * Vector of all variant names 450*0e209d39SAndroid Build Coastguard Worker */ 451*0e209d39SAndroid Build Coastguard Worker UVector variantList; 452*0e209d39SAndroid Build Coastguard Worker 453*0e209d39SAndroid Build Coastguard Worker /** 454*0e209d39SAndroid Build Coastguard Worker * Vector of public full IDs. 455*0e209d39SAndroid Build Coastguard Worker */ 456*0e209d39SAndroid Build Coastguard Worker Hashtable availableIDs; 457*0e209d39SAndroid Build Coastguard Worker 458*0e209d39SAndroid Build Coastguard Worker TransliteratorRegistry(const TransliteratorRegistry &other); // forbid copying of this class 459*0e209d39SAndroid Build Coastguard Worker TransliteratorRegistry &operator=(const TransliteratorRegistry &other); // forbid copying of this class 460*0e209d39SAndroid Build Coastguard Worker }; 461*0e209d39SAndroid Build Coastguard Worker 462*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 463*0e209d39SAndroid Build Coastguard Worker 464*0e209d39SAndroid Build Coastguard Worker U_CFUNC UBool utrans_transliterator_cleanup(); 465*0e209d39SAndroid Build Coastguard Worker 466*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_TRANSLITERATION */ 467*0e209d39SAndroid Build Coastguard Worker 468*0e209d39SAndroid Build Coastguard Worker #endif 469*0e209d39SAndroid Build Coastguard Worker //eof 470