[an error occurred while processing this directive]
A token may have subsequences of characters enclosed in double quotes. All tokens have a string value except when their text contains an unmatched double quote. White characters within quotes are not treated as token separators so that a token can have a string value which contains white characters. Within double quotes, C or Java escape sequences are recognized. The string value of a token with quoted substrings contains the standard C or Java translation for escape sequences. A token that has a quoted substring can not have a float or int value.
Empty lines and lines that begin with white characters are treated in a special way by a LineScanner. Such lines are regarded as having an initial empty string token.
Other functions generate error messages that are saved by the LineScanner. The number of saved messages can be determined by calling errorCount(), and the messages can be printed with calls to printFirstError() or printAllErrors(). The client can also add error messages by calling addError() and remove error messages by calling removeLastError().
A LineScanner can be attached permanently to a text source. For this kind of use, the source can reuse the LineScanner for new lines by calling setText() with the text of the new line as a parameter. If necessary, the source can change the echo policy by calling setEchoPolicy(). The functions getText() and getEchoPolicy() are provided for retieving the current text and echo policy.
When using the first group of functions, error message are saved automatically when the text for the current token is incorrectly formatted.
The second group of functions has three subgroups of functions. Methods atString, atFloat, atInt, and atEnd check the type of the token at the current position. Methods currentString, currentFloat, and currentInt retrieve the string, float, or int value of the current token without advancing the current position. These functions have preconditions which, when violated, result in immediate program termination with an error message. Finally, the advance function advances the current position.
When using the second group of functions, the client is responsible for checking the token type with atString(), atFloat(), atInt(), or atEnd(), and adding error messages with addError.
#include "LineScanner.h"
Error messages:
Unterminated quote.
String expected.
Error messages:
Real number expected.
Error messages:
Integer expected.
Error messages:
no more arguments expected
Preconditions:
atString(ls) is true.
Preconditions:
atFloat(ls) is true.
Preconditions:
atInt(ls) is true.
Preconditions:
atEnd(ls) is false.
Preconditions:
errorCount(ls) > 0.