Package org.ctan.markup.markdown
Class MarkdownScanner
java.lang.Object
java.io.Reader
java.io.FilterReader
java.io.PushbackReader
org.ctan.markup.markdown.MarkdownScanner
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
This class is the reader for the markdown parser. It contains additional
methods to support this task.
This reader applies a filter operation to map the line endings \r, \n, and \r\n to \n. Thus all major types of line endings are treated the same.
-
Field Summary
Fields inherited from class java.io.FilterReader
in
-
Constructor Summary
ConstructorsConstructorDescriptionMarkdownScanner
(Reader in, int size) This is the constructor forMarkdownScanner
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
expect
(int... s) This method checks that the lookahead of several characters are identical to the expected character.boolean
expectAfterSpace
(char cc) This method skips spaces and checks for an expected character.boolean
expectLineWith
(int cc) This method checks that the line contains only whitespace and at least 2 instances of the given character.expectNumberPeriod
(int cc) The methodexpectNumberPeriod
skips spaces and checks for at most 9 digits followed by a period and an optional space.String[]
This method parses to the closing parenthesis.This method expects a string enclosed in single or double quotes.expectUrl
(int endChar, boolean absolute) This method parses a URL and returns it.int
This method looks at the next character without actually removing it from the input.int
read()
This method reads text in brackets.readLine()
This method eats up all characters till the next newline.int
readLineTo
(int c, StringBuilder buffer, char c1, char c2) This method collects characters in a target buffer until a newline or one of two terminating characters is found.readLineTo
(StringBuilder buffer) This method eats up all characters till the next newline.int
readLineTo
(StringBuilder buffer, char cc) This method eats up all characters till the next newline or the terminating character is encountered.int
This method eats up all whitespace characters.readToWhitespace
(StringBuilder buffer) This method reads characters to the next whitespace into a target buffer.int
scanSectionDepth
(int max) This method digests all hash marks found and returns their number.void
skipLine()
This method skips to EOL.int
skipSpace
(StringBuilder buffer) This method reads ahead and stores all whitespace characters in the provided buffer.int
skipWhiteSpace
(int indent) This method reads ahead and skips all whitespace characters.void
unget
(int c) This method pushes back a character to the input stream.void
unget
(int c, CharSequence s) This method pushes back a string to the input stream.void
unget
(int c, CharSequence s, int c2) This method pushes back a string to the input stream.void
unget
(int c, CharSequence s, CharSequence s2) This method pushes back a string to the input stream.void
unget
(int c, CharSequence s, CharSequence s2, int c2) This method pushes back a string to the input stream.void
This method pushes back a string to the input stream.Methods inherited from class java.io.PushbackReader
close, mark, markSupported, read, ready, reset, skip, unread, unread, unread
Methods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Constructor Details
-
MarkdownScanner
This is the constructor forMarkdownScanner
.- Parameters:
in
- the input readersize
- the push-back buffer size
-
-
Method Details
-
expect
This method checks that the lookahead of several characters are identical to the expected character. Then these are digested. Otherwise the characters are pushed back into the input.- Parameters:
s
- the expected characters- Returns:
true
iff n characters have been found- Throws:
IOException
- in case of an I/O error
-
expectAfterSpace
This method skips spaces and checks for an expected character. If the character is found then it is skipped as well. Otherwise the character found is pushed back to the input stream.- Parameters:
cc
- the expected character- Returns:
true
iff the expected character has been found- Throws:
IOException
- in case of an I/O error
-
expectLineWith
This method checks that the line contains only whitespace and at least 2 instances of the given character.- Parameters:
cc
- the additional terminating character- Returns:
- the next undigested character
- Throws:
IOException
- in case of an I/O error
-
expectNumberPeriod
The methodexpectNumberPeriod
skips spaces and checks for at most 9 digits followed by a period and an optional space. If the characters are found then they are skipped as well. Otherwise the characters found are pushed back to the input stream.- Parameters:
cc
- the digit already read- Returns:
- the number found or
null
- Throws:
IOException
- in case of an I/O error
-
expectParens
This method parses to the closing parenthesis.- Returns:
- a pair of the items contained
- Throws:
IOException
- in case of an I/O error
-
expectString
This method expects a string enclosed in single or double quotes.- Returns:
- the string found or
null
on failure - Throws:
IOException
- in case of an I/O error
-
expectUrl
This method parses a URL and returns it. If no proper URL is found then the input stream is left unchanged andnull
is returned.- Parameters:
endChar
- the additional end character – except whitespaceabsolute
- indicate that only absolute URLs are allowed- Returns:
- the URL found or
null
on failure - Throws:
IOException
- in case of an I/O error
-
lookahead
This method looks at the next character without actually removing it from the input.- Returns:
- the next character
- Throws:
IOException
- in case of an I/O error
-
read
- Overrides:
read
in classPushbackReader
- Throws:
IOException
- See Also:
-
readBrackets
This method reads text in brackets. It is assumed that the opening bracket has already been digested.- Returns:
- the contents found in the brackets or
null
- Throws:
IOException
- in case of an I/O error
-
readLine
This method eats up all characters till the next newline.- Returns:
- the line read
- Throws:
IOException
- in case of an I/O error
-
readLineTo
This method collects characters in a target buffer until a newline or one of two terminating characters is found.- Parameters:
c
- the character already readbuffer
- the target bufferc1
- the first terminating characterc2
- the second terminating character- Returns:
- the character which caused the slurping to be terminated
- Throws:
IOException
- in case of an I/O error
-
readLineTo
This method eats up all characters till the next newline.- Parameters:
buffer
- the target buffer- Returns:
- the target buffer
- Throws:
IOException
- in case of an I/O error
-
readLineTo
This method eats up all characters till the next newline or the terminating character is encountered.- Parameters:
buffer
- the target buffercc
- the additional terminating character- Returns:
- the next undigested character
- Throws:
IOException
- in case of an I/O error
-
readNonSpace
This method eats up all whitespace characters.- Returns:
- the next undigested character
- Throws:
IOException
- in case of an I/O error
-
readToWhitespace
This method reads characters to the next whitespace into a target buffer.- Parameters:
buffer
- the target buffer- Returns:
- the buffer
- Throws:
IOException
- in case of an I/O error
-
scanSectionDepth
This method digests all hash marks found and returns their number.- Parameters:
max
- the limit for the return value- Returns:
- the number of hashes up to the limit
- Throws:
IOException
- in case of an I/O error
-
skipLine
This method skips to EOL.- Throws:
IOException
- in case of an I/O error
-
skipSpace
This method reads ahead and stores all whitespace characters in the provided buffer.- Parameters:
buffer
- the target buffer- Returns:
- the first non-whitespace character
- Throws:
IOException
- in case of an I/O error
-
skipWhiteSpace
This method reads ahead and skips all whitespace characters.- Parameters:
indent
- the previous indentation- Returns:
- the new indentation level
- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a string to the input stream.- Parameters:
s
- the string- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a character to the input stream.- Parameters:
c
- the character code- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a string to the input stream.- Parameters:
c
- the character codes
- the string- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a string to the input stream.- Parameters:
c
- the character codes
- the strings2
- the second string- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a string to the input stream.- Parameters:
c
- the character codes
- the strings2
- the second stringc2
- the terminating character- Throws:
IOException
- in case of an I/O error
-
unget
This method pushes back a string to the input stream.- Parameters:
c
- the character codes
- the stringc2
- the terminating character- Throws:
IOException
- in case of an I/O error
-