Class StringReplacer

java.lang.Object
com.ibm.icu.text.StringReplacer
All Implemented Interfaces:
UnicodeReplacer

class StringReplacer extends Object implements UnicodeReplacer
A replacer that produces static text as its output. The text may contain transliterator stand-in characters that represent nested UnicodeReplacer objects, making it possible to encode a tree of replacers in a StringReplacer. A StringReplacer that contains such stand-ins is called a complex StringReplacer. A complex StringReplacer has a slower processing loop than a non-complex one.
  • Field Details

    • output

      private String output
      Output text, possibly containing stand-in characters that represent nested UnicodeReplacers.
    • cursorPos

      private int cursorPos
      Cursor position. Value is ignored if hasCursor is false.
    • hasCursor

      private boolean hasCursor
      True if this object outputs a cursor position.
    • isComplex

      private boolean isComplex
      A complex object contains nested replacers and requires more complex processing. StringReplacers are initially assumed to be complex. If no nested replacers are seen during processing, then isComplex is set to false, and future replacements are short circuited for better performance.
    • data

      private final RuleBasedTransliterator.Data data
      Object that translates stand-in characters in 'output' to UnicodeReplacer objects.
  • Constructor Details

    • StringReplacer

      public StringReplacer(String theOutput, int theCursorPos, RuleBasedTransliterator.Data theData)
      Construct a StringReplacer that sets the emits the given output text and sets the cursor to the given position.
      Parameters:
      theOutput - text that will replace input text when the replace() method is called. May contain stand-in characters that represent nested replacers.
      theCursorPos - cursor position that will be returned by the replace() method
      theData - transliterator context object that translates stand-in characters to UnicodeReplacer objects
    • StringReplacer

      public StringReplacer(String theOutput, RuleBasedTransliterator.Data theData)
      Construct a StringReplacer that sets the emits the given output text and does not modify the cursor.
      Parameters:
      theOutput - text that will replace input text when the replace() method is called. May contain stand-in characters that represent nested replacers.
      theData - transliterator context object that translates stand-in characters to UnicodeReplacer objects
  • Method Details

    • replace

      public int replace(Replaceable text, int start, int limit, int[] cursor)
      UnicodeReplacer API
      Specified by:
      replace in interface UnicodeReplacer
      Parameters:
      text - the text to be matched
      start - inclusive start index of text to be replaced
      limit - exclusive end index of text to be replaced; must be greater than or equal to start
      cursor - output parameter for the cursor position. Not all replacer objects will update this, but in a complete tree of replacer objects, representing the entire output side of a transliteration rule, at least one must update it.
      Returns:
      the number of 16-bit code units in the text replacing the characters at offsets start..(limit-1) in text
    • toReplacerPattern

      public String toReplacerPattern(boolean escapeUnprintable)
      UnicodeReplacer API
      Specified by:
      toReplacerPattern in interface UnicodeReplacer
      Parameters:
      escapeUnprintable - if true then convert unprintable character to their hex escape representations, \\uxxxx or \\Uxxxxxxxx. Unprintable characters are defined by Utility.isUnprintable().
    • addReplacementSetTo

      public void addReplacementSetTo(UnicodeSet toUnionTo)
      Union the set of all characters that may output by this object into the given set.
      Specified by:
      addReplacementSetTo in interface UnicodeReplacer
      Parameters:
      toUnionTo - the set into which to union the output characters