THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1

}
}
return attrs;
}


The attribute file uses '#' to mark comments. Ignoring these comments, the stream is searched for a string
token followed by an optional '=' followed by a word or number. Each such attribute is put into an Attr
object, which is added to a set of attributes in an AttributedImpl object. When the file has been parsed,
the set of attributes is returned.


Setting the comment character to '#' sets its character class. The tokenizer recognizes several character
classes that are set by the following methods:


public voidwordChars(int low, int hi)

Characters in this range are word characters: They can be part of a TT_WORD
token. You can invoke this several times with different ranges. A word
consists of one or more characters inside any of the legal ranges.

public voidwhitespaceChars(int low, int hi)

Characters in this range are whitespace. Whitespace is ignored, except to
separate tokens such as two consecutive words. As with the wordChars
range, you can make several invocations, and the union of the invocations is
the set of whitespace characters.

public voidordinaryChars(int low, int hi)

Characters in this range are ordinary. An ordinary character is returned as
itself, not as a token. This removes any special significance the characters
may have had as comment characters, delimiters, word components,
whitespace, or number characters. In the above example, we used
ordinaryChar to remove the special comment significance of the '/'
character.

public voidordinaryChar(int ch)

Equivalent to ordinaryChars(ch,ch).

public voidcommentChar(int ch)

The character ch starts a single-line commentcharacters after ch up to the
next end-of-line are treated as one run of whitespace.

public voidquoteChar(int ch)

Matching pairs of the character ch delimit String constants. When a
String constant is recognized, the character ch is returned as the token,
and the field sval contains the body of the string with surrounding ch
characters removed. When string constants are read, some of the standard \
processing is applied (for example, \t can be in the string). The string
processing in StreamTokenizer is a subset of the language's strings. In
particular, you cannot use \uxxxx, \', \", or (unfortunately) \Q, where Q
Free download pdf