[18501] | 1 | const ENCODING * |
---|
| 2 | NS(XmlGetUtf8InternalEncoding)(void) |
---|
| 3 | { |
---|
| 4 | return &ns(internal_utf8_encoding).enc; |
---|
| 5 | } |
---|
| 6 | |
---|
| 7 | const ENCODING * |
---|
| 8 | NS(XmlGetUtf16InternalEncoding)(void) |
---|
| 9 | { |
---|
| 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 |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | static const ENCODING *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 */ |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | static int FASTCALL |
---|
| 33 | NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, |
---|
| 34 | const char **nextTokPtr) |
---|
| 35 | { |
---|
| 36 | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
---|
| 37 | XML_PROLOG_STATE, ptr, end, nextTokPtr); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static int FASTCALL |
---|
| 41 | NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, |
---|
| 42 | const char **nextTokPtr) |
---|
| 43 | { |
---|
| 44 | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
---|
| 45 | XML_CONTENT_STATE, ptr, end, nextTokPtr); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | int |
---|
| 49 | NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, |
---|
| 50 | const char *name) |
---|
| 51 | { |
---|
| 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; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | static const ENCODING * |
---|
| 65 | NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) |
---|
| 66 | { |
---|
| 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]; |
---|
| 81 | } |
---|
| 82 | |
---|
| 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) |
---|
| 94 | { |
---|
| 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); |
---|
| 106 | } |
---|