Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmexpat/lib/xmltok_ns.c
Line
Count
Source
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-2026 Sebastian Pipping <sebastian@pipping.org>
15
   Copyright (c) 2025      Alfonso Gregory <gfunni234@gmail.com>
16
   Licensed under the MIT license:
17
18
   Permission is  hereby granted,  free of charge,  to any  person obtaining
19
   a  copy  of  this  software   and  associated  documentation  files  (the
20
   "Software"),  to  deal in  the  Software  without restriction,  including
21
   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
22
   distribute, sublicense, and/or sell copies of the Software, and to permit
23
   persons  to whom  the Software  is  furnished to  do so,  subject to  the
24
   following conditions:
25
26
   The above copyright  notice and this permission notice  shall be included
27
   in all copies or substantial portions of the Software.
28
29
   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
30
   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
31
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32
   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33
   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
34
   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35
   USE OR OTHER DEALINGS IN THE SOFTWARE.
36
37
   SPDX-License-Identifier: MIT
38
*/
39
40
#ifdef XML_TOK_NS_C
41
42
const ENCODING *
43
9.40k
NS(XmlGetUtf8InternalEncoding)(void) {
44
9.40k
  return &ns(internal_utf8_encoding).enc;
45
9.40k
}
46
47
const ENCODING *
48
0
NS(XmlGetUtf16InternalEncoding)(void) {
49
0
#  if BYTEORDER == 1234
50
0
  return &ns(internal_little2_encoding).enc;
51
#  elif BYTEORDER == 4321
52
  return &ns(internal_big2_encoding).enc;
53
#  else
54
  const short n = 1;
55
  return (*(const char *)&n ? &ns(internal_little2_encoding).enc
56
                            : &ns(internal_big2_encoding).enc);
57
#  endif
58
0
}
59
60
static const ENCODING *const NS(encodings)[] = {
61
    &ns(latin1_encoding).enc, &ns(ascii_encoding).enc,
62
    &ns(utf8_encoding).enc,   &ns(big2_encoding).enc,
63
    &ns(big2_encoding).enc,   &ns(little2_encoding).enc,
64
    &ns(utf8_encoding).enc /* NO_ENC */
65
};
66
67
static int
68
NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
69
9.40k
                   const char **nextTokPtr) {
70
9.40k
  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE,
71
9.40k
                  ptr, end, nextTokPtr);
72
9.40k
}
73
74
static int
75
NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
76
0
                    const char **nextTokPtr) {
77
0
  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE,
78
0
                  ptr, end, nextTokPtr);
79
0
}
80
81
int
82
NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
83
18.8k
                    const char *name) {
84
18.8k
  int i = getEncodingIndex(name);
85
18.8k
  if (i == UNKNOWN_ENC)
86
0
    return 0;
87
18.8k
  SET_INIT_ENC_INDEX(p, i);
88
18.8k
  p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
89
18.8k
  p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
90
18.8k
  p->initEnc.updatePosition = initUpdatePosition;
91
18.8k
  p->encPtr = encPtr;
92
18.8k
  *encPtr = &(p->initEnc);
93
18.8k
  return 1;
94
18.8k
}
95
96
static const ENCODING *
97
161
NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) {
98
161
#  define ENCODING_MAX 128
99
161
  char buf[ENCODING_MAX] = "";
100
161
  char *p = buf;
101
161
  int i;
102
161
  XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
103
161
  if (ptr != end)
104
6
    return NULL;
105
155
  *p = 0;
106
155
  if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
107
0
    return enc;
108
155
  i = getEncodingIndex(buf);
109
155
  if (i == UNKNOWN_ENC)
110
33
    return NULL;
111
122
  return NS(encodings)[i];
112
155
}
113
114
int
115
NS(XmlParseXmlDecl)(int isGeneralTextEntity, const ENCODING *enc,
116
                    const char *ptr, const char *end, const char **badPtr,
117
                    const char **versionPtr, const char **versionEndPtr,
118
                    const char **encodingName, const ENCODING **encoding,
119
503
                    int *standalone) {
120
503
  return doParseXmlDecl(NS(findEncoding), isGeneralTextEntity, enc, ptr, end,
121
503
                        badPtr, versionPtr, versionEndPtr, encodingName,
122
503
                        encoding, standalone);
123
503
}
124
125
#endif /* XML_TOK_NS_C */