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

« back to all changes in this revision

Viewing changes to source/i18n/rbt_set.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* Copyright (C) {1999}, International Business Machines Corporation and others. All Rights Reserved.
3
 
**********************************************************************
4
 
*   Date        Name        Description
5
 
*   11/17/99    aliu        Creation.
6
 
**********************************************************************
7
 
*/
8
 
#ifndef RBT_SET_H
9
 
#define RBT_SET_H
10
 
 
11
 
#include "uvector.h"
12
 
#include "unicode/utrans.h"
13
 
 
14
 
U_NAMESPACE_BEGIN
15
 
 
16
 
class Replaceable;
17
 
class TransliterationRule;
18
 
class TransliterationRuleData;
19
 
class UnicodeFilter;
20
 
class UnicodeString;
21
 
 
22
 
/**
23
 
 * A set of rules for a <code>RuleBasedTransliterator</code>.
24
 
 * @author Alan Liu
25
 
 */
26
 
class U_I18N_API TransliterationRuleSet {
27
 
    /**
28
 
     * Vector of rules, in the order added.  This is used while the
29
 
     * rule set is getting built.  After that, freeze() reorders and
30
 
     * indexes the rules into rules[].  Any given rule is stored once
31
 
     * in ruleVector, and one or more times in rules[].  ruleVector
32
 
     * owns and deletes the rules.
33
 
     */
34
 
    UVector* ruleVector;
35
 
 
36
 
    /**
37
 
     * Sorted and indexed table of rules.  This is created by freeze()
38
 
     * from the rules in ruleVector.  It contains alias pointers to
39
 
     * the rules in ruleVector.  It is zero before freeze() is called
40
 
     * and non-zero thereafter.
41
 
     */
42
 
    TransliterationRule** rules;
43
 
 
44
 
    /**
45
 
     * Index table.  For text having a first character c, compute x = c&0xFF.
46
 
     * Now use rules[index[x]..index[x+1]-1].  This index table is created by
47
 
     * freeze().  Before freeze() is called it contains garbage.
48
 
     */
49
 
    int32_t index[257];
50
 
 
51
 
    /**
52
 
     * Length of the longest preceding context
53
 
     */
54
 
    int32_t maxContextLength;
55
 
 
56
 
public:
57
 
 
58
 
    /**
59
 
     * Construct a new empty rule set.
60
 
     */
61
 
    TransliterationRuleSet(UErrorCode& status);
62
 
 
63
 
    /**
64
 
     * Copy constructor.
65
 
     */
66
 
    TransliterationRuleSet(const TransliterationRuleSet&);
67
 
 
68
 
    /**
69
 
     * Destructor.
70
 
     */
71
 
    virtual ~TransliterationRuleSet();
72
 
 
73
 
    /**
74
 
     * Change the data object that this rule belongs to.  Used
75
 
     * internally by the TransliterationRuleData copy constructor.
76
 
     */
77
 
    void setData(const TransliterationRuleData* data);
78
 
 
79
 
    /**
80
 
     * Return the maximum context length.
81
 
     * @return the length of the longest preceding context.
82
 
     */
83
 
    virtual int32_t getMaximumContextLength(void) const;
84
 
 
85
 
    /**
86
 
     * Add a rule to this set.  Rules are added in order, and order is
87
 
     * significant.  The last call to this method must be followed by
88
 
     * a call to <code>freeze()</code> before the rule set is used.
89
 
     * This method must <em>not</em> be called after freeze() has been
90
 
     * called.
91
 
     *
92
 
     * @param adoptedRule the rule to add
93
 
     */
94
 
    virtual void addRule(TransliterationRule* adoptedRule,
95
 
                         UErrorCode& status);
96
 
 
97
 
    /**
98
 
     * Check this for masked rules and index it to optimize performance.
99
 
     * The sequence of operations is: (1) add rules to a set using
100
 
     * <code>addRule()</code>; (2) freeze the set using
101
 
     * <code>freeze()</code>; (3) use the rule set.  If
102
 
     * <code>addRule()</code> is called after calling this method, it
103
 
     * invalidates this object, and this method must be called again.
104
 
     * That is, <code>freeze()</code> may be called multiple times,
105
 
     * although for optimal performance it shouldn't be.
106
 
     */
107
 
    virtual void freeze(UParseError& parseError, UErrorCode& status);
108
 
    
109
 
    /**
110
 
     * Transliterate the given text with the given UTransPosition
111
 
     * indices.  Return TRUE if the transliteration should continue
112
 
     * or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
113
 
     * Note that FALSE is only ever returned if isIncremental is TRUE.
114
 
     * @param text the text to be transliterated
115
 
     * @param index the position indices, which will be updated
116
 
     * @param isIncremental if TRUE, assume new text may be inserted
117
 
     * at index.limit, and return FALSE if thre is a partial match.
118
 
     * @return TRUE unless a U_PARTIAL_MATCH has been obtained,
119
 
     * indicating that transliteration should stop until more text
120
 
     * arrives.
121
 
     */
122
 
    UBool transliterate(Replaceable& text,
123
 
                        UTransPosition& index,
124
 
                        UBool isIncremental);
125
 
 
126
 
    /**
127
 
     * Create rule strings that represents this rule set.
128
 
     * @param result string to receive the rule strings.  Current
129
 
     * contents will be deleted.
130
 
     */
131
 
    virtual UnicodeString& toRules(UnicodeString& result,
132
 
                                   UBool escapeUnprintable) const;
133
 
};
134
 
 
135
 
U_NAMESPACE_END
136
 
#endif