Package io.pebbletemplates.pebble.lexer
Class TemplateSource
- java.lang.Object
-
- io.pebbletemplates.pebble.lexer.TemplateSource
-
- All Implemented Interfaces:
java.lang.CharSequence
public class TemplateSource extends java.lang.Object implements java.lang.CharSequenceAn implementation of CharSequence that is tuned to be used specifically byLexerImpl. 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
Fields Modifier and Type Field Description private static intDEFAULT_CAPACITYDefault capacityprivate java.lang.StringfilenameFilename of the templateprivate intlineNumberTracking the line number that we are currently tokenizing.private org.slf4j.Loggerloggerprivate intoffsetAn index of the first character for the remaining un-tokenized source.private intsizeNumber of characters stored in source array remaining to be tokenizedprivate char[]sourceThe characters found within the template.
-
Constructor Summary
Constructors Constructor Description TemplateSource(java.io.Reader reader, java.lang.String filename)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvance(int amount)Moves the start index a certain amount.private intadvanceThroughNewline(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).voidadvanceThroughWhitespace()private voidappend(char[] characters, int amount)Append characters to the internal array.charcharAt(int index)private voidcopyReaderIntoCharArray(java.io.Reader reader)Read the contents of the template into the internal char[].private voidensureCapacity(int minCapacity)Ensure that the internal array has a minimum capacity.java.lang.StringgetFilename()intgetLineNumber()private voidgrow(int minCapacity)Grow the internal array to at least the desired minimum capacity.intlength()java.lang.CharSequencesubSequence(int start, int end)java.lang.Stringsubstring(int end)java.lang.Stringsubstring(int start, int end)java.lang.StringtoString()
-
-
-
Field Detail
-
logger
private final org.slf4j.Logger logger
-
source
private char[] source
The characters found within the template.
-
size
private int size
Number of characters stored in source array remaining to be tokenized
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY
Default capacity- See Also:
- Constant Field Values
-
offset
private int offset
An index of the first character for the remaining un-tokenized source.
-
lineNumber
private int lineNumber
Tracking the line number that we are currently tokenizing.
-
filename
private final java.lang.String filename
Filename of the template
-
-
Method Detail
-
copyReaderIntoCharArray
private void copyReaderIntoCharArray(java.io.Reader reader) throws java.io.IOExceptionRead the contents of the template into the internal char[].- Throws:
java.io.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
public java.lang.String substring(int start, int end)
-
substring
public java.lang.String substring(int end)
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
getLineNumber
public int getLineNumber()
-
getFilename
public java.lang.String getFilename()
-
-