Package com.ibm.icu.text
Class TransliterationRuleSet
java.lang.Object
com.ibm.icu.text.TransliterationRuleSet
A set of rules for a
RuleBasedTransliterator
. This set encodes
the transliteration in one direction from one set of characters or short
strings to another. A RuleBasedTransliterator
consists of up to
two such sets, one for the forward direction, and one for the reverse.
A TransliterationRuleSet
has one important operation, that of
finding a matching rule at a given point in the text. This is accomplished
by the findMatch()
method.
Copyright © IBM Corporation 1999. All rights reserved.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]
Index table.private int
Length of the longest preceding contextprivate TransliterationRule[]
Sorted and indexed table of rules.private List<TransliterationRule>
Vector of rules, in the order added. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRule
(TransliterationRule rule) Add a rule to this set.(package private) void
addSourceTargetSet
(UnicodeSet filter, UnicodeSet sourceSet, UnicodeSet targetSet) void
freeze()
Close this rule set to further additions, check it for masked rules, and index it to optimize performance.int
Return the maximum context length.(package private) String
toRules
(boolean escapeUnprintable) Create rule strings that represents this rule set.boolean
transliterate
(Replaceable text, Transliterator.Position pos, boolean incremental) Transliterate the given text with the given UTransPosition indices.
-
Field Details
-
ruleVector
Vector of rules, in the order added. -
maxContextLength
private int maxContextLengthLength of the longest preceding context -
rules
Sorted and indexed table of rules. This is created by freeze() from the rules in ruleVector. rules.length >= ruleVector.size(), and the references in rules[] are aliases of the references in ruleVector. A single rule in ruleVector is listed one or more times in rules[]. -
index
private int[] indexIndex table. For text having a first character c, compute x = c&0xFF. Now use rules[index[x]..index[x+1]-1]. This index table is created by freeze().
-
-
Constructor Details
-
TransliterationRuleSet
public TransliterationRuleSet()Construct a new empty rule set.
-
-
Method Details
-
getMaximumContextLength
public int getMaximumContextLength()Return the maximum context length.- Returns:
- the length of the longest preceding context.
-
addRule
Add a rule to this set. Rules are added in order, and order is significant.- Parameters:
rule
- the rule to add
-
freeze
public void freeze()Close this rule set to further additions, check it for masked rules, and index it to optimize performance.- Throws:
IllegalArgumentException
- if some rules are masked
-
transliterate
Transliterate the given text with the given UTransPosition indices. Return true if the transliteration should continue or false if it should halt (because of a U_PARTIAL_MATCH match). Note that false is only ever returned if isIncremental is true.- Parameters:
text
- the text to be transliteratedpos
- the position indices, which will be updatedincremental
- if true, assume new text may be inserted at index.limit, and return false if there is a partial match.- Returns:
- true unless a U_PARTIAL_MATCH has been obtained, indicating that transliteration should stop until more text arrives.
-
toRules
Create rule strings that represents this rule set. -
addSourceTargetSet
-