public class CharacterStream extends Object
Example:
final CharacterStream characterStream = new CharacterStream("...");
while (characterStream.hasNext()) {
final char currentChar = characterStream.next();
// Do something with the current char.
}
TODO: Implement line and column.| Modifier and Type | Field and Description |
|---|---|
private int |
index
Current character position.
|
private String |
input
Accessed string.
|
| Constructor and Description |
|---|
CharacterStream(String input)
Initializes stream with string.
|
| Modifier and Type | Method and Description |
|---|---|
char |
current()
Returns the current character.
|
int |
getIndex()
Get the current index position.
|
boolean |
hasNext()
True if there are more characters.
|
char |
next()
Returns next character.
|
char |
peek()
Look ahead one character w/o advancing the internal pointer for the current character.
|
private final String input
private int index
public CharacterStream(String input)
input - Streamed string.public char next()
IndexOutOfBoundsException - if, there are no more characters.
// CHECKSTYLE:ONpublic boolean hasNext()
public char current()
next() not yet called, it is called implicitly.public char peek()
IndexOutOfBoundsException - if there are no more character to peek
// CHECKSTYLE:ONpublic int getIndex()
Copyright © 2014 Sven Strittmatter. All Rights Reserved.