Package com.ibm.icu.text
Class StringReplacer
- java.lang.Object
-
- com.ibm.icu.text.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 APIjava.lang.String
toReplacerPattern(boolean escapeUnprintable)
UnicodeReplacer API
-
-
-
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.
-
data
private final RuleBasedTransliterator.Data data
Object that translates stand-in characters in 'output' to UnicodeReplacer objects.
-
-
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() methodtheData
- 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 interfaceUnicodeReplacer
- Parameters:
text
- the text to be matchedstart
- inclusive start index of text to be replacedlimit
- exclusive end index of text to be replaced; must be greater than or equal to startcursor
- 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 interfaceUnicodeReplacer
- 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 interfaceUnicodeReplacer
- Parameters:
toUnionTo
- the set into which to union the output characters
-
-