Java Reference
In-Depth Information
If a leading delimiter is not found, then the string is parsed up to the first white space
character.
}
else
{
while ( ! Character.isWhitespace(source.peek())
&& source.peek() != -1)
{
result.append(this.parseSpecialCharacter());
}
}
Because there is no delimiter, the only choice is to parse until the first white space char-
acter. This means that the string can contain no embedded white space characters.
return result.toString();
Finally, the parsed string is returned.
Parse a Tag with parseTag
The parseTag method is called whenever an HTML tag is encountered. This method
will parse the tag, as well as any HTML attributes of the tag. The parseTag method first
creates a StringBuilder object to hold the tag name, as well as a new HTMLTag ob-
ject that will hold the tag and attributes. A call to the read function moves past the opening
less-than symbol for the tag.
StringBuilder tagName = new StringBuilder();
tag = new HTMLTag();
source.read();
Next, the parseTag method checks to see if this tag is an HTML comment. If it is an
HTML comment, this tag will be ignored. HTML comments begin with the <!-- symbols.
// Is it a comment?
if ((source.peek(0) == '!') && (source.peek(1) == '-')
&& (source.peek(2) == '-'))
{
If the tag is an HTML comment, then enter a while loop to read the rest of the com-
ment.
while (source.peek() != -1)
{
if ((source.peek(0) == '-') && (source.peek(1) == '-')
&& (source.peek(2) == '>'))
break;
if (source.peek() != '\r')
Search WWH ::




Custom Search