Class TransliterationRuleSet

java.lang.Object
com.ibm.icu.text.TransliterationRuleSet

class TransliterationRuleSet extends Object
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 Details

    • ruleVector

      private List<TransliterationRule> ruleVector
      Vector of rules, in the order added.
    • maxContextLength

      private int maxContextLength
      Length of the longest preceding context
    • rules

      private TransliterationRule[] 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[] index
      Index 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

      public void addRule(TransliterationRule rule)
      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

      public boolean transliterate(Replaceable text, Transliterator.Position pos, boolean incremental)
      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 transliterated
      pos - the position indices, which will be updated
      incremental - 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

      String toRules(boolean escapeUnprintable)
      Create rule strings that represents this rule set.
    • addSourceTargetSet

      void addSourceTargetSet(UnicodeSet filter, UnicodeSet sourceSet, UnicodeSet targetSet)