Package io.pebbletemplates.pebble.lexer
Class TemplateSource
java.lang.Object
io.pebbletemplates.pebble.lexer.TemplateSource
- All Implemented Interfaces:
CharSequence
An implementation of CharSequence that is tuned to be used specifically by
LexerImpl
. It
is possible to advance through the sequence without allocating a copy and it is possible to
perform regex matches from the logical beginning of the remaining un-tokenized source. This class
will also standardize newline characters from different architectures.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Default capacityprivate final String
Filename of the templateprivate int
Tracking the line number that we are currently tokenizing.private final org.slf4j.Logger
private int
An index of the first character for the remaining un-tokenized source.private int
Number of characters stored in source array remaining to be tokenizedprivate char[]
The characters found within the template. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
advance
(int amount) Moves the start index a certain amount.private int
advanceThroughNewline
(int index) Advances through possible newline character and returns how many characters were used to represent the newline (windows uses two characters to represent one newline).void
private void
append
(char[] characters, int amount) Append characters to the internal array.char
charAt
(int index) private void
copyReaderIntoCharArray
(Reader reader) Read the contents of the template into the internal char[].private void
ensureCapacity
(int minCapacity) Ensure that the internal array has a minimum capacity.int
private void
grow
(int minCapacity) Grow the internal array to at least the desired minimum capacity.int
length()
subSequence
(int start, int end) substring
(int end) substring
(int start, int end) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
logger
private final org.slf4j.Logger logger -
source
private char[] sourceThe characters found within the template. -
size
private int sizeNumber of characters stored in source array remaining to be tokenized -
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITYDefault capacity- See Also:
-
offset
private int offsetAn index of the first character for the remaining un-tokenized source. -
lineNumber
private int lineNumberTracking the line number that we are currently tokenizing. -
filename
Filename of the template
-
-
Constructor Details
-
TemplateSource
Constructor- Parameters:
reader
- Reader provided by the Loaderfilename
- Filename of the template- Throws:
IOException
- Exceptions thrown from the reader
-
-
Method Details
-
copyReaderIntoCharArray
Read the contents of the template into the internal char[].- Throws:
IOException
-
append
private void append(char[] characters, int amount) Append characters to the internal array. -
ensureCapacity
private void ensureCapacity(int minCapacity) Ensure that the internal array has a minimum capacity. -
grow
private void grow(int minCapacity) Grow the internal array to at least the desired minimum capacity. -
advance
public void advance(int amount) Moves the start index a certain amount. While traversing this amount we will count how many newlines have been encountered.- Parameters:
amount
- Amount of characters to advance by
-
advanceThroughWhitespace
public void advanceThroughWhitespace() -
advanceThroughNewline
private int advanceThroughNewline(int index) Advances through possible newline character and returns how many characters were used to represent the newline (windows uses two characters to represent one newline).- Parameters:
index
- The index of the potential newline character
-
substring
-
substring
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
getLineNumber
public int getLineNumber() -
getFilename
-