|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpicedt.format.input.util.Context
public class Context
A class that stores context information about the parsing process, like: current line number, current parsed substring, block markers, stack for markers…
By convention, end markers (EOF, EndOfBlocks, …) always refer to a position one character ahead of the last character (e.g. of the block), so that String.substring() works properly w/o adding 1 to the end-index.
Context also offers a "convenience" marker which may be handled by using mark() and reset().
Constructor Summary | |
---|---|
Context(Reader reader)
Build a new Context fed by the given reader . |
Method Summary | |
---|---|
void |
enterBlock(int blockEnd)
Save current markers in the stack, and set new block boundaries : new endBlockMarker is set to the given position new beginBlockMarker is set to the current caret position convenience marker is saved, and a new one is initialized to the beginning of the (new) current block. |
void |
exitBlock()
Restore old markers (and forget current value), then move caret to the end of the block we just went out. |
String |
find(Pattern re)
Attempts to find the next subsequence of the current block that matches the given pattern, starting at the caret position, then moves the caret past the matched string if found. |
int |
getBeginningOfBlock()
Return the position of the beginning of the current block |
String |
getBlockContent()
Return the content of the current block. |
int |
getBOL()
Returns the position of the beginning of the current line, or the beginning of the current block if the caret is located b/w the B.of.Block and the first CR inside the current block. |
String |
getBuffer()
Return the entire buffer |
int |
getCaretPosition()
Return the start-index of the remaining substring to be analysed. |
Character |
getCharAt(int index)
Return the character at the given position, or null if index is negative, or past EOF |
String |
getCurrentLine()
|
int |
getEndOfBlock()
Return the position of the end of the current block, i.e. the position of the last char in the block, plus one (so that for example substring(getBeginningOfBlock(), getEndOfBlock()) returns the entire block string. |
int |
getEOF()
Return the position of the end of the buffer, i.e. of the last character in the buffer. |
int |
getEOL()
Returns the position of the end of the current line, i.e. the location of the "\n" character, OR the end of the current block, if the caret is located b/w the E.of.Block and the last CR inside the block. |
int |
getLineNumber()
Return the current line number ; beware that first line is numbered "0" !!! |
Matcher |
getMatcher(Pattern re)
Returns the matcher built by matching the given pattern against the current block, starting at the current caret position. |
int |
indexOf(String s)
Return the index of the first occurence of the given String, starting from the current caret position. |
int |
indexOf(String s,
int fromIndex)
Return the index of the first occurence of the given String in the current block, starting from the given position |
int |
indexOfBeforeEOL(String s)
Return the index of the first occurence of the given String, starting from the current caret position, ending at getEndOfBlock() (not included!). |
boolean |
isAtBeginningOfBlock()
Return true if the caret is located at the beginning of the current block |
boolean |
isAtEndOfBlock()
Return true if the caret is located at the end of the current block |
boolean |
isAtEOF()
Return true if the caret is located at the end of the entire buffer |
boolean |
lineFeed()
Move cursor to the beginning of the next line, EVEN if we aren't at an EOL |
boolean |
lookingAt(Pattern re)
match the given RE pattern on the current block, starting at the caret position, then move the caret past the matched string if found. |
static void |
main(String[] arg)
Context standalone test |
void |
mark()
Set the convenience marker to the current caret position. |
boolean |
matchAndMove(String s)
Test if the string at the caret position starts with the given string, and in case of success moves the caret past this string ; return false otherwise. |
boolean |
moveCaretBy(int increment)
Move cursor position forward by the given increment, possibly proceeding to linefeeds. |
boolean |
moveCaretTo(int newPos)
Move cursor position forward to the given position, possibly proceeding to linefeeds. |
boolean |
pushBack()
After a read(), pushes back the char that has been read |
Character |
read()
read a character, and increment the caret position by one, if this is possible. |
String |
read(int n)
read the given number of character, wrapped in a String, and move the caret past the String being returned. |
String |
readTo(int pos)
Return the remaining substring up to the given position if (pos < caret) return "". |
String |
readToEOL()
Returns the remaining substring up to the end of the current line, EOL NOT INCLUDED ! |
static String |
removeLineFeeds(String s)
Remove '\n' and '\r' from a given string, and return a new string. |
static String |
removeRedundantWhiteSpaces(String s)
Replace " " (double-space) or tabs by ' ' ; always return a new String. |
void |
reset()
reset caret position to the convenience marker position, or to the beginning of the current block if no marker has been set. |
boolean |
startsWith(String s)
Return whether the string at the caret position starts with the given string or not. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Context(Reader reader) throws REParserException.EOF
Context
fed by the given reader
.
reader
- a reader encapsulating the text to be parsed
REParserException.EOF
Method Detail |
---|
public String toString()
toString
in class Object
public int getLineNumber()
public int getCaretPosition()
Ranges from 0 to currentLine.length()-1
public int getBOL()
public int getEOL()
public boolean isAtEOF()
public int getEOF()
public boolean moveCaretBy(int increment) throws REParserException.EOF
REParserException.EOF
public boolean moveCaretTo(int newPos) throws REParserException.EOF
In any case, caret CAN'T move out of the current block.
newPos
- new caret position ; can be negative, null, or positive.
REParserException.EOF
- if EOF was reached.public boolean lineFeed() throws REParserException.EOF
REParserException.EOF
- if there's nothing to be read from the reader (EOF)public void mark()
public void reset()
There's one convenience marker per block, i.e. marker defaults to beginning-of-block when entering a block.
public String getBuffer()
public Character getCharAt(int index)
public String getCurrentLine()
public Character read() throws REParserException.EOF
REParserException.EOF
public boolean pushBack() throws REParserException.EOF
REParserException.EOF
public String read(int n) throws REParserException.EOF
REParserException.EOF
public String readToEOL() throws REParserException.EOF
!!! If we're inside a block, and current EOL is greater than getEndOfBlock(), getEndOfBlock() is taken as the EOL (see getEOL()). Note that this wouldn't make sense otherwise…
REParserException.EOF
public String readTo(int pos) throws REParserException.EOF
REParserException.EOF
public boolean matchAndMove(String s) throws REParserException.EOF
REParserException.EOF
public int indexOf(String s)
public int indexOf(String s, int fromIndex)
public int indexOfBeforeEOL(String s)
public boolean startsWith(String s)
public static String removeLineFeeds(String s)
public static String removeRedundantWhiteSpaces(String s)
public Matcher getMatcher(Pattern re)
public boolean lookingAt(Pattern re)
public String find(Pattern re)
public int getBeginningOfBlock()
public int getEndOfBlock()
public boolean isAtBeginningOfBlock()
public boolean isAtEndOfBlock()
public String getBlockContent()
public void enterBlock(int blockEnd)
public void exitBlock()
public static void main(String[] arg)
arg
- arg[0] is the name of file to parse.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |