Class Parser
java.lang.Object
org.simpleframework.common.parse.Parser
- Direct Known Subclasses:
AddressParser, ContentDispositionParser, ContentTypeParser, CookieParser, DateParser, ListParser, MapParser, PathParser, PrincipalParser
This
Parser object is to be used as a simple template
for parsing uncomplicated expressions. This object is used to parse
a String. This provides a few methods that can be used
to store and track the reading of data from a buffer. There are two
abstract methods provided to allow this to be subclassed to create
a Parser for a given String.-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedParser()This is a no argument constructor for theParser. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandigit(char c) This is used to determine weather or not a given character is a digit character.protected voidensureCapacity(int min) This ensure that there is enough space in the buffer to allow for morechar's to be added.protected abstract voidinit()This will initialize theParserwhen it is ready to parse a newString.protected abstract voidparse()This is the method that should be implemented to read the buf.voidThis is used to parse theStringgiven to it.protected booleanThis is used to skip an arbitraryStringwithin thecharbuf.protected booleanspace(char c) This is used to determine if a given ISO-8859-1 character is a space character.protected chartoLower(char c) This takes a unicode character and assumes an encoding of ISO-8859-1.
-
Field Details
-
buf
protected char[] bufThis is the buffer that is being parsed. -
off
protected int offThis represents the current read offset. -
count
protected int countThis represents the length of the buffer.
-
-
Constructor Details
-
Parser
protected Parser()This is a no argument constructor for theParser. This will be invoked by each subclass of this object. It will set the buffer to a zero length buffer so that when theensureCapacitymethod is used the buf's length can be checked.
-
-
Method Details
-
parse
This is used to parse theStringgiven to it. This will ensure that thecharbuffer has enough space to contain the characters from theString. This will firstly ensure that the buffer is resized if nessecary. The second step in thisparsemethod is to initialize theParserobject so that multiple parse invocations can be made. Theinitmethod will reset this to an prepared state. Then finally theparsemethod is called to parse thecharbuffer.- Parameters:
text- theStringto be parsed with thisParser
-
ensureCapacity
protected void ensureCapacity(int min) This ensure that there is enough space in the buffer to allow for morechar's to be added. If the buffer is already larger than min then the buffer will not be expanded at all.- Parameters:
min- the minimum size needed to accommodate the characters
-
space
protected boolean space(char c) This is used to determine if a given ISO-8859-1 character is a space character. That is a whitespace character this sees the, space, carriage return and line feed characters as whitespace characters.- Parameters:
c- the character that is being determined by this- Returns:
- true if the character given it is a space character
-
digit
protected boolean digit(char c) This is used to determine weather or not a given character is a digit character. It assumes iso-8859-1 encoding to compare.- Parameters:
c- the character being determined by this method- Returns:
- true if the character given is a digit character
-
toLower
protected char toLower(char c) This takes a unicode character and assumes an encoding of ISO-8859-1. This then checks to see if the given character is uppercase if it is it converts it into is ISO-8859-1 lowercase char.- Parameters:
c- thecharto be converted to lowercase- Returns:
- the lowercase ISO-8859-1 of the given character
-
skip
This is used to skip an arbitraryStringwithin thecharbuf. It checks the length of theStringfirst to ensure that it will not go out of bounds. A comparison is then made with the buffers contents and theStringif the reigon in the buffer matched theStringthen the offset within the buffer is increased by theString's length so that it has effectively skipped it.- Parameters:
text- this is theStringvalue to be skipped- Returns:
- true if the
Stringwas skipped
-
init
protected abstract void init()This will initialize theParserwhen it is ready to parse a newString. This will reset theParserto a ready state. Theinitmethod is invoked by theParserwhen theparsemethod is invoked. -
parse
protected abstract void parse()This is the method that should be implemented to read the buf. This method should attempt to extract tokens from the buffer so that thes tokens may some how be used to determine the semantics. This method is invoked after theinitmethod is invoked.
-