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 **********************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_TRANSLITERATION
15 #include "unicode/uobject.h"
16 #include "unicode/utrans.h"
22 class TransliterationRule
;
23 class TransliterationRuleData
;
29 * A set of rules for a <code>RuleBasedTransliterator</code>.
32 class U_I18N_API TransliterationRuleSet
: public UMemory
{
34 * Vector of rules, in the order added. This is used while the
35 * rule set is getting built. After that, freeze() reorders and
36 * indexes the rules into rules[]. Any given rule is stored once
37 * in ruleVector, and one or more times in rules[]. ruleVector
38 * owns and deletes the rules.
43 * Sorted and indexed table of rules. This is created by freeze()
44 * from the rules in ruleVector. It contains alias pointers to
45 * the rules in ruleVector. It is zero before freeze() is called
46 * and non-zero thereafter.
48 TransliterationRule
** rules
;
51 * Index table. For text having a first character c, compute x = c&0xFF.
52 * Now use rules[index[x]..index[x+1]-1]. This index table is created by
53 * freeze(). Before freeze() is called it contains garbage.
58 * Length of the longest preceding context
60 int32_t maxContextLength
;
65 * Construct a new empty rule set.
66 * @param status Output parameter filled in with success or failure status.
68 TransliterationRuleSet(UErrorCode
& status
);
73 TransliterationRuleSet(const TransliterationRuleSet
&);
78 virtual ~TransliterationRuleSet();
81 * Change the data object that this rule belongs to. Used
82 * internally by the TransliterationRuleData copy constructor.
83 * @param data the new data value to be set.
85 void setData(const TransliterationRuleData
* data
);
88 * Return the maximum context length.
89 * @return the length of the longest preceding context.
91 virtual int32_t getMaximumContextLength(void) const;
94 * Add a rule to this set. Rules are added in order, and order is
95 * significant. The last call to this method must be followed by
96 * a call to <code>freeze()</code> before the rule set is used.
97 * This method must <em>not</em> be called after freeze() has been
100 * @param adoptedRule the rule to add
102 virtual void addRule(TransliterationRule
* adoptedRule
,
106 * Check this for masked rules and index it to optimize performance.
107 * The sequence of operations is: (1) add rules to a set using
108 * <code>addRule()</code>; (2) freeze the set using
109 * <code>freeze()</code>; (3) use the rule set. If
110 * <code>addRule()</code> is called after calling this method, it
111 * invalidates this object, and this method must be called again.
112 * That is, <code>freeze()</code> may be called multiple times,
113 * although for optimal performance it shouldn't be.
114 * @param parseError A pointer to UParseError to receive information about errors
116 * @param status Output parameter filled in with success or failure status.
118 virtual void freeze(UParseError
& parseError
, UErrorCode
& status
);
121 * Transliterate the given text with the given UTransPosition
122 * indices. Return TRUE if the transliteration should continue
123 * or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
124 * Note that FALSE is only ever returned if isIncremental is TRUE.
125 * @param text the text to be transliterated
126 * @param index the position indices, which will be updated
127 * @param isIncremental if TRUE, assume new text may be inserted
128 * at index.limit, and return FALSE if thre is a partial match.
129 * @return TRUE unless a U_PARTIAL_MATCH has been obtained,
130 * indicating that transliteration should stop until more text
133 UBool
transliterate(Replaceable
& text
,
134 UTransPosition
& index
,
135 UBool isIncremental
);
138 * Create rule strings that represents this rule set.
139 * @param result string to receive the rule strings. Current
140 * contents will be deleted.
141 * @param escapeUnprintable True, will escape the unprintable characters
142 * @return A reference to 'result'.
144 virtual UnicodeString
& toRules(UnicodeString
& result
,
145 UBool escapeUnprintable
) const;
148 * Return the set of all characters that may be modified
149 * (getTarget=false) or emitted (getTarget=true) by this set.
151 UnicodeSet
& getSourceTargetSet(UnicodeSet
& result
,
152 UBool getTarget
) const;
156 TransliterationRuleSet
&operator=(const TransliterationRuleSet
&other
); // forbid copying of this class
161 #endif /* #if !UCONFIG_NO_TRANSLITERATION */