Scanner Class Reference

#include "scanner.h"

List of all members.

Public Types

enum  spaceOptionT { PreserveSpaces, IgnoreSpaces }
enum  numberOptionT { ScanNumbersAsLetters, ScanNumbersAsIntegers, ScanNumbersAsReals }
enum  stringOptionT { ScanQuotesAsPunctuation, ScanQuotesAsStrings }
enum  bracketOptionT { ScanBracketsAsPunctuation, ScanBracketsAsTag }

Public Member Functions

 Scanner ()
 ~Scanner ()
void setInput (string str)
string nextToken ()
bool hasMoreTokens ()
void saveToken (string token)
void setSpaceOption (spaceOptionT option)
spaceOptionT getSpaceOption ()
void setNumberOption (numberOptionT option)
numberOptionT getNumberOption ()
void setStringOption (stringOptionT option)
stringOptionT getStringOption ()
void setBracketOption (bracketOptionT option)
bracketOptionT getBracketOption ()


Detailed Description

This class is used to represent a single instance of a scanner.


Member Enumeration Documentation

enum Scanner::spaceOptionT

This member function controls whether this scanner ignores whitespace characters or treats them as valid tokens. By default, the nextToken function treats whitespace characters, such as spaces and tabs, just like any other punctuation mark. If, however, you call

scanner.setSpaceOption(Scanner::IgnoreSpaces);

the scanner will skip over any white space before reading a token. You can restore the original behavior by calling

scanner.setSpaceOption(Scanner::PreserveSpaces);

The getSpaceOption function returns the current setting of this option.

Enumerator:
PreserveSpaces 
IgnoreSpaces 

enum Scanner::numberOptionT

This member function controls whether this scanner treats numeric values specially. The default behavior for a scanner is to treat digits as equivalent to letters. If you call

scanner.setNumberOption(Scanner::ScanNumbersAsIntegers);

a token beginning with a digit will end at the first nondigit. (Note that digits can still be scanned as part of a token as in the token "x1".) If you call

scanner.setNumberOption(Scanner::ScanNumbersAsReals);

the scanner will return the longest token string that represents a real number, if the next character to be scanned is a digit. The format for a real number is a sequence of digit characters that may include at most one decimal point, optionally followed by the letter 'E' in either upper- or lowercase, an optional sign, and an exponent. You can restore the default behavior by calling

scanner.setNumberOption(Scanner::ScanNumbersAsLetters);

Even if the number options are enabled, nextToken always returns its result as a string, which means that you need to call StringToInteger or StringToReal to convert the token to a number.

Enumerator:
ScanNumbersAsLetters 
ScanNumbersAsIntegers 
ScanNumbersAsReals 

enum Scanner::stringOptionT

This member function controls how this scanner treats double quotation marks in the input. The default behavior for a scanner is to treat quotes just like any other punctuation character. If, however, you call

scanner.setStringOption(Scanner::ScanQuotesAsStrings);

a token beginning with a quotation mark will be scanned up to the closing quotation mark. The quotation marks are returned as part of the scanned token so that clients can differentiate strings from other token types. The original behavior can be restored by calling

scanner.setStringOption(Scanner::ScanQuotesAsPunctuation);

When scanning a string, the scanner recognizes the standard escape sequences from ANSI C, such as
and .

Enumerator:
ScanQuotesAsPunctuation 
ScanQuotesAsStrings 

enum Scanner::bracketOptionT

This member function controls how this scanner treats angle brackets in the input. The default behavior for a scanner is to treat brackets just like any other punctuation character. If, however, you call

scanner.setBracketOption(Scanner::ScanBracketsAsTag);

a token beginning with a open < bracket will be scanned up to the closing > bracket. The brackets are returned as part of the scanned token so that clients can differentiate tags from other token types. The original behavior can be restored by calling

scanner.setBracketOption(Scanner::ScanBracketsAsPunctuation);

Enumerator:
ScanBracketsAsPunctuation 
ScanBracketsAsTag 


Constructor & Destructor Documentation

Scanner::Scanner (  ) 

The constructor initializes a new scanner object. The scanner starts empty, with no input to scan.

Scanner::~Scanner (  ) 

The destructor deallocates the storage associated with this scanner.


Member Function Documentation

void Scanner::setInput ( string  str  ) 

This member function configures this scanner to start extracting tokens from the input string str. Any previous input string is discarded.

string Scanner::nextToken (  ) 

This member function returns the next token from this scanner. If nextToken is called when no tokens are available, it returns the empty string.

bool Scanner::hasMoreTokens (  ) 

This member function returns true as long as there are additional tokens for this scanner to read.

void Scanner::saveToken ( string  token  ) 

This member function restores token into this scanner's input in such a way that the next time nextToken is called, the scanner will return this token without reading any additional characters from the input.

void Scanner::setSpaceOption ( spaceOptionT  option  ) 

spaceOptionT Scanner::getSpaceOption (  ) 

void Scanner::setNumberOption ( numberOptionT  option  ) 

numberOptionT Scanner::getNumberOption (  ) 

void Scanner::setStringOption ( stringOptionT  option  ) 

stringOptionT Scanner::getStringOption (  ) 

void Scanner::setBracketOption ( bracketOptionT  option  ) 

bracketOptionT Scanner::getBracketOption (  ) 


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1