NetTopologySuite
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
RTools_NTS.Util.StreamTokenizer Class Reference

A StreamTokenizer similar to Java's. This breaks an input stream (coming from a TextReader) into Tokens based on various settings. The settings are stored in the TokenizerSettings property, which is a StreamTokenizerSettings instance. More...

Inheritance diagram for RTools_NTS.Util.StreamTokenizer:

Public Member Functions

 StreamTokenizer ()
 Default constructor. More...
 
 StreamTokenizer (TextReader sr)
 Construct and set this object's TextReader to the one specified. More...
 
 StreamTokenizer (string str)
 Construct and set a string to tokenize. More...
 
void Display ()
 Display the state of this object. More...
 
void Display (string prefix)
 Display the state of this object, with a per-line prefix. More...
 
bool NextToken (out Token token)
 Get the next token. The last token will be an EofToken unless there's an unterminated quote or unterminated block comment and Settings.DoUntermCheck is true, in which case this throws an exception of type StreamTokenizerUntermException or sub-class. More...
 
bool Tokenize (IList< Token > tokens)
 Parse the rest of the stream and put all the tokens in the input ArrayList. This resets the line number to 1. More...
 
bool TokenizeReader (TextReader tr, IList< Token > tokens)
 Parse all tokens from the specified TextReader, put them into the input ArrayList. More...
 
bool TokenizeFile (string fileName, IList< Token > tokens)
 Parse all tokens from the specified file, put them into the input ArrayList. More...
 
Token[] TokenizeFile (string fileName)
 Tokenize a file completely and return the tokens in a Token[]. More...
 
bool TokenizeString (string str, IList< Token > tokens)
 Parse all tokens from the specified string, put them into the input ArrayList. More...
 
bool TokenizeStream (Stream s, IList< Token > tokens)
 Parse all tokens from the specified Stream, put them into the input ArrayList. More...
 
IEnumerator< TokenGetEnumerator ()
 Gibt einen Enumerator zurück, der die Auflistung durchläuft. More...
 

Static Public Attributes

static readonly int NChars = 128
 This is the number of characters in the character table. More...
 

Properties

TextReader TextReader [get, set]
 This is the TextReader that this object will read from. Set this to set the input reader for the parse. More...
 
StreamTokenizerSettings Settings [get]
 The settings which govern the behavior of the tokenization. More...
 
VerbosityLevel Verbosity [get, set]
 The verbosity level for this object's Logger. More...
 

Detailed Description

A StreamTokenizer similar to Java's. This breaks an input stream (coming from a TextReader) into Tokens based on various settings. The settings are stored in the TokenizerSettings property, which is a StreamTokenizerSettings instance.

This is configurable in that you can modify TokenizerSettings.CharTypes[] array to specify which characters are which type, along with other settings such as whether to look for comments or not.

WARNING: This is not internationalized. This treats all characters beyond the 7-bit ASCII range (decimal 127) as Word characters.

There are two main ways to use this: 1) Parse the entire stream at once and get an ArrayList of Tokens (see the Tokenize* methods), and 2) call NextToken() successively. This reads from a TextReader, which you can set directly, and this also provides some convenient methods to parse files and strings. This returns an Eof token if the end of the input is reached.

Here's an example of the NextToken() endCapStyle of use:

StreamTokenizer tokenizer = new StreamTokenizer();
tokenizer.GrabWhitespace = true;
tokenizer.Verbosity = VerbosityLevel.Debug; // just for debugging
tokenizer.TextReader = File.OpenText(fileName);
Token token;
while (tokenizer.NextToken(out token)) log.Info("Token = '{0}'", token);

Here's an example of the Tokenize... endCapStyle of use:

StreamTokenizer tokenizer = new StreamTokenizer("some string");
ArrayList tokens = new ArrayList();
if (!tokenizer.Tokenize(tokens))
{
// error handling
}
foreach (Token t in tokens) Console.WriteLine("t = {0}", t);

Comment delimiters are hardcoded (// and /*), not affected by char type table.

This sets line numbers in the tokens it produces. These numbers are normally the line on which the token starts. There is one known caveat, and that is that when GrabWhitespace setting is true, and a whitespace token contains a newline, that token's line number will be set to the following line rather than the line on which the token started.

Constructor & Destructor Documentation

RTools_NTS.Util.StreamTokenizer.StreamTokenizer ( )

Default constructor.

RTools_NTS.Util.StreamTokenizer.StreamTokenizer ( TextReader  sr)

Construct and set this object's TextReader to the one specified.

Parameters
srThe TextReader to read from.
RTools_NTS.Util.StreamTokenizer.StreamTokenizer ( string  str)

Construct and set a string to tokenize.

Parameters
strThe string to tokenize.

Member Function Documentation

void RTools_NTS.Util.StreamTokenizer.Display ( )

Display the state of this object.

void RTools_NTS.Util.StreamTokenizer.Display ( string  prefix)

Display the state of this object, with a per-line prefix.

Parameters
prefixThe pre-line prefix.
IEnumerator<Token> RTools_NTS.Util.StreamTokenizer.GetEnumerator ( )

Gibt einen Enumerator zurück, der die Auflistung durchläuft.

Returns
Ein T:System.Collections.Generic.IEnumerator`1, der zum Durchlaufen der Auflistung verwendet werden kann.

<filterpriority>1</filterpriority>

bool RTools_NTS.Util.StreamTokenizer.NextToken ( out Token  token)

Get the next token. The last token will be an EofToken unless there's an unterminated quote or unterminated block comment and Settings.DoUntermCheck is true, in which case this throws an exception of type StreamTokenizerUntermException or sub-class.

Parameters
tokenThe output token.
Returns
bool - true for success, false for failure.
bool RTools_NTS.Util.StreamTokenizer.Tokenize ( IList< Token tokens)

Parse the rest of the stream and put all the tokens in the input ArrayList. This resets the line number to 1.

Parameters
tokensThe ArrayList to append to.
Returns
bool - true for success
bool RTools_NTS.Util.StreamTokenizer.TokenizeFile ( string  fileName,
IList< Token tokens 
)

Parse all tokens from the specified file, put them into the input ArrayList.

Parameters
fileNameThe file to read.
tokensThe ArrayList to put tokens in.
Returns
bool - true for success, false for failure.
Token [] RTools_NTS.Util.StreamTokenizer.TokenizeFile ( string  fileName)

Tokenize a file completely and return the tokens in a Token[].

Parameters
fileNameThe file to tokenize.
Returns
A Token[] with all tokens.
bool RTools_NTS.Util.StreamTokenizer.TokenizeReader ( TextReader  tr,
IList< Token tokens 
)

Parse all tokens from the specified TextReader, put them into the input ArrayList.

Parameters
trThe TextReader to read from.
tokensThe ArrayList to append to.
Returns
bool - true for success, false for failure.
bool RTools_NTS.Util.StreamTokenizer.TokenizeStream ( Stream  s,
IList< Token tokens 
)

Parse all tokens from the specified Stream, put them into the input ArrayList.

Parameters
s
tokensThe ArrayList to put tokens in.
Returns
bool - true for success, false for failure.
bool RTools_NTS.Util.StreamTokenizer.TokenizeString ( string  str,
IList< Token tokens 
)

Parse all tokens from the specified string, put them into the input ArrayList.

Parameters
str
tokensThe ArrayList to put tokens in.
Returns
bool - true for success, false for failure.

Member Data Documentation

readonly int RTools_NTS.Util.StreamTokenizer.NChars = 128
static

This is the number of characters in the character table.

Property Documentation

StreamTokenizerSettings RTools_NTS.Util.StreamTokenizer.Settings
get

The settings which govern the behavior of the tokenization.

TextReader RTools_NTS.Util.StreamTokenizer.TextReader
getset

This is the TextReader that this object will read from. Set this to set the input reader for the parse.

VerbosityLevel RTools_NTS.Util.StreamTokenizer.Verbosity
getset

The verbosity level for this object's Logger.


The documentation for this class was generated from the following file: