Package com.sshtools.daemon.util
Class StringScanner
- java.lang.Object
-
- com.sshtools.daemon.util.StringScanner
-
- Direct Known Subclasses:
StringExaminer
public class StringScanner extends java.lang.ObjectSimple scanner that allows to navigate over the characters of a string.- Version:
- 1.1
- Author:
- Manfred Duchrow
-
-
Field Summary
Fields Modifier and Type Field Description protected char[]bufferstatic charEND_REACHEDprotected intlengthprotected intpos_markerprotected intposition
-
Constructor Summary
Constructors Constructor Description StringScanner(java.lang.String stringToScan)Initialize the new instance with the string that should be scanned.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanatEnd()Returns true, if the scanner has reached the end and a further invocation of nextChar() would return the END_REACHED character.booleanendNotReached(char character)Returns true, if the given character does not indicate that the end of the scanned string si reached.booleanendReached(char character)Returns true, if the given character indicates that the end of the scanned string is reached.intgetPosition()Returns the current position in the stringbooleanhasNext()Returns true, if the scanner has not yet reached the end.protected intlength()voidmarkPosition()Remembers the current position for later use with restorePosition()charnextChar()Returns the character at the current position and increments the position afterwards by 1.charnextNoneWhitespaceChar()Returns the next character that is no whitespace and leaves the position pointer one character after the returned one.charpeek()Returns the character at the current position without changing the position, that is subsequent calls to this method return always the same character.voidrestorePosition()Restores the position to the value of the latest markPosition() callprotected voidsetPosition(int pos)voidskip(int count)Moves the position pointer count characters.java.lang.StringtoString()Returns the string the scanner was initialized with
-
-
-
Field Detail
-
END_REACHED
public static final char END_REACHED
- See Also:
- Constant Field Values
-
length
protected int length
-
position
protected int position
-
pos_marker
protected int pos_marker
-
buffer
protected char[] buffer
-
-
Method Detail
-
endReached
public boolean endReached(char character)
Returns true, if the given character indicates that the end of the scanned string is reached.- Parameters:
character-- Returns:
-
endNotReached
public boolean endNotReached(char character)
Returns true, if the given character does not indicate that the end of the scanned string si reached.- Parameters:
character-- Returns:
-
toString
public java.lang.String toString()
Returns the string the scanner was initialized with- Overrides:
toStringin classjava.lang.Object- Returns:
-
skip
public void skip(int count)
Moves the position pointer count characters. positive values move forwards, negative backwards. The position never becomes negative !- Parameters:
count-
-
peek
public char peek()
Returns the character at the current position without changing the position, that is subsequent calls to this method return always the same character.- Returns:
-
nextChar
public char nextChar()
Returns the character at the current position and increments the position afterwards by 1.- Returns:
-
atEnd
public boolean atEnd()
Returns true, if the scanner has reached the end and a further invocation of nextChar() would return the END_REACHED character.- Returns:
-
hasNext
public boolean hasNext()
Returns true, if the scanner has not yet reached the end.- Returns:
-
nextNoneWhitespaceChar
public char nextNoneWhitespaceChar()
Returns the next character that is no whitespace and leaves the position pointer one character after the returned one.- Returns:
-
getPosition
public int getPosition()
Returns the current position in the string- Returns:
-
markPosition
public void markPosition()
Remembers the current position for later use with restorePosition()
-
restorePosition
public void restorePosition()
Restores the position to the value of the latest markPosition() call
-
length
protected int length()
- Returns:
-
setPosition
protected void setPosition(int pos)
-
-