]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f | 3 | /* |
73c04bcf | 4 | *********************************************************************** |
46f4442e | 5 | * Copyright (c) 2002-2007, International Business Machines Corporation |
b75a7d8f | 6 | * and others. All Rights Reserved. |
73c04bcf | 7 | *********************************************************************** |
b75a7d8f A |
8 | * Date Name Description |
9 | * 06/06/2002 aliu Creation. | |
73c04bcf | 10 | *********************************************************************** |
b75a7d8f A |
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 | */ | |
46f4442e | 37 | class AnyTransliterator : public Transliterator { |
b75a7d8f A |
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 | ||
b75a7d8f | 54 | public: |
374ca955 | 55 | |
b75a7d8f A |
56 | /** |
57 | * Destructor. | |
58 | */ | |
59 | virtual ~AnyTransliterator(); | |
60 | ||
61 | /** | |
62 | * Copy constructor. | |
63 | */ | |
64 | AnyTransliterator(const AnyTransliterator&); | |
65 | ||
66 | /** | |
67 | * Transliterator API. | |
68 | */ | |
374ca955 | 69 | virtual Transliterator* clone() const; |
b75a7d8f A |
70 | |
71 | /** | |
72 | * Implements {@link Transliterator#handleTransliterate}. | |
73 | */ | |
74 | virtual void handleTransliterate(Replaceable& text, UTransPosition& index, | |
75 | UBool incremental) const; | |
374ca955 | 76 | |
b75a7d8f A |
77 | /** |
78 | * ICU "poor man's RTTI", returns a UClassID for the actual class. | |
b75a7d8f | 79 | */ |
374ca955 | 80 | virtual UClassID getDynamicClassID() const; |
b75a7d8f A |
81 | |
82 | /** | |
83 | * ICU "poor man's RTTI", returns a UClassID for this class. | |
b75a7d8f | 84 | */ |
46f4442e | 85 | U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); |
b75a7d8f A |
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() | |
b75a7d8f A |
125 | }; |
126 | ||
127 | U_NAMESPACE_END | |
128 | ||
129 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ | |
130 | ||
131 | #endif |