Package org.jsoup.parser
Class CharacterReader
java.lang.Object
org.jsoup.parser.CharacterReader
- All Implemented Interfaces:
AutoCloseable
CharacterReader consumes tokens off a string. Used internally by jsoup. API subject to changes.
If the underlying reader throws an IOException during any operation, the CharacterReader will throw an
UncheckedIOException. That won't happen with String / StringReader inputs.
-
Constructor Summary
ConstructorsConstructorDescriptionCharacterReader(Reader input) CharacterReader(Reader input, int sz) CharacterReader(String input) -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance()Moves the current position by one.voidclose()intGet the current column number (that the reader has consumed to).charconsume()Consume one character off the queue.consumeTo(char c) Reads characters up to the specific char.Reads the characters up to (but not including) the specified case-sensitive string.consumeToAny(char... chars) Read characters until the first of any delimiters is found.charcurrent()Get the char at the current position.booleanisEmpty()Tests if all the content has been read.booleanCheck if the tracking of newlines is enabled.intGet the current line number (that the reader has consumed to).intpos()Gets the position currently read to in the content.toString()voidtrackNewlines(boolean track) Enables or disables line number tracking.
-
Constructor Details
-
CharacterReader
-
CharacterReader
-
CharacterReader
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable
-
pos
Gets the position currently read to in the content. Starts at 0.- Returns:
- current position
-
trackNewlines
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
Check if the tracking of newlines is enabled.- Returns:
- the current newline tracking state
- Since:
- 1.14.3
-
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:
-
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:
-
isEmpty
Tests if all the content has been read.- Returns:
- true if nothing left to read.
-
current
Get the char at the current position.- Returns:
- char
-
consume
Consume one character off the queue.- Returns:
- first character on queue, or EOF if the queue is empty.
-
advance
Moves the current position by one. -
consumeTo
Reads characters up to the specific char.- Parameters:
c- the delimiter- Returns:
- the chars read
-
consumeTo
Reads the characters up to (but not including) the specified case-sensitive string.If the sequence is not found in the buffer, will return the remainder of the current buffered amount, less the length of the sequence, such that this call may be repeated.
- Parameters:
seq- the delimiter- Returns:
- the chars read
-
consumeToAny
Read characters until the first of any delimiters is found.- Parameters:
chars- delimiters to scan for- Returns:
- characters read up to the matched delimiter.
-
toString
-