MjSip Stack
v1.6

org.zoolu.tools
Class Parser

java.lang.Object
  |
  +--org.zoolu.tools.Parser
Direct Known Subclasses:
SipParser

public class Parser
extends java.lang.Object

Class Parser allows the parsing of String objects.
An object Parser is costructed from a String object and provides various methods for parsing the String in a stream oriented manner. The class Parser also collects different static methods for parsing non-pre-associated strings.
Parser uses the following definitions:

   
string = any string of chars included between ' ' and '~'
word = any string of chars without separators
separators = a vector of chars; e.g. ( ) < > @ , ; : \ " / | [ ] ? = { } HT SP
alpha = a-z, A-Z
digit = 0-9
integer = any digit word parsed by Integer.parseInt(String)


Field Summary
static char[] CRLF
          Characters CR and LF.
protected  int index
          The the current pointer to the next char within the string.
static char[] SPACE
          The same as WSP (for legacy)
protected  java.lang.String str
          The string that is being parsed.
static char[] WSP
          Characters space (SP) and tab (HT).
static char[] WSPCRLF
          Characters white-space, tab, CR, and LF.
 
Constructor Summary
Parser(java.lang.String s)
          Creates the Parser from the String s and point to the beginning of the string.
Parser(java.lang.StringBuffer sb)
          Creates the Parser from the StringBuffer sb and point to the beginning of the string.
Parser(java.lang.StringBuffer sb, int i)
          Creates the Parser from the StringBuffer sb and point to the position i.
Parser(java.lang.String s, int i)
          Creates the Parser from the String s and point to the position i.
 
Method Summary
 char charAt(int n)
          Gets the char at distance n WITHOUT going over
static int compareIgnoreCase(char c1, char c2)
          Compares two chars ignoring case
 char getChar()
          Gets the next char and go over
 double getDouble()
          Gets a double and point to the next char
 int getInt()
          Gets an integer and point to the next char
 java.lang.String getLine()
          Gets all chars until the end of the line (or the end of the parser) and go to the next line.
 int getPos()
          Gets the current index position.
 java.lang.String getRemainingString()
          Gets the rest of the (unparsed) string.
 java.lang.String getString()
          Gets a continuous string of char and go to the next char
 java.lang.String getString(int len)
          Gets a string of length len and move over.
 java.lang.String[] getStringArray()
          Gets all string
 java.lang.String getStringUnquoted()
          Gets the first quatable string, that is a normal string, or text in quotes.
 java.util.Vector getStringVector()
          Gets all strings
 java.lang.String getWholeString()
          Gets the entire string
 java.lang.String getWord(char[] separators)
          Gets a string of chars separated by any of chars of separators
 java.lang.String[] getWordArray(char[] separators)
          Gets all string of chars separated by any char belonging to separators
 java.lang.String getWordSkippingQuoted(char[] separators)
          Gets a string of chars separated by any of chars in separators , skipping any separator inside possible quoted texts.
 java.util.Vector getWordVector(char[] separators)
          Gets all string of chars separated by any char belonging to separators
 Parser goTo(char c)
          Goes to the next occurence of char c
 Parser goTo(char[] cc)
          Goes to the next occurence of any char of array cc
 Parser goTo(java.lang.String s)
          Goes to the next occurence of String s
 Parser goTo(java.lang.String[] ss)
          Goes to the next occurence of any string of array ss
 Parser goToIgnoreCase(java.lang.String s)
          Goes to the next occurence of String s
 Parser goToIgnoreCase(java.lang.String[] ss)
          Goes to the next occurence of any string of array ss
 Parser goToNextLine()
          Goes to the begin of the new line
 Parser goToSkippingQuoted(char c)
          Points to the next occurence of char c not in quotes.
 boolean hasMore()
          Whether there are more chars to parse.
 int indexOf(char c)
          Gets the index of the first occurence of char c
 int indexOf(char[] cc)
          Gets the index of the first occurence of any char of array cc within string str starting form begin; return -1 if no occurence is found
 int indexOf(java.lang.String s)
          Gets the index of the first occurence of String s
 int indexOf(java.lang.String[] ss)
          Gets the index of the first occurence of any string of array ss within string str; return -1 if no occurence is found.
 int indexOfIgnoreCase(java.lang.String s)
          Gets the index of the first occurence of String s ignoring case.
 int indexOfIgnoreCase(java.lang.String[] ss)
          Gets the index of the first occurence of any string of array ss ignoring case.
 int indexOfNextLine()
          Gets the begin of next line
static boolean isAlpha(char c)
          Alpha
static boolean isAlphanum(char c)
          Alphanum
static boolean isAnyOf(char[] ca, char ch)
          True if char ch is any char of array ca
static boolean isChar(char c)
          Valid ASCII char
static boolean isCR(char c)
          CR
static boolean isCRLF(char c)
          CR or LF
static boolean isDigit(char c)
          Digit
static boolean isHT(char c)
          HT
static boolean isLF(char c)
          LF
static boolean isLowAlpha(char c)
          Low alpha
static boolean isSP(char c)
          SP
static boolean isUpAlpha(char c)
          Up alpha
static boolean isWSP(char c)
          SP or tab
static boolean isWSPCRLF(char c)
          SP, tab, CR, or LF
 int length()
          Length of unparsed string.
 char nextChar()
          Gets the next char WITHOUT going over
 Parser setPos(int i)
          Goes to position i
 Parser skipChar()
          Skips one char
 Parser skipChars(char[] cc)
          Skips any selected chars
 Parser skipCRLF()
          Skips return lines
 Parser skipN(int n)
          Skips N chars
 Parser skipString()
          Skips a continuous string of char and go to the next "blank" char
 Parser skipWSP()
          Skips all spaces
 Parser skipWSPCRLF()
          Skips white spaces or return lines
 boolean startsWith(java.lang.String s)
          Whether next chars equal to a specific String s.
 boolean startsWith(java.lang.String[] ss)
          Whether next chars equal to any string of array ss.
 boolean startsWithIgnoreCase(java.lang.String s)
          Whether next chars equal to a specific String s ignoring case.
 boolean startsWithIgnoreCase(java.lang.String[] ss)
          Whether next chars equal to any string of array ss ignoring case.
 Parser subParser(int len)
          Returns a new the Parser of len chars statirng from the current position.
 java.lang.String toString()
          convert the rest of the unparsed chars into a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

str

protected java.lang.String str
The string that is being parsed.

index

protected int index
The the current pointer to the next char within the string.

WSP

public static char[] WSP
Characters space (SP) and tab (HT).

SPACE

public static char[] SPACE
The same as WSP (for legacy)

CRLF

public static char[] CRLF
Characters CR and LF.

WSPCRLF

public static char[] WSPCRLF
Characters white-space, tab, CR, and LF.
Constructor Detail

Parser

public Parser(java.lang.String s)
Creates the Parser from the String s and point to the beginning of the string.

Parser

public Parser(java.lang.String s,
              int i)
Creates the Parser from the String s and point to the position i.

Parser

public Parser(java.lang.StringBuffer sb)
Creates the Parser from the StringBuffer sb and point to the beginning of the string.

Parser

public Parser(java.lang.StringBuffer sb,
              int i)
Creates the Parser from the StringBuffer sb and point to the position i.
Method Detail

getPos

public int getPos()
Gets the current index position.

getWholeString

public java.lang.String getWholeString()
Gets the entire string

getRemainingString

public java.lang.String getRemainingString()
Gets the rest of the (unparsed) string.

subParser

public Parser subParser(int len)
Returns a new the Parser of len chars statirng from the current position.

length

public int length()
Length of unparsed string.

hasMore

public boolean hasMore()
Whether there are more chars to parse.

getChar

public char getChar()
Gets the next char and go over

charAt

public char charAt(int n)
Gets the char at distance n WITHOUT going over

nextChar

public char nextChar()
Gets the next char WITHOUT going over

setPos

public Parser setPos(int i)
Goes to position i

goTo

public Parser goTo(char c)
Goes to the next occurence of char c

goTo

public Parser goTo(char[] cc)
Goes to the next occurence of any char of array cc

goTo

public Parser goTo(java.lang.String s)
Goes to the next occurence of String s

goTo

public Parser goTo(java.lang.String[] ss)
Goes to the next occurence of any string of array ss

goToIgnoreCase

public Parser goToIgnoreCase(java.lang.String s)
Goes to the next occurence of String s

goToIgnoreCase

public Parser goToIgnoreCase(java.lang.String[] ss)
Goes to the next occurence of any string of array ss

goToNextLine

public Parser goToNextLine()
Goes to the begin of the new line

isAnyOf

public static boolean isAnyOf(char[] ca,
                              char ch)
True if char ch is any char of array ca

isUpAlpha

public static boolean isUpAlpha(char c)
Up alpha

isLowAlpha

public static boolean isLowAlpha(char c)
Low alpha

isAlpha

public static boolean isAlpha(char c)
Alpha

isAlphanum

public static boolean isAlphanum(char c)
Alphanum

isDigit

public static boolean isDigit(char c)
Digit

isChar

public static boolean isChar(char c)
Valid ASCII char

isCR

public static boolean isCR(char c)
CR

isLF

public static boolean isLF(char c)
LF

isCRLF

public static boolean isCRLF(char c)
CR or LF

isHT

public static boolean isHT(char c)
HT

isSP

public static boolean isSP(char c)
SP

isWSP

public static boolean isWSP(char c)
SP or tab

isWSPCRLF

public static boolean isWSPCRLF(char c)
SP, tab, CR, or LF

compareIgnoreCase

public static int compareIgnoreCase(char c1,
                                    char c2)
Compares two chars ignoring case

indexOf

public int indexOf(char c)
Gets the index of the first occurence of char c

indexOf

public int indexOf(char[] cc)
Gets the index of the first occurence of any char of array cc within string str starting form begin; return -1 if no occurence is found

indexOf

public int indexOf(java.lang.String s)
Gets the index of the first occurence of String s

indexOf

public int indexOf(java.lang.String[] ss)
Gets the index of the first occurence of any string of array ss within string str; return -1 if no occurence is found.

indexOfIgnoreCase

public int indexOfIgnoreCase(java.lang.String s)
Gets the index of the first occurence of String s ignoring case.

indexOfIgnoreCase

public int indexOfIgnoreCase(java.lang.String[] ss)
Gets the index of the first occurence of any string of array ss ignoring case.

indexOfNextLine

public int indexOfNextLine()
Gets the begin of next line

startsWith

public boolean startsWith(java.lang.String s)
Whether next chars equal to a specific String s.

startsWith

public boolean startsWith(java.lang.String[] ss)
Whether next chars equal to any string of array ss.

startsWithIgnoreCase

public boolean startsWithIgnoreCase(java.lang.String s)
Whether next chars equal to a specific String s ignoring case.

startsWithIgnoreCase

public boolean startsWithIgnoreCase(java.lang.String[] ss)
Whether next chars equal to any string of array ss ignoring case.

skipChar

public Parser skipChar()
Skips one char

skipN

public Parser skipN(int n)
Skips N chars

skipWSP

public Parser skipWSP()
Skips all spaces

skipCRLF

public Parser skipCRLF()
Skips return lines

skipWSPCRLF

public Parser skipWSPCRLF()
Skips white spaces or return lines

skipChars

public Parser skipChars(char[] cc)
Skips any selected chars

skipString

public Parser skipString()
Skips a continuous string of char and go to the next "blank" char

getString

public java.lang.String getString()
Gets a continuous string of char and go to the next char

getString

public java.lang.String getString(int len)
Gets a string of length len and move over.

getWord

public java.lang.String getWord(char[] separators)
Gets a string of chars separated by any of chars of separators

getInt

public int getInt()
Gets an integer and point to the next char

getDouble

public double getDouble()
Gets a double and point to the next char

getLine

public java.lang.String getLine()
Gets all chars until the end of the line (or the end of the parser) and go to the next line.

getWordVector

public java.util.Vector getWordVector(char[] separators)
Gets all string of chars separated by any char belonging to separators

getWordArray

public java.lang.String[] getWordArray(char[] separators)
Gets all string of chars separated by any char belonging to separators

getStringVector

public java.util.Vector getStringVector()
Gets all strings

getStringArray

public java.lang.String[] getStringArray()
Gets all string

getWordSkippingQuoted

public java.lang.String getWordSkippingQuoted(char[] separators)
Gets a string of chars separated by any of chars in separators , skipping any separator inside possible quoted texts.

getStringUnquoted

public java.lang.String getStringUnquoted()
Gets the first quatable string, that is a normal string, or text in quotes.
In the latter case, quotes are dropped.

goToSkippingQuoted

public Parser goToSkippingQuoted(char c)
Points to the next occurence of char c not in quotes.

toString

public java.lang.String toString()
convert the rest of the unparsed chars into a string
Overrides:
toString in class java.lang.Object

MjSip Stack
v1.6