Geant4 Cross Reference |
1 /* This file is included! 1 2 __ __ 3 ___\ \/ /_ __ __ _| 4 / _ \\ /| '_ \ / _` | 5 | __// \| |_) | (_| | 6 \___/_/\_\ .__/ \__,_| 7 |_| XML parse 8 9 Copyright (c) 1997-2000 Thai Open Source So 10 Copyright (c) 2000 Clark Cooper <coope 11 Copyright (c) 2002 Greg Stein <gstein@ 12 Copyright (c) 2002 Fred L. Drake, Jr. 13 Copyright (c) 2002-2006 Karl Waclawek <karl 14 Copyright (c) 2017-2021 Sebastian Pipping < 15 Licensed under the MIT license: 16 17 Permission is hereby granted, free of cha 18 a copy of this software and associat 19 "Software"), to deal in the Software w 20 without limitation the rights to use, c 21 distribute, sublicense, and/or sell copies 22 persons to whom the Software is furnish 23 following conditions: 24 25 The above copyright notice and this permis 26 in all copies or substantial portions of th 27 28 THE SOFTWARE IS PROVIDED "AS IS", WIT 29 EXPRESS OR IMPLIED, INCLUDING BUT NOT L 30 MERCHANTABILITY, FITNESS FOR A PARTICULAR P 31 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HO 32 DAMAGES OR OTHER LIABILITY, WHETHER IN AN 33 OTHERWISE, ARISING FROM, OUT OF OR IN CONNE 34 USE OR OTHER DEALINGS IN THE SOFTWARE. 35 */ 36 37 #ifdef XML_TOK_NS_C 38 39 const ENCODING * 40 NS(XmlGetUtf8InternalEncoding)(void) { 41 return &ns(internal_utf8_encoding).enc; 42 } 43 44 const ENCODING * 45 NS(XmlGetUtf16InternalEncoding)(void) { 46 # if BYTEORDER == 1234 47 return &ns(internal_little2_encoding).enc; 48 # elif BYTEORDER == 4321 49 return &ns(internal_big2_encoding).enc; 50 # else 51 const short n = 1; 52 return (*(const char *)&n ? &ns(internal_lit 53 : &ns(internal_big 54 # endif 55 } 56 57 static const ENCODING *const NS(encodings)[] = 58 &ns(latin1_encoding).enc, &ns(ascii_encodi 59 &ns(utf8_encoding).enc, &ns(big2_encodin 60 &ns(big2_encoding).enc, &ns(little2_enco 61 &ns(utf8_encoding).enc /* NO_ENC */ 62 }; 63 64 static int PTRCALL 65 NS(initScanProlog)(const ENCODING *enc, const 66 const char **nextTokPtr) { 67 return initScan(NS(encodings), (const INIT_E 68 ptr, end, nextTokPtr); 69 } 70 71 static int PTRCALL 72 NS(initScanContent)(const ENCODING *enc, const 73 const char **nextTokPtr) { 74 return initScan(NS(encodings), (const INIT_E 75 ptr, end, nextTokPtr); 76 } 77 78 int 79 NS(XmlInitEncoding)(INIT_ENCODING *p, const EN 80 const char *name) { 81 int i = getEncodingIndex(name); 82 if (i == UNKNOWN_ENC) 83 return 0; 84 SET_INIT_ENC_INDEX(p, i); 85 p->initEnc.scanners[XML_PROLOG_STATE] = NS(i 86 p->initEnc.scanners[XML_CONTENT_STATE] = NS( 87 p->initEnc.updatePosition = initUpdatePositi 88 p->encPtr = encPtr; 89 *encPtr = &(p->initEnc); 90 return 1; 91 } 92 93 static const ENCODING * 94 NS(findEncoding)(const ENCODING *enc, const ch 95 # define ENCODING_MAX 128 96 char buf[ENCODING_MAX] = ""; 97 char *p = buf; 98 int i; 99 XmlUtf8Convert(enc, &ptr, end, &p, p + ENCOD 100 if (ptr != end) 101 return 0; 102 *p = 0; 103 if (streqci(buf, KW_UTF_16) && enc->minBytes 104 return enc; 105 i = getEncodingIndex(buf); 106 if (i == UNKNOWN_ENC) 107 return 0; 108 return NS(encodings)[i]; 109 } 110 111 int 112 NS(XmlParseXmlDecl)(int isGeneralTextEntity, c 113 const char *ptr, const cha 114 const char **versionPtr, c 115 const char **encodingName, 116 int *standalone) { 117 return doParseXmlDecl(NS(findEncoding), isGe 118 badPtr, versionPtr, ve 119 encoding, standalone); 120 } 121 122 #endif /* XML_TOK_NS_C */ 123