Class StringReplacer

  • All Implemented Interfaces:
    UnicodeReplacer

    class StringReplacer
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private int cursorPos
      Cursor position.
      private RuleBasedTransliterator.Data data
      Object that translates stand-in characters in 'output' to UnicodeReplacer objects.
      private boolean hasCursor
      True if this object outputs a cursor position.
      private boolean isComplex
      A complex object contains nested replacers and requires more complex processing.
      private java.lang.String output
      Output text, possibly containing stand-in characters that represent nested UnicodeReplacers.
    • Constructor Summary

      Constructors 
      Constructor Description
      StringReplacer​(java.lang.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.
      StringReplacer​(java.lang.String theOutput, RuleBasedTransliterator.Data theData)
      Construct a StringReplacer that sets the emits the given output text and does not modify the cursor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addReplacementSetTo​(UnicodeSet toUnionTo)
      Union the set of all characters that may output by this object into the given set.
      int replace​(Replaceable text, int start, int limit, int[] cursor)
      UnicodeReplacer API
      java.lang.String toReplacerPattern​(boolean escapeUnprintable)
      UnicodeReplacer API
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • output

        private java.lang.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.
    • Constructor Detail

      • StringReplacer

        public StringReplacer​(java.lang.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​(java.lang.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 Detail

      • 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 java.lang.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