Class CharIterator
java.lang.Object
com.github.curiousoddman.rgxgen.parsing.dflt.CharIterator
Class incorporates functionality to iterate String char by char
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontext()Returns context of cursor (text around the cursor)context(int index) Returns context around passed indexbooleanhasNext()booleanCheck if next characters are same as argumentcharlastChar()Returns last character that would be iterated overvoidmodifyBound(int offset) Move the bound until which iterator will iteratecharnext()Returns next character and advances the cursornext(int length) Return nextlengthcharacters as a substring and advance cursornextUntil(char c) Returns substring from 'next' character UP TO first not escaped charactercCursor is advanced to a position after charactercReturns substring from next character up to next occurrence ofsCursor is advanced to a position after last character inscharpeek()Return next character, without advancing cursorcharpeek(int offset) Return character by offset from the next, without advancing cursorpeekUntil(char c) Returns substring from 'next' character UP TO first not escaped charactercintprevPos()Return position of last symbol returned by next()intCalculate number of characters remaining to iterate overvoidskip()Skip next charactervoidskip(int n) Skip nextncharacterssubstringToCurrPos(int pos) Create substring starting from next character whileconditionis true Cursor is advanced to the first character which does not match condition
-
Constructor Details
-
CharIterator
-
-
Method Details
-
hasNext
public boolean hasNext() -
skip
public void skip(int n) Skip nextncharacters- Parameters:
n- number of characters to skip
-
skip
public void skip()Skip next character -
peek
public char peek()Return next character, without advancing cursor- Returns:
- next character
-
peek
public char peek(int offset) Return character by offset from the next, without advancing cursor- Parameters:
offset- offset value.- Returns:
- character by offset from next
-
next
public char next()Returns next character and advances the cursor -
next
Return nextlengthcharacters as a substring and advance cursor- Parameters:
length- number of characters to return- Returns:
- substring start from next of
lengthcharacters
-
context
Returns context of cursor (text around the cursor)- Returns:
- substring [-5,+5) chars from current position
-
context
Returns context around passed index- Parameters:
index- center point of context- Returns:
- substring [-5,+5) chars from index
-
remaining
public int remaining()Calculate number of characters remaining to iterate over- Returns:
- num of characters
-
nextUntil
Returns substring from 'next' character UP TO first not escaped charactercCursor is advanced to a position after charactercExample: For text
'0123456789',nextUntil('8')will return'01234567'and put cursor before'9'- Parameters:
c- character to search for- Returns:
- substring from next character up to next not escaped character
c - Throws:
NoSuchElementException- if no such character present after next character
-
nextUntil
Returns substring from next character up to next occurrence ofsCursor is advanced to a position after last character insExample: For text
'0123456789',nextUntil("456")will return'0123'and put cursor before'7'- Parameters:
s- string to search for- Returns:
- substring from next character up to next not escaped occurrence of s. if string not found - returns all remaining characters
-
peekUntil
Returns substring from 'next' character UP TO first not escaped charactercExample: For text
'0123456789',nextUntil('8')will return'01234567'- Parameters:
c- character to search for- Returns:
- substring from next character up to next not escaped character
c - Throws:
NoSuchElementException- if no such character present after next character
-
takeWhile
Create substring starting from next character whileconditionis true Cursor is advanced to the first character which does not match condition- Parameters:
condition- condition to test each character with- Returns:
- substring of characters that matches condition
-
lastChar
public char lastChar()Returns last character that would be iterated over- Returns:
- last character that would be iterated over
-
modifyBound
public void modifyBound(int offset) Move the bound until which iterator will iterate- Parameters:
offset- offset in respect to current bound
-
prevPos
public int prevPos()Return position of last symbol returned by next()- Returns:
- index
-
substringToCurrPos
-
hasNext
Check if next characters are same as argument- Parameters:
nextChars- expected next characters- Returns:
- true if next characters match argument
-