xmltok_ns.c revision 1.1.1.1.44.1 1 1.1.1.1.44.1 martin /* This file is included!
2 1.1.1.1.44.1 martin __ __ _
3 1.1.1.1.44.1 martin ___\ \/ /_ __ __ _| |_
4 1.1.1.1.44.1 martin / _ \\ /| '_ \ / _` | __|
5 1.1.1.1.44.1 martin | __// \| |_) | (_| | |_
6 1.1.1.1.44.1 martin \___/_/\_\ .__/ \__,_|\__|
7 1.1.1.1.44.1 martin |_| XML parser
8 1.1.1.1.44.1 martin
9 1.1.1.1.44.1 martin Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 1.1.1.1.44.1 martin Copyright (c) 2000-2017 Expat development team
11 1.1.1.1.44.1 martin Licensed under the MIT license:
12 1.1.1.1.44.1 martin
13 1.1.1.1.44.1 martin Permission is hereby granted, free of charge, to any person obtaining
14 1.1.1.1.44.1 martin a copy of this software and associated documentation files (the
15 1.1.1.1.44.1 martin "Software"), to deal in the Software without restriction, including
16 1.1.1.1.44.1 martin without limitation the rights to use, copy, modify, merge, publish,
17 1.1.1.1.44.1 martin distribute, sublicense, and/or sell copies of the Software, and to permit
18 1.1.1.1.44.1 martin persons to whom the Software is furnished to do so, subject to the
19 1.1.1.1.44.1 martin following conditions:
20 1.1.1.1.44.1 martin
21 1.1.1.1.44.1 martin The above copyright notice and this permission notice shall be included
22 1.1.1.1.44.1 martin in all copies or substantial portions of the Software.
23 1.1.1.1.44.1 martin
24 1.1.1.1.44.1 martin THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 1.1.1.1.44.1 martin EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 1.1.1.1.44.1 martin MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27 1.1.1.1.44.1 martin NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28 1.1.1.1.44.1 martin DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
29 1.1.1.1.44.1 martin OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30 1.1.1.1.44.1 martin USE OR OTHER DEALINGS IN THE SOFTWARE.
31 1.1 tron */
32 1.1 tron
33 1.1 tron #ifdef XML_TOK_NS_C
34 1.1 tron
35 1.1 tron const ENCODING *
36 1.1.1.1.44.1 martin NS(XmlGetUtf8InternalEncoding)(void) {
37 1.1 tron return &ns(internal_utf8_encoding).enc;
38 1.1 tron }
39 1.1 tron
40 1.1 tron const ENCODING *
41 1.1.1.1.44.1 martin NS(XmlGetUtf16InternalEncoding)(void) {
42 1.1.1.1.44.1 martin # if BYTEORDER == 1234
43 1.1 tron return &ns(internal_little2_encoding).enc;
44 1.1.1.1.44.1 martin # elif BYTEORDER == 4321
45 1.1 tron return &ns(internal_big2_encoding).enc;
46 1.1.1.1.44.1 martin # else
47 1.1 tron const short n = 1;
48 1.1.1.1.44.1 martin return (*(const char *)&n ? &ns(internal_little2_encoding).enc
49 1.1.1.1.44.1 martin : &ns(internal_big2_encoding).enc);
50 1.1.1.1.44.1 martin # endif
51 1.1 tron }
52 1.1 tron
53 1.1.1.1.44.1 martin static const ENCODING *const NS(encodings)[] = {
54 1.1.1.1.44.1 martin &ns(latin1_encoding).enc, &ns(ascii_encoding).enc,
55 1.1.1.1.44.1 martin &ns(utf8_encoding).enc, &ns(big2_encoding).enc,
56 1.1.1.1.44.1 martin &ns(big2_encoding).enc, &ns(little2_encoding).enc,
57 1.1.1.1.44.1 martin &ns(utf8_encoding).enc /* NO_ENC */
58 1.1 tron };
59 1.1 tron
60 1.1 tron static int PTRCALL
61 1.1 tron NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
62 1.1.1.1.44.1 martin const char **nextTokPtr) {
63 1.1.1.1.44.1 martin return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE,
64 1.1.1.1.44.1 martin ptr, end, nextTokPtr);
65 1.1 tron }
66 1.1 tron
67 1.1 tron static int PTRCALL
68 1.1 tron NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
69 1.1.1.1.44.1 martin const char **nextTokPtr) {
70 1.1.1.1.44.1 martin return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE,
71 1.1.1.1.44.1 martin ptr, end, nextTokPtr);
72 1.1 tron }
73 1.1 tron
74 1.1 tron int
75 1.1 tron NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
76 1.1.1.1.44.1 martin const char *name) {
77 1.1 tron int i = getEncodingIndex(name);
78 1.1 tron if (i == UNKNOWN_ENC)
79 1.1 tron return 0;
80 1.1 tron SET_INIT_ENC_INDEX(p, i);
81 1.1 tron p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
82 1.1 tron p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
83 1.1 tron p->initEnc.updatePosition = initUpdatePosition;
84 1.1 tron p->encPtr = encPtr;
85 1.1 tron *encPtr = &(p->initEnc);
86 1.1 tron return 1;
87 1.1 tron }
88 1.1 tron
89 1.1 tron static const ENCODING *
90 1.1.1.1.44.1 martin NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) {
91 1.1.1.1.44.1 martin # define ENCODING_MAX 128
92 1.1 tron char buf[ENCODING_MAX];
93 1.1 tron char *p = buf;
94 1.1 tron int i;
95 1.1 tron XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
96 1.1 tron if (ptr != end)
97 1.1 tron return 0;
98 1.1 tron *p = 0;
99 1.1 tron if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
100 1.1 tron return enc;
101 1.1 tron i = getEncodingIndex(buf);
102 1.1 tron if (i == UNKNOWN_ENC)
103 1.1 tron return 0;
104 1.1 tron return NS(encodings)[i];
105 1.1 tron }
106 1.1 tron
107 1.1 tron int
108 1.1.1.1.44.1 martin NS(XmlParseXmlDecl)(int isGeneralTextEntity, const ENCODING *enc,
109 1.1.1.1.44.1 martin const char *ptr, const char *end, const char **badPtr,
110 1.1.1.1.44.1 martin const char **versionPtr, const char **versionEndPtr,
111 1.1.1.1.44.1 martin const char **encodingName, const ENCODING **encoding,
112 1.1.1.1.44.1 martin int *standalone) {
113 1.1.1.1.44.1 martin return doParseXmlDecl(NS(findEncoding), isGeneralTextEntity, enc, ptr, end,
114 1.1.1.1.44.1 martin badPtr, versionPtr, versionEndPtr, encodingName,
115 1.1.1.1.44.1 martin encoding, standalone);
116 1.1 tron }
117 1.1 tron
118 1.1 tron #endif /* XML_TOK_NS_C */
119