| 1 | // © 2016 and later: Unicode, Inc. and others. | 
|---|
| 2 | // License & terms of use: http://www.unicode.org/copyright.html | 
|---|
| 3 | /* | 
|---|
| 4 | *********************************************************************** | 
|---|
| 5 | * Copyright (c) 2002-2007, International Business Machines Corporation | 
|---|
| 6 | * and others.  All Rights Reserved. | 
|---|
| 7 | *********************************************************************** | 
|---|
| 8 | * Date        Name        Description | 
|---|
| 9 | * 06/06/2002  aliu        Creation. | 
|---|
| 10 | *********************************************************************** | 
|---|
| 11 | */ | 
|---|
| 12 | #ifndef _ANYTRANS_H_ | 
|---|
| 13 | #define _ANYTRANS_H_ | 
|---|
| 14 |  | 
|---|
| 15 | #include "unicode/utypes.h" | 
|---|
| 16 |  | 
|---|
| 17 | #if !UCONFIG_NO_TRANSLITERATION | 
|---|
| 18 |  | 
|---|
| 19 | #include "unicode/translit.h" | 
|---|
| 20 | #include "unicode/uscript.h" | 
|---|
| 21 | #include "uhash.h" | 
|---|
| 22 |  | 
|---|
| 23 | U_NAMESPACE_BEGIN | 
|---|
| 24 |  | 
|---|
| 25 | /** | 
|---|
| 26 | * A transliterator named Any-T or Any-T/V, where T is the target | 
|---|
| 27 | * script and V is the optional variant, that uses multiple | 
|---|
| 28 | * transliterators, all going to T or T/V, all with script sources. | 
|---|
| 29 | * The target must be a script.  It partitions text into runs of the | 
|---|
| 30 | * same script, and then based on the script of each run, | 
|---|
| 31 | * transliterates from that script to the given target or | 
|---|
| 32 | * target/variant.  Adjacent COMMON or INHERITED script characters are | 
|---|
| 33 | * included in each run. | 
|---|
| 34 | * | 
|---|
| 35 | * @author Alan Liu | 
|---|
| 36 | */ | 
|---|
| 37 | class AnyTransliterator : public Transliterator { | 
|---|
| 38 |  | 
|---|
| 39 | /** | 
|---|
| 40 | * Cache mapping UScriptCode values to Transliterator*. | 
|---|
| 41 | */ | 
|---|
| 42 | UHashtable* cache; | 
|---|
| 43 |  | 
|---|
| 44 | /** | 
|---|
| 45 | * The target or target/variant string. | 
|---|
| 46 | */ | 
|---|
| 47 | UnicodeString target; | 
|---|
| 48 |  | 
|---|
| 49 | /** | 
|---|
| 50 | * The target script code.  Never USCRIPT_INVALID_CODE. | 
|---|
| 51 | */ | 
|---|
| 52 | UScriptCode targetScript; | 
|---|
| 53 |  | 
|---|
| 54 | public: | 
|---|
| 55 |  | 
|---|
| 56 | /** | 
|---|
| 57 | * Destructor. | 
|---|
| 58 | */ | 
|---|
| 59 | virtual ~AnyTransliterator(); | 
|---|
| 60 |  | 
|---|
| 61 | /** | 
|---|
| 62 | * Copy constructor. | 
|---|
| 63 | */ | 
|---|
| 64 | AnyTransliterator(const AnyTransliterator&); | 
|---|
| 65 |  | 
|---|
| 66 | /** | 
|---|
| 67 | * Transliterator API. | 
|---|
| 68 | */ | 
|---|
| 69 | virtual AnyTransliterator* clone() const; | 
|---|
| 70 |  | 
|---|
| 71 | /** | 
|---|
| 72 | * Implements {@link Transliterator#handleTransliterate}. | 
|---|
| 73 | */ | 
|---|
| 74 | virtual void handleTransliterate(Replaceable& text, UTransPosition& index, | 
|---|
| 75 | UBool incremental) const; | 
|---|
| 76 |  | 
|---|
| 77 | /** | 
|---|
| 78 | * ICU "poor man's RTTI", returns a UClassID for the actual class. | 
|---|
| 79 | */ | 
|---|
| 80 | virtual UClassID getDynamicClassID() const; | 
|---|
| 81 |  | 
|---|
| 82 | /** | 
|---|
| 83 | * ICU "poor man's RTTI", returns a UClassID for this class. | 
|---|
| 84 | */ | 
|---|
| 85 | U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); | 
|---|
| 86 |  | 
|---|
| 87 | private: | 
|---|
| 88 |  | 
|---|
| 89 | /** | 
|---|
| 90 | * Private constructor | 
|---|
| 91 | * @param id the ID of the form S-T or S-T/V, where T is theTarget | 
|---|
| 92 | * and V is theVariant.  Must not be empty. | 
|---|
| 93 | * @param theTarget the target name.  Must not be empty, and must | 
|---|
| 94 | * name a script corresponding to theTargetScript. | 
|---|
| 95 | * @param theVariant the variant name, or the empty string if | 
|---|
| 96 | * there is no variant | 
|---|
| 97 | * @param theTargetScript the script code corresponding to | 
|---|
| 98 | * theTarget. | 
|---|
| 99 | * @param ec error code, fails if the internal hashtable cannot be | 
|---|
| 100 | * allocated | 
|---|
| 101 | */ | 
|---|
| 102 | AnyTransliterator(const UnicodeString& id, | 
|---|
| 103 | const UnicodeString& theTarget, | 
|---|
| 104 | const UnicodeString& theVariant, | 
|---|
| 105 | UScriptCode theTargetScript, | 
|---|
| 106 | UErrorCode& ec); | 
|---|
| 107 |  | 
|---|
| 108 | /** | 
|---|
| 109 | * Returns a transliterator from the given source to our target or | 
|---|
| 110 | * target/variant.  Returns NULL if the source is the same as our | 
|---|
| 111 | * target script, or if the source is USCRIPT_INVALID_CODE. | 
|---|
| 112 | * Caches the result and returns the same transliterator the next | 
|---|
| 113 | * time.  The caller does NOT own the result and must not delete | 
|---|
| 114 | * it. | 
|---|
| 115 | */ | 
|---|
| 116 | Transliterator* getTransliterator(UScriptCode source) const; | 
|---|
| 117 |  | 
|---|
| 118 | /** | 
|---|
| 119 | * Registers standard transliterators with the system.  Called by | 
|---|
| 120 | * Transliterator during initialization. | 
|---|
| 121 | */ | 
|---|
| 122 | static void registerIDs(); | 
|---|
| 123 |  | 
|---|
| 124 | friend class Transliterator; // for registerIDs() | 
|---|
| 125 | }; | 
|---|
| 126 |  | 
|---|
| 127 | U_NAMESPACE_END | 
|---|
| 128 |  | 
|---|
| 129 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ | 
|---|
| 130 |  | 
|---|
| 131 | #endif | 
|---|
| 132 |  | 
|---|