Package ghidra.app.util.demangler
Class CharacterIterator
java.lang.Object
ghidra.app.util.demangler.CharacterIterator
A class for bidirectional iteration over a string.
Iterators maintain a current character index, whose valid range is from
0 to string.length()-1.
The current index can be retrieved by calling getIndex() and set directly
by calling setIndex().
The methods previous() and next() are used for iteration. They return DONE if
they would move outside the range from 0 to string.length()-1.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
Constant that is returned when the iterator has reached either the end or the beginning of the text. -
Constructor Summary
ConstructorDescriptionCharacterIterator
(String str) Constructs a new character iterator using str. -
Method Summary
Modifier and TypeMethodDescriptionint
find
(char c) Looks for the next occurrence of 'c' starting at the current index.char
Returns the character at the current index and then increments the index by one.int
getIndex()
Returns the current index.int
Returns the length of the iterator.Returns the underlying string.boolean
hasNext()
Returns true if there are more characters to read.char
next()
Increments the current index by one and returns the character at the new index.int
Returns the next integer.nextString
(int len) Returns the next ascii string of the specified length starting at the current index.char
peek()
Returns the next character without incrementing the current index.char
peek
(int lookAhead) Peeks at the character current index + lookAhead.char
previous()
Decrements the current index by one and returns the character at the new index.void
setIndex
(int index) Sets the position to the specified position in the text.toString()
-
Field Details
-
DONE
public static final char DONEConstant that is returned when the iterator has reached either the end or the beginning of the text. The value is '\\uFFFF', the "not a character" value which should not occur in any valid Unicode string.- See Also:
-
-
Constructor Details
-
CharacterIterator
Constructs a new character iterator using str.- Parameters:
str
- the string to iterate
-
-
Method Details
-
getString
Returns the underlying string.- Returns:
- the underlying string
-
getIndex
public int getIndex()Returns the current index.- Returns:
- the current index.
-
getLength
public int getLength()Returns the length of the iterator.- Returns:
- the length of the iterator
-
setIndex
public void setIndex(int index) Sets the position to the specified position in the text.- Parameters:
index
- the position within the text.
-
hasNext
public boolean hasNext()Returns true if there are more characters to read.- Returns:
- true if there are more characters to read
-
peek
public char peek()Returns the next character without incrementing the current index.- Returns:
- the next character without incrementing the current index
-
peek
public char peek(int lookAhead) Peeks at the character current index + lookAhead. Returns DONE if the computed position is out of range.- Parameters:
lookAhead
- number of characters to look ahead- Returns:
- the character at index+lookAhead
-
next
public char next()Increments the current index by one and returns the character at the new index. If the resulting index is greater or equal to the end index, the current index is reset to the end index and a value of DONE is returned.- Returns:
- the character at the new position or DONE
-
getAndIncrement
public char getAndIncrement()Returns the character at the current index and then increments the index by one. If the resulting index is greater or equal to the end index, the current index is reset to the end index and a value of DONE is returned.- Returns:
- the character at the new position or DONE
-
previous
public char previous()Decrements the current index by one and returns the character at the new index. If the current index is 0, the index remains at 0 and a value of DONE is returned.- Returns:
- the character at the new position or DONE
-
nextString
Returns the next ascii string of the specified length starting at the current index.- Parameters:
len
- the length of the string to read- Returns:
- the next ascii string
-
nextInteger
public int nextInteger()Returns the next integer. The radix must be 10 (decimal). For example, given "...12fred..". If current index is pointing to the '1', then this value will return 12.- Returns:
- the next base-10 integer.
-
find
public int find(char c) Looks for the next occurrence of 'c' starting at the current index. Returns the character position in the underlying string or -1 if 'c' is not found. -
toString
-