~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/i18n/caniter.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2005-05-21 22:44:31 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: package-import@ubuntu.com-20050521224431-r7rktfhnu1n4tf1g
Tags: 2.1-2.1
Rename icu-doc to icu21-doc. icu-doc is built by the icu28 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *******************************************************************************
 
3
 * Copyright (C) 1996-2002, International Business Machines Corporation and    *
 
4
 * others. All Rights Reserved.                                                *
 
5
 *******************************************************************************
 
6
 */
 
7
 
 
8
#ifndef CANITER_H
 
9
#define CANITER_H
 
10
 
 
11
#include "unicode/unistr.h"
 
12
#include "unicode/uniset.h"
 
13
#include "unicode/normlzr.h"
 
14
#include "unicode/unicode.h"
 
15
 
 
16
#define SKIP_ZEROES TRUE
 
17
 
 
18
U_NAMESPACE_BEGIN
 
19
 
 
20
class Hashtable;
 
21
 
 
22
/**
 
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}
 
38
7: \u00C5\u1E0B\u0327
 
39
 = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
 
40
8: \u00C5\u1E11\u0307
 
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.
 
52
 *@author M. Davis
 
53
 *@draft
 
54
 */
 
55
class U_I18N_API CanonicalIterator {
 
56
public:
 
57
    /**
 
58
     *@param source string to get results for
 
59
     */
 
60
    CanonicalIterator(UnicodeString source, UErrorCode &status);    
 
61
 
 
62
    /** Destructor
 
63
     *  Cleans pieces
 
64
     */
 
65
    ~CanonicalIterator();
 
66
 
 
67
    /**
 
68
     *@return gets the source: NOTE: it is the NFD form of source
 
69
     */
 
70
    UnicodeString getSource();    
 
71
 
 
72
    /**
 
73
     * Resets the iterator so that one can start again from the beginning.
 
74
     */
 
75
    void reset();    
 
76
 
 
77
    /**
 
78
     *@return the next string that is canonically equivalent. The value null is returned when
 
79
     * the iteration is done.
 
80
     */
 
81
    UnicodeString next();    
 
82
 
 
83
    /**
 
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.
 
86
     */
 
87
    void setSource(const UnicodeString &newSource, UErrorCode &status);    
 
88
 
 
89
    /**
 
90
     * Dumb recursive implementation of permutation. 
 
91
     * TODO: optimize
 
92
     * @param source the string to find permutations for
 
93
     * @return the results in a set.
 
94
     */
 
95
    static void permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status);     
 
96
    
 
97
private:
 
98
    // ===================== PRIVATES ==============================
 
99
    
 
100
    // fields
 
101
    UnicodeString source;
 
102
    UBool done;
 
103
 
 
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;
 
109
 
 
110
    // current is used in iterating to combine pieces
 
111
    int32_t *current;
 
112
    int32_t current_length;
 
113
    
 
114
    // transient fields
 
115
    UnicodeString buffer;
 
116
    
 
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)
 
119
    
 
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);
 
123
    
 
124
    /**
 
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 
 
128
     */
 
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);
 
132
 
 
133
    void cleanPieces();
 
134
};
 
135
U_NAMESPACE_END
 
136
#endif