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_NS_C |
---|
7 | n/a | |
---|
8 | n/a | const ENCODING * |
---|
9 | n/a | NS(XmlGetUtf8InternalEncoding)(void) |
---|
10 | n/a | { |
---|
11 | n/a | return &ns(internal_utf8_encoding).enc; |
---|
12 | n/a | } |
---|
13 | n/a | |
---|
14 | n/a | const ENCODING * |
---|
15 | n/a | NS(XmlGetUtf16InternalEncoding)(void) |
---|
16 | n/a | { |
---|
17 | n/a | #if BYTEORDER == 1234 |
---|
18 | n/a | return &ns(internal_little2_encoding).enc; |
---|
19 | n/a | #elif BYTEORDER == 4321 |
---|
20 | n/a | return &ns(internal_big2_encoding).enc; |
---|
21 | n/a | #else |
---|
22 | n/a | const short n = 1; |
---|
23 | n/a | return (*(const char *)&n |
---|
24 | n/a | ? &ns(internal_little2_encoding).enc |
---|
25 | n/a | : &ns(internal_big2_encoding).enc); |
---|
26 | n/a | #endif |
---|
27 | n/a | } |
---|
28 | n/a | |
---|
29 | n/a | static const ENCODING * const NS(encodings)[] = { |
---|
30 | n/a | &ns(latin1_encoding).enc, |
---|
31 | n/a | &ns(ascii_encoding).enc, |
---|
32 | n/a | &ns(utf8_encoding).enc, |
---|
33 | n/a | &ns(big2_encoding).enc, |
---|
34 | n/a | &ns(big2_encoding).enc, |
---|
35 | n/a | &ns(little2_encoding).enc, |
---|
36 | n/a | &ns(utf8_encoding).enc /* NO_ENC */ |
---|
37 | n/a | }; |
---|
38 | n/a | |
---|
39 | n/a | static int PTRCALL |
---|
40 | n/a | NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, |
---|
41 | n/a | const char **nextTokPtr) |
---|
42 | n/a | { |
---|
43 | n/a | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
---|
44 | n/a | XML_PROLOG_STATE, ptr, end, nextTokPtr); |
---|
45 | n/a | } |
---|
46 | n/a | |
---|
47 | n/a | static int PTRCALL |
---|
48 | n/a | NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, |
---|
49 | n/a | const char **nextTokPtr) |
---|
50 | n/a | { |
---|
51 | n/a | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
---|
52 | n/a | XML_CONTENT_STATE, ptr, end, nextTokPtr); |
---|
53 | n/a | } |
---|
54 | n/a | |
---|
55 | n/a | int |
---|
56 | n/a | NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, |
---|
57 | n/a | const char *name) |
---|
58 | n/a | { |
---|
59 | n/a | int i = getEncodingIndex(name); |
---|
60 | n/a | if (i == UNKNOWN_ENC) |
---|
61 | n/a | return 0; |
---|
62 | n/a | SET_INIT_ENC_INDEX(p, i); |
---|
63 | n/a | p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); |
---|
64 | n/a | p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); |
---|
65 | n/a | p->initEnc.updatePosition = initUpdatePosition; |
---|
66 | n/a | p->encPtr = encPtr; |
---|
67 | n/a | *encPtr = &(p->initEnc); |
---|
68 | n/a | return 1; |
---|
69 | n/a | } |
---|
70 | n/a | |
---|
71 | n/a | static const ENCODING * |
---|
72 | n/a | NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) |
---|
73 | n/a | { |
---|
74 | n/a | #define ENCODING_MAX 128 |
---|
75 | n/a | char buf[ENCODING_MAX]; |
---|
76 | n/a | char *p = buf; |
---|
77 | n/a | int i; |
---|
78 | n/a | XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); |
---|
79 | n/a | if (ptr != end) |
---|
80 | n/a | return 0; |
---|
81 | n/a | *p = 0; |
---|
82 | n/a | if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) |
---|
83 | n/a | return enc; |
---|
84 | n/a | i = getEncodingIndex(buf); |
---|
85 | n/a | if (i == UNKNOWN_ENC) |
---|
86 | n/a | return 0; |
---|
87 | n/a | return NS(encodings)[i]; |
---|
88 | n/a | } |
---|
89 | n/a | |
---|
90 | n/a | int |
---|
91 | n/a | NS(XmlParseXmlDecl)(int isGeneralTextEntity, |
---|
92 | n/a | const ENCODING *enc, |
---|
93 | n/a | const char *ptr, |
---|
94 | n/a | const char *end, |
---|
95 | n/a | const char **badPtr, |
---|
96 | n/a | const char **versionPtr, |
---|
97 | n/a | const char **versionEndPtr, |
---|
98 | n/a | const char **encodingName, |
---|
99 | n/a | const ENCODING **encoding, |
---|
100 | n/a | int *standalone) |
---|
101 | n/a | { |
---|
102 | n/a | return doParseXmlDecl(NS(findEncoding), |
---|
103 | n/a | isGeneralTextEntity, |
---|
104 | n/a | enc, |
---|
105 | n/a | ptr, |
---|
106 | n/a | end, |
---|
107 | n/a | badPtr, |
---|
108 | n/a | versionPtr, |
---|
109 | n/a | versionEndPtr, |
---|
110 | n/a | encodingName, |
---|
111 | n/a | encoding, |
---|
112 | n/a | standalone); |
---|
113 | n/a | } |
---|
114 | n/a | |
---|
115 | n/a | #endif /* XML_TOK_NS_C */ |
---|