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