Methods Summary |
---|
private int | _countTokens()
int tokens = 0;
boolean bQuote = false;
boolean bEscaped = false;
final CharIterator it = new CharIterator(ca);
char c;
while ((c = it.next()) != CharIterator.EOF)
{
char next = it.peekNext();
if (!isDelimiter(c) && !bEscaped)
{
if (c == '\"")
bQuote = !bQuote;
if (next == CharIterator.EOF || (isDelimiter(next) && !bQuote))
tokens++;
}
else if (next == CharIterator.EOF && bQuote) //eg :- "\" "
tokens++;
if(c=='\\")
bEscaped = !bEscaped;
else
bEscaped = false;
}
return tokens;
|
public int | countTokens()
return numTokens;
|
public boolean | hasMoreTokens()
return curToken < numTokens;
|
boolean | isDelimiter(char c)
return delimiters.indexOf(c) >= 0;
|
public java.lang.String | nextToken()
if (curToken == numTokens)
throw new NoSuchElementException();
final StringBuffer sb = new StringBuffer();
boolean bQuote = false;
boolean bEscaped = false;
char c;
while ((c = iterator.next()) != CharIterator.EOF)
{
boolean isDelimiter = isDelimiter(c);
if (!isDelimiter && !bEscaped)
{
sb.append(c);
if (c == '\"")
bQuote = !bQuote;
char next = iterator.peekNext();
if (next == CharIterator.EOF || (isDelimiter(next) && !bQuote))
break;
}
else if (bQuote || bEscaped)
{
sb.append(c);
}
if(c=='\\")
bEscaped = !bEscaped;
else
bEscaped = false;
}
curToken++;
return sb.toString();
|