Package com.ibm.icu.text
Class StringReplacer
java.lang.Object
com.ibm.icu.text.StringReplacer
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate int
Cursor position.private final RuleBasedTransliterator.Data
Object that translates stand-in characters in 'output' to UnicodeReplacer objects.private boolean
True if this object outputs a cursor position.private boolean
A complex object contains nested replacers and requires more complex processing.private String
Output text, possibly containing stand-in characters that represent nested UnicodeReplacers. -
Constructor Summary
ConstructorsConstructorDescriptionStringReplacer
(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
(String theOutput, RuleBasedTransliterator.Data theData) Construct a StringReplacer that sets the emits the given output text and does not modify the cursor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 APItoReplacerPattern
(boolean escapeUnprintable) UnicodeReplacer API
-
Field Details
-
output
Output text, possibly containing stand-in characters that represent nested UnicodeReplacers. -
cursorPos
private int cursorPosCursor position. Value is ignored if hasCursor is false. -
hasCursor
private boolean hasCursorTrue if this object outputs a cursor position. -
isComplex
private boolean isComplexA 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
Object that translates stand-in characters in 'output' to UnicodeReplacer objects.
-
-
Constructor Details
-
StringReplacer
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
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
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
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
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
-