Class EscapeTranslator
java.lang.Object
net.sourceforge.pmd.lang.ast.impl.javacc.EscapeTranslator
- Direct Known Subclasses:
BackslashEscapeTranslator
An object that can translate an input document into an output document,
typically by replacing escape sequences with the character they represent.
This is an abstract class because the default implementation does not perform any escape processing. Subclasses refine this behavior.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEscapeTranslator(TextDocument original) Create a translator that will read from the given document. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidCheck to make sure that the stream has not been closedprotected intgobbleMaxWithoutEscape(int maxOff) Returns the max offset, EXclusive, up to which we can cut the input array from the bufpos to dump it into the output array.protected FileLocationlocationAt(int indexInInput) protected intrecordEscape(int startOffsetInclusive, int endOffsetExclusive, Chars translation) Translate all the input in the buffer.
-
Field Details
-
input
Source characters. When there is an escape, eg \ u00a0, the first backslash is replaced with the translated value of the escape. The bufpos is updated so that we read the next char after the escape. -
bufpos
protected int bufposPosition of the next char to read in the input.
-
-
Constructor Details
-
EscapeTranslator
Create a translator that will read from the given document.- Parameters:
original- Original document- Throws:
NullPointerException- If the parameter is null
-
-
Method Details
-
translateDocument
Translate all the input in the buffer. This consumes this object.- Returns:
- The translated text document. If there is no escape, returns the original text
- Throws:
IllegalStateException- If this method is called more than once on the same objectMalformedSourceException- If there are invalid escapes in the source
-
gobbleMaxWithoutEscape
Returns the max offset, EXclusive, up to which we can cut the input array from the bufpos to dump it into the output array.- Parameters:
maxOff- Max offset up to which to read ahead- Throws:
MalformedSourceException
-
recordEscape
-
ensureOpen
protected final void ensureOpen()Check to make sure that the stream has not been closed -
locationAt
-