Package org.jsoup.parser
Class CharacterReader
- java.lang.Object
-
- org.jsoup.parser.CharacterReader
-
public final class CharacterReader extends java.lang.ObjectCharacterReader consumes tokens off a string. Used internally by jsoup. API subject to changes.
-
-
Field Summary
Fields Modifier and Type Field Description private intbufLengthprivate intbufMarkprivate intbufPosprivate intbufSplitPointprivate char[]charBuf(package private) static charEOFprivate intlastIcIndexprivate java.lang.StringlastIcSeqprivate intlineNumberOffset(package private) static intmaxBufferLenprivate static intmaxStringCacheLenprivate static intminReadAheadLenprivate java.util.ArrayList<java.lang.Integer>newlinePositions(package private) static intreadAheadLimitprivate java.io.Readerreaderprivate intreaderPosprivate booleanreadFullyprivate java.lang.String[]stringCacheprivate static intstringCacheSize
-
Constructor Summary
Constructors Constructor Description CharacterReader(java.io.Reader input)CharacterReader(java.io.Reader input, int sz)CharacterReader(java.lang.String input)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvance()Moves the current position by one.private voidbufferUp()private static java.lang.StringcacheString(char[] charBuf, java.lang.String[] stringCache, int start, int count)Caches short strings, as a flyweight pattern, to reduce GC load.voidclose()(package private) intcolumnNumber()Get the current column number (that the reader has consumed to).(package private) charconsume()(package private) java.lang.StringconsumeAttributeQuoted(boolean single)(package private) java.lang.StringconsumeData()(package private) java.lang.StringconsumeDigitSequence()(package private) java.lang.StringconsumeHexSequence()(package private) java.lang.StringconsumeLetterSequence()(package private) java.lang.StringconsumeLetterThenDigitSequence()(package private) java.lang.StringconsumeRawData()(package private) java.lang.StringconsumeTagName()java.lang.StringconsumeTo(char c)Reads characters up to the specific char.(package private) java.lang.StringconsumeTo(java.lang.String seq)java.lang.StringconsumeToAny(char... chars)Read characters until the first of any delimiters is found.(package private) java.lang.StringconsumeToAnySorted(char... chars)(package private) java.lang.StringconsumeToEnd()(package private) booleancontainsIgnoreCase(java.lang.String seq)Used to check presence of , when we're in RCData and see acharcurrent()Get the char at the current position.(package private) java.lang.StringcursorPos()Get a formatted string representing the current line and cursor positions.booleanisEmpty()Tests if all the content has been read.private booleanisEmptyNoBufferUp()booleanisTrackNewlines()Check if the tracking of newlines is enabled.intlineNumber()Get the current line number (that the reader has consumed to).private intlineNumIndex()(package private) voidmark()(package private) booleanmatchConsume(java.lang.String seq)(package private) booleanmatchConsumeIgnoreCase(java.lang.String seq)(package private) booleanmatches(char c)(package private) booleanmatches(java.lang.String seq)(package private) booleanmatchesAny(char... seq)(package private) booleanmatchesAnySorted(char[] seq)(package private) booleanmatchesAsciiAlpha()Checks if the current pos matches an ascii alpha (A-Z a-z) per https://infra.spec.whatwg.org/#ascii-alpha(package private) booleanmatchesDigit()(package private) booleanmatchesIgnoreCase(java.lang.String seq)(package private) booleanmatchesLetter()(package private) intnextIndexOf(char c)Returns the number of characters between the current position and the next instance of the input char(package private) intnextIndexOf(java.lang.CharSequence seq)Returns the number of characters between the current position and the next instance of the input sequenceintpos()Gets the current cursor position in the content.(package private) static booleanrangeEquals(char[] charBuf, int start, int count, java.lang.String cached)Check if the value of the provided range equals the string.(package private) booleanrangeEquals(int start, int count, java.lang.String cached)(package private) voidrewindToMark()private voidscanBufferForNewlines()Scans the buffer for newline position, and tracks their location in newlinePositions.java.lang.StringtoString()voidtrackNewlines(boolean track)Enables or disables line number tracking.(package private) voidunconsume()Unconsume one character (bufPos--).(package private) voidunmark()
-
-
-
Field Detail
-
EOF
static final char EOF
- See Also:
- Constant Field Values
-
maxStringCacheLen
private static final int maxStringCacheLen
- See Also:
- Constant Field Values
-
maxBufferLen
static final int maxBufferLen
- See Also:
- Constant Field Values
-
readAheadLimit
static final int readAheadLimit
- See Also:
- Constant Field Values
-
minReadAheadLen
private static final int minReadAheadLen
- See Also:
- Constant Field Values
-
charBuf
private char[] charBuf
-
reader
private java.io.Reader reader
-
bufLength
private int bufLength
-
bufSplitPoint
private int bufSplitPoint
-
bufPos
private int bufPos
-
readerPos
private int readerPos
-
bufMark
private int bufMark
-
stringCacheSize
private static final int stringCacheSize
- See Also:
- Constant Field Values
-
stringCache
private java.lang.String[] stringCache
-
newlinePositions
@Nullable private java.util.ArrayList<java.lang.Integer> newlinePositions
-
lineNumberOffset
private int lineNumberOffset
-
readFully
private boolean readFully
-
lastIcSeq
@Nullable private java.lang.String lastIcSeq
-
lastIcIndex
private int lastIcIndex
-
-
Method Detail
-
close
public void close()
-
bufferUp
private void bufferUp()
-
pos
public int pos()
Gets the current cursor position in the content.- Returns:
- current position
-
trackNewlines
public void trackNewlines(boolean track)
Enables or disables line number tracking. By default, will be off.Tracking line numbers improves the legibility of parser error messages, for example. Tracking should be enabled before any content is read to be of use.- Parameters:
track- set tracking on|off- Since:
- 1.14.3
-
isTrackNewlines
public boolean isTrackNewlines()
Check if the tracking of newlines is enabled.- Returns:
- the current newline tracking state
- Since:
- 1.14.3
-
lineNumber
public int lineNumber()
Get the current line number (that the reader has consumed to). Starts at line #1.- Returns:
- the current line number, or 1 if line tracking is not enabled.
- Since:
- 1.14.3
- See Also:
trackNewlines(boolean)
-
columnNumber
int columnNumber()
Get the current column number (that the reader has consumed to). Starts at column #1.- Returns:
- the current column number
- Since:
- 1.14.3
- See Also:
trackNewlines(boolean)
-
cursorPos
java.lang.String cursorPos()
Get a formatted string representing the current line and cursor positions. E.g.5:10indicating line number 5 and column number 10.- Returns:
- line:col position
- Since:
- 1.14.3
- See Also:
trackNewlines(boolean)
-
lineNumIndex
private int lineNumIndex()
-
scanBufferForNewlines
private void scanBufferForNewlines()
Scans the buffer for newline position, and tracks their location in newlinePositions.
-
isEmpty
public boolean isEmpty()
Tests if all the content has been read.- Returns:
- true if nothing left to read.
-
isEmptyNoBufferUp
private boolean isEmptyNoBufferUp()
-
current
public char current()
Get the char at the current position.- Returns:
- char
-
consume
char consume()
-
unconsume
void unconsume()
Unconsume one character (bufPos--). MUST only be called directly after a consume(), and no chance of a bufferUp.
-
advance
public void advance()
Moves the current position by one.
-
mark
void mark()
-
unmark
void unmark()
-
rewindToMark
void rewindToMark()
-
nextIndexOf
int nextIndexOf(char c)
Returns the number of characters between the current position and the next instance of the input char- Parameters:
c- scan target- Returns:
- offset between current position and next instance of target. -1 if not found.
-
nextIndexOf
int nextIndexOf(java.lang.CharSequence seq)
Returns the number of characters between the current position and the next instance of the input sequence- Parameters:
seq- scan target- Returns:
- offset between current position and next instance of target. -1 if not found.
-
consumeTo
public java.lang.String consumeTo(char c)
Reads characters up to the specific char.- Parameters:
c- the delimiter- Returns:
- the chars read
-
consumeTo
java.lang.String consumeTo(java.lang.String seq)
-
consumeToAny
public java.lang.String consumeToAny(char... chars)
Read characters until the first of any delimiters is found.- Parameters:
chars- delimiters to scan for- Returns:
- characters read up to the matched delimiter.
-
consumeToAnySorted
java.lang.String consumeToAnySorted(char... chars)
-
consumeData
java.lang.String consumeData()
-
consumeAttributeQuoted
java.lang.String consumeAttributeQuoted(boolean single)
-
consumeRawData
java.lang.String consumeRawData()
-
consumeTagName
java.lang.String consumeTagName()
-
consumeToEnd
java.lang.String consumeToEnd()
-
consumeLetterSequence
java.lang.String consumeLetterSequence()
-
consumeLetterThenDigitSequence
java.lang.String consumeLetterThenDigitSequence()
-
consumeHexSequence
java.lang.String consumeHexSequence()
-
consumeDigitSequence
java.lang.String consumeDigitSequence()
-
matches
boolean matches(char c)
-
matches
boolean matches(java.lang.String seq)
-
matchesIgnoreCase
boolean matchesIgnoreCase(java.lang.String seq)
-
matchesAny
boolean matchesAny(char... seq)
-
matchesAnySorted
boolean matchesAnySorted(char[] seq)
-
matchesLetter
boolean matchesLetter()
-
matchesAsciiAlpha
boolean matchesAsciiAlpha()
Checks if the current pos matches an ascii alpha (A-Z a-z) per https://infra.spec.whatwg.org/#ascii-alpha- Returns:
- if it matches or not
-
matchesDigit
boolean matchesDigit()
-
matchConsume
boolean matchConsume(java.lang.String seq)
-
matchConsumeIgnoreCase
boolean matchConsumeIgnoreCase(java.lang.String seq)
-
containsIgnoreCase
boolean containsIgnoreCase(java.lang.String seq)
Used to check presence of , when we're in RCData and see a-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
cacheString
private static java.lang.String cacheString(char[] charBuf, java.lang.String[] stringCache, int start, int count)Caches short strings, as a flyweight pattern, to reduce GC load. Just for this doc, to prevent leaks. Simplistic, and on hash collisions just falls back to creating a new string, vs a full HashMap with Entry list. That saves both having to create objects as hash keys, and running through the entry list, at the expense of some more duplicates.
-
rangeEquals
static boolean rangeEquals(char[] charBuf, int start, int count, java.lang.String cached)Check if the value of the provided range equals the string.
-
rangeEquals
boolean rangeEquals(int start, int count, java.lang.String cached)
-
-
-