Methods Summary |
---|
public void | consume()Advances the current pointer to the saved peek pointer
to consume the characters that were pending parsing
completion.
ptr = savedPtr;
|
public void | consume(int k)Consume the specified number of characters from the input
buffer.
ptr += k;
|
public static java.lang.String | convertNewLines(java.lang.String s)According to the RFC 3261, section 7.3.1:
Header fields can be extended over multiple lines by preceding each
extra line with at least one SP or horizontal tab (HT). The line
break and the whitespace at the beginning of the next line are
treated as a single SP character.
This function converts all pairs of newline+space/tab in the
string 's' into signle spaces.
int i;
char chCurr;
String result = "";
// new Exception("convertNewLines").printStackTrace();
if (s.length() == 0) {
return result;
}
// Eat leading spaces and carriage returns (necessary??).
i = 0;
i = skipWhiteSpace(s, i);
while (i < s.length()) {
chCurr = s.charAt(i);
// Actually, the spec requires "<CRLF> <Space|Tab>" for multiline
// header values, but we support also LFCR, LF and CR.
if (chCurr == '\n" || chCurr == '\r") {
if (i < s.length() - 1 &&
(s.charAt(i+1) == '\t" || s.charAt(i+1) == ' ")) {
// Check if the last saved symbol is CR or LF.
// This will be needed if we decide not to skip CRLF bellow.
result += ' ";
i++;
} else {
/*
* RFC 3261, p. 221:
* A CRLF is allowed in the definition of TEXT-UTF8-TRIM
* only as part of a header field continuation. It is
* expected that the folding LWS will be replaced with
* a single SP before interpretation of the TEXT-UTF8-TRIM
* value.
*
* But it's not clearly defined what to do if CRLF or CR, or
* LF without following LWS is occured, so we just skip it.
*/
}
} else {
result += chCurr;
}
i++;
} // end while()
// System.out.println("@@@\nconverted from:\n<<"+s+">> " +
// "into:\n<<"+result+">>");
return result;
|
public java.lang.String | getLine()Gets the next line of text.
StringBuffer retval = new StringBuffer();
while (ptr < buffer.length() && buffer.charAt(ptr) != '\n") {
retval.append(buffer.charAt(ptr));
ptr++;
}
if (ptr < buffer.length() && buffer.charAt(ptr) == '\n") {
retval.append('\n");
ptr++;
}
return retval.toString();
|
public java.util.Vector | getLines()Gets a Vector of the buffer tokenized by lines.
Vector result = new Vector();
while (hasMoreChars()) {
String line = getLine();
result.addElement(line);
}
return result;
|
public char | getNextChar()Gets one character in the input buffer
and consumes the character.
if (ptr >= buffer.length())
throw new ParseException
(buffer + " getNextChar: End of buffer", ptr);
else return buffer.charAt(ptr++);
|
public java.lang.String | getNextToken(char delim)Gets the next token from the buffer.
StringBuffer retval = new StringBuffer();
while (true) {
char la = lookAhead(0);
// System.out.println("la = " + la);
if (la == delim) break;
else if (la == '\0")
throw new ParseException("EOL reached", 0);
retval.append(buffer.charAt(ptr));
consume(1);
}
return retval.toString();
|
public static java.lang.String | getSDPFieldName(java.lang.String line)Gets the SDP field name of the line.
if (line == null)
return null;
String fieldName = null;
try {
int begin = line.indexOf("=");
fieldName = line.substring(0, begin);
} catch (IndexOutOfBoundsException e) {
return null;
}
return fieldName;
|
public boolean | hasMoreChars()Checks if more characters are available.
return ptr < buffer.length();
|
public static boolean | isAlpha(char ch)Checks if the character is an alphabetic character.
boolean retval = Character.isUpperCase(ch) ||
Character.isLowerCase(ch);
// Debug.println("isAlpha is returning " + retval + " for " + ch);
return retval;
|
public static boolean | isDigit(char ch)Checks if the character is a numeric character.
boolean retval = Character.isDigit(ch);
// Debug.println("isDigit is returning " + retval + " for " + ch);
return retval;
|
public static boolean | isDigitString(java.lang.String str)Checks if the string contains numeric characters only.
int len = str.length();
if (len == 0) { // empty string - return false
return false;
} else {
boolean retval = true;
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
retval = false;
break;
}
}
return retval;
}
|
public static boolean | isEscaped(java.lang.String name, int index)Checks if the given symbol belongs to the escaped group.
The character is escaped if it is satisfies the next ABNF
(see RFC3261 p.220):
escaped = "%" HEXDIG HEXDIG
// RFC3261 p.220
// escaped = "%" HEXDIG HEXDIG
//
if (name.charAt(index) != '%" ||
(name.length() - index - 2) < 0 ||
!isHexDigit(name.charAt(index + 1)) ||
!isHexDigit(name.charAt(index + 2))) {
return false;
}
return true;
|
public static boolean | isHexDigit(char ch)Checks if character is part of a hexadecimal number.
if (isDigit(ch))
return true;
else {
char ch1 = Character.toUpperCase(ch);
return ch1 == 'A" || ch1 == 'B" || ch1 == 'C" ||
ch1 == 'D" || ch1 == 'E" || ch1 == 'F";
}
|
public static boolean | isQuotedPair(java.lang.String name, int offset)Checks if the given sequence is quoted pair.
// RFC3261 p.222
// quoted-pair = "\" (%x00-09 / %x0B-0C
// / %x0E-7F)
//
if (name.charAt(offset) != '\\" ||
(name.length() - offset - 1) <= 0) {
return false;
}
char ch = name.charAt(offset + 1);
if (ch == 0xA ||
ch == 0xD ||
ch > 0x7F) {
return false;
}
return true;
|
public static boolean | isValidChar(char ch)Checks if the given character is allowed in method/header/parameter name.
The character is valid if it is: (1) a digit or (2) a letter, or
(3) is one of the characters on the next list: -.!%*_+`'~
String validChars = "-.!%*_+`'~";
if (!((ch >= '0" && ch <= '9") || (ch >= 'A" && ch <= 'Z") ||
(ch >= 'a" && ch <= 'z")) && (validChars.indexOf(ch) == -1)) {
// ("Invalid character '" + ch + "' in the name.");
return false;
}
return true;
|
public char | lookAhead()Looks ahead one character in the input buffer
without consuming the character.
return lookAhead(0);
|
public char | lookAhead(int k)Looks ahead a specified number of characters in the input buffer
without consuming the character.
// Debug.out.println("ptr = " + ptr);
if (ptr+k < buffer.length())
return buffer.charAt(ptr + k);
else return '\0";
|
public java.lang.String | nextToken()Gets the next token.
StringBuffer retval = new StringBuffer();
while (ptr < buffer.length()) {
if (buffer.charAt(ptr) == delimiter) {
retval.append(buffer.charAt(ptr));
ptr++;
break;
} else {
retval.append(buffer.charAt(ptr));
ptr++;
}
}
return retval.toString();
|
public java.lang.String | peekLine()Peeks at the next line without consuming the
characters.
int curPos = ptr;
String retval = this.getLine();
ptr = curPos;
return retval;
|
private static int | skipWhiteSpace(java.lang.String s, int i)Skip whitespace that starts at offset i in the string s
int len = s.length();
if (i >= len) {
return i;
}
char chCurr;
chCurr = s.charAt(i);
while (chCurr == '\n" || chCurr == '\r" ||
chCurr == '\t" || chCurr == ' ") {
i++;
if (i >= len) break;
chCurr = s.charAt(i);
}
return i;
|