]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/expat/xmltok/xmltok.h
2 Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3 See the file copying.txt for copying permission.
6 #ifndef XmlTok_INCLUDED
7 #define XmlTok_INCLUDED 1
14 #define XMLTOKAPI /* as nothing */
17 /* The following token may be returned by XmlContentTok */
18 #define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
19 illegal ]]> sequence */
20 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
21 #define XML_TOK_NONE -4 /* The string to be scanned is empty */
22 #define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
23 might be part of CRLF sequence */
24 #define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
25 #define XML_TOK_PARTIAL -1 /* only part of a token */
26 #define XML_TOK_INVALID 0
28 /* The following tokens are returned by XmlContentTok; some are also
29 returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
31 #define XML_TOK_START_TAG_WITH_ATTS 1
32 #define XML_TOK_START_TAG_NO_ATTS 2
33 #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
34 #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
35 #define XML_TOK_END_TAG 5
36 #define XML_TOK_DATA_CHARS 6
37 #define XML_TOK_DATA_NEWLINE 7
38 #define XML_TOK_CDATA_SECT_OPEN 8
39 #define XML_TOK_ENTITY_REF 9
40 #define XML_TOK_CHAR_REF 10 /* numeric character reference */
42 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
43 #define XML_TOK_PI 11 /* processing instruction */
44 #define XML_TOK_XML_DECL 12 /* XML decl or text decl */
45 #define XML_TOK_COMMENT 13
46 #define XML_TOK_BOM 14 /* Byte order mark */
48 /* The following tokens are returned only by XmlPrologTok */
49 #define XML_TOK_PROLOG_S 15
50 #define XML_TOK_DECL_OPEN 16 /* <!foo */
51 #define XML_TOK_DECL_CLOSE 17 /* > */
52 #define XML_TOK_NAME 18
53 #define XML_TOK_NMTOKEN 19
54 #define XML_TOK_POUND_NAME 20 /* #name */
55 #define XML_TOK_OR 21 /* | */
56 #define XML_TOK_PERCENT 22
57 #define XML_TOK_OPEN_PAREN 23
58 #define XML_TOK_CLOSE_PAREN 24
59 #define XML_TOK_OPEN_BRACKET 25
60 #define XML_TOK_CLOSE_BRACKET 26
61 #define XML_TOK_LITERAL 27
62 #define XML_TOK_PARAM_ENTITY_REF 28
63 #define XML_TOK_INSTANCE_START 29
65 /* The following occur only in element type declarations */
66 #define XML_TOK_NAME_QUESTION 30 /* name? */
67 #define XML_TOK_NAME_ASTERISK 31 /* name* */
68 #define XML_TOK_NAME_PLUS 32 /* name+ */
69 #define XML_TOK_COND_SECT_OPEN 33 /* <![ */
70 #define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
71 #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
72 #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
73 #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
74 #define XML_TOK_COMMA 38
76 /* The following token is returned only by XmlAttributeValueTok */
77 #define XML_TOK_ATTRIBUTE_VALUE_S 39
79 /* The following token is returned only by XmlCdataSectionTok */
80 #define XML_TOK_CDATA_SECT_CLOSE 40
82 /* With namespace processing this is returned by XmlPrologTok
83 for a name with a colon. */
84 #define XML_TOK_PREFIXED_NAME 41
87 #define XML_TOK_IGNORE_SECT 42
91 #define XML_N_STATES 4
92 #else /* not XML_DTD */
93 #define XML_N_STATES 3
94 #endif /* not XML_DTD */
96 #define XML_PROLOG_STATE 0
97 #define XML_CONTENT_STATE 1
98 #define XML_CDATA_SECTION_STATE 2
100 #define XML_IGNORE_SECTION_STATE 3
103 #define XML_N_LITERAL_TYPES 2
104 #define XML_ATTRIBUTE_VALUE_LITERAL 0
105 #define XML_ENTITY_VALUE_LITERAL 1
107 /* The size of the buffer passed to XmlUtf8Encode must be at least this. */
108 #define XML_UTF8_ENCODE_MAX 4
109 /* The size of the buffer passed to XmlUtf16Encode must be at least this. */
110 #define XML_UTF16_ENCODE_MAX 2
112 typedef struct position
{
113 /* first line and first column are 0 not 1 */
114 unsigned long lineNumber
;
115 unsigned long columnNumber
;
120 const char *valuePtr
;
121 const char *valueEnd
;
126 typedef struct encoding ENCODING
;
129 int (*scanners
[XML_N_STATES
])(const ENCODING
*,
133 int (*literalScanners
[XML_N_LITERAL_TYPES
])(const ENCODING
*,
137 int (*sameName
)(const ENCODING
*,
138 const char *, const char *);
139 int (*nameMatchesAscii
)(const ENCODING
*,
140 const char *, const char *, const char *);
141 int (*nameLength
)(const ENCODING
*, const char *);
142 const char *(*skipS
)(const ENCODING
*, const char *);
143 int (*getAtts
)(const ENCODING
*enc
, const char *ptr
,
144 int attsMax
, ATTRIBUTE
*atts
);
145 int (*charRefNumber
)(const ENCODING
*enc
, const char *ptr
);
146 int (*predefinedEntityName
)(const ENCODING
*, const char *, const char *);
147 void (*updatePosition
)(const ENCODING
*,
151 int (*isPublicId
)(const ENCODING
*enc
, const char *ptr
, const char *end
,
152 const char **badPtr
);
153 void (*utf8Convert
)(const ENCODING
*enc
,
158 void (*utf16Convert
)(const ENCODING
*enc
,
161 unsigned short **toP
,
162 const unsigned short *toLim
);
169 Scan the string starting at ptr until the end of the next complete token,
170 but do not scan past eptr. Return an integer giving the type of token.
172 Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
174 Return XML_TOK_PARTIAL when the string does not contain a complete token;
175 nextTokPtr will not be set.
177 Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
178 will be set to point to the character which made the token invalid.
180 Otherwise the string starts with a valid token; nextTokPtr will be set to point
181 to the character following the end of that token.
183 Each data character counts as a single token, but adjacent data characters
184 may be returned together. Similarly for characters in the prolog outside
185 literals, comments and processing instructions.
189 #define XmlTok(enc, state, ptr, end, nextTokPtr) \
190 (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
192 #define XmlPrologTok(enc, ptr, end, nextTokPtr) \
193 XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
195 #define XmlContentTok(enc, ptr, end, nextTokPtr) \
196 XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
198 #define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
199 XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
203 #define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
204 XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
208 /* This is used for performing a 2nd-level tokenization on
209 the content of a literal that has already been returned by XmlTok. */
211 #define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
212 (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
214 #define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
215 XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
217 #define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
218 XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
220 #define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
222 #define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
223 (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
225 #define XmlNameLength(enc, ptr) \
226 (((enc)->nameLength)(enc, ptr))
228 #define XmlSkipS(enc, ptr) \
229 (((enc)->skipS)(enc, ptr))
231 #define XmlGetAttributes(enc, ptr, attsMax, atts) \
232 (((enc)->getAtts)(enc, ptr, attsMax, atts))
234 #define XmlCharRefNumber(enc, ptr) \
235 (((enc)->charRefNumber)(enc, ptr))
237 #define XmlPredefinedEntityName(enc, ptr, end) \
238 (((enc)->predefinedEntityName)(enc, ptr, end))
240 #define XmlUpdatePosition(enc, ptr, end, pos) \
241 (((enc)->updatePosition)(enc, ptr, end, pos))
243 #define XmlIsPublicId(enc, ptr, end, badPtr) \
244 (((enc)->isPublicId)(enc, ptr, end, badPtr))
246 #define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
247 (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
249 #define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
250 (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
254 const ENCODING
**encPtr
;
257 int XMLTOKAPI
XmlParseXmlDecl(int isGeneralTextEntity
,
262 const char **versionPtr
,
263 const char **encodingNamePtr
,
264 const ENCODING
**namedEncodingPtr
,
267 int XMLTOKAPI
XmlInitEncoding(INIT_ENCODING
*, const ENCODING
**, const char *name
);
268 const ENCODING XMLTOKAPI
*XmlGetUtf8InternalEncoding(void);
269 const ENCODING XMLTOKAPI
*XmlGetUtf16InternalEncoding(void);
270 int XMLTOKAPI
XmlUtf8Encode(int charNumber
, char *buf
);
271 int XMLTOKAPI
XmlUtf16Encode(int charNumber
, unsigned short *buf
);
273 int XMLTOKAPI
XmlSizeOfUnknownEncoding(void);
275 XmlInitUnknownEncoding(void *mem
,
277 int (*conv
)(void *userData
, const char *p
),
280 int XMLTOKAPI
XmlParseXmlDeclNS(int isGeneralTextEntity
,
285 const char **versionPtr
,
286 const char **encodingNamePtr
,
287 const ENCODING
**namedEncodingPtr
,
289 int XMLTOKAPI
XmlInitEncodingNS(INIT_ENCODING
*, const ENCODING
**, const char *name
);
290 const ENCODING XMLTOKAPI
*XmlGetUtf8InternalEncodingNS(void);
291 const ENCODING XMLTOKAPI
*XmlGetUtf16InternalEncodingNS(void);
293 XmlInitUnknownEncodingNS(void *mem
,
295 int (*conv
)(void *userData
, const char *p
),
301 #endif /* not XmlTok_INCLUDED */