Coverage Report

Created: 2024-07-27 06:44

/src/CMake/Utilities/cmexpat/lib/xmltok_ns.c
Line
Count
Source (jump to first uncovered line)
1
/* This file is included!
2
                            __  __            _
3
                         ___\ \/ /_ __   __ _| |_
4
                        / _ \\  /| '_ \ / _` | __|
5
                       |  __//  \| |_) | (_| | |_
6
                        \___/_/\_\ .__/ \__,_|\__|
7
                                 |_| XML parser
8
9
   Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10
   Copyright (c) 2000      Clark Cooper <coopercc@users.sourceforge.net>
11
   Copyright (c) 2002      Greg Stein <gstein@users.sourceforge.net>
12
   Copyright (c) 2002      Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
13
   Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
14
   Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org>
15
   Licensed under the MIT license:
16
17
   Permission is  hereby granted,  free of charge,  to any  person obtaining
18
   a  copy  of  this  software   and  associated  documentation  files  (the
19
   "Software"),  to  deal in  the  Software  without restriction,  including
20
   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
21
   distribute, sublicense, and/or sell copies of the Software, and to permit
22
   persons  to whom  the Software  is  furnished to  do so,  subject to  the
23
   following conditions:
24
25
   The above copyright  notice and this permission notice  shall be included
26
   in all copies or substantial portions of the Software.
27
28
   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
29
   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
30
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
31
   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
32
   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
33
   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
34
   USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*/
36
37
#ifdef XML_TOK_NS_C
38
39
const ENCODING *
40
10.0k
NS(XmlGetUtf8InternalEncoding)(void) {
41
10.0k
  return &ns(internal_utf8_encoding).enc;
42
10.0k
}
43
44
const ENCODING *
45
0
NS(XmlGetUtf16InternalEncoding)(void) {
46
0
#  if BYTEORDER == 1234
47
0
  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_little2_encoding).enc
53
                            : &ns(internal_big2_encoding).enc);
54
#  endif
55
0
}
56
57
static const ENCODING *const NS(encodings)[] = {
58
    &ns(latin1_encoding).enc, &ns(ascii_encoding).enc,
59
    &ns(utf8_encoding).enc,   &ns(big2_encoding).enc,
60
    &ns(big2_encoding).enc,   &ns(little2_encoding).enc,
61
    &ns(utf8_encoding).enc /* NO_ENC */
62
};
63
64
static int PTRCALL
65
NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
66
10.0k
                   const char **nextTokPtr) {
67
10.0k
  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE,
68
10.0k
                  ptr, end, nextTokPtr);
69
10.0k
}
70
71
static int PTRCALL
72
NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
73
0
                    const char **nextTokPtr) {
74
0
  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE,
75
0
                  ptr, end, nextTokPtr);
76
0
}
77
78
int
79
NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
80
20.0k
                    const char *name) {
81
20.0k
  int i = getEncodingIndex(name);
82
20.0k
  if (i == UNKNOWN_ENC)
83
0
    return 0;
84
20.0k
  SET_INIT_ENC_INDEX(p, i);
85
20.0k
  p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
86
20.0k
  p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
87
20.0k
  p->initEnc.updatePosition = initUpdatePosition;
88
20.0k
  p->encPtr = encPtr;
89
20.0k
  *encPtr = &(p->initEnc);
90
20.0k
  return 1;
91
20.0k
}
92
93
static const ENCODING *
94
1.47k
NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) {
95
1.47k
#  define ENCODING_MAX 128
96
1.47k
  char buf[ENCODING_MAX] = "";
97
1.47k
  char *p = buf;
98
1.47k
  int i;
99
1.47k
  XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
100
1.47k
  if (ptr != end)
101
7
    return 0;
102
1.46k
  *p = 0;
103
1.46k
  if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
104
0
    return enc;
105
1.46k
  i = getEncodingIndex(buf);
106
1.46k
  if (i == UNKNOWN_ENC)
107
48
    return 0;
108
1.41k
  return NS(encodings)[i];
109
1.46k
}
110
111
int
112
NS(XmlParseXmlDecl)(int isGeneralTextEntity, const ENCODING *enc,
113
                    const char *ptr, const char *end, const char **badPtr,
114
                    const char **versionPtr, const char **versionEndPtr,
115
                    const char **encodingName, const ENCODING **encoding,
116
1.78k
                    int *standalone) {
117
1.78k
  return doParseXmlDecl(NS(findEncoding), isGeneralTextEntity, enc, ptr, end,
118
1.78k
                        badPtr, versionPtr, versionEndPtr, encodingName,
119
1.78k
                        encoding, standalone);
120
1.78k
}
121
122
#endif /* XML_TOK_NS_C */