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