Class CharSequenceTranslator
java.lang.Object
org.apache.commons.text.translate.CharSequenceTranslator
- Direct Known Subclasses:
AggregateTranslator, CodePointTranslator, CsvTranslators.CsvEscaper, CsvTranslators.CsvUnescaper, LookupTranslator, NumericEntityUnescaper, OctalUnescaper, UnicodeUnescaper
An API for translating text. Its core use is to escape and unescape text. Because escaping and unescaping is completely contextual, the API does not present
two separate signatures.
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringhex(int codePoint) Returns an upper case hexadecimalStringfor the given character.final Stringtranslate(CharSequence input) Translates an input.abstract inttranslate(CharSequence input, int index, Writer writer) Translates a set of code points, represented by an int index into a CharSequence, into another set of code points.final voidtranslate(CharSequence input, Writer writer) Translates an input onto a Writer.final CharSequenceTranslatorwith(CharSequenceTranslator... translators) Creates a merger of this translator with another set of translators.
-
Constructor Details
-
CharSequenceTranslator
public CharSequenceTranslator()Construct a new instance.
-
-
Method Details
-
hex
-
translate
Translates an input. This is intentionally final as its algorithm is tightly coupled with the abstract method of this class.- Parameters:
input- CharSequence to be translated.- Returns:
- String output of translation.
-
translate
Translates a set of code points, represented by an int index into a CharSequence, into another set of code points. The number of code points consumed must be returned, and the only IOExceptions thrown must be from interacting with the Writer so that the top level API may reliably ignore StringWriter IOExceptions.- Parameters:
input- CharSequence that is being translated.index- int representing the current point of translation.writer- Writer to translate the text to.- Returns:
- int count of code points consumed.
- Throws:
IOException- Thrown if and only if the Writer produces an IOException.
-
translate
Translates an input onto a Writer. This is intentionally final as its algorithm is tightly coupled with the abstract method of this class.- Parameters:
input- CharSequence that is being translated.writer- Writer to translate the text to.- Throws:
IOException- Thrown if and only if the Writer produces an IOException.
-
with
Creates a merger of this translator with another set of translators. Useful in customizing the standard functionality.- Parameters:
translators- CharSequenceTranslator array of translators to merge with this one.- Returns:
- CharSequenceTranslator merging this translator with the others.
-