1 | n/a | /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd |
---|
2 | n/a | See the file COPYING for copying permission. |
---|
3 | n/a | */ |
---|
4 | n/a | |
---|
5 | n/a | /* This file is included! */ |
---|
6 | n/a | #ifdef XML_TOK_IMPL_C |
---|
7 | n/a | |
---|
8 | n/a | #ifndef IS_INVALID_CHAR |
---|
9 | n/a | #define IS_INVALID_CHAR(enc, ptr, n) (0) |
---|
10 | n/a | #endif |
---|
11 | n/a | |
---|
12 | n/a | #define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ |
---|
13 | n/a | case BT_LEAD ## n: \ |
---|
14 | n/a | if (end - ptr < n) \ |
---|
15 | n/a | return XML_TOK_PARTIAL_CHAR; \ |
---|
16 | n/a | if (IS_INVALID_CHAR(enc, ptr, n)) { \ |
---|
17 | n/a | *(nextTokPtr) = (ptr); \ |
---|
18 | n/a | return XML_TOK_INVALID; \ |
---|
19 | n/a | } \ |
---|
20 | n/a | ptr += n; \ |
---|
21 | n/a | break; |
---|
22 | n/a | |
---|
23 | n/a | #define INVALID_CASES(ptr, nextTokPtr) \ |
---|
24 | n/a | INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ |
---|
25 | n/a | INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ |
---|
26 | n/a | INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ |
---|
27 | n/a | case BT_NONXML: \ |
---|
28 | n/a | case BT_MALFORM: \ |
---|
29 | n/a | case BT_TRAIL: \ |
---|
30 | n/a | *(nextTokPtr) = (ptr); \ |
---|
31 | n/a | return XML_TOK_INVALID; |
---|
32 | n/a | |
---|
33 | n/a | #define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ |
---|
34 | n/a | case BT_LEAD ## n: \ |
---|
35 | n/a | if (end - ptr < n) \ |
---|
36 | n/a | return XML_TOK_PARTIAL_CHAR; \ |
---|
37 | n/a | if (!IS_NAME_CHAR(enc, ptr, n)) { \ |
---|
38 | n/a | *nextTokPtr = ptr; \ |
---|
39 | n/a | return XML_TOK_INVALID; \ |
---|
40 | n/a | } \ |
---|
41 | n/a | ptr += n; \ |
---|
42 | n/a | break; |
---|
43 | n/a | |
---|
44 | n/a | #define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ |
---|
45 | n/a | case BT_NONASCII: \ |
---|
46 | n/a | if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ |
---|
47 | n/a | *nextTokPtr = ptr; \ |
---|
48 | n/a | return XML_TOK_INVALID; \ |
---|
49 | n/a | } \ |
---|
50 | n/a | case BT_NMSTRT: \ |
---|
51 | n/a | case BT_HEX: \ |
---|
52 | n/a | case BT_DIGIT: \ |
---|
53 | n/a | case BT_NAME: \ |
---|
54 | n/a | case BT_MINUS: \ |
---|
55 | n/a | ptr += MINBPC(enc); \ |
---|
56 | n/a | break; \ |
---|
57 | n/a | CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ |
---|
58 | n/a | CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ |
---|
59 | n/a | CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) |
---|
60 | n/a | |
---|
61 | n/a | #define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ |
---|
62 | n/a | case BT_LEAD ## n: \ |
---|
63 | n/a | if (end - ptr < n) \ |
---|
64 | n/a | return XML_TOK_PARTIAL_CHAR; \ |
---|
65 | n/a | if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ |
---|
66 | n/a | *nextTokPtr = ptr; \ |
---|
67 | n/a | return XML_TOK_INVALID; \ |
---|
68 | n/a | } \ |
---|
69 | n/a | ptr += n; \ |
---|
70 | n/a | break; |
---|
71 | n/a | |
---|
72 | n/a | #define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ |
---|
73 | n/a | case BT_NONASCII: \ |
---|
74 | n/a | if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ |
---|
75 | n/a | *nextTokPtr = ptr; \ |
---|
76 | n/a | return XML_TOK_INVALID; \ |
---|
77 | n/a | } \ |
---|
78 | n/a | case BT_NMSTRT: \ |
---|
79 | n/a | case BT_HEX: \ |
---|
80 | n/a | ptr += MINBPC(enc); \ |
---|
81 | n/a | break; \ |
---|
82 | n/a | CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ |
---|
83 | n/a | CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ |
---|
84 | n/a | CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) |
---|
85 | n/a | |
---|
86 | n/a | #ifndef PREFIX |
---|
87 | n/a | #define PREFIX(ident) ident |
---|
88 | n/a | #endif |
---|
89 | n/a | |
---|
90 | n/a | /* ptr points to character following "<!-" */ |
---|
91 | n/a | |
---|
92 | n/a | static int PTRCALL |
---|
93 | n/a | PREFIX(scanComment)(const ENCODING *enc, const char *ptr, |
---|
94 | n/a | const char *end, const char **nextTokPtr) |
---|
95 | n/a | { |
---|
96 | n/a | if (ptr != end) { |
---|
97 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { |
---|
98 | n/a | *nextTokPtr = ptr; |
---|
99 | n/a | return XML_TOK_INVALID; |
---|
100 | n/a | } |
---|
101 | n/a | ptr += MINBPC(enc); |
---|
102 | n/a | while (ptr != end) { |
---|
103 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
104 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
105 | n/a | case BT_MINUS: |
---|
106 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
107 | n/a | return XML_TOK_PARTIAL; |
---|
108 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { |
---|
109 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
110 | n/a | return XML_TOK_PARTIAL; |
---|
111 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
112 | n/a | *nextTokPtr = ptr; |
---|
113 | n/a | return XML_TOK_INVALID; |
---|
114 | n/a | } |
---|
115 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
116 | n/a | return XML_TOK_COMMENT; |
---|
117 | n/a | } |
---|
118 | n/a | break; |
---|
119 | n/a | default: |
---|
120 | n/a | ptr += MINBPC(enc); |
---|
121 | n/a | break; |
---|
122 | n/a | } |
---|
123 | n/a | } |
---|
124 | n/a | } |
---|
125 | n/a | return XML_TOK_PARTIAL; |
---|
126 | n/a | } |
---|
127 | n/a | |
---|
128 | n/a | /* ptr points to character following "<!" */ |
---|
129 | n/a | |
---|
130 | n/a | static int PTRCALL |
---|
131 | n/a | PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, |
---|
132 | n/a | const char *end, const char **nextTokPtr) |
---|
133 | n/a | { |
---|
134 | n/a | if (ptr == end) |
---|
135 | n/a | return XML_TOK_PARTIAL; |
---|
136 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
137 | n/a | case BT_MINUS: |
---|
138 | n/a | return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
139 | n/a | case BT_LSQB: |
---|
140 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
141 | n/a | return XML_TOK_COND_SECT_OPEN; |
---|
142 | n/a | case BT_NMSTRT: |
---|
143 | n/a | case BT_HEX: |
---|
144 | n/a | ptr += MINBPC(enc); |
---|
145 | n/a | break; |
---|
146 | n/a | default: |
---|
147 | n/a | *nextTokPtr = ptr; |
---|
148 | n/a | return XML_TOK_INVALID; |
---|
149 | n/a | } |
---|
150 | n/a | while (ptr != end) { |
---|
151 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
152 | n/a | case BT_PERCNT: |
---|
153 | n/a | if (ptr + MINBPC(enc) == end) |
---|
154 | n/a | return XML_TOK_PARTIAL; |
---|
155 | n/a | /* don't allow <!ENTITY% foo "whatever"> */ |
---|
156 | n/a | switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { |
---|
157 | n/a | case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: |
---|
158 | n/a | *nextTokPtr = ptr; |
---|
159 | n/a | return XML_TOK_INVALID; |
---|
160 | n/a | } |
---|
161 | n/a | /* fall through */ |
---|
162 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
163 | n/a | *nextTokPtr = ptr; |
---|
164 | n/a | return XML_TOK_DECL_OPEN; |
---|
165 | n/a | case BT_NMSTRT: |
---|
166 | n/a | case BT_HEX: |
---|
167 | n/a | ptr += MINBPC(enc); |
---|
168 | n/a | break; |
---|
169 | n/a | default: |
---|
170 | n/a | *nextTokPtr = ptr; |
---|
171 | n/a | return XML_TOK_INVALID; |
---|
172 | n/a | } |
---|
173 | n/a | } |
---|
174 | n/a | return XML_TOK_PARTIAL; |
---|
175 | n/a | } |
---|
176 | n/a | |
---|
177 | n/a | static int PTRCALL |
---|
178 | n/a | PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, |
---|
179 | n/a | const char *end, int *tokPtr) |
---|
180 | n/a | { |
---|
181 | n/a | int upper = 0; |
---|
182 | n/a | *tokPtr = XML_TOK_PI; |
---|
183 | n/a | if (end - ptr != MINBPC(enc)*3) |
---|
184 | n/a | return 1; |
---|
185 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
186 | n/a | case ASCII_x: |
---|
187 | n/a | break; |
---|
188 | n/a | case ASCII_X: |
---|
189 | n/a | upper = 1; |
---|
190 | n/a | break; |
---|
191 | n/a | default: |
---|
192 | n/a | return 1; |
---|
193 | n/a | } |
---|
194 | n/a | ptr += MINBPC(enc); |
---|
195 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
196 | n/a | case ASCII_m: |
---|
197 | n/a | break; |
---|
198 | n/a | case ASCII_M: |
---|
199 | n/a | upper = 1; |
---|
200 | n/a | break; |
---|
201 | n/a | default: |
---|
202 | n/a | return 1; |
---|
203 | n/a | } |
---|
204 | n/a | ptr += MINBPC(enc); |
---|
205 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
206 | n/a | case ASCII_l: |
---|
207 | n/a | break; |
---|
208 | n/a | case ASCII_L: |
---|
209 | n/a | upper = 1; |
---|
210 | n/a | break; |
---|
211 | n/a | default: |
---|
212 | n/a | return 1; |
---|
213 | n/a | } |
---|
214 | n/a | if (upper) |
---|
215 | n/a | return 0; |
---|
216 | n/a | *tokPtr = XML_TOK_XML_DECL; |
---|
217 | n/a | return 1; |
---|
218 | n/a | } |
---|
219 | n/a | |
---|
220 | n/a | /* ptr points to character following "<?" */ |
---|
221 | n/a | |
---|
222 | n/a | static int PTRCALL |
---|
223 | n/a | PREFIX(scanPi)(const ENCODING *enc, const char *ptr, |
---|
224 | n/a | const char *end, const char **nextTokPtr) |
---|
225 | n/a | { |
---|
226 | n/a | int tok; |
---|
227 | n/a | const char *target = ptr; |
---|
228 | n/a | if (ptr == end) |
---|
229 | n/a | return XML_TOK_PARTIAL; |
---|
230 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
231 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
232 | n/a | default: |
---|
233 | n/a | *nextTokPtr = ptr; |
---|
234 | n/a | return XML_TOK_INVALID; |
---|
235 | n/a | } |
---|
236 | n/a | while (ptr != end) { |
---|
237 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
238 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
239 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
240 | n/a | if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) { |
---|
241 | n/a | *nextTokPtr = ptr; |
---|
242 | n/a | return XML_TOK_INVALID; |
---|
243 | n/a | } |
---|
244 | n/a | ptr += MINBPC(enc); |
---|
245 | n/a | while (ptr != end) { |
---|
246 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
247 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
248 | n/a | case BT_QUEST: |
---|
249 | n/a | ptr += MINBPC(enc); |
---|
250 | n/a | if (ptr == end) |
---|
251 | n/a | return XML_TOK_PARTIAL; |
---|
252 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
253 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
254 | n/a | return tok; |
---|
255 | n/a | } |
---|
256 | n/a | break; |
---|
257 | n/a | default: |
---|
258 | n/a | ptr += MINBPC(enc); |
---|
259 | n/a | break; |
---|
260 | n/a | } |
---|
261 | n/a | } |
---|
262 | n/a | return XML_TOK_PARTIAL; |
---|
263 | n/a | case BT_QUEST: |
---|
264 | n/a | if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) { |
---|
265 | n/a | *nextTokPtr = ptr; |
---|
266 | n/a | return XML_TOK_INVALID; |
---|
267 | n/a | } |
---|
268 | n/a | ptr += MINBPC(enc); |
---|
269 | n/a | if (ptr == end) |
---|
270 | n/a | return XML_TOK_PARTIAL; |
---|
271 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
272 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
273 | n/a | return tok; |
---|
274 | n/a | } |
---|
275 | n/a | /* fall through */ |
---|
276 | n/a | default: |
---|
277 | n/a | *nextTokPtr = ptr; |
---|
278 | n/a | return XML_TOK_INVALID; |
---|
279 | n/a | } |
---|
280 | n/a | } |
---|
281 | n/a | return XML_TOK_PARTIAL; |
---|
282 | n/a | } |
---|
283 | n/a | |
---|
284 | n/a | static int PTRCALL |
---|
285 | n/a | PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, |
---|
286 | n/a | const char *end, const char **nextTokPtr) |
---|
287 | n/a | { |
---|
288 | n/a | static const char CDATA_LSQB[] = { ASCII_C, ASCII_D, ASCII_A, |
---|
289 | n/a | ASCII_T, ASCII_A, ASCII_LSQB }; |
---|
290 | n/a | int i; |
---|
291 | n/a | /* CDATA[ */ |
---|
292 | n/a | if (end - ptr < 6 * MINBPC(enc)) |
---|
293 | n/a | return XML_TOK_PARTIAL; |
---|
294 | n/a | for (i = 0; i < 6; i++, ptr += MINBPC(enc)) { |
---|
295 | n/a | if (!CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) { |
---|
296 | n/a | *nextTokPtr = ptr; |
---|
297 | n/a | return XML_TOK_INVALID; |
---|
298 | n/a | } |
---|
299 | n/a | } |
---|
300 | n/a | *nextTokPtr = ptr; |
---|
301 | n/a | return XML_TOK_CDATA_SECT_OPEN; |
---|
302 | n/a | } |
---|
303 | n/a | |
---|
304 | n/a | static int PTRCALL |
---|
305 | n/a | PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, |
---|
306 | n/a | const char *end, const char **nextTokPtr) |
---|
307 | n/a | { |
---|
308 | n/a | if (ptr == end) |
---|
309 | n/a | return XML_TOK_NONE; |
---|
310 | n/a | if (MINBPC(enc) > 1) { |
---|
311 | n/a | size_t n = end - ptr; |
---|
312 | n/a | if (n & (MINBPC(enc) - 1)) { |
---|
313 | n/a | n &= ~(MINBPC(enc) - 1); |
---|
314 | n/a | if (n == 0) |
---|
315 | n/a | return XML_TOK_PARTIAL; |
---|
316 | n/a | end = ptr + n; |
---|
317 | n/a | } |
---|
318 | n/a | } |
---|
319 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
320 | n/a | case BT_RSQB: |
---|
321 | n/a | ptr += MINBPC(enc); |
---|
322 | n/a | if (ptr == end) |
---|
323 | n/a | return XML_TOK_PARTIAL; |
---|
324 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) |
---|
325 | n/a | break; |
---|
326 | n/a | ptr += MINBPC(enc); |
---|
327 | n/a | if (ptr == end) |
---|
328 | n/a | return XML_TOK_PARTIAL; |
---|
329 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
330 | n/a | ptr -= MINBPC(enc); |
---|
331 | n/a | break; |
---|
332 | n/a | } |
---|
333 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
334 | n/a | return XML_TOK_CDATA_SECT_CLOSE; |
---|
335 | n/a | case BT_CR: |
---|
336 | n/a | ptr += MINBPC(enc); |
---|
337 | n/a | if (ptr == end) |
---|
338 | n/a | return XML_TOK_PARTIAL; |
---|
339 | n/a | if (BYTE_TYPE(enc, ptr) == BT_LF) |
---|
340 | n/a | ptr += MINBPC(enc); |
---|
341 | n/a | *nextTokPtr = ptr; |
---|
342 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
343 | n/a | case BT_LF: |
---|
344 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
345 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
346 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
347 | n/a | default: |
---|
348 | n/a | ptr += MINBPC(enc); |
---|
349 | n/a | break; |
---|
350 | n/a | } |
---|
351 | n/a | while (ptr != end) { |
---|
352 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
353 | n/a | #define LEAD_CASE(n) \ |
---|
354 | n/a | case BT_LEAD ## n: \ |
---|
355 | n/a | if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ |
---|
356 | n/a | *nextTokPtr = ptr; \ |
---|
357 | n/a | return XML_TOK_DATA_CHARS; \ |
---|
358 | n/a | } \ |
---|
359 | n/a | ptr += n; \ |
---|
360 | n/a | break; |
---|
361 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
362 | n/a | #undef LEAD_CASE |
---|
363 | n/a | case BT_NONXML: |
---|
364 | n/a | case BT_MALFORM: |
---|
365 | n/a | case BT_TRAIL: |
---|
366 | n/a | case BT_CR: |
---|
367 | n/a | case BT_LF: |
---|
368 | n/a | case BT_RSQB: |
---|
369 | n/a | *nextTokPtr = ptr; |
---|
370 | n/a | return XML_TOK_DATA_CHARS; |
---|
371 | n/a | default: |
---|
372 | n/a | ptr += MINBPC(enc); |
---|
373 | n/a | break; |
---|
374 | n/a | } |
---|
375 | n/a | } |
---|
376 | n/a | *nextTokPtr = ptr; |
---|
377 | n/a | return XML_TOK_DATA_CHARS; |
---|
378 | n/a | } |
---|
379 | n/a | |
---|
380 | n/a | /* ptr points to character following "</" */ |
---|
381 | n/a | |
---|
382 | n/a | static int PTRCALL |
---|
383 | n/a | PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, |
---|
384 | n/a | const char *end, const char **nextTokPtr) |
---|
385 | n/a | { |
---|
386 | n/a | if (ptr == end) |
---|
387 | n/a | return XML_TOK_PARTIAL; |
---|
388 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
389 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
390 | n/a | default: |
---|
391 | n/a | *nextTokPtr = ptr; |
---|
392 | n/a | return XML_TOK_INVALID; |
---|
393 | n/a | } |
---|
394 | n/a | while (ptr != end) { |
---|
395 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
396 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
397 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
398 | n/a | for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { |
---|
399 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
400 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
401 | n/a | break; |
---|
402 | n/a | case BT_GT: |
---|
403 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
404 | n/a | return XML_TOK_END_TAG; |
---|
405 | n/a | default: |
---|
406 | n/a | *nextTokPtr = ptr; |
---|
407 | n/a | return XML_TOK_INVALID; |
---|
408 | n/a | } |
---|
409 | n/a | } |
---|
410 | n/a | return XML_TOK_PARTIAL; |
---|
411 | n/a | #ifdef XML_NS |
---|
412 | n/a | case BT_COLON: |
---|
413 | n/a | /* no need to check qname syntax here, |
---|
414 | n/a | since end-tag must match exactly */ |
---|
415 | n/a | ptr += MINBPC(enc); |
---|
416 | n/a | break; |
---|
417 | n/a | #endif |
---|
418 | n/a | case BT_GT: |
---|
419 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
420 | n/a | return XML_TOK_END_TAG; |
---|
421 | n/a | default: |
---|
422 | n/a | *nextTokPtr = ptr; |
---|
423 | n/a | return XML_TOK_INVALID; |
---|
424 | n/a | } |
---|
425 | n/a | } |
---|
426 | n/a | return XML_TOK_PARTIAL; |
---|
427 | n/a | } |
---|
428 | n/a | |
---|
429 | n/a | /* ptr points to character following "&#X" */ |
---|
430 | n/a | |
---|
431 | n/a | static int PTRCALL |
---|
432 | n/a | PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, |
---|
433 | n/a | const char *end, const char **nextTokPtr) |
---|
434 | n/a | { |
---|
435 | n/a | if (ptr != end) { |
---|
436 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
437 | n/a | case BT_DIGIT: |
---|
438 | n/a | case BT_HEX: |
---|
439 | n/a | break; |
---|
440 | n/a | default: |
---|
441 | n/a | *nextTokPtr = ptr; |
---|
442 | n/a | return XML_TOK_INVALID; |
---|
443 | n/a | } |
---|
444 | n/a | for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { |
---|
445 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
446 | n/a | case BT_DIGIT: |
---|
447 | n/a | case BT_HEX: |
---|
448 | n/a | break; |
---|
449 | n/a | case BT_SEMI: |
---|
450 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
451 | n/a | return XML_TOK_CHAR_REF; |
---|
452 | n/a | default: |
---|
453 | n/a | *nextTokPtr = ptr; |
---|
454 | n/a | return XML_TOK_INVALID; |
---|
455 | n/a | } |
---|
456 | n/a | } |
---|
457 | n/a | } |
---|
458 | n/a | return XML_TOK_PARTIAL; |
---|
459 | n/a | } |
---|
460 | n/a | |
---|
461 | n/a | /* ptr points to character following "&#" */ |
---|
462 | n/a | |
---|
463 | n/a | static int PTRCALL |
---|
464 | n/a | PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, |
---|
465 | n/a | const char *end, const char **nextTokPtr) |
---|
466 | n/a | { |
---|
467 | n/a | if (ptr != end) { |
---|
468 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_x)) |
---|
469 | n/a | return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
470 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
471 | n/a | case BT_DIGIT: |
---|
472 | n/a | break; |
---|
473 | n/a | default: |
---|
474 | n/a | *nextTokPtr = ptr; |
---|
475 | n/a | return XML_TOK_INVALID; |
---|
476 | n/a | } |
---|
477 | n/a | for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { |
---|
478 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
479 | n/a | case BT_DIGIT: |
---|
480 | n/a | break; |
---|
481 | n/a | case BT_SEMI: |
---|
482 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
483 | n/a | return XML_TOK_CHAR_REF; |
---|
484 | n/a | default: |
---|
485 | n/a | *nextTokPtr = ptr; |
---|
486 | n/a | return XML_TOK_INVALID; |
---|
487 | n/a | } |
---|
488 | n/a | } |
---|
489 | n/a | } |
---|
490 | n/a | return XML_TOK_PARTIAL; |
---|
491 | n/a | } |
---|
492 | n/a | |
---|
493 | n/a | /* ptr points to character following "&" */ |
---|
494 | n/a | |
---|
495 | n/a | static int PTRCALL |
---|
496 | n/a | PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end, |
---|
497 | n/a | const char **nextTokPtr) |
---|
498 | n/a | { |
---|
499 | n/a | if (ptr == end) |
---|
500 | n/a | return XML_TOK_PARTIAL; |
---|
501 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
502 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
503 | n/a | case BT_NUM: |
---|
504 | n/a | return PREFIX(scanCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
505 | n/a | default: |
---|
506 | n/a | *nextTokPtr = ptr; |
---|
507 | n/a | return XML_TOK_INVALID; |
---|
508 | n/a | } |
---|
509 | n/a | while (ptr != end) { |
---|
510 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
511 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
512 | n/a | case BT_SEMI: |
---|
513 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
514 | n/a | return XML_TOK_ENTITY_REF; |
---|
515 | n/a | default: |
---|
516 | n/a | *nextTokPtr = ptr; |
---|
517 | n/a | return XML_TOK_INVALID; |
---|
518 | n/a | } |
---|
519 | n/a | } |
---|
520 | n/a | return XML_TOK_PARTIAL; |
---|
521 | n/a | } |
---|
522 | n/a | |
---|
523 | n/a | /* ptr points to character following first character of attribute name */ |
---|
524 | n/a | |
---|
525 | n/a | static int PTRCALL |
---|
526 | n/a | PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, |
---|
527 | n/a | const char **nextTokPtr) |
---|
528 | n/a | { |
---|
529 | n/a | #ifdef XML_NS |
---|
530 | n/a | int hadColon = 0; |
---|
531 | n/a | #endif |
---|
532 | n/a | while (ptr != end) { |
---|
533 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
534 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
535 | n/a | #ifdef XML_NS |
---|
536 | n/a | case BT_COLON: |
---|
537 | n/a | if (hadColon) { |
---|
538 | n/a | *nextTokPtr = ptr; |
---|
539 | n/a | return XML_TOK_INVALID; |
---|
540 | n/a | } |
---|
541 | n/a | hadColon = 1; |
---|
542 | n/a | ptr += MINBPC(enc); |
---|
543 | n/a | if (ptr == end) |
---|
544 | n/a | return XML_TOK_PARTIAL; |
---|
545 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
546 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
547 | n/a | default: |
---|
548 | n/a | *nextTokPtr = ptr; |
---|
549 | n/a | return XML_TOK_INVALID; |
---|
550 | n/a | } |
---|
551 | n/a | break; |
---|
552 | n/a | #endif |
---|
553 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
554 | n/a | for (;;) { |
---|
555 | n/a | int t; |
---|
556 | n/a | |
---|
557 | n/a | ptr += MINBPC(enc); |
---|
558 | n/a | if (ptr == end) |
---|
559 | n/a | return XML_TOK_PARTIAL; |
---|
560 | n/a | t = BYTE_TYPE(enc, ptr); |
---|
561 | n/a | if (t == BT_EQUALS) |
---|
562 | n/a | break; |
---|
563 | n/a | switch (t) { |
---|
564 | n/a | case BT_S: |
---|
565 | n/a | case BT_LF: |
---|
566 | n/a | case BT_CR: |
---|
567 | n/a | break; |
---|
568 | n/a | default: |
---|
569 | n/a | *nextTokPtr = ptr; |
---|
570 | n/a | return XML_TOK_INVALID; |
---|
571 | n/a | } |
---|
572 | n/a | } |
---|
573 | n/a | /* fall through */ |
---|
574 | n/a | case BT_EQUALS: |
---|
575 | n/a | { |
---|
576 | n/a | int open; |
---|
577 | n/a | #ifdef XML_NS |
---|
578 | n/a | hadColon = 0; |
---|
579 | n/a | #endif |
---|
580 | n/a | for (;;) { |
---|
581 | n/a | ptr += MINBPC(enc); |
---|
582 | n/a | if (ptr == end) |
---|
583 | n/a | return XML_TOK_PARTIAL; |
---|
584 | n/a | open = BYTE_TYPE(enc, ptr); |
---|
585 | n/a | if (open == BT_QUOT || open == BT_APOS) |
---|
586 | n/a | break; |
---|
587 | n/a | switch (open) { |
---|
588 | n/a | case BT_S: |
---|
589 | n/a | case BT_LF: |
---|
590 | n/a | case BT_CR: |
---|
591 | n/a | break; |
---|
592 | n/a | default: |
---|
593 | n/a | *nextTokPtr = ptr; |
---|
594 | n/a | return XML_TOK_INVALID; |
---|
595 | n/a | } |
---|
596 | n/a | } |
---|
597 | n/a | ptr += MINBPC(enc); |
---|
598 | n/a | /* in attribute value */ |
---|
599 | n/a | for (;;) { |
---|
600 | n/a | int t; |
---|
601 | n/a | if (ptr == end) |
---|
602 | n/a | return XML_TOK_PARTIAL; |
---|
603 | n/a | t = BYTE_TYPE(enc, ptr); |
---|
604 | n/a | if (t == open) |
---|
605 | n/a | break; |
---|
606 | n/a | switch (t) { |
---|
607 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
608 | n/a | case BT_AMP: |
---|
609 | n/a | { |
---|
610 | n/a | int tok = PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, &ptr); |
---|
611 | n/a | if (tok <= 0) { |
---|
612 | n/a | if (tok == XML_TOK_INVALID) |
---|
613 | n/a | *nextTokPtr = ptr; |
---|
614 | n/a | return tok; |
---|
615 | n/a | } |
---|
616 | n/a | break; |
---|
617 | n/a | } |
---|
618 | n/a | case BT_LT: |
---|
619 | n/a | *nextTokPtr = ptr; |
---|
620 | n/a | return XML_TOK_INVALID; |
---|
621 | n/a | default: |
---|
622 | n/a | ptr += MINBPC(enc); |
---|
623 | n/a | break; |
---|
624 | n/a | } |
---|
625 | n/a | } |
---|
626 | n/a | ptr += MINBPC(enc); |
---|
627 | n/a | if (ptr == end) |
---|
628 | n/a | return XML_TOK_PARTIAL; |
---|
629 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
630 | n/a | case BT_S: |
---|
631 | n/a | case BT_CR: |
---|
632 | n/a | case BT_LF: |
---|
633 | n/a | break; |
---|
634 | n/a | case BT_SOL: |
---|
635 | n/a | goto sol; |
---|
636 | n/a | case BT_GT: |
---|
637 | n/a | goto gt; |
---|
638 | n/a | default: |
---|
639 | n/a | *nextTokPtr = ptr; |
---|
640 | n/a | return XML_TOK_INVALID; |
---|
641 | n/a | } |
---|
642 | n/a | /* ptr points to closing quote */ |
---|
643 | n/a | for (;;) { |
---|
644 | n/a | ptr += MINBPC(enc); |
---|
645 | n/a | if (ptr == end) |
---|
646 | n/a | return XML_TOK_PARTIAL; |
---|
647 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
648 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
649 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
650 | n/a | continue; |
---|
651 | n/a | case BT_GT: |
---|
652 | n/a | gt: |
---|
653 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
654 | n/a | return XML_TOK_START_TAG_WITH_ATTS; |
---|
655 | n/a | case BT_SOL: |
---|
656 | n/a | sol: |
---|
657 | n/a | ptr += MINBPC(enc); |
---|
658 | n/a | if (ptr == end) |
---|
659 | n/a | return XML_TOK_PARTIAL; |
---|
660 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
661 | n/a | *nextTokPtr = ptr; |
---|
662 | n/a | return XML_TOK_INVALID; |
---|
663 | n/a | } |
---|
664 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
665 | n/a | return XML_TOK_EMPTY_ELEMENT_WITH_ATTS; |
---|
666 | n/a | default: |
---|
667 | n/a | *nextTokPtr = ptr; |
---|
668 | n/a | return XML_TOK_INVALID; |
---|
669 | n/a | } |
---|
670 | n/a | break; |
---|
671 | n/a | } |
---|
672 | n/a | break; |
---|
673 | n/a | } |
---|
674 | n/a | default: |
---|
675 | n/a | *nextTokPtr = ptr; |
---|
676 | n/a | return XML_TOK_INVALID; |
---|
677 | n/a | } |
---|
678 | n/a | } |
---|
679 | n/a | return XML_TOK_PARTIAL; |
---|
680 | n/a | } |
---|
681 | n/a | |
---|
682 | n/a | /* ptr points to character following "<" */ |
---|
683 | n/a | |
---|
684 | n/a | static int PTRCALL |
---|
685 | n/a | PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, |
---|
686 | n/a | const char **nextTokPtr) |
---|
687 | n/a | { |
---|
688 | n/a | #ifdef XML_NS |
---|
689 | n/a | int hadColon; |
---|
690 | n/a | #endif |
---|
691 | n/a | if (ptr == end) |
---|
692 | n/a | return XML_TOK_PARTIAL; |
---|
693 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
694 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
695 | n/a | case BT_EXCL: |
---|
696 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
697 | n/a | return XML_TOK_PARTIAL; |
---|
698 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
699 | n/a | case BT_MINUS: |
---|
700 | n/a | return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
701 | n/a | case BT_LSQB: |
---|
702 | n/a | return PREFIX(scanCdataSection)(enc, ptr + MINBPC(enc), |
---|
703 | n/a | end, nextTokPtr); |
---|
704 | n/a | } |
---|
705 | n/a | *nextTokPtr = ptr; |
---|
706 | n/a | return XML_TOK_INVALID; |
---|
707 | n/a | case BT_QUEST: |
---|
708 | n/a | return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
709 | n/a | case BT_SOL: |
---|
710 | n/a | return PREFIX(scanEndTag)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
711 | n/a | default: |
---|
712 | n/a | *nextTokPtr = ptr; |
---|
713 | n/a | return XML_TOK_INVALID; |
---|
714 | n/a | } |
---|
715 | n/a | #ifdef XML_NS |
---|
716 | n/a | hadColon = 0; |
---|
717 | n/a | #endif |
---|
718 | n/a | /* we have a start-tag */ |
---|
719 | n/a | while (ptr != end) { |
---|
720 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
721 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
722 | n/a | #ifdef XML_NS |
---|
723 | n/a | case BT_COLON: |
---|
724 | n/a | if (hadColon) { |
---|
725 | n/a | *nextTokPtr = ptr; |
---|
726 | n/a | return XML_TOK_INVALID; |
---|
727 | n/a | } |
---|
728 | n/a | hadColon = 1; |
---|
729 | n/a | ptr += MINBPC(enc); |
---|
730 | n/a | if (ptr == end) |
---|
731 | n/a | return XML_TOK_PARTIAL; |
---|
732 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
733 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
734 | n/a | default: |
---|
735 | n/a | *nextTokPtr = ptr; |
---|
736 | n/a | return XML_TOK_INVALID; |
---|
737 | n/a | } |
---|
738 | n/a | break; |
---|
739 | n/a | #endif |
---|
740 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
741 | n/a | { |
---|
742 | n/a | ptr += MINBPC(enc); |
---|
743 | n/a | while (ptr != end) { |
---|
744 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
745 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
746 | n/a | case BT_GT: |
---|
747 | n/a | goto gt; |
---|
748 | n/a | case BT_SOL: |
---|
749 | n/a | goto sol; |
---|
750 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
751 | n/a | ptr += MINBPC(enc); |
---|
752 | n/a | continue; |
---|
753 | n/a | default: |
---|
754 | n/a | *nextTokPtr = ptr; |
---|
755 | n/a | return XML_TOK_INVALID; |
---|
756 | n/a | } |
---|
757 | n/a | return PREFIX(scanAtts)(enc, ptr, end, nextTokPtr); |
---|
758 | n/a | } |
---|
759 | n/a | return XML_TOK_PARTIAL; |
---|
760 | n/a | } |
---|
761 | n/a | case BT_GT: |
---|
762 | n/a | gt: |
---|
763 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
764 | n/a | return XML_TOK_START_TAG_NO_ATTS; |
---|
765 | n/a | case BT_SOL: |
---|
766 | n/a | sol: |
---|
767 | n/a | ptr += MINBPC(enc); |
---|
768 | n/a | if (ptr == end) |
---|
769 | n/a | return XML_TOK_PARTIAL; |
---|
770 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
771 | n/a | *nextTokPtr = ptr; |
---|
772 | n/a | return XML_TOK_INVALID; |
---|
773 | n/a | } |
---|
774 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
775 | n/a | return XML_TOK_EMPTY_ELEMENT_NO_ATTS; |
---|
776 | n/a | default: |
---|
777 | n/a | *nextTokPtr = ptr; |
---|
778 | n/a | return XML_TOK_INVALID; |
---|
779 | n/a | } |
---|
780 | n/a | } |
---|
781 | n/a | return XML_TOK_PARTIAL; |
---|
782 | n/a | } |
---|
783 | n/a | |
---|
784 | n/a | static int PTRCALL |
---|
785 | n/a | PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, |
---|
786 | n/a | const char **nextTokPtr) |
---|
787 | n/a | { |
---|
788 | n/a | if (ptr == end) |
---|
789 | n/a | return XML_TOK_NONE; |
---|
790 | n/a | if (MINBPC(enc) > 1) { |
---|
791 | n/a | size_t n = end - ptr; |
---|
792 | n/a | if (n & (MINBPC(enc) - 1)) { |
---|
793 | n/a | n &= ~(MINBPC(enc) - 1); |
---|
794 | n/a | if (n == 0) |
---|
795 | n/a | return XML_TOK_PARTIAL; |
---|
796 | n/a | end = ptr + n; |
---|
797 | n/a | } |
---|
798 | n/a | } |
---|
799 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
800 | n/a | case BT_LT: |
---|
801 | n/a | return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
802 | n/a | case BT_AMP: |
---|
803 | n/a | return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
804 | n/a | case BT_CR: |
---|
805 | n/a | ptr += MINBPC(enc); |
---|
806 | n/a | if (ptr == end) |
---|
807 | n/a | return XML_TOK_TRAILING_CR; |
---|
808 | n/a | if (BYTE_TYPE(enc, ptr) == BT_LF) |
---|
809 | n/a | ptr += MINBPC(enc); |
---|
810 | n/a | *nextTokPtr = ptr; |
---|
811 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
812 | n/a | case BT_LF: |
---|
813 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
814 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
815 | n/a | case BT_RSQB: |
---|
816 | n/a | ptr += MINBPC(enc); |
---|
817 | n/a | if (ptr == end) |
---|
818 | n/a | return XML_TOK_TRAILING_RSQB; |
---|
819 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) |
---|
820 | n/a | break; |
---|
821 | n/a | ptr += MINBPC(enc); |
---|
822 | n/a | if (ptr == end) |
---|
823 | n/a | return XML_TOK_TRAILING_RSQB; |
---|
824 | n/a | if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
825 | n/a | ptr -= MINBPC(enc); |
---|
826 | n/a | break; |
---|
827 | n/a | } |
---|
828 | n/a | *nextTokPtr = ptr; |
---|
829 | n/a | return XML_TOK_INVALID; |
---|
830 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
831 | n/a | default: |
---|
832 | n/a | ptr += MINBPC(enc); |
---|
833 | n/a | break; |
---|
834 | n/a | } |
---|
835 | n/a | while (ptr != end) { |
---|
836 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
837 | n/a | #define LEAD_CASE(n) \ |
---|
838 | n/a | case BT_LEAD ## n: \ |
---|
839 | n/a | if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ |
---|
840 | n/a | *nextTokPtr = ptr; \ |
---|
841 | n/a | return XML_TOK_DATA_CHARS; \ |
---|
842 | n/a | } \ |
---|
843 | n/a | ptr += n; \ |
---|
844 | n/a | break; |
---|
845 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
846 | n/a | #undef LEAD_CASE |
---|
847 | n/a | case BT_RSQB: |
---|
848 | n/a | if (ptr + MINBPC(enc) != end) { |
---|
849 | n/a | if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { |
---|
850 | n/a | ptr += MINBPC(enc); |
---|
851 | n/a | break; |
---|
852 | n/a | } |
---|
853 | n/a | if (ptr + 2*MINBPC(enc) != end) { |
---|
854 | n/a | if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { |
---|
855 | n/a | ptr += MINBPC(enc); |
---|
856 | n/a | break; |
---|
857 | n/a | } |
---|
858 | n/a | *nextTokPtr = ptr + 2*MINBPC(enc); |
---|
859 | n/a | return XML_TOK_INVALID; |
---|
860 | n/a | } |
---|
861 | n/a | } |
---|
862 | n/a | /* fall through */ |
---|
863 | n/a | case BT_AMP: |
---|
864 | n/a | case BT_LT: |
---|
865 | n/a | case BT_NONXML: |
---|
866 | n/a | case BT_MALFORM: |
---|
867 | n/a | case BT_TRAIL: |
---|
868 | n/a | case BT_CR: |
---|
869 | n/a | case BT_LF: |
---|
870 | n/a | *nextTokPtr = ptr; |
---|
871 | n/a | return XML_TOK_DATA_CHARS; |
---|
872 | n/a | default: |
---|
873 | n/a | ptr += MINBPC(enc); |
---|
874 | n/a | break; |
---|
875 | n/a | } |
---|
876 | n/a | } |
---|
877 | n/a | *nextTokPtr = ptr; |
---|
878 | n/a | return XML_TOK_DATA_CHARS; |
---|
879 | n/a | } |
---|
880 | n/a | |
---|
881 | n/a | /* ptr points to character following "%" */ |
---|
882 | n/a | |
---|
883 | n/a | static int PTRCALL |
---|
884 | n/a | PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, |
---|
885 | n/a | const char **nextTokPtr) |
---|
886 | n/a | { |
---|
887 | n/a | if (ptr == end) |
---|
888 | n/a | return XML_TOK_PARTIAL; |
---|
889 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
890 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
891 | n/a | case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: |
---|
892 | n/a | *nextTokPtr = ptr; |
---|
893 | n/a | return XML_TOK_PERCENT; |
---|
894 | n/a | default: |
---|
895 | n/a | *nextTokPtr = ptr; |
---|
896 | n/a | return XML_TOK_INVALID; |
---|
897 | n/a | } |
---|
898 | n/a | while (ptr != end) { |
---|
899 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
900 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
901 | n/a | case BT_SEMI: |
---|
902 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
903 | n/a | return XML_TOK_PARAM_ENTITY_REF; |
---|
904 | n/a | default: |
---|
905 | n/a | *nextTokPtr = ptr; |
---|
906 | n/a | return XML_TOK_INVALID; |
---|
907 | n/a | } |
---|
908 | n/a | } |
---|
909 | n/a | return XML_TOK_PARTIAL; |
---|
910 | n/a | } |
---|
911 | n/a | |
---|
912 | n/a | static int PTRCALL |
---|
913 | n/a | PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, |
---|
914 | n/a | const char **nextTokPtr) |
---|
915 | n/a | { |
---|
916 | n/a | if (ptr == end) |
---|
917 | n/a | return XML_TOK_PARTIAL; |
---|
918 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
919 | n/a | CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) |
---|
920 | n/a | default: |
---|
921 | n/a | *nextTokPtr = ptr; |
---|
922 | n/a | return XML_TOK_INVALID; |
---|
923 | n/a | } |
---|
924 | n/a | while (ptr != end) { |
---|
925 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
926 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
927 | n/a | case BT_CR: case BT_LF: case BT_S: |
---|
928 | n/a | case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: |
---|
929 | n/a | *nextTokPtr = ptr; |
---|
930 | n/a | return XML_TOK_POUND_NAME; |
---|
931 | n/a | default: |
---|
932 | n/a | *nextTokPtr = ptr; |
---|
933 | n/a | return XML_TOK_INVALID; |
---|
934 | n/a | } |
---|
935 | n/a | } |
---|
936 | n/a | return -XML_TOK_POUND_NAME; |
---|
937 | n/a | } |
---|
938 | n/a | |
---|
939 | n/a | static int PTRCALL |
---|
940 | n/a | PREFIX(scanLit)(int open, const ENCODING *enc, |
---|
941 | n/a | const char *ptr, const char *end, |
---|
942 | n/a | const char **nextTokPtr) |
---|
943 | n/a | { |
---|
944 | n/a | while (ptr != end) { |
---|
945 | n/a | int t = BYTE_TYPE(enc, ptr); |
---|
946 | n/a | switch (t) { |
---|
947 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
948 | n/a | case BT_QUOT: |
---|
949 | n/a | case BT_APOS: |
---|
950 | n/a | ptr += MINBPC(enc); |
---|
951 | n/a | if (t != open) |
---|
952 | n/a | break; |
---|
953 | n/a | if (ptr == end) |
---|
954 | n/a | return -XML_TOK_LITERAL; |
---|
955 | n/a | *nextTokPtr = ptr; |
---|
956 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
957 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
958 | n/a | case BT_GT: case BT_PERCNT: case BT_LSQB: |
---|
959 | n/a | return XML_TOK_LITERAL; |
---|
960 | n/a | default: |
---|
961 | n/a | return XML_TOK_INVALID; |
---|
962 | n/a | } |
---|
963 | n/a | default: |
---|
964 | n/a | ptr += MINBPC(enc); |
---|
965 | n/a | break; |
---|
966 | n/a | } |
---|
967 | n/a | } |
---|
968 | n/a | return XML_TOK_PARTIAL; |
---|
969 | n/a | } |
---|
970 | n/a | |
---|
971 | n/a | static int PTRCALL |
---|
972 | n/a | PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, |
---|
973 | n/a | const char **nextTokPtr) |
---|
974 | n/a | { |
---|
975 | n/a | int tok; |
---|
976 | n/a | if (ptr == end) |
---|
977 | n/a | return XML_TOK_NONE; |
---|
978 | n/a | if (MINBPC(enc) > 1) { |
---|
979 | n/a | size_t n = end - ptr; |
---|
980 | n/a | if (n & (MINBPC(enc) - 1)) { |
---|
981 | n/a | n &= ~(MINBPC(enc) - 1); |
---|
982 | n/a | if (n == 0) |
---|
983 | n/a | return XML_TOK_PARTIAL; |
---|
984 | n/a | end = ptr + n; |
---|
985 | n/a | } |
---|
986 | n/a | } |
---|
987 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
988 | n/a | case BT_QUOT: |
---|
989 | n/a | return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
990 | n/a | case BT_APOS: |
---|
991 | n/a | return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
992 | n/a | case BT_LT: |
---|
993 | n/a | { |
---|
994 | n/a | ptr += MINBPC(enc); |
---|
995 | n/a | if (ptr == end) |
---|
996 | n/a | return XML_TOK_PARTIAL; |
---|
997 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
998 | n/a | case BT_EXCL: |
---|
999 | n/a | return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1000 | n/a | case BT_QUEST: |
---|
1001 | n/a | return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1002 | n/a | case BT_NMSTRT: |
---|
1003 | n/a | case BT_HEX: |
---|
1004 | n/a | case BT_NONASCII: |
---|
1005 | n/a | case BT_LEAD2: |
---|
1006 | n/a | case BT_LEAD3: |
---|
1007 | n/a | case BT_LEAD4: |
---|
1008 | n/a | *nextTokPtr = ptr - MINBPC(enc); |
---|
1009 | n/a | return XML_TOK_INSTANCE_START; |
---|
1010 | n/a | } |
---|
1011 | n/a | *nextTokPtr = ptr; |
---|
1012 | n/a | return XML_TOK_INVALID; |
---|
1013 | n/a | } |
---|
1014 | n/a | case BT_CR: |
---|
1015 | n/a | if (ptr + MINBPC(enc) == end) { |
---|
1016 | n/a | *nextTokPtr = end; |
---|
1017 | n/a | /* indicate that this might be part of a CR/LF pair */ |
---|
1018 | n/a | return -XML_TOK_PROLOG_S; |
---|
1019 | n/a | } |
---|
1020 | n/a | /* fall through */ |
---|
1021 | n/a | case BT_S: case BT_LF: |
---|
1022 | n/a | for (;;) { |
---|
1023 | n/a | ptr += MINBPC(enc); |
---|
1024 | n/a | if (ptr == end) |
---|
1025 | n/a | break; |
---|
1026 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1027 | n/a | case BT_S: case BT_LF: |
---|
1028 | n/a | break; |
---|
1029 | n/a | case BT_CR: |
---|
1030 | n/a | /* don't split CR/LF pair */ |
---|
1031 | n/a | if (ptr + MINBPC(enc) != end) |
---|
1032 | n/a | break; |
---|
1033 | n/a | /* fall through */ |
---|
1034 | n/a | default: |
---|
1035 | n/a | *nextTokPtr = ptr; |
---|
1036 | n/a | return XML_TOK_PROLOG_S; |
---|
1037 | n/a | } |
---|
1038 | n/a | } |
---|
1039 | n/a | *nextTokPtr = ptr; |
---|
1040 | n/a | return XML_TOK_PROLOG_S; |
---|
1041 | n/a | case BT_PERCNT: |
---|
1042 | n/a | return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1043 | n/a | case BT_COMMA: |
---|
1044 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1045 | n/a | return XML_TOK_COMMA; |
---|
1046 | n/a | case BT_LSQB: |
---|
1047 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1048 | n/a | return XML_TOK_OPEN_BRACKET; |
---|
1049 | n/a | case BT_RSQB: |
---|
1050 | n/a | ptr += MINBPC(enc); |
---|
1051 | n/a | if (ptr == end) |
---|
1052 | n/a | return -XML_TOK_CLOSE_BRACKET; |
---|
1053 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { |
---|
1054 | n/a | if (ptr + MINBPC(enc) == end) |
---|
1055 | n/a | return XML_TOK_PARTIAL; |
---|
1056 | n/a | if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { |
---|
1057 | n/a | *nextTokPtr = ptr + 2*MINBPC(enc); |
---|
1058 | n/a | return XML_TOK_COND_SECT_CLOSE; |
---|
1059 | n/a | } |
---|
1060 | n/a | } |
---|
1061 | n/a | *nextTokPtr = ptr; |
---|
1062 | n/a | return XML_TOK_CLOSE_BRACKET; |
---|
1063 | n/a | case BT_LPAR: |
---|
1064 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1065 | n/a | return XML_TOK_OPEN_PAREN; |
---|
1066 | n/a | case BT_RPAR: |
---|
1067 | n/a | ptr += MINBPC(enc); |
---|
1068 | n/a | if (ptr == end) |
---|
1069 | n/a | return -XML_TOK_CLOSE_PAREN; |
---|
1070 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1071 | n/a | case BT_AST: |
---|
1072 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1073 | n/a | return XML_TOK_CLOSE_PAREN_ASTERISK; |
---|
1074 | n/a | case BT_QUEST: |
---|
1075 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1076 | n/a | return XML_TOK_CLOSE_PAREN_QUESTION; |
---|
1077 | n/a | case BT_PLUS: |
---|
1078 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1079 | n/a | return XML_TOK_CLOSE_PAREN_PLUS; |
---|
1080 | n/a | case BT_CR: case BT_LF: case BT_S: |
---|
1081 | n/a | case BT_GT: case BT_COMMA: case BT_VERBAR: |
---|
1082 | n/a | case BT_RPAR: |
---|
1083 | n/a | *nextTokPtr = ptr; |
---|
1084 | n/a | return XML_TOK_CLOSE_PAREN; |
---|
1085 | n/a | } |
---|
1086 | n/a | *nextTokPtr = ptr; |
---|
1087 | n/a | return XML_TOK_INVALID; |
---|
1088 | n/a | case BT_VERBAR: |
---|
1089 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1090 | n/a | return XML_TOK_OR; |
---|
1091 | n/a | case BT_GT: |
---|
1092 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1093 | n/a | return XML_TOK_DECL_CLOSE; |
---|
1094 | n/a | case BT_NUM: |
---|
1095 | n/a | return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1096 | n/a | #define LEAD_CASE(n) \ |
---|
1097 | n/a | case BT_LEAD ## n: \ |
---|
1098 | n/a | if (end - ptr < n) \ |
---|
1099 | n/a | return XML_TOK_PARTIAL_CHAR; \ |
---|
1100 | n/a | if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ |
---|
1101 | n/a | ptr += n; \ |
---|
1102 | n/a | tok = XML_TOK_NAME; \ |
---|
1103 | n/a | break; \ |
---|
1104 | n/a | } \ |
---|
1105 | n/a | if (IS_NAME_CHAR(enc, ptr, n)) { \ |
---|
1106 | n/a | ptr += n; \ |
---|
1107 | n/a | tok = XML_TOK_NMTOKEN; \ |
---|
1108 | n/a | break; \ |
---|
1109 | n/a | } \ |
---|
1110 | n/a | *nextTokPtr = ptr; \ |
---|
1111 | n/a | return XML_TOK_INVALID; |
---|
1112 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1113 | n/a | #undef LEAD_CASE |
---|
1114 | n/a | case BT_NMSTRT: |
---|
1115 | n/a | case BT_HEX: |
---|
1116 | n/a | tok = XML_TOK_NAME; |
---|
1117 | n/a | ptr += MINBPC(enc); |
---|
1118 | n/a | break; |
---|
1119 | n/a | case BT_DIGIT: |
---|
1120 | n/a | case BT_NAME: |
---|
1121 | n/a | case BT_MINUS: |
---|
1122 | n/a | #ifdef XML_NS |
---|
1123 | n/a | case BT_COLON: |
---|
1124 | n/a | #endif |
---|
1125 | n/a | tok = XML_TOK_NMTOKEN; |
---|
1126 | n/a | ptr += MINBPC(enc); |
---|
1127 | n/a | break; |
---|
1128 | n/a | case BT_NONASCII: |
---|
1129 | n/a | if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { |
---|
1130 | n/a | ptr += MINBPC(enc); |
---|
1131 | n/a | tok = XML_TOK_NAME; |
---|
1132 | n/a | break; |
---|
1133 | n/a | } |
---|
1134 | n/a | if (IS_NAME_CHAR_MINBPC(enc, ptr)) { |
---|
1135 | n/a | ptr += MINBPC(enc); |
---|
1136 | n/a | tok = XML_TOK_NMTOKEN; |
---|
1137 | n/a | break; |
---|
1138 | n/a | } |
---|
1139 | n/a | /* fall through */ |
---|
1140 | n/a | default: |
---|
1141 | n/a | *nextTokPtr = ptr; |
---|
1142 | n/a | return XML_TOK_INVALID; |
---|
1143 | n/a | } |
---|
1144 | n/a | while (ptr != end) { |
---|
1145 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1146 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
1147 | n/a | case BT_GT: case BT_RPAR: case BT_COMMA: |
---|
1148 | n/a | case BT_VERBAR: case BT_LSQB: case BT_PERCNT: |
---|
1149 | n/a | case BT_S: case BT_CR: case BT_LF: |
---|
1150 | n/a | *nextTokPtr = ptr; |
---|
1151 | n/a | return tok; |
---|
1152 | n/a | #ifdef XML_NS |
---|
1153 | n/a | case BT_COLON: |
---|
1154 | n/a | ptr += MINBPC(enc); |
---|
1155 | n/a | switch (tok) { |
---|
1156 | n/a | case XML_TOK_NAME: |
---|
1157 | n/a | if (ptr == end) |
---|
1158 | n/a | return XML_TOK_PARTIAL; |
---|
1159 | n/a | tok = XML_TOK_PREFIXED_NAME; |
---|
1160 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1161 | n/a | CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) |
---|
1162 | n/a | default: |
---|
1163 | n/a | tok = XML_TOK_NMTOKEN; |
---|
1164 | n/a | break; |
---|
1165 | n/a | } |
---|
1166 | n/a | break; |
---|
1167 | n/a | case XML_TOK_PREFIXED_NAME: |
---|
1168 | n/a | tok = XML_TOK_NMTOKEN; |
---|
1169 | n/a | break; |
---|
1170 | n/a | } |
---|
1171 | n/a | break; |
---|
1172 | n/a | #endif |
---|
1173 | n/a | case BT_PLUS: |
---|
1174 | n/a | if (tok == XML_TOK_NMTOKEN) { |
---|
1175 | n/a | *nextTokPtr = ptr; |
---|
1176 | n/a | return XML_TOK_INVALID; |
---|
1177 | n/a | } |
---|
1178 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1179 | n/a | return XML_TOK_NAME_PLUS; |
---|
1180 | n/a | case BT_AST: |
---|
1181 | n/a | if (tok == XML_TOK_NMTOKEN) { |
---|
1182 | n/a | *nextTokPtr = ptr; |
---|
1183 | n/a | return XML_TOK_INVALID; |
---|
1184 | n/a | } |
---|
1185 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1186 | n/a | return XML_TOK_NAME_ASTERISK; |
---|
1187 | n/a | case BT_QUEST: |
---|
1188 | n/a | if (tok == XML_TOK_NMTOKEN) { |
---|
1189 | n/a | *nextTokPtr = ptr; |
---|
1190 | n/a | return XML_TOK_INVALID; |
---|
1191 | n/a | } |
---|
1192 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1193 | n/a | return XML_TOK_NAME_QUESTION; |
---|
1194 | n/a | default: |
---|
1195 | n/a | *nextTokPtr = ptr; |
---|
1196 | n/a | return XML_TOK_INVALID; |
---|
1197 | n/a | } |
---|
1198 | n/a | } |
---|
1199 | n/a | return -tok; |
---|
1200 | n/a | } |
---|
1201 | n/a | |
---|
1202 | n/a | static int PTRCALL |
---|
1203 | n/a | PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, |
---|
1204 | n/a | const char *end, const char **nextTokPtr) |
---|
1205 | n/a | { |
---|
1206 | n/a | const char *start; |
---|
1207 | n/a | if (ptr == end) |
---|
1208 | n/a | return XML_TOK_NONE; |
---|
1209 | n/a | start = ptr; |
---|
1210 | n/a | while (ptr != end) { |
---|
1211 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1212 | n/a | #define LEAD_CASE(n) \ |
---|
1213 | n/a | case BT_LEAD ## n: ptr += n; break; |
---|
1214 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1215 | n/a | #undef LEAD_CASE |
---|
1216 | n/a | case BT_AMP: |
---|
1217 | n/a | if (ptr == start) |
---|
1218 | n/a | return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1219 | n/a | *nextTokPtr = ptr; |
---|
1220 | n/a | return XML_TOK_DATA_CHARS; |
---|
1221 | n/a | case BT_LT: |
---|
1222 | n/a | /* this is for inside entity references */ |
---|
1223 | n/a | *nextTokPtr = ptr; |
---|
1224 | n/a | return XML_TOK_INVALID; |
---|
1225 | n/a | case BT_LF: |
---|
1226 | n/a | if (ptr == start) { |
---|
1227 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1228 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
1229 | n/a | } |
---|
1230 | n/a | *nextTokPtr = ptr; |
---|
1231 | n/a | return XML_TOK_DATA_CHARS; |
---|
1232 | n/a | case BT_CR: |
---|
1233 | n/a | if (ptr == start) { |
---|
1234 | n/a | ptr += MINBPC(enc); |
---|
1235 | n/a | if (ptr == end) |
---|
1236 | n/a | return XML_TOK_TRAILING_CR; |
---|
1237 | n/a | if (BYTE_TYPE(enc, ptr) == BT_LF) |
---|
1238 | n/a | ptr += MINBPC(enc); |
---|
1239 | n/a | *nextTokPtr = ptr; |
---|
1240 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
1241 | n/a | } |
---|
1242 | n/a | *nextTokPtr = ptr; |
---|
1243 | n/a | return XML_TOK_DATA_CHARS; |
---|
1244 | n/a | case BT_S: |
---|
1245 | n/a | if (ptr == start) { |
---|
1246 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1247 | n/a | return XML_TOK_ATTRIBUTE_VALUE_S; |
---|
1248 | n/a | } |
---|
1249 | n/a | *nextTokPtr = ptr; |
---|
1250 | n/a | return XML_TOK_DATA_CHARS; |
---|
1251 | n/a | default: |
---|
1252 | n/a | ptr += MINBPC(enc); |
---|
1253 | n/a | break; |
---|
1254 | n/a | } |
---|
1255 | n/a | } |
---|
1256 | n/a | *nextTokPtr = ptr; |
---|
1257 | n/a | return XML_TOK_DATA_CHARS; |
---|
1258 | n/a | } |
---|
1259 | n/a | |
---|
1260 | n/a | static int PTRCALL |
---|
1261 | n/a | PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, |
---|
1262 | n/a | const char *end, const char **nextTokPtr) |
---|
1263 | n/a | { |
---|
1264 | n/a | const char *start; |
---|
1265 | n/a | if (ptr == end) |
---|
1266 | n/a | return XML_TOK_NONE; |
---|
1267 | n/a | start = ptr; |
---|
1268 | n/a | while (ptr != end) { |
---|
1269 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1270 | n/a | #define LEAD_CASE(n) \ |
---|
1271 | n/a | case BT_LEAD ## n: ptr += n; break; |
---|
1272 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1273 | n/a | #undef LEAD_CASE |
---|
1274 | n/a | case BT_AMP: |
---|
1275 | n/a | if (ptr == start) |
---|
1276 | n/a | return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); |
---|
1277 | n/a | *nextTokPtr = ptr; |
---|
1278 | n/a | return XML_TOK_DATA_CHARS; |
---|
1279 | n/a | case BT_PERCNT: |
---|
1280 | n/a | if (ptr == start) { |
---|
1281 | n/a | int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), |
---|
1282 | n/a | end, nextTokPtr); |
---|
1283 | n/a | return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; |
---|
1284 | n/a | } |
---|
1285 | n/a | *nextTokPtr = ptr; |
---|
1286 | n/a | return XML_TOK_DATA_CHARS; |
---|
1287 | n/a | case BT_LF: |
---|
1288 | n/a | if (ptr == start) { |
---|
1289 | n/a | *nextTokPtr = ptr + MINBPC(enc); |
---|
1290 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
1291 | n/a | } |
---|
1292 | n/a | *nextTokPtr = ptr; |
---|
1293 | n/a | return XML_TOK_DATA_CHARS; |
---|
1294 | n/a | case BT_CR: |
---|
1295 | n/a | if (ptr == start) { |
---|
1296 | n/a | ptr += MINBPC(enc); |
---|
1297 | n/a | if (ptr == end) |
---|
1298 | n/a | return XML_TOK_TRAILING_CR; |
---|
1299 | n/a | if (BYTE_TYPE(enc, ptr) == BT_LF) |
---|
1300 | n/a | ptr += MINBPC(enc); |
---|
1301 | n/a | *nextTokPtr = ptr; |
---|
1302 | n/a | return XML_TOK_DATA_NEWLINE; |
---|
1303 | n/a | } |
---|
1304 | n/a | *nextTokPtr = ptr; |
---|
1305 | n/a | return XML_TOK_DATA_CHARS; |
---|
1306 | n/a | default: |
---|
1307 | n/a | ptr += MINBPC(enc); |
---|
1308 | n/a | break; |
---|
1309 | n/a | } |
---|
1310 | n/a | } |
---|
1311 | n/a | *nextTokPtr = ptr; |
---|
1312 | n/a | return XML_TOK_DATA_CHARS; |
---|
1313 | n/a | } |
---|
1314 | n/a | |
---|
1315 | n/a | #ifdef XML_DTD |
---|
1316 | n/a | |
---|
1317 | n/a | static int PTRCALL |
---|
1318 | n/a | PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, |
---|
1319 | n/a | const char *end, const char **nextTokPtr) |
---|
1320 | n/a | { |
---|
1321 | n/a | int level = 0; |
---|
1322 | n/a | if (MINBPC(enc) > 1) { |
---|
1323 | n/a | size_t n = end - ptr; |
---|
1324 | n/a | if (n & (MINBPC(enc) - 1)) { |
---|
1325 | n/a | n &= ~(MINBPC(enc) - 1); |
---|
1326 | n/a | end = ptr + n; |
---|
1327 | n/a | } |
---|
1328 | n/a | } |
---|
1329 | n/a | while (ptr != end) { |
---|
1330 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1331 | n/a | INVALID_CASES(ptr, nextTokPtr) |
---|
1332 | n/a | case BT_LT: |
---|
1333 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
1334 | n/a | return XML_TOK_PARTIAL; |
---|
1335 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { |
---|
1336 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
1337 | n/a | return XML_TOK_PARTIAL; |
---|
1338 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { |
---|
1339 | n/a | ++level; |
---|
1340 | n/a | ptr += MINBPC(enc); |
---|
1341 | n/a | } |
---|
1342 | n/a | } |
---|
1343 | n/a | break; |
---|
1344 | n/a | case BT_RSQB: |
---|
1345 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
1346 | n/a | return XML_TOK_PARTIAL; |
---|
1347 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { |
---|
1348 | n/a | if ((ptr += MINBPC(enc)) == end) |
---|
1349 | n/a | return XML_TOK_PARTIAL; |
---|
1350 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { |
---|
1351 | n/a | ptr += MINBPC(enc); |
---|
1352 | n/a | if (level == 0) { |
---|
1353 | n/a | *nextTokPtr = ptr; |
---|
1354 | n/a | return XML_TOK_IGNORE_SECT; |
---|
1355 | n/a | } |
---|
1356 | n/a | --level; |
---|
1357 | n/a | } |
---|
1358 | n/a | } |
---|
1359 | n/a | break; |
---|
1360 | n/a | default: |
---|
1361 | n/a | ptr += MINBPC(enc); |
---|
1362 | n/a | break; |
---|
1363 | n/a | } |
---|
1364 | n/a | } |
---|
1365 | n/a | return XML_TOK_PARTIAL; |
---|
1366 | n/a | } |
---|
1367 | n/a | |
---|
1368 | n/a | #endif /* XML_DTD */ |
---|
1369 | n/a | |
---|
1370 | n/a | static int PTRCALL |
---|
1371 | n/a | PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, |
---|
1372 | n/a | const char **badPtr) |
---|
1373 | n/a | { |
---|
1374 | n/a | ptr += MINBPC(enc); |
---|
1375 | n/a | end -= MINBPC(enc); |
---|
1376 | n/a | for (; ptr != end; ptr += MINBPC(enc)) { |
---|
1377 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1378 | n/a | case BT_DIGIT: |
---|
1379 | n/a | case BT_HEX: |
---|
1380 | n/a | case BT_MINUS: |
---|
1381 | n/a | case BT_APOS: |
---|
1382 | n/a | case BT_LPAR: |
---|
1383 | n/a | case BT_RPAR: |
---|
1384 | n/a | case BT_PLUS: |
---|
1385 | n/a | case BT_COMMA: |
---|
1386 | n/a | case BT_SOL: |
---|
1387 | n/a | case BT_EQUALS: |
---|
1388 | n/a | case BT_QUEST: |
---|
1389 | n/a | case BT_CR: |
---|
1390 | n/a | case BT_LF: |
---|
1391 | n/a | case BT_SEMI: |
---|
1392 | n/a | case BT_EXCL: |
---|
1393 | n/a | case BT_AST: |
---|
1394 | n/a | case BT_PERCNT: |
---|
1395 | n/a | case BT_NUM: |
---|
1396 | n/a | #ifdef XML_NS |
---|
1397 | n/a | case BT_COLON: |
---|
1398 | n/a | #endif |
---|
1399 | n/a | break; |
---|
1400 | n/a | case BT_S: |
---|
1401 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { |
---|
1402 | n/a | *badPtr = ptr; |
---|
1403 | n/a | return 0; |
---|
1404 | n/a | } |
---|
1405 | n/a | break; |
---|
1406 | n/a | case BT_NAME: |
---|
1407 | n/a | case BT_NMSTRT: |
---|
1408 | n/a | if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) |
---|
1409 | n/a | break; |
---|
1410 | n/a | default: |
---|
1411 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
1412 | n/a | case 0x24: /* $ */ |
---|
1413 | n/a | case 0x40: /* @ */ |
---|
1414 | n/a | break; |
---|
1415 | n/a | default: |
---|
1416 | n/a | *badPtr = ptr; |
---|
1417 | n/a | return 0; |
---|
1418 | n/a | } |
---|
1419 | n/a | break; |
---|
1420 | n/a | } |
---|
1421 | n/a | } |
---|
1422 | n/a | return 1; |
---|
1423 | n/a | } |
---|
1424 | n/a | |
---|
1425 | n/a | /* This must only be called for a well-formed start-tag or empty |
---|
1426 | n/a | element tag. Returns the number of attributes. Pointers to the |
---|
1427 | n/a | first attsMax attributes are stored in atts. |
---|
1428 | n/a | */ |
---|
1429 | n/a | |
---|
1430 | n/a | static int PTRCALL |
---|
1431 | n/a | PREFIX(getAtts)(const ENCODING *enc, const char *ptr, |
---|
1432 | n/a | int attsMax, ATTRIBUTE *atts) |
---|
1433 | n/a | { |
---|
1434 | n/a | enum { other, inName, inValue } state = inName; |
---|
1435 | n/a | int nAtts = 0; |
---|
1436 | n/a | int open = 0; /* defined when state == inValue; |
---|
1437 | n/a | initialization just to shut up compilers */ |
---|
1438 | n/a | |
---|
1439 | n/a | for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { |
---|
1440 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1441 | n/a | #define START_NAME \ |
---|
1442 | n/a | if (state == other) { \ |
---|
1443 | n/a | if (nAtts < attsMax) { \ |
---|
1444 | n/a | atts[nAtts].name = ptr; \ |
---|
1445 | n/a | atts[nAtts].normalized = 1; \ |
---|
1446 | n/a | } \ |
---|
1447 | n/a | state = inName; \ |
---|
1448 | n/a | } |
---|
1449 | n/a | #define LEAD_CASE(n) \ |
---|
1450 | n/a | case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; |
---|
1451 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1452 | n/a | #undef LEAD_CASE |
---|
1453 | n/a | case BT_NONASCII: |
---|
1454 | n/a | case BT_NMSTRT: |
---|
1455 | n/a | case BT_HEX: |
---|
1456 | n/a | START_NAME |
---|
1457 | n/a | break; |
---|
1458 | n/a | #undef START_NAME |
---|
1459 | n/a | case BT_QUOT: |
---|
1460 | n/a | if (state != inValue) { |
---|
1461 | n/a | if (nAtts < attsMax) |
---|
1462 | n/a | atts[nAtts].valuePtr = ptr + MINBPC(enc); |
---|
1463 | n/a | state = inValue; |
---|
1464 | n/a | open = BT_QUOT; |
---|
1465 | n/a | } |
---|
1466 | n/a | else if (open == BT_QUOT) { |
---|
1467 | n/a | state = other; |
---|
1468 | n/a | if (nAtts < attsMax) |
---|
1469 | n/a | atts[nAtts].valueEnd = ptr; |
---|
1470 | n/a | nAtts++; |
---|
1471 | n/a | } |
---|
1472 | n/a | break; |
---|
1473 | n/a | case BT_APOS: |
---|
1474 | n/a | if (state != inValue) { |
---|
1475 | n/a | if (nAtts < attsMax) |
---|
1476 | n/a | atts[nAtts].valuePtr = ptr + MINBPC(enc); |
---|
1477 | n/a | state = inValue; |
---|
1478 | n/a | open = BT_APOS; |
---|
1479 | n/a | } |
---|
1480 | n/a | else if (open == BT_APOS) { |
---|
1481 | n/a | state = other; |
---|
1482 | n/a | if (nAtts < attsMax) |
---|
1483 | n/a | atts[nAtts].valueEnd = ptr; |
---|
1484 | n/a | nAtts++; |
---|
1485 | n/a | } |
---|
1486 | n/a | break; |
---|
1487 | n/a | case BT_AMP: |
---|
1488 | n/a | if (nAtts < attsMax) |
---|
1489 | n/a | atts[nAtts].normalized = 0; |
---|
1490 | n/a | break; |
---|
1491 | n/a | case BT_S: |
---|
1492 | n/a | if (state == inName) |
---|
1493 | n/a | state = other; |
---|
1494 | n/a | else if (state == inValue |
---|
1495 | n/a | && nAtts < attsMax |
---|
1496 | n/a | && atts[nAtts].normalized |
---|
1497 | n/a | && (ptr == atts[nAtts].valuePtr |
---|
1498 | n/a | || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE |
---|
1499 | n/a | || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE |
---|
1500 | n/a | || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) |
---|
1501 | n/a | atts[nAtts].normalized = 0; |
---|
1502 | n/a | break; |
---|
1503 | n/a | case BT_CR: case BT_LF: |
---|
1504 | n/a | /* This case ensures that the first attribute name is counted |
---|
1505 | n/a | Apart from that we could just change state on the quote. */ |
---|
1506 | n/a | if (state == inName) |
---|
1507 | n/a | state = other; |
---|
1508 | n/a | else if (state == inValue && nAtts < attsMax) |
---|
1509 | n/a | atts[nAtts].normalized = 0; |
---|
1510 | n/a | break; |
---|
1511 | n/a | case BT_GT: |
---|
1512 | n/a | case BT_SOL: |
---|
1513 | n/a | if (state != inValue) |
---|
1514 | n/a | return nAtts; |
---|
1515 | n/a | break; |
---|
1516 | n/a | default: |
---|
1517 | n/a | break; |
---|
1518 | n/a | } |
---|
1519 | n/a | } |
---|
1520 | n/a | /* not reached */ |
---|
1521 | n/a | } |
---|
1522 | n/a | |
---|
1523 | n/a | static int PTRFASTCALL |
---|
1524 | n/a | PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) |
---|
1525 | n/a | { |
---|
1526 | n/a | int result = 0; |
---|
1527 | n/a | /* skip &# */ |
---|
1528 | n/a | ptr += 2*MINBPC(enc); |
---|
1529 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_x)) { |
---|
1530 | n/a | for (ptr += MINBPC(enc); |
---|
1531 | n/a | !CHAR_MATCHES(enc, ptr, ASCII_SEMI); |
---|
1532 | n/a | ptr += MINBPC(enc)) { |
---|
1533 | n/a | int c = BYTE_TO_ASCII(enc, ptr); |
---|
1534 | n/a | switch (c) { |
---|
1535 | n/a | case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: |
---|
1536 | n/a | case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: |
---|
1537 | n/a | result <<= 4; |
---|
1538 | n/a | result |= (c - ASCII_0); |
---|
1539 | n/a | break; |
---|
1540 | n/a | case ASCII_A: case ASCII_B: case ASCII_C: |
---|
1541 | n/a | case ASCII_D: case ASCII_E: case ASCII_F: |
---|
1542 | n/a | result <<= 4; |
---|
1543 | n/a | result += 10 + (c - ASCII_A); |
---|
1544 | n/a | break; |
---|
1545 | n/a | case ASCII_a: case ASCII_b: case ASCII_c: |
---|
1546 | n/a | case ASCII_d: case ASCII_e: case ASCII_f: |
---|
1547 | n/a | result <<= 4; |
---|
1548 | n/a | result += 10 + (c - ASCII_a); |
---|
1549 | n/a | break; |
---|
1550 | n/a | } |
---|
1551 | n/a | if (result >= 0x110000) |
---|
1552 | n/a | return -1; |
---|
1553 | n/a | } |
---|
1554 | n/a | } |
---|
1555 | n/a | else { |
---|
1556 | n/a | for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { |
---|
1557 | n/a | int c = BYTE_TO_ASCII(enc, ptr); |
---|
1558 | n/a | result *= 10; |
---|
1559 | n/a | result += (c - ASCII_0); |
---|
1560 | n/a | if (result >= 0x110000) |
---|
1561 | n/a | return -1; |
---|
1562 | n/a | } |
---|
1563 | n/a | } |
---|
1564 | n/a | return checkCharRefNumber(result); |
---|
1565 | n/a | } |
---|
1566 | n/a | |
---|
1567 | n/a | static int PTRCALL |
---|
1568 | n/a | PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, |
---|
1569 | n/a | const char *end) |
---|
1570 | n/a | { |
---|
1571 | n/a | switch ((end - ptr)/MINBPC(enc)) { |
---|
1572 | n/a | case 2: |
---|
1573 | n/a | if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { |
---|
1574 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
1575 | n/a | case ASCII_l: |
---|
1576 | n/a | return ASCII_LT; |
---|
1577 | n/a | case ASCII_g: |
---|
1578 | n/a | return ASCII_GT; |
---|
1579 | n/a | } |
---|
1580 | n/a | } |
---|
1581 | n/a | break; |
---|
1582 | n/a | case 3: |
---|
1583 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_a)) { |
---|
1584 | n/a | ptr += MINBPC(enc); |
---|
1585 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_m)) { |
---|
1586 | n/a | ptr += MINBPC(enc); |
---|
1587 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_p)) |
---|
1588 | n/a | return ASCII_AMP; |
---|
1589 | n/a | } |
---|
1590 | n/a | } |
---|
1591 | n/a | break; |
---|
1592 | n/a | case 4: |
---|
1593 | n/a | switch (BYTE_TO_ASCII(enc, ptr)) { |
---|
1594 | n/a | case ASCII_q: |
---|
1595 | n/a | ptr += MINBPC(enc); |
---|
1596 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_u)) { |
---|
1597 | n/a | ptr += MINBPC(enc); |
---|
1598 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_o)) { |
---|
1599 | n/a | ptr += MINBPC(enc); |
---|
1600 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_t)) |
---|
1601 | n/a | return ASCII_QUOT; |
---|
1602 | n/a | } |
---|
1603 | n/a | } |
---|
1604 | n/a | break; |
---|
1605 | n/a | case ASCII_a: |
---|
1606 | n/a | ptr += MINBPC(enc); |
---|
1607 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_p)) { |
---|
1608 | n/a | ptr += MINBPC(enc); |
---|
1609 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_o)) { |
---|
1610 | n/a | ptr += MINBPC(enc); |
---|
1611 | n/a | if (CHAR_MATCHES(enc, ptr, ASCII_s)) |
---|
1612 | n/a | return ASCII_APOS; |
---|
1613 | n/a | } |
---|
1614 | n/a | } |
---|
1615 | n/a | break; |
---|
1616 | n/a | } |
---|
1617 | n/a | } |
---|
1618 | n/a | return 0; |
---|
1619 | n/a | } |
---|
1620 | n/a | |
---|
1621 | n/a | static int PTRCALL |
---|
1622 | n/a | PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) |
---|
1623 | n/a | { |
---|
1624 | n/a | for (;;) { |
---|
1625 | n/a | switch (BYTE_TYPE(enc, ptr1)) { |
---|
1626 | n/a | #define LEAD_CASE(n) \ |
---|
1627 | n/a | case BT_LEAD ## n: \ |
---|
1628 | n/a | if (*ptr1++ != *ptr2++) \ |
---|
1629 | n/a | return 0; |
---|
1630 | n/a | LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2) |
---|
1631 | n/a | #undef LEAD_CASE |
---|
1632 | n/a | /* fall through */ |
---|
1633 | n/a | if (*ptr1++ != *ptr2++) |
---|
1634 | n/a | return 0; |
---|
1635 | n/a | break; |
---|
1636 | n/a | case BT_NONASCII: |
---|
1637 | n/a | case BT_NMSTRT: |
---|
1638 | n/a | #ifdef XML_NS |
---|
1639 | n/a | case BT_COLON: |
---|
1640 | n/a | #endif |
---|
1641 | n/a | case BT_HEX: |
---|
1642 | n/a | case BT_DIGIT: |
---|
1643 | n/a | case BT_NAME: |
---|
1644 | n/a | case BT_MINUS: |
---|
1645 | n/a | if (*ptr2++ != *ptr1++) |
---|
1646 | n/a | return 0; |
---|
1647 | n/a | if (MINBPC(enc) > 1) { |
---|
1648 | n/a | if (*ptr2++ != *ptr1++) |
---|
1649 | n/a | return 0; |
---|
1650 | n/a | if (MINBPC(enc) > 2) { |
---|
1651 | n/a | if (*ptr2++ != *ptr1++) |
---|
1652 | n/a | return 0; |
---|
1653 | n/a | if (MINBPC(enc) > 3) { |
---|
1654 | n/a | if (*ptr2++ != *ptr1++) |
---|
1655 | n/a | return 0; |
---|
1656 | n/a | } |
---|
1657 | n/a | } |
---|
1658 | n/a | } |
---|
1659 | n/a | break; |
---|
1660 | n/a | default: |
---|
1661 | n/a | if (MINBPC(enc) == 1 && *ptr1 == *ptr2) |
---|
1662 | n/a | return 1; |
---|
1663 | n/a | switch (BYTE_TYPE(enc, ptr2)) { |
---|
1664 | n/a | case BT_LEAD2: |
---|
1665 | n/a | case BT_LEAD3: |
---|
1666 | n/a | case BT_LEAD4: |
---|
1667 | n/a | case BT_NONASCII: |
---|
1668 | n/a | case BT_NMSTRT: |
---|
1669 | n/a | #ifdef XML_NS |
---|
1670 | n/a | case BT_COLON: |
---|
1671 | n/a | #endif |
---|
1672 | n/a | case BT_HEX: |
---|
1673 | n/a | case BT_DIGIT: |
---|
1674 | n/a | case BT_NAME: |
---|
1675 | n/a | case BT_MINUS: |
---|
1676 | n/a | return 0; |
---|
1677 | n/a | default: |
---|
1678 | n/a | return 1; |
---|
1679 | n/a | } |
---|
1680 | n/a | } |
---|
1681 | n/a | } |
---|
1682 | n/a | /* not reached */ |
---|
1683 | n/a | } |
---|
1684 | n/a | |
---|
1685 | n/a | static int PTRCALL |
---|
1686 | n/a | PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, |
---|
1687 | n/a | const char *end1, const char *ptr2) |
---|
1688 | n/a | { |
---|
1689 | n/a | for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { |
---|
1690 | n/a | if (ptr1 == end1) |
---|
1691 | n/a | return 0; |
---|
1692 | n/a | if (!CHAR_MATCHES(enc, ptr1, *ptr2)) |
---|
1693 | n/a | return 0; |
---|
1694 | n/a | } |
---|
1695 | n/a | return ptr1 == end1; |
---|
1696 | n/a | } |
---|
1697 | n/a | |
---|
1698 | n/a | static int PTRFASTCALL |
---|
1699 | n/a | PREFIX(nameLength)(const ENCODING *enc, const char *ptr) |
---|
1700 | n/a | { |
---|
1701 | n/a | const char *start = ptr; |
---|
1702 | n/a | for (;;) { |
---|
1703 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1704 | n/a | #define LEAD_CASE(n) \ |
---|
1705 | n/a | case BT_LEAD ## n: ptr += n; break; |
---|
1706 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1707 | n/a | #undef LEAD_CASE |
---|
1708 | n/a | case BT_NONASCII: |
---|
1709 | n/a | case BT_NMSTRT: |
---|
1710 | n/a | #ifdef XML_NS |
---|
1711 | n/a | case BT_COLON: |
---|
1712 | n/a | #endif |
---|
1713 | n/a | case BT_HEX: |
---|
1714 | n/a | case BT_DIGIT: |
---|
1715 | n/a | case BT_NAME: |
---|
1716 | n/a | case BT_MINUS: |
---|
1717 | n/a | ptr += MINBPC(enc); |
---|
1718 | n/a | break; |
---|
1719 | n/a | default: |
---|
1720 | n/a | return (int)(ptr - start); |
---|
1721 | n/a | } |
---|
1722 | n/a | } |
---|
1723 | n/a | } |
---|
1724 | n/a | |
---|
1725 | n/a | static const char * PTRFASTCALL |
---|
1726 | n/a | PREFIX(skipS)(const ENCODING *enc, const char *ptr) |
---|
1727 | n/a | { |
---|
1728 | n/a | for (;;) { |
---|
1729 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1730 | n/a | case BT_LF: |
---|
1731 | n/a | case BT_CR: |
---|
1732 | n/a | case BT_S: |
---|
1733 | n/a | ptr += MINBPC(enc); |
---|
1734 | n/a | break; |
---|
1735 | n/a | default: |
---|
1736 | n/a | return ptr; |
---|
1737 | n/a | } |
---|
1738 | n/a | } |
---|
1739 | n/a | } |
---|
1740 | n/a | |
---|
1741 | n/a | static void PTRCALL |
---|
1742 | n/a | PREFIX(updatePosition)(const ENCODING *enc, |
---|
1743 | n/a | const char *ptr, |
---|
1744 | n/a | const char *end, |
---|
1745 | n/a | POSITION *pos) |
---|
1746 | n/a | { |
---|
1747 | n/a | while (ptr < end) { |
---|
1748 | n/a | switch (BYTE_TYPE(enc, ptr)) { |
---|
1749 | n/a | #define LEAD_CASE(n) \ |
---|
1750 | n/a | case BT_LEAD ## n: \ |
---|
1751 | n/a | ptr += n; \ |
---|
1752 | n/a | break; |
---|
1753 | n/a | LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) |
---|
1754 | n/a | #undef LEAD_CASE |
---|
1755 | n/a | case BT_LF: |
---|
1756 | n/a | pos->columnNumber = (XML_Size)-1; |
---|
1757 | n/a | pos->lineNumber++; |
---|
1758 | n/a | ptr += MINBPC(enc); |
---|
1759 | n/a | break; |
---|
1760 | n/a | case BT_CR: |
---|
1761 | n/a | pos->lineNumber++; |
---|
1762 | n/a | ptr += MINBPC(enc); |
---|
1763 | n/a | if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) |
---|
1764 | n/a | ptr += MINBPC(enc); |
---|
1765 | n/a | pos->columnNumber = (XML_Size)-1; |
---|
1766 | n/a | break; |
---|
1767 | n/a | default: |
---|
1768 | n/a | ptr += MINBPC(enc); |
---|
1769 | n/a | break; |
---|
1770 | n/a | } |
---|
1771 | n/a | pos->columnNumber++; |
---|
1772 | n/a | } |
---|
1773 | n/a | } |
---|
1774 | n/a | |
---|
1775 | n/a | #undef DO_LEAD_CASE |
---|
1776 | n/a | #undef MULTIBYTE_CASES |
---|
1777 | n/a | #undef INVALID_CASES |
---|
1778 | n/a | #undef CHECK_NAME_CASE |
---|
1779 | n/a | #undef CHECK_NAME_CASES |
---|
1780 | n/a | #undef CHECK_NMSTRT_CASE |
---|
1781 | n/a | #undef CHECK_NMSTRT_CASES |
---|
1782 | n/a | |
---|
1783 | n/a | #endif /* XML_TOK_IMPL_C */ |
---|