2
*******************************************************************************
3
* Copyright (C) 1996-2002, International Business Machines Corporation and *
4
* others. All Rights Reserved. *
5
*******************************************************************************
11
#include "unicode/unistr.h"
12
#include "unicode/uniset.h"
13
#include "unicode/normlzr.h"
14
#include "unicode/unicode.h"
16
#define SKIP_ZEROES TRUE
23
* This class allows one to iterate through all the strings that are canonically equivalent to a given
24
* string. For example, here are some sample results:
25
Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
26
1: \u0041\u030A\u0064\u0307\u0327
27
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
28
2: \u0041\u030A\u0064\u0327\u0307
29
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
30
3: \u0041\u030A\u1E0B\u0327
31
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
32
4: \u0041\u030A\u1E11\u0307
33
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
34
5: \u00C5\u0064\u0307\u0327
35
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
36
6: \u00C5\u0064\u0327\u0307
37
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
39
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
41
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
42
9: \u212B\u0064\u0307\u0327
43
= {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
44
10: \u212B\u0064\u0327\u0307
45
= {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
46
11: \u212B\u1E0B\u0327
47
= {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
48
12: \u212B\u1E11\u0307
49
= {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
50
*<br>Note: the code is intended for use with small strings, and is not suitable for larger ones,
51
* since it has not been optimized for that situation.
55
class U_I18N_API CanonicalIterator {
58
*@param source string to get results for
60
CanonicalIterator(UnicodeString source, UErrorCode &status);
68
*@return gets the source: NOTE: it is the NFD form of source
70
UnicodeString getSource();
73
* Resets the iterator so that one can start again from the beginning.
78
*@return the next string that is canonically equivalent. The value null is returned when
79
* the iteration is done.
84
*@param set the source string to iterate against. This allows the same iterator to be used
85
* while changing the source string, saving object creation.
87
void setSource(const UnicodeString &newSource, UErrorCode &status);
90
* Dumb recursive implementation of permutation.
92
* @param source the string to find permutations for
93
* @return the results in a set.
95
static void permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status);
98
// ===================== PRIVATES ==============================
101
UnicodeString source;
104
// 2 dimensional array holds the pieces of the string with
105
// their different canonically equivalent representations
106
UnicodeString **pieces;
107
int32_t pieces_length;
108
int32_t *pieces_lengths;
110
// current is used in iterating to combine pieces
112
int32_t current_length;
115
UnicodeString buffer;
117
// we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
118
UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment)
120
//Set getEquivalents2(String segment);
121
Hashtable *getEquivalents2(const UChar *segment, int32_t segLen, UErrorCode &status);
122
//Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status);
125
* See if the decomposition of cp2 is at segment starting at segmentPos
126
* (with canonical rearrangment!)
127
* If so, take the remainder, and return the equivalents
129
//Set extract(int comp, String segment, int segmentPos, StringBuffer buffer);
130
Hashtable *extract(UChar32 comp, const UChar *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
131
//Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);