Class CharIterator
- java.lang.Object
-
- com.github.curiousoddman.rgxgen.parsing.dflt.CharIterator
-
-
Constructor Summary
Constructors Constructor Description CharIterator(String value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringcontext()Returns context of cursor (text around the cursor)Stringcontext(int index)Returns context around passed indexbooleanhasNext()charlastChar()Returns last character that would be iterated overvoidmodifyBound(int offset)Move the bound until which iterator will iterateCharacternext()Returns next character and advances the cursorStringnext(int length)Return nextlengthcharacters as a substring and advance cursorStringnextUntil(char c)Returns substring from 'next' character UP TO first not escaped charactercCursor is advanced to a position after charactercStringnextUntil(String s)Returns 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 cursorintprevPos()Return position of last symbol returned by next()intremaining()Calculate number of characters remaining to iterate overvoidskip()Skip next charactervoidskip(int n)Skip nextncharactersStringsubstringToCurrPos(int pos)StringtakeWhile(Predicate<Character> condition)Create substring starting from next character whileconditionis true Cursor is advanced to the first character which does not match condition-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
CharIterator
public CharIterator(String value)
-
-
Method Detail
-
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 Character next()
Returns next character and advances the cursor
-
next
public String next(int length)
Return nextlengthcharacters as a substring and advance cursor- Parameters:
length- number of characters to return- Returns:
- substring start from next of
lengthcharacters
-
context
public String context()
Returns context of cursor (text around the cursor)- Returns:
- substring [-5,+5) chars from current position
-
context
public String context(int index)
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
public String nextUntil(char c)
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
public String nextUntil(String s)
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
-
takeWhile
public String takeWhile(Predicate<Character> condition)
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
public String substringToCurrPos(int pos)
-
-