for (int i = 0; i < CDATA.length(); i++, off += minBPC)
checkCharMatches(buf, off, CDATA.charAt(i));
token.tokenEnd = off;
return TOK_CDATA_SECT_OPEN;
}
/**
* Scans the first token of a byte subarrary that starts with the
* content of a CDATA section.
* Returns one of the following integers according to the type of token
* that the subarray starts with:
* <ul>
* <li><code>TOK_DATA_CHARS</code>
* <li><code>TOK_DATA_NEWLINE</code>
* <li><code>TOK_CDATA_SECT_CLOSE</code>
* </ul>
* <p>
* Information about the token is stored in <code>token</code>.
* <p>
* After <code>TOK_CDATA_SECT_CLOSE</code> is returned, the application
* should use <code>tokenizeContent</code>.
*
* @exception EmptyTokenException if the subarray is empty
* @exception PartialTokenException if the subarray contains only part of
* a legal token
* @exception InvalidTokenException if the subarrary does not start
* with a legal token or part of one
* @exception ExtensibleTokenException if the subarray encodes just a carriage
* return ('\r')
*
* @see #TOK_DATA_CHARS
* @see #TOK_DATA_NEWLINE
* @see #TOK_CDATA_SECT_CLOSE
* @see Token
* @see EmptyTokenException
* @see PartialTokenException
* @see InvalidTokenException
* @see ExtensibleTokenException
* @see #tokenizeContent
*/
public final int tokenizeCdataSection(byte[] buf, int off, int end, Token token) throws EmptyTokenException, PartialTokenException, InvalidTokenException, ExtensibleTokenException {
if (minBPC > 1)
end = adjustEnd(off, end);
if (off == end)
throw new EmptyTokenException();
switch (byteType(buf, off)) {
case BT_RSQB:
off += minBPC;
if (off == end)
throw new PartialTokenException();
if (!charMatches(buf, off, ']'))
break;
off += minBPC;
if (off == end)
throw new PartialTokenException();
if (!charMatches(buf, off, '>')) {
off -= minBPC;
break;
}
token.tokenEnd = off + minBPC;
return TOK_CDATA_SECT_CLOSE;
case BT_CR:
off += minBPC;
if (off == end)
throw new ExtensibleTokenException(TOK_DATA_NEWLINE);
if (byteType(buf, off) == BT_LF)
off += minBPC;
token.tokenEnd = off;
return TOK_DATA_NEWLINE;
case BT_LF:
token.tokenEnd = off + minBPC;
return TOK_DATA_NEWLINE;
case BT_NONXML:
case BT_MALFORM:
throw new InvalidTokenException(off);
case BT_LEAD2:
if (end - off < 2)
throw new PartialCharException(off);
check2(buf, off);
off += 2;
break;
case BT_LEAD3:
if (end - off < 3)
throw new PartialCharException(off);
check3(buf, off);
off += 3;
break;
case BT_LEAD4:
if (end - off < 4)
throw new PartialCharException(off);
check4(buf, off);
off += 4;
break;
default:
off += minBPC;
break;
}
token.tokenEnd = extendCdata(buf, off, end);
return TOK_DATA_CHARS;
}
int extendCdata(final byte[] buf, int off, final int end) throws InvalidTokenException {
while (off != end) {
switch (byteType(buf, off)) {
case BT_LEAD2:
if (end - off < 2)
return off;
check2(buf, off);
off += 2;
break;
case BT_LEAD3:
if (end - off < 3)
return off;
check3(buf, off);
off += 3;
break;
case BT_LEAD4:
if (end - off < 4)
return off;
check4(buf, off);
off += 4;
break;
case BT_RSQB:
case BT_NONXML:
case BT_MALFORM:
case BT_CR:
case BT_LF:
return off;
default:
off += minBPC;
break;
}
}
return off;
}
/* off points to character following "</" */
private final
int scanEndTag(byte[] buf, int off, int end, Token token)