1 const ENCODING *
NS(xmlrpc_XmlGetUtf8InternalEncoding)2 NS(xmlrpc_XmlGetUtf8InternalEncoding)(void) {
3
4 return &ns(internal_utf8_encoding).enc;
5 }
6
7
8
9 const ENCODING *
NS(xmlrpc_XmlGetUtf16InternalEncoding)10 NS(xmlrpc_XmlGetUtf16InternalEncoding)(void) {
11
12 #if XML_BYTE_ORDER == 12
13 return &ns(internal_little2_encoding).enc;
14 #elif XML_BYTE_ORDER == 21
15 return &ns(internal_big2_encoding).enc;
16 #else
17 const short n = 1;
18 return *(const char *)&n ?
19 &ns(internal_little2_encoding).enc :
20 &ns(internal_big2_encoding).enc;
21 #endif
22 }
23
24 static
25 const ENCODING *NS(encodings)[] = {
26 &ns(latin1_encoding).enc,
27 &ns(ascii_encoding).enc,
28 &ns(utf8_encoding).enc,
29 &ns(big2_encoding).enc,
30 &ns(big2_encoding).enc,
31 &ns(little2_encoding).enc,
32 &ns(utf8_encoding).enc /* NO_ENC */
33 };
34
35 static
NS(initScanProlog)36 int NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
37 const char **nextTokPtr)
38 {
39 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
40 }
41
42 static
NS(initScanContent)43 int NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
44 const char **nextTokPtr)
45 {
46 return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
47 }
48
49
50
51 int
NS(xmlrpc_XmlInitEncoding)52 NS(xmlrpc_XmlInitEncoding)(INIT_ENCODING * const p,
53 const ENCODING ** const encPtr,
54 const char * const name) {
55
56 int i = getEncodingIndex(name);
57 if (i == UNKNOWN_ENC)
58 return 0;
59 SET_INIT_ENC_INDEX(p, i);
60 p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
61 p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
62 p->initEnc.updatePosition = initUpdatePosition;
63 p->encPtr = encPtr;
64 *encPtr = &(p->initEnc);
65 return 1;
66 }
67
68
69
70 static
NS(findEncoding)71 const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
72 {
73 #define ENCODING_MAX 128
74 char buf[ENCODING_MAX];
75 char *p = buf;
76 int i;
77 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
78 if (ptr != end)
79 return 0;
80 *p = 0;
81 if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
82 return enc;
83 i = getEncodingIndex(buf);
84 if (i == UNKNOWN_ENC)
85 return 0;
86 return NS(encodings)[i];
87 }
88
89
90
91 int
NS(xmlrpc_XmlParseXmlDecl)92 NS(xmlrpc_XmlParseXmlDecl)(int const isGeneralTextEntity,
93 const ENCODING * const enc,
94 const char * const ptr,
95 const char * const end,
96 const char ** const badPtr,
97 const char ** const versionPtr,
98 const char ** const encodingName,
99 const ENCODING ** const encoding,
100 int * const standalone) {
101
102 return doParseXmlDecl(NS(findEncoding),
103 isGeneralTextEntity,
104 enc,
105 ptr,
106 end,
107 badPtr,
108 versionPtr,
109 encodingName,
110 encoding,
111 standalone);
112 }
113