]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
374ca955 | 3 | * Copyright (C) 1996-2004, International Business Machines Corporation and * |
b75a7d8f A |
4 | * others. All Rights Reserved. * |
5 | ******************************************************************************* | |
6 | */ | |
7 | ||
8 | #ifndef CANITER_H | |
9 | #define CANITER_H | |
10 | ||
11 | #include "unicode/utypes.h" | |
12 | ||
13 | #if !UCONFIG_NO_NORMALIZATION | |
14 | ||
15 | #include "unicode/uobject.h" | |
16 | #include "unicode/unistr.h" | |
17 | ||
18 | /** Should permutation skip characters with combining class zero | |
19 | * Should be either TRUE or FALSE. This is a compile time option | |
374ca955 | 20 | * @stable ICU 2.4 |
b75a7d8f A |
21 | */ |
22 | #ifndef CANITER_SKIP_ZEROES | |
23 | #define CANITER_SKIP_ZEROES TRUE | |
24 | #endif | |
25 | ||
26 | U_NAMESPACE_BEGIN | |
27 | ||
28 | class Hashtable; | |
29 | ||
30 | /** | |
31 | * This class allows one to iterate through all the strings that are canonically equivalent to a given | |
32 | * string. For example, here are some sample results: | |
33 | Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} | |
374ca955 | 34 | 1: \\u0041\\u030A\\u0064\\u0307\\u0327 |
b75a7d8f | 35 | = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 36 | 2: \\u0041\\u030A\\u0064\\u0327\\u0307 |
b75a7d8f | 37 | = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} |
374ca955 | 38 | 3: \\u0041\\u030A\\u1E0B\\u0327 |
b75a7d8f | 39 | = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 40 | 4: \\u0041\\u030A\\u1E11\\u0307 |
b75a7d8f | 41 | = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} |
374ca955 | 42 | 5: \\u00C5\\u0064\\u0307\\u0327 |
b75a7d8f | 43 | = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 44 | 6: \\u00C5\\u0064\\u0327\\u0307 |
b75a7d8f | 45 | = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} |
374ca955 | 46 | 7: \\u00C5\\u1E0B\\u0327 |
b75a7d8f | 47 | = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 48 | 8: \\u00C5\\u1E11\\u0307 |
b75a7d8f | 49 | = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} |
374ca955 | 50 | 9: \\u212B\\u0064\\u0307\\u0327 |
b75a7d8f | 51 | = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 52 | 10: \\u212B\\u0064\\u0327\\u0307 |
b75a7d8f | 53 | = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} |
374ca955 | 54 | 11: \\u212B\\u1E0B\\u0327 |
b75a7d8f | 55 | = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} |
374ca955 | 56 | 12: \\u212B\\u1E11\\u0307 |
b75a7d8f A |
57 | = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} |
58 | *<br>Note: the code is intended for use with small strings, and is not suitable for larger ones, | |
59 | * since it has not been optimized for that situation. | |
60 | * Note, CanonicalIterator is not intended to be subclassed. | |
61 | * @author M. Davis | |
62 | * @author C++ port by V. Weinstein | |
374ca955 | 63 | * @stable ICU 2.4 |
b75a7d8f A |
64 | */ |
65 | class U_COMMON_API CanonicalIterator : public UObject { | |
66 | public: | |
67 | /** | |
68 | * Construct a CanonicalIterator object | |
69 | * @param source string to get results for | |
70 | * @param status Fill-in parameter which receives the status of this operation. | |
374ca955 | 71 | * @stable ICU 2.4 |
b75a7d8f | 72 | */ |
374ca955 | 73 | CanonicalIterator(const UnicodeString &source, UErrorCode &status); |
b75a7d8f A |
74 | |
75 | /** Destructor | |
76 | * Cleans pieces | |
374ca955 | 77 | * @stable ICU 2.4 |
b75a7d8f | 78 | */ |
374ca955 | 79 | virtual ~CanonicalIterator(); |
b75a7d8f A |
80 | |
81 | /** | |
82 | * Gets the NFD form of the current source we are iterating over. | |
83 | * @return gets the source: NOTE: it is the NFD form of source | |
374ca955 | 84 | * @stable ICU 2.4 |
b75a7d8f | 85 | */ |
374ca955 | 86 | UnicodeString getSource(); |
b75a7d8f A |
87 | |
88 | /** | |
89 | * Resets the iterator so that one can start again from the beginning. | |
374ca955 | 90 | * @stable ICU 2.4 |
b75a7d8f | 91 | */ |
374ca955 | 92 | void reset(); |
b75a7d8f A |
93 | |
94 | /** | |
95 | * Get the next canonically equivalent string. | |
374ca955 | 96 | * <br><b>Warning: The strings are not guaranteed to be in any particular order.</b> |
b75a7d8f A |
97 | * @return the next string that is canonically equivalent. A bogus string is returned when |
98 | * the iteration is done. | |
374ca955 | 99 | * @stable ICU 2.4 |
b75a7d8f | 100 | */ |
374ca955 | 101 | UnicodeString next(); |
b75a7d8f A |
102 | |
103 | /** | |
104 | * Set a new source for this iterator. Allows object reuse. | |
105 | * @param newSource the source string to iterate against. This allows the same iterator to be used | |
106 | * while changing the source string, saving object creation. | |
107 | * @param status Fill-in parameter which receives the status of this operation. | |
374ca955 | 108 | * @stable ICU 2.4 |
b75a7d8f | 109 | */ |
374ca955 | 110 | void setSource(const UnicodeString &newSource, UErrorCode &status); |
b75a7d8f A |
111 | |
112 | /** | |
374ca955 | 113 | * Dumb recursive implementation of permutation. |
b75a7d8f A |
114 | * TODO: optimize |
115 | * @param source the string to find permutations for | |
116 | * @param skipZeros determine if skip zeros | |
117 | * @param result the results in a set. | |
118 | * @param status Fill-in parameter which receives the status of this operation. | |
374ca955 | 119 | * @internal |
b75a7d8f | 120 | */ |
374ca955 A |
121 | static void U_EXPORT2 permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status); |
122 | ||
b75a7d8f | 123 | /** |
374ca955 | 124 | * ICU "poor man's RTTI", returns a UClassID for this class. |
b75a7d8f | 125 | * |
374ca955 | 126 | * @stable ICU 2.2 |
b75a7d8f | 127 | */ |
374ca955 | 128 | static UClassID U_EXPORT2 getStaticClassID(); |
b75a7d8f A |
129 | |
130 | /** | |
374ca955 | 131 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
b75a7d8f | 132 | * |
374ca955 | 133 | * @stable ICU 2.2 |
b75a7d8f | 134 | */ |
374ca955 | 135 | virtual UClassID getDynamicClassID() const; |
b75a7d8f A |
136 | |
137 | private: | |
138 | // ===================== PRIVATES ============================== | |
139 | // private default constructor | |
374ca955 A |
140 | CanonicalIterator(); |
141 | ||
b75a7d8f A |
142 | |
143 | /** | |
144 | * Copy constructor. Private for now. | |
145 | * @internal | |
146 | */ | |
147 | CanonicalIterator(const CanonicalIterator& other); | |
148 | ||
149 | /** | |
150 | * Assignment operator. Private for now. | |
151 | * @internal | |
152 | */ | |
153 | CanonicalIterator& operator=(const CanonicalIterator& other); | |
154 | ||
155 | // fields | |
156 | UnicodeString source; | |
157 | UBool done; | |
158 | ||
159 | // 2 dimensional array holds the pieces of the string with | |
160 | // their different canonically equivalent representations | |
161 | UnicodeString **pieces; | |
162 | int32_t pieces_length; | |
163 | int32_t *pieces_lengths; | |
164 | ||
165 | // current is used in iterating to combine pieces | |
166 | int32_t *current; | |
167 | int32_t current_length; | |
374ca955 | 168 | |
b75a7d8f A |
169 | // transient fields |
170 | UnicodeString buffer; | |
374ca955 | 171 | |
b75a7d8f A |
172 | // we have a segment, in NFD. Find all the strings that are canonically equivalent to it. |
173 | UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment) | |
374ca955 | 174 | |
b75a7d8f A |
175 | //Set getEquivalents2(String segment); |
176 | Hashtable *getEquivalents2(const UChar *segment, int32_t segLen, UErrorCode &status); | |
177 | //Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status); | |
374ca955 | 178 | |
b75a7d8f | 179 | /** |
374ca955 | 180 | * See if the decomposition of cp2 is at segment starting at segmentPos |
b75a7d8f | 181 | * (with canonical rearrangment!) |
374ca955 | 182 | * If so, take the remainder, and return the equivalents |
b75a7d8f A |
183 | */ |
184 | //Set extract(int comp, String segment, int segmentPos, StringBuffer buffer); | |
185 | Hashtable *extract(UChar32 comp, const UChar *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status); | |
186 | //Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status); | |
187 | ||
188 | void cleanPieces(); | |
189 | ||
b75a7d8f A |
190 | }; |
191 | ||
b75a7d8f A |
192 | U_NAMESPACE_END |
193 | ||
194 | #endif /* #if !UCONFIG_NO_NORMALIZATION */ | |
195 | ||
196 | #endif |