2
* $Id: KRTFTokenizer.cpp,v 1.5 2001/04/07 17:36:53 mueller Exp $
5
#include "KRTFTokenizer.h"
10
KRTFTokenizer::KRTFTokenizer( QFile* file )
16
KRTFToken* KRTFTokenizer::nextToken()
18
// first check whether there is anything on the pushback stack and
20
if( !_pushbackstack.isEmpty() ) {
21
return _pushbackstack.pop();
26
KRTFToken* token = new KRTFToken( this );
27
int ch = _file->getch();
29
// skip leading whitespace
30
while( isspace( ch ) && !_file->atEnd() )
33
if( _file->atEnd() ) {
34
token->_type = TokenEOF;
39
// first find out what this is
41
// type is either control word or control symbol
43
if( !isalnum( ch ) ) {
45
token->_type = ControlSymbol;
46
token->_text += (char)ch;
49
token->_type = ControlWord;
52
} else if( ch == '{' ) {
53
token->_type = OpenGroup;
54
} else if( ch == '}' ) {
55
token->_type = CloseGroup;
57
token->_type = ::PlainText;
61
// Lump together what might be needed additionally.
62
switch( token->_type ) {
65
while( isalpha( ch ) ) {
69
// ch is not alpha, control word is over, let�s see what we do about it
71
// space: part of the control word, which ends here
73
} else if( isdigit( ch ) || ( ch == '-' ) ) {
74
// digit or hyphen, build up numeric parameter
77
while( isalnum( ch ) ) {
84
token->_param = param;
87
// everything until next backslash, opener or closer
89
while( ch != '\\' && ch != '{' && ch != '}' ) {
94
// give back last char
102
void KRTFTokenizer::pushBack( KRTFToken* token )
104
_pushbackstack.push( token );