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