15#include "rtfimport_tokenizer.h"
18RTFTokenizer::RTFTokenizer()
20 tokenText.resize( 4113 );
21 fileBuffer.resize( 4096 );
34 type = RTFTokenizer::PlainText;
37int RTFTokenizer::nextChar()
39 if ( fileBufferPtr == fileBufferEnd ) {
40 int n = infile->readBlock( fileBuffer.data(), fileBuffer.size() );
41 fileBufferPtr = ( uchar* ) fileBuffer.data();
42 fileBufferEnd = fileBufferPtr;
47 fileBufferEnd = fileBufferPtr + n;
49 return *fileBufferPtr++;
73 while (ch == '\n' || ch == '\r' && ch != 0);
76 text = (tokenText.data() + 1);
79 uchar *_text = (uchar *) text;
83 type = RTFTokenizer::OpenGroup;
85 type = RTFTokenizer::CloseGroup;
88 type = RTFTokenizer::ControlWord;
94 type = RTFTokenizer::CloseGroup;
100 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
105 while (_text < ( uchar* )tokenText.data()+tokenText.size()-3 &&
106 ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) )
119 bool isneg = (ch == '-');
124 type = RTFTokenizer::CloseGroup;
130 while (ch >= '0' && ch <= '9') {
131 v = (10 * v) + ch - '0';
140 value = isneg ? -v : v;
149 if ( !memcmp( tokenText.data()+1, "bin", 4 ) )
151 kdDebug(30515) << "Token:" << tokenText << endl;
154 kdDebug(30515) << "\\bin" << value << endl;
155 type = RTFTokenizer::BinaryData;
157 for ( int i=0; i< value; i++)
161 type = RTFTokenizer::CloseGroup;
175 type = RTFTokenizer::ControlWord;
184 type = RTFTokenizer::CloseGroup;
196 value= value|((ch + ((ch & 16) ? 0 : 9)) & 0xf);
201 type = RTFTokenizer::ControlWord;
207 type = RTFTokenizer::PlainText;
210 while ( ch != '\\' && ch != '{' && ch != '}' && ch != '\n' &&
214 if(fileBufferPtr >= fileBufferEnd)
216 ch = *fileBufferPtr++;
218 if(fileBufferPtr < fileBufferEnd)
void open(TQFile *in) Open tokenizer from file.
void next() Reads the next token.
TQByteArray binaryData Binary data (of \bin keyword).
char * text plain text or control word/symbol
int value numeric parameter
bool hasParam token has a (numeric) parameter
|