2086
|
1 /*
|
3127
|
2 The contents of this file are subject to the Mozilla Public License
|
|
3 Version 1.1 (the "License"); you may not use this file except in
|
|
4 compliance with the License. You may obtain a copy of the License at
|
|
5 http://www.mozilla.org/MPL/
|
|
6
|
|
7 Software distributed under the License is distributed on an "AS IS"
|
|
8 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
9 License for the specific language governing rights and limitations
|
|
10 under the License.
|
|
11
|
|
12 The Original Code is expat.
|
|
13
|
|
14 The Initial Developer of the Original Code is James Clark.
|
|
15 Portions created by James Clark are Copyright (C) 1998, 1999
|
|
16 James Clark. All Rights Reserved.
|
|
17
|
|
18 Contributor(s):
|
|
19
|
|
20 */
|
2086
|
21
|
|
22 const ENCODING *NS(XmlGetUtf8InternalEncoding)()
|
|
23 {
|
|
24 return &ns(internal_utf8_encoding).enc;
|
|
25 }
|
|
26
|
|
27 const ENCODING *NS(XmlGetUtf16InternalEncoding)()
|
|
28 {
|
|
29 #if XML_BYTE_ORDER == 12
|
|
30 return &ns(internal_little2_encoding).enc;
|
|
31 #elif XML_BYTE_ORDER == 21
|
|
32 return &ns(internal_big2_encoding).enc;
|
|
33 #else
|
|
34 const short n = 1;
|
|
35 return *(const char *)&n ? &ns(internal_little2_encoding).enc : &ns(internal_big2_encoding).enc;
|
|
36 #endif
|
|
37 }
|
|
38
|
|
39 static
|
|
40 const ENCODING *NS(encodings)[] = {
|
|
41 &ns(latin1_encoding).enc,
|
|
42 &ns(ascii_encoding).enc,
|
|
43 &ns(utf8_encoding).enc,
|
|
44 &ns(big2_encoding).enc,
|
|
45 &ns(big2_encoding).enc,
|
|
46 &ns(little2_encoding).enc,
|
|
47 &ns(utf8_encoding).enc /* NO_ENC */
|
|
48 };
|
|
49
|
|
50 static
|
|
51 int NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
|
|
52 const char **nextTokPtr)
|
|
53 {
|
|
54 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
|
|
55 }
|
|
56
|
|
57 static
|
|
58 int NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
|
|
59 const char **nextTokPtr)
|
|
60 {
|
|
61 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
|
|
62 }
|
|
63
|
|
64 int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
|
|
65 {
|
|
66 int i = getEncodingIndex(name);
|
|
67 if (i == UNKNOWN_ENC)
|
|
68 return 0;
|
|
69 INIT_ENC_INDEX(p) = (char)i;
|
|
70 p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
|
|
71 p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
|
|
72 p->initEnc.updatePosition = initUpdatePosition;
|
|
73 p->encPtr = encPtr;
|
|
74 *encPtr = &(p->initEnc);
|
|
75 return 1;
|
|
76 }
|
|
77
|
|
78 static
|
|
79 const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
|
|
80 {
|
|
81 #define ENCODING_MAX 128
|
|
82 char buf[ENCODING_MAX];
|
|
83 char *p = buf;
|
|
84 int i;
|
|
85 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
|
|
86 if (ptr != end)
|
|
87 return 0;
|
|
88 *p = 0;
|
|
89 if (streqci(buf, "UTF-16") && enc->minBytesPerChar == 2)
|
|
90 return enc;
|
|
91 i = getEncodingIndex(buf);
|
|
92 if (i == UNKNOWN_ENC)
|
|
93 return 0;
|
|
94 return NS(encodings)[i];
|
|
95 }
|
|
96
|
|
97 int NS(XmlParseXmlDecl)(int isGeneralTextEntity,
|
|
98 const ENCODING *enc,
|
|
99 const char *ptr,
|
|
100 const char *end,
|
|
101 const char **badPtr,
|
|
102 const char **versionPtr,
|
|
103 const char **encodingName,
|
|
104 const ENCODING **encoding,
|
|
105 int *standalone)
|
|
106 {
|
|
107 return doParseXmlDecl(NS(findEncoding),
|
|
108 isGeneralTextEntity,
|
|
109 enc,
|
|
110 ptr,
|
|
111 end,
|
|
112 badPtr,
|
|
113 versionPtr,
|
|
114 encodingName,
|
|
115 encoding,
|
|
116 standalone);
|
|
117 }
|