Made it consistent that in the case of namespace triplets, the namespace
[mirror-ossqm-expat.git] / lib / xmltok_ns.c
blobd2f893836fb4a842463846d50a2d2fa1e4d3e822
1 const ENCODING *
2 NS(XmlGetUtf8InternalEncoding)(void)
4 return &ns(internal_utf8_encoding).enc;
7 const ENCODING *
8 NS(XmlGetUtf16InternalEncoding)(void)
10 #if BYTEORDER == 1234
11 return &ns(internal_little2_encoding).enc;
12 #elif BYTEORDER == 4321
13 return &ns(internal_big2_encoding).enc;
14 #else
15 const short n = 1;
16 return (*(const char *)&n
17 ? &ns(internal_little2_encoding).enc
18 : &ns(internal_big2_encoding).enc);
19 #endif
22 static const ENCODING * const NS(encodings)[] = {
23 &ns(latin1_encoding).enc,
24 &ns(ascii_encoding).enc,
25 &ns(utf8_encoding).enc,
26 &ns(big2_encoding).enc,
27 &ns(big2_encoding).enc,
28 &ns(little2_encoding).enc,
29 &ns(utf8_encoding).enc /* NO_ENC */
32 static int PTRCALL
33 NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
34 const char **nextTokPtr)
36 return initScan(NS(encodings), (const INIT_ENCODING *)enc,
37 XML_PROLOG_STATE, ptr, end, nextTokPtr);
40 static int PTRCALL
41 NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
42 const char **nextTokPtr)
44 return initScan(NS(encodings), (const INIT_ENCODING *)enc,
45 XML_CONTENT_STATE, ptr, end, nextTokPtr);
48 int
49 NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
50 const char *name)
52 int i = getEncodingIndex(name);
53 if (i == UNKNOWN_ENC)
54 return 0;
55 SET_INIT_ENC_INDEX(p, i);
56 p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
57 p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
58 p->initEnc.updatePosition = initUpdatePosition;
59 p->encPtr = encPtr;
60 *encPtr = &(p->initEnc);
61 return 1;
64 static const ENCODING *
65 NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
67 #define ENCODING_MAX 128
68 char buf[ENCODING_MAX];
69 char *p = buf;
70 int i;
71 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
72 if (ptr != end)
73 return 0;
74 *p = 0;
75 if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
76 return enc;
77 i = getEncodingIndex(buf);
78 if (i == UNKNOWN_ENC)
79 return 0;
80 return NS(encodings)[i];
83 int
84 NS(XmlParseXmlDecl)(int isGeneralTextEntity,
85 const ENCODING *enc,
86 const char *ptr,
87 const char *end,
88 const char **badPtr,
89 const char **versionPtr,
90 const char **versionEndPtr,
91 const char **encodingName,
92 const ENCODING **encoding,
93 int *standalone)
95 return doParseXmlDecl(NS(findEncoding),
96 isGeneralTextEntity,
97 enc,
98 ptr,
99 end,
100 badPtr,
101 versionPtr,
102 versionEndPtr,
103 encodingName,
104 encoding,
105 standalone);