source: trunk/src/helpers/xmltok_ns.c@ 38

Last change on this file since 38 was 38, checked in by umoeller, 25 years ago

Updates to XML.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1
2/*
3 *sourcefile xmltok_ns.c
4 * part of the expat implementation. See xmlparse.c.
5 *
6 * NOTE: This file must not be compiled directly. It is
7 * #include'd from xmltok.c several times.
8 */
9
10/*
11 * Copyright (C) 2001 Ulrich M”ller.
12 * Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd.
13 * and Clark Cooper.
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included
24 * in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 */
34
35const ENCODING* EXPATENTRY NS(XmlGetUtf8InternalEncoding) (void)
36{
37 return &ns(internal_utf8_encoding).enc;
38}
39
40const ENCODING* EXPATENTRY NS(XmlGetUtf16InternalEncoding) (void)
41{
42#if XML_BYTE_ORDER == 12
43 return &ns(internal_little2_encoding).enc;
44#elif XML_BYTE_ORDER == 21
45 return &ns(internal_big2_encoding).enc;
46#else
47 const short n = 1;
48
49 return *(const char *)&n ? &ns(internal_little2_encoding).enc : &ns(internal_big2_encoding).enc;
50#endif
51}
52
53static
54const ENCODING *NS(encodings)[] =
55{
56 &ns(latin1_encoding).enc,
57 &ns(ascii_encoding).enc,
58 &ns(utf8_encoding).enc,
59 &ns(big2_encoding).enc,
60 &ns(big2_encoding).enc,
61 &ns(little2_encoding).enc,
62 &ns(utf8_encoding).enc /* NO_ENC */
63};
64
65static int EXPATENTRY NS(initScanProlog)(const ENCODING * enc,
66 const char *ptr,
67 const char *end,
68 const char **nextTokPtr)
69{
70 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
71}
72
73static int EXPATENTRY NS(initScanContent)(const ENCODING * enc,
74 const char *ptr,
75 const char *end,
76 const char **nextTokPtr)
77{
78 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
79}
80
81int EXPATENTRY NS(XmlInitEncoding)(INIT_ENCODING * p, const ENCODING ** encPtr, const char *name)
82{
83 int i = getEncodingIndex(name);
84
85 if (i == UNKNOWN_ENC)
86 return 0;
87 SET_INIT_ENC_INDEX(p, i);
88 p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
89 p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
90 p->initEnc.updatePosition = initUpdatePosition;
91 p->encPtr = encPtr;
92 *encPtr = &(p->initEnc);
93 return 1;
94}
95
96static const ENCODING* EXPATENTRY NS(findEncoding)(const ENCODING * enc,
97 const char *ptr,
98 const char *end)
99{
100#define ENCODING_MAX 128
101 char buf[ENCODING_MAX];
102 char *p = buf;
103 int i;
104
105 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
106 if (ptr != end)
107 return 0;
108 *p = 0;
109 if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
110 return enc;
111 i = getEncodingIndex(buf);
112 if (i == UNKNOWN_ENC)
113 return 0;
114 return NS(encodings)[i];
115}
116
117int NS(XmlParseXmlDecl) (int isGeneralTextEntity,
118 const ENCODING * enc,
119 const char *ptr,
120 const char *end,
121 const char **badPtr,
122 const char **versionPtr,
123 const char **versionEndPtr,
124 const char **encodingName,
125 const ENCODING ** encoding,
126 int *standalone)
127{
128 return doParseXmlDecl(NS(findEncoding),
129 isGeneralTextEntity,
130 enc,
131 ptr,
132 end,
133 badPtr,
134 versionPtr,
135 versionEndPtr,
136 encodingName,
137 encoding,
138 standalone);
139}
Note: See TracBrowser for help on using the repository browser.