source: protocols/jabber/xmltok_ns.c @ 96863f6

Last change on this file since 96863f6 was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2The contents of this file are subject to the Mozilla Public License
3Version 1.1 (the "License"); you may not use this file except in
4compliance with the License. You may obtain a copy of the License at
5http://www.mozilla.org/MPL/
6
7Software distributed under the License is distributed on an "AS IS"
8basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9License for the specific language governing rights and limitations
10under the License.
11
12The Original Code is expat.
13
14The Initial Developer of the Original Code is James Clark.
15Portions created by James Clark are Copyright (C) 1998, 1999
16James Clark. All Rights Reserved.
17
18Contributor(s):
19
20*/
21
22const ENCODING *NS(XmlGetUtf8InternalEncoding)()
23{
24    return &ns(internal_utf8_encoding).enc;
25}
26
27const ENCODING *NS(XmlGetUtf16InternalEncoding)()
28{
29#if XML_BYTE_ORDER == 12
30    return &ns(internal_little2_encoding).enc;
31#elif XML_BYTE_ORDER == 21
32return &ns(internal_big2_encoding).enc;
33#else
34const short n = 1;
35    return *(const char *)&n ? &ns(internal_little2_encoding).enc : &ns(internal_big2_encoding).enc;
36#endif
37}
38
39static
40const 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
50static
51int 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
57static
58int 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
64int 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
78static
79const 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
97int 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}
Note: See TracBrowser for help on using the repository browser.