1 /* This file is included!
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000-2017 Expat development team
11 Licensed under the MIT license:
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to permit
18 persons to whom the Software is furnished to do so, subject to the
21 The above copyright notice and this permission notice shall be included
22 in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
29 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30 USE OR OTHER DEALINGS IN THE SOFTWARE.
36 NS(XmlGetUtf8InternalEncoding)(void)
38 return &ns(internal_utf8_encoding).enc;
42 NS(XmlGetUtf16InternalEncoding)(void)
45 return &ns(internal_little2_encoding).enc;
46 #elif BYTEORDER == 4321
47 return &ns(internal_big2_encoding).enc;
50 return (*(const char *)&n
51 ? &ns(internal_little2_encoding).enc
52 : &ns(internal_big2_encoding).enc);
56 static const ENCODING * const NS(encodings)[] = {
57 &ns(latin1_encoding).enc,
58 &ns(ascii_encoding).enc,
59 &ns(utf8_encoding).enc,
60 &ns(big2_encoding).enc,
61 &ns(big2_encoding).enc,
62 &ns(little2_encoding).enc,
63 &ns(utf8_encoding).enc /* NO_ENC */
67 NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
68 const char **nextTokPtr)
70 return initScan(NS(encodings), (const INIT_ENCODING *)enc,
71 XML_PROLOG_STATE, ptr, end, nextTokPtr);
75 NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
76 const char **nextTokPtr)
78 return initScan(NS(encodings), (const INIT_ENCODING *)enc,
79 XML_CONTENT_STATE, ptr, end, nextTokPtr);
83 NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
86 int i = getEncodingIndex(name);
89 SET_INIT_ENC_INDEX(p, i);
90 p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
91 p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
92 p->initEnc.updatePosition = initUpdatePosition;
94 *encPtr = &(p->initEnc);
98 static const ENCODING *
99 NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
101 #define ENCODING_MAX 128
102 char buf[ENCODING_MAX];
105 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
109 if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
111 i = getEncodingIndex(buf);
112 if (i == UNKNOWN_ENC)
114 return NS(encodings)[i];
118 NS(XmlParseXmlDecl)(int isGeneralTextEntity,
123 const char **versionPtr,
124 const char **versionEndPtr,
125 const char **encodingName,
126 const ENCODING **encoding,
129 return doParseXmlDecl(NS(findEncoding),
142 #endif /* XML_TOK_NS_C */