org.databene.commons
Class StringCharacterIterator

java.lang.Object
  extended by org.databene.commons.StringCharacterIterator
All Implemented Interfaces:
CharacterIterator

public class StringCharacterIterator
extends java.lang.Object
implements CharacterIterator

Supports iterating the characters of a String. This is especially useful for writing parsers that iterate over Strings, since it encapsules the cursor index.

Created: 18.08.2006 19:21:45

Author:
Volker Bergmann

Constructor Summary
StringCharacterIterator(java.lang.String source)
          Creates an iterator that starts at the String's beginning
StringCharacterIterator(java.lang.String source, int index)
          Creates an iterator that starts at a specified position
 
Method Summary
 void assertNext(char c)
           
 int column()
           
 boolean hasNext()
          Tells if the iterator has not reached the String's end.
 int index()
           
 int line()
           
 char next()
           
 java.lang.String parsedSubstring(int from)
           
 java.lang.String parseLetters()
           
 char peekNext()
           
 void pushBack()
          Pushes back the cursor by one character.
 java.lang.String remainingText()
           
 void remove()
          Implements the remove() operation of the Iterator interface, raising an UnsupportedOperationException.
 void skipWhitespace()
           
 java.lang.String substring(int from, int to)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringCharacterIterator

public StringCharacterIterator(java.lang.String source)
Creates an iterator that starts at the String's beginning


StringCharacterIterator

public StringCharacterIterator(java.lang.String source,
                               int index)
Creates an iterator that starts at a specified position

Method Detail

hasNext

public boolean hasNext()
Tells if the iterator has not reached the String's end. java.util.Iterator#hasNext()

Specified by:
hasNext in interface CharacterIterator
Returns:
true if there are more characters available, false, if the end was reached.

next

public char next()
Specified by:
next in interface CharacterIterator
Returns:
the next character.
See Also:
Iterator.next()

remove

public void remove()
Implements the remove() operation of the Iterator interface, raising an UnsupportedOperationException.

See Also:
Iterator.remove()

peekNext

public char peekNext()

pushBack

public void pushBack()
Pushes back the cursor by one character.


index

public int index()
Returns:
the cursor index.

skipWhitespace

public void skipWhitespace()

parseLetters

public java.lang.String parseLetters()

remainingText

public java.lang.String remainingText()

substring

public java.lang.String substring(int from,
                                  int to)

parsedSubstring

public java.lang.String parsedSubstring(int from)

assertNext

public void assertNext(char c)

line

public int line()

column

public int column()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the String that is iterated.


Copyright © 2010. All Rights Reserved.