|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.text.CPunctuationState
public class CPunctuationState
An object that represents the state within a string that uses C-style punctuation (braces, brackets, parentheses, escape characters, quotations). Note that, unlike C, single quotes can contain multiple characters.
Field Summary | |
---|---|
static int |
BLOCK_COMMENT_STATE_END_STAR
Value for blockCommentState that means we are in a a
comment block, after an eligible '*' to start the termination sequence. |
static int |
BLOCK_COMMENT_STATE_FIRST_SLASH
Value for blockCommentState that means we have encountered
the first slash for a comment block. |
static int |
BLOCK_COMMENT_STATE_MIDDLE
Value for blockCommentState that means we are in the
middle of a comment block, before both the terminating '*' and '/'. |
static int |
BLOCK_COMMENT_STATE_NOT_IN_BLOCK
Value for blockCommentState that means we have not started
comment block. |
int |
blockCommentState
The state of being in block comment. |
int |
braces
The number of opening brace ('{') yet to be closed. |
int |
brackets
The number of opening brackets ('[') yet to be closed. |
java.lang.StringBuffer |
digitBuffer
The digits used for a octal or unicode escape, encountered so far. |
boolean |
doubleQuoted
True if this instance is in a double-quoted context. |
boolean |
escaped
True if this instance is in an escaped context. |
static java.lang.String |
HEX_DIGITS
A string of all possible hex digits. |
boolean |
inLineComment
True if this instance is in a line comment. |
char |
lastOctalChar
Because octal escapes have a variable length, a character that ends an octal escape may result in two output characters: one for the octal escape that has ended and one for the original character. |
static java.lang.String |
OCTAL_DIGITS
A string of all possible octal digits. |
boolean |
octalEscaped
True if this instance is in a octal escaped context. |
char |
outChar
If set to something other than Character.MAX_VALUE , the
character that was represented by the last character scanned. |
int |
parentheses
The number of opening parentheses ('(') yet to be closed. |
boolean |
singleQuoted
True if this instance is in a single-quoted context. |
boolean |
unicodeEscaped
True if this instance is in a Unicode escaped context. |
Constructor Summary | |
---|---|
CPunctuationState()
|
Method Summary | |
---|---|
protected void |
_finishOctalEscape(int index)
Finish an octal escape sequence, using digitBuffer to
compute the last octal character (saved in outChar ),
and reseting the state. |
protected static char |
_hexDigitsToChar(java.lang.CharSequence cs,
int index)
Convert the char sequence which is a sequence of hex digits to a character. |
protected static char |
_octalDigitsToChar(java.lang.CharSequence cs,
int index)
Convert the char sequence which is a sequence of octal digits to a character. |
java.lang.Object |
clone()
|
boolean |
inComment()
Return true if we are in a line or block comment. |
boolean |
isClosed()
Return true if the number of unclosed parentheses, brackets, and braces is 0, and the state is not in an escaped or quoted context. |
static boolean |
isClosingPunctuation(char c)
Return true if c is one of ')', ']', '}', '\'', or '"'. |
static boolean |
isOpeningPunctuation(char c)
Return true if c is one of '(', '[', '{', '\'', or '"'. |
static char |
matchingPunctuation(char c)
Return the punctuation character that either opens or closes the argument character. |
int |
matchPunctuation(java.lang.CharSequence cs,
int startIndex)
Assuming cs has C-style syntax, and using this instance
as the punctuation state, return the index of the punctuation symbol
that closes the opening punctuation symbol at startIndex
(either '{' , '[', '(' , '\'' , or
'"' ). |
void |
reset()
Reset the state to be as it was just after construction. |
java.lang.String |
toString()
|
char |
update(char c,
int index)
Update the state using the next character. |
java.lang.String |
update(java.lang.CharSequence cs)
Update the state with the characters in cs . |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public int parentheses
public int brackets
public int braces
public boolean escaped
public boolean octalEscaped
public boolean unicodeEscaped
public boolean inLineComment
public int blockCommentState
public java.lang.StringBuffer digitBuffer
null
, we are not in an octal or unicode escape.
public char lastOctalChar
update()
can only return one character, so the octal
character built is saved here. If equal to
Character.MAX_VALUE
, the last character did not end an
octal sequence.
public boolean doubleQuoted
public boolean singleQuoted
public char outChar
Character.MAX_VALUE
, the
character that was represented by the last character scanned. Ordinary,
this is the same as the last character, but in an escaped context, the
last character might mean another character. If equal to
Character.MAX_VALUE
, the last character was escaped so no
character was represented.
public static final int BLOCK_COMMENT_STATE_NOT_IN_BLOCK
blockCommentState
that means we have not started
comment block.
public static final int BLOCK_COMMENT_STATE_FIRST_SLASH
blockCommentState
that means we have encountered
the first slash for a comment block.
public static final int BLOCK_COMMENT_STATE_MIDDLE
blockCommentState
that means we are in the
middle of a comment block, before both the terminating '*' and '/'.
public static final int BLOCK_COMMENT_STATE_END_STAR
blockCommentState
that means we are in a a
comment block, after an eligible '*' to start the termination sequence.
If we encounter a '/', we will leave the block.
public static final java.lang.String OCTAL_DIGITS
public static final java.lang.String HEX_DIGITS
Constructor Detail |
---|
public CPunctuationState()
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public void reset()
public char update(char c, int index) throws java.text.ParseException
Character.MAX_VALUE
if
the state is in an escaped context. If the character is a closing
punctuation mark, throw a ParseException
using the
argument index as the index of error.
java.text.ParseException
public java.lang.String update(java.lang.CharSequence cs) throws java.text.ParseException
cs
. Output the
unescaped characters.
java.text.ParseException
public boolean isClosed()
public boolean inComment()
public int matchPunctuation(java.lang.CharSequence cs, int startIndex) throws java.text.ParseException
Assuming cs
has C-style syntax, and using this instance
as the punctuation state, return the index of the punctuation symbol
that closes the opening punctuation symbol at startIndex
(either '{'
, '[', '('
, '\''
, or
'"'
). If the character at startIndex
is not
an opening punctation symbol, throw an
IllegalArgumentException
. If a matching symbol cannot be
found by the end of cs
, throw a
ParseException
. Also, if a closing punctuation symbol is
encountered before its corresponding opening punctuation symbol, throw
a ParseException
. Characters before
startIndex
are not scanned, so it is assumed this instance
accurately reflects the punctuation state at startIndex
.
As a side effect, this instance's state is updated with the characters scanned, even if an exception is thrown. It may be prudent to call this method on a clone of an existing state.
java.text.ParseException
protected void _finishOctalEscape(int index) throws java.text.ParseException
digitBuffer
to
compute the last octal character (saved in outChar
),
and reseting the state.
java.text.ParseException
protected static char _octalDigitsToChar(java.lang.CharSequence cs, int index) throws java.text.ParseException
java.text.ParseException
protected static char _hexDigitsToChar(java.lang.CharSequence cs, int index) throws java.text.ParseException
java.text.ParseException
public static final boolean isOpeningPunctuation(char c)
c
is one of '(', '[', '{', '\'', or '"'.
public static final boolean isClosingPunctuation(char c)
c
is one of ')', ']', '}', '\'', or '"'.
public static final char matchingPunctuation(char c)
c
is not a valid punctuation
character, throw an IllegalArgumentException
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |