Gregory P. Smith | 7c6309c | 2012-07-14 14:12:35 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd |
| 2 | See the file COPYING for copying permission. |
| 3 | */ |
| 4 | |
| 5 | /* This file is included! */ |
| 6 | #ifdef XML_TOK_NS_C |
| 7 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 8 | const ENCODING * |
| 9 | NS(XmlGetUtf8InternalEncoding)(void) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 10 | { |
| 11 | return &ns(internal_utf8_encoding).enc; |
| 12 | } |
| 13 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 14 | const ENCODING * |
| 15 | NS(XmlGetUtf16InternalEncoding)(void) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 16 | { |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 17 | #if BYTEORDER == 1234 |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 18 | return &ns(internal_little2_encoding).enc; |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 19 | #elif BYTEORDER == 4321 |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 20 | return &ns(internal_big2_encoding).enc; |
| 21 | #else |
| 22 | const short n = 1; |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 23 | return (*(const char *)&n |
| 24 | ? &ns(internal_little2_encoding).enc |
| 25 | : &ns(internal_big2_encoding).enc); |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 26 | #endif |
| 27 | } |
| 28 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 29 | static const ENCODING * const NS(encodings)[] = { |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 30 | &ns(latin1_encoding).enc, |
| 31 | &ns(ascii_encoding).enc, |
| 32 | &ns(utf8_encoding).enc, |
| 33 | &ns(big2_encoding).enc, |
| 34 | &ns(big2_encoding).enc, |
| 35 | &ns(little2_encoding).enc, |
| 36 | &ns(utf8_encoding).enc /* NO_ENC */ |
| 37 | }; |
| 38 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 39 | static int PTRCALL |
| 40 | NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, |
| 41 | const char **nextTokPtr) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 42 | { |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 43 | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
| 44 | XML_PROLOG_STATE, ptr, end, nextTokPtr); |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 47 | static int PTRCALL |
| 48 | NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, |
| 49 | const char **nextTokPtr) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 50 | { |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 51 | return initScan(NS(encodings), (const INIT_ENCODING *)enc, |
| 52 | XML_CONTENT_STATE, ptr, end, nextTokPtr); |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 55 | int |
| 56 | NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, |
| 57 | const char *name) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 58 | { |
| 59 | int i = getEncodingIndex(name); |
| 60 | if (i == UNKNOWN_ENC) |
| 61 | return 0; |
| 62 | SET_INIT_ENC_INDEX(p, i); |
| 63 | p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); |
| 64 | p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); |
| 65 | p->initEnc.updatePosition = initUpdatePosition; |
| 66 | p->encPtr = encPtr; |
| 67 | *encPtr = &(p->initEnc); |
| 68 | return 1; |
| 69 | } |
| 70 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 71 | static const ENCODING * |
| 72 | NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 73 | { |
| 74 | #define ENCODING_MAX 128 |
| 75 | char buf[ENCODING_MAX]; |
| 76 | char *p = buf; |
| 77 | int i; |
| 78 | XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); |
| 79 | if (ptr != end) |
| 80 | return 0; |
| 81 | *p = 0; |
| 82 | if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) |
| 83 | return enc; |
| 84 | i = getEncodingIndex(buf); |
| 85 | if (i == UNKNOWN_ENC) |
| 86 | return 0; |
| 87 | return NS(encodings)[i]; |
| 88 | } |
| 89 | |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 90 | int |
| 91 | NS(XmlParseXmlDecl)(int isGeneralTextEntity, |
| 92 | const ENCODING *enc, |
| 93 | const char *ptr, |
| 94 | const char *end, |
| 95 | const char **badPtr, |
| 96 | const char **versionPtr, |
| 97 | const char **versionEndPtr, |
| 98 | const char **encodingName, |
| 99 | const ENCODING **encoding, |
| 100 | int *standalone) |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 101 | { |
| 102 | return doParseXmlDecl(NS(findEncoding), |
Martin v. Löwis | fc03a94 | 2003-01-25 22:41:29 +0000 | [diff] [blame] | 103 | isGeneralTextEntity, |
| 104 | enc, |
| 105 | ptr, |
| 106 | end, |
| 107 | badPtr, |
| 108 | versionPtr, |
| 109 | versionEndPtr, |
| 110 | encodingName, |
| 111 | encoding, |
| 112 | standalone); |
Martin v. Löwis | 1dbb1ca | 2002-02-11 23:13:04 +0000 | [diff] [blame] | 113 | } |
Gregory P. Smith | 7c6309c | 2012-07-14 14:12:35 -0700 | [diff] [blame^] | 114 | |
| 115 | #endif /* XML_TOK_NS_C */ |