1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/* -*- C++ -*-
This file is part of KIllustrator.
Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April ´99
*/
#ifndef XmlTokenizer_h_
#define XmlTokenizer_h_
#include "koxml_config.h"
/**
* The XMLTokenizer class allows an application to break a XML stream
* into tokens.
*
* @short A class for tokenizing an XML stream.
* @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de)
* @version 2000/07/02
*/
class XmlTokenizer {
public:
/**
* The expected tokens for a XML stream.
*/
enum Token { Tok_Invalid, /* 0 */
Tok_EOF, /* 1 */
Tok_Symbol, /* 2 */
Tok_String, /* 3 */
Tok_Text, /* 4 */
Tok_Comment, /* 5 */
Tok_Lt, /* < 6 */
Tok_Gt, /* > 7 */
Tok_QSign, /* ? 8 */
Tok_Eq, /* = 9 */
Tok_Slash, /* / 10 */
Tok_Exclam, /* ! 11 */
Tok_Bar, /* | 12 */
Tok_LParen, /* ( 13 */
Tok_RParen, /* ) 14 */
Tok_LBracket, /* [ 15 */
Tok_RBracket, /* ] 16 */
Tok_Plus, /* + 17 */
Tok_Asterisk, /* * 18 */
Tok_Comma, /* , 19 */
Tok_Semicolon,/* ; 20 */
Tok_NSign, /* # 21 */
Tok_Apostr, /* ' 22 */
Tok_Percent /* % 23 */
};
/**
* Create a XmlTokenizer instance for the given input stream.
*
* @param is The open input stream for reading.
*/
XmlTokenizer (KOXML_ISTREAM& is);
/**
* Destructor.
*/
~XmlTokenizer ();
/**
* Return the next token from the stream.
* @return The next token from the stream.
*/
Token nextToken ();
/**
* Return the string representation of the current token.
*
* @return The string representation.
*/
const KOXML_STRING& element ();
KOXML_CHAR readchar ();
void putback (KOXML_CHAR c);
/**
* Cause the next call to method @p nextToken of this tokenizer
* to return the current token.
*/
void unget ();
inline int lineNumber() { return lineno; }
protected:
void skipWhitespace ();
Token readString ();
Token readSymbol ();
Token readText ();
Token readComment ();
private:
// QIODevice *strm;
KOXML_STRING last_chars;
KOXML_ISTREAM &istrm;
KOXML_STRING elem;
Token last_tok;
bool use_last;
bool is_open;
int lineno;
};
#endif
|