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