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