Coverage Report

Created: 2025-08-28 06:56

/src/CMake/Utilities/cmexpat/lib/xmltok_impl.c
Line
Count
Source (jump to first uncovered line)
1
/* This file is included (from xmltok.c, 1-3 times depending on XML_MIN_SIZE)!
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      Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
12
   Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
13
   Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
14
   Copyright (c) 2017      Rhodri James <rhodri@wildebeest.org.uk>
15
   Copyright (c) 2018      Benjamin Peterson <benjamin@python.org>
16
   Copyright (c) 2018      Anton Maklakov <antmak.pub@gmail.com>
17
   Copyright (c) 2019      David Loffredo <loffredo@steptools.com>
18
   Copyright (c) 2020      Boris Kolpackov <boris@codesynthesis.com>
19
   Copyright (c) 2022      Martin Ettl <ettl.martin78@googlemail.com>
20
   Licensed under the MIT license:
21
22
   Permission is  hereby granted,  free of charge,  to any  person obtaining
23
   a  copy  of  this  software   and  associated  documentation  files  (the
24
   "Software"),  to  deal in  the  Software  without restriction,  including
25
   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
26
   distribute, sublicense, and/or sell copies of the Software, and to permit
27
   persons  to whom  the Software  is  furnished to  do so,  subject to  the
28
   following conditions:
29
30
   The above copyright  notice and this permission notice  shall be included
31
   in all copies or substantial portions of the Software.
32
33
   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
34
   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
35
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
36
   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
37
   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
38
   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
39
   USE OR OTHER DEALINGS IN THE SOFTWARE.
40
*/
41
42
#ifdef XML_TOK_IMPL_C
43
44
#  ifndef IS_INVALID_CHAR // i.e. for UTF-16 and XML_MIN_SIZE not defined
45
33
#    define IS_INVALID_CHAR(enc, ptr, n) (0)
46
#  endif
47
48
#  define INVALID_LEAD_CASE(n, ptr, nextTokPtr)                                \
49
790k
  case BT_LEAD##n:                                                             \
50
790k
    if (end - ptr < n)                                                         \
51
790k
      return XML_TOK_PARTIAL_CHAR;                                             \
52
790k
    if (IS_INVALID_CHAR(enc, ptr, n)) {                                        \
53
86
      *(nextTokPtr) = (ptr);                                                   \
54
86
      return XML_TOK_INVALID;                                                  \
55
86
    }                                                                          \
56
790k
    ptr += n;                                                                  \
57
790k
    break;
58
59
#  define INVALID_CASES(ptr, nextTokPtr)                                       \
60
268k
    INVALID_LEAD_CASE(2, ptr, nextTokPtr)                                      \
61
331k
    INVALID_LEAD_CASE(3, ptr, nextTokPtr)                                      \
62
331k
    INVALID_LEAD_CASE(4, ptr, nextTokPtr)                                      \
63
190k
  case BT_NONXML:                                                              \
64
51
  case BT_MALFORM:                                                             \
65
93
  case BT_TRAIL:                                                               \
66
93
    *(nextTokPtr) = (ptr);                                                     \
67
93
    return XML_TOK_INVALID;
68
69
#  define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr)                        \
70
471k
  case BT_LEAD##n:                                                             \
71
471k
    if (end - ptr < n)                                                         \
72
471k
      return XML_TOK_PARTIAL_CHAR;                                             \
73
471k
    if (IS_INVALID_CHAR(enc, ptr, n) || ! IS_NAME_CHAR(enc, ptr, n)) {         \
74
276
      *nextTokPtr = ptr;                                                       \
75
276
      return XML_TOK_INVALID;                                                  \
76
276
    }                                                                          \
77
471k
    ptr += n;                                                                  \
78
471k
    break;
79
80
#  define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)                          \
81
29.3M
  case BT_NONASCII:                                                            \
82
29.3M
    if (! IS_NAME_CHAR_MINBPC(enc, ptr)) {                                     \
83
65
      *nextTokPtr = ptr;                                                       \
84
65
      return XML_TOK_INVALID;                                                  \
85
65
    }                                                                          \
86
29.3M
    /* fall through */                                                         \
87
29.3M
  case BT_NMSTRT:                                                              \
88
24.8M
  case BT_HEX:                                                                 \
89
28.8M
  case BT_DIGIT:                                                               \
90
28.9M
  case BT_NAME:                                                                \
91
29.3M
  case BT_MINUS:                                                               \
92
29.3M
    ptr += MINBPC(enc);                                                        \
93
29.3M
    break;                                                                     \
94
29.3M
    CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr)                              \
95
291k
    CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr)                              \
96
291k
    CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr)
97
98
#  define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr)                      \
99
139k
  case BT_LEAD##n:                                                             \
100
140k
    if ((end) - (ptr) < (n))                                                   \
101
139k
      return XML_TOK_PARTIAL_CHAR;                                             \
102
140k
    if (IS_INVALID_CHAR(enc, ptr, n) || ! IS_NMSTRT_CHAR(enc, ptr, n)) {       \
103
149
      *nextTokPtr = ptr;                                                       \
104
149
      return XML_TOK_INVALID;                                                  \
105
149
    }                                                                          \
106
140k
    ptr += n;                                                                  \
107
139k
    break;
108
109
#  define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)                        \
110
4.60M
  case BT_NONASCII:                                                            \
111
4.60M
    if (! IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {                                   \
112
0
      *nextTokPtr = ptr;                                                       \
113
0
      return XML_TOK_INVALID;                                                  \
114
0
    }                                                                          \
115
4.60M
    /* fall through */                                                         \
116
4.60M
  case BT_NMSTRT:                                                              \
117
4.60M
  case BT_HEX:                                                                 \
118
4.60M
    ptr += MINBPC(enc);                                                        \
119
4.60M
    break;                                                                     \
120
4.60M
    CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr)                            \
121
81.3k
    CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr)                            \
122
81.2k
    CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr)
123
124
#  ifndef PREFIX
125
#    define PREFIX(ident) ident
126
#  endif
127
128
#  define HAS_CHARS(enc, ptr, end, count)                                      \
129
314M
    ((end) - (ptr) >= ((count) * MINBPC(enc)))
130
131
10.4M
#  define HAS_CHAR(enc, ptr, end) HAS_CHARS(enc, ptr, end, 1)
132
133
#  define REQUIRE_CHARS(enc, ptr, end, count)                                  \
134
42.3M
    {                                                                          \
135
42.3M
      if (! HAS_CHARS(enc, ptr, end, count)) {                                 \
136
569
        return XML_TOK_PARTIAL;                                                \
137
569
      }                                                                        \
138
42.3M
    }
139
140
42.3M
#  define REQUIRE_CHAR(enc, ptr, end) REQUIRE_CHARS(enc, ptr, end, 1)
141
142
/* ptr points to character following "<!-" */
143
144
static int PTRCALL
145
PREFIX(scanComment)(const ENCODING *enc, const char *ptr, const char *end,
146
20.4k
                    const char **nextTokPtr) {
147
20.4k
  if (HAS_CHAR(enc, ptr, end)) {
148
20.3k
    if (! CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
149
12
      *nextTokPtr = ptr;
150
12
      return XML_TOK_INVALID;
151
12
    }
152
20.3k
    ptr += MINBPC(enc);
153
6.36M
    while (HAS_CHAR(enc, ptr, end)) {
154
6.36M
      switch (BYTE_TYPE(enc, ptr)) {
155
364k
        INVALID_CASES(ptr, nextTokPtr)
156
50.6k
      case BT_MINUS:
157
50.6k
        ptr += MINBPC(enc);
158
50.6k
        REQUIRE_CHAR(enc, ptr, end);
159
50.6k
        if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
160
20.2k
          ptr += MINBPC(enc);
161
20.2k
          REQUIRE_CHAR(enc, ptr, end);
162
20.2k
          if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
163
14
            *nextTokPtr = ptr;
164
14
            return XML_TOK_INVALID;
165
14
          }
166
20.2k
          *nextTokPtr = ptr + MINBPC(enc);
167
20.2k
          return XML_TOK_COMMENT;
168
20.2k
        }
169
30.4k
        break;
170
6.12M
      default:
171
6.12M
        ptr += MINBPC(enc);
172
6.12M
        break;
173
6.36M
      }
174
6.36M
    }
175
20.3k
  }
176
92
  return XML_TOK_PARTIAL;
177
20.4k
}
xmltok.c:normal_scanComment
Line
Count
Source
146
20.4k
                    const char **nextTokPtr) {
147
20.4k
  if (HAS_CHAR(enc, ptr, end)) {
148
20.3k
    if (! CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
149
12
      *nextTokPtr = ptr;
150
12
      return XML_TOK_INVALID;
151
12
    }
152
20.3k
    ptr += MINBPC(enc);
153
6.36M
    while (HAS_CHAR(enc, ptr, end)) {
154
6.36M
      switch (BYTE_TYPE(enc, ptr)) {
155
364k
        INVALID_CASES(ptr, nextTokPtr)
156
50.6k
      case BT_MINUS:
157
50.6k
        ptr += MINBPC(enc);
158
50.6k
        REQUIRE_CHAR(enc, ptr, end);
159
50.6k
        if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
160
20.2k
          ptr += MINBPC(enc);
161
20.2k
          REQUIRE_CHAR(enc, ptr, end);
162
20.2k
          if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
163
14
            *nextTokPtr = ptr;
164
14
            return XML_TOK_INVALID;
165
14
          }
166
20.2k
          *nextTokPtr = ptr + MINBPC(enc);
167
20.2k
          return XML_TOK_COMMENT;
168
20.2k
        }
169
30.4k
        break;
170
6.12M
      default:
171
6.12M
        ptr += MINBPC(enc);
172
6.12M
        break;
173
6.36M
      }
174
6.36M
    }
175
20.3k
  }
176
92
  return XML_TOK_PARTIAL;
177
20.4k
}
Unexecuted instantiation: xmltok.c:little2_scanComment
Unexecuted instantiation: xmltok.c:big2_scanComment
178
179
/* ptr points to character following "<!" */
180
181
static int PTRCALL
182
PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, const char *end,
183
62.7k
                 const char **nextTokPtr) {
184
62.7k
  REQUIRE_CHAR(enc, ptr, end);
185
62.7k
  switch (BYTE_TYPE(enc, ptr)) {
186
3.48k
  case BT_MINUS:
187
3.48k
    return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
188
1
  case BT_LSQB:
189
1
    *nextTokPtr = ptr + MINBPC(enc);
190
1
    return XML_TOK_COND_SECT_OPEN;
191
1.31k
  case BT_NMSTRT:
192
59.2k
  case BT_HEX:
193
59.2k
    ptr += MINBPC(enc);
194
59.2k
    break;
195
1
  default:
196
1
    *nextTokPtr = ptr;
197
1
    return XML_TOK_INVALID;
198
62.7k
  }
199
418k
  while (HAS_CHAR(enc, ptr, end)) {
200
418k
    switch (BYTE_TYPE(enc, ptr)) {
201
23
    case BT_PERCNT:
202
23
      REQUIRE_CHARS(enc, ptr, end, 2);
203
      /* don't allow <!ENTITY% foo "whatever"> */
204
19
      switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) {
205
1
      case BT_S:
206
3
      case BT_CR:
207
4
      case BT_LF:
208
5
      case BT_PERCNT:
209
5
        *nextTokPtr = ptr;
210
5
        return XML_TOK_INVALID;
211
19
      }
212
      /* fall through */
213
20.4k
    case BT_S:
214
55.3k
    case BT_CR:
215
59.1k
    case BT_LF:
216
59.1k
      *nextTokPtr = ptr;
217
59.1k
      return XML_TOK_DECL_OPEN;
218
327k
    case BT_NMSTRT:
219
359k
    case BT_HEX:
220
359k
      ptr += MINBPC(enc);
221
359k
      break;
222
8
    default:
223
8
      *nextTokPtr = ptr;
224
8
      return XML_TOK_INVALID;
225
418k
    }
226
418k
  }
227
80
  return XML_TOK_PARTIAL;
228
59.2k
}
xmltok.c:normal_scanDecl
Line
Count
Source
183
62.7k
                 const char **nextTokPtr) {
184
62.7k
  REQUIRE_CHAR(enc, ptr, end);
185
62.7k
  switch (BYTE_TYPE(enc, ptr)) {
186
3.48k
  case BT_MINUS:
187
3.48k
    return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
188
1
  case BT_LSQB:
189
1
    *nextTokPtr = ptr + MINBPC(enc);
190
1
    return XML_TOK_COND_SECT_OPEN;
191
1.31k
  case BT_NMSTRT:
192
59.2k
  case BT_HEX:
193
59.2k
    ptr += MINBPC(enc);
194
59.2k
    break;
195
1
  default:
196
1
    *nextTokPtr = ptr;
197
1
    return XML_TOK_INVALID;
198
62.7k
  }
199
418k
  while (HAS_CHAR(enc, ptr, end)) {
200
418k
    switch (BYTE_TYPE(enc, ptr)) {
201
23
    case BT_PERCNT:
202
23
      REQUIRE_CHARS(enc, ptr, end, 2);
203
      /* don't allow <!ENTITY% foo "whatever"> */
204
19
      switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) {
205
1
      case BT_S:
206
3
      case BT_CR:
207
4
      case BT_LF:
208
5
      case BT_PERCNT:
209
5
        *nextTokPtr = ptr;
210
5
        return XML_TOK_INVALID;
211
19
      }
212
      /* fall through */
213
20.4k
    case BT_S:
214
55.3k
    case BT_CR:
215
59.1k
    case BT_LF:
216
59.1k
      *nextTokPtr = ptr;
217
59.1k
      return XML_TOK_DECL_OPEN;
218
327k
    case BT_NMSTRT:
219
359k
    case BT_HEX:
220
359k
      ptr += MINBPC(enc);
221
359k
      break;
222
8
    default:
223
8
      *nextTokPtr = ptr;
224
8
      return XML_TOK_INVALID;
225
418k
    }
226
418k
  }
227
80
  return XML_TOK_PARTIAL;
228
59.2k
}
Unexecuted instantiation: xmltok.c:little2_scanDecl
Unexecuted instantiation: xmltok.c:big2_scanDecl
229
230
static int PTRCALL
231
PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, const char *end,
232
36.9k
                      int *tokPtr) {
233
36.9k
  int upper = 0;
234
36.9k
  UNUSED_P(enc);
235
36.9k
  *tokPtr = XML_TOK_PI;
236
36.9k
  if (end - ptr != MINBPC(enc) * 3)
237
27.2k
    return 1;
238
9.72k
  switch (BYTE_TO_ASCII(enc, ptr)) {
239
6.75k
  case ASCII_x:
240
6.75k
    break;
241
1.08k
  case ASCII_X:
242
1.08k
    upper = 1;
243
1.08k
    break;
244
1.89k
  default:
245
1.89k
    return 1;
246
9.72k
  }
247
7.83k
  ptr += MINBPC(enc);
248
7.83k
  switch (BYTE_TO_ASCII(enc, ptr)) {
249
2.22k
  case ASCII_m:
250
2.22k
    break;
251
751
  case ASCII_M:
252
751
    upper = 1;
253
751
    break;
254
4.85k
  default:
255
4.85k
    return 1;
256
7.83k
  }
257
2.97k
  ptr += MINBPC(enc);
258
2.97k
  switch (BYTE_TO_ASCII(enc, ptr)) {
259
1.14k
  case ASCII_l:
260
1.14k
    break;
261
4
  case ASCII_L:
262
4
    upper = 1;
263
4
    break;
264
1.83k
  default:
265
1.83k
    return 1;
266
2.97k
  }
267
1.14k
  if (upper)
268
6
    return 0;
269
1.14k
  *tokPtr = XML_TOK_XML_DECL;
270
1.14k
  return 1;
271
1.14k
}
xmltok.c:normal_checkPiTarget
Line
Count
Source
232
36.9k
                      int *tokPtr) {
233
36.9k
  int upper = 0;
234
36.9k
  UNUSED_P(enc);
235
36.9k
  *tokPtr = XML_TOK_PI;
236
36.9k
  if (end - ptr != MINBPC(enc) * 3)
237
27.2k
    return 1;
238
9.72k
  switch (BYTE_TO_ASCII(enc, ptr)) {
239
6.75k
  case ASCII_x:
240
6.75k
    break;
241
1.08k
  case ASCII_X:
242
1.08k
    upper = 1;
243
1.08k
    break;
244
1.89k
  default:
245
1.89k
    return 1;
246
9.72k
  }
247
7.83k
  ptr += MINBPC(enc);
248
7.83k
  switch (BYTE_TO_ASCII(enc, ptr)) {
249
2.22k
  case ASCII_m:
250
2.22k
    break;
251
751
  case ASCII_M:
252
751
    upper = 1;
253
751
    break;
254
4.85k
  default:
255
4.85k
    return 1;
256
7.83k
  }
257
2.97k
  ptr += MINBPC(enc);
258
2.97k
  switch (BYTE_TO_ASCII(enc, ptr)) {
259
1.14k
  case ASCII_l:
260
1.14k
    break;
261
4
  case ASCII_L:
262
4
    upper = 1;
263
4
    break;
264
1.83k
  default:
265
1.83k
    return 1;
266
2.97k
  }
267
1.14k
  if (upper)
268
6
    return 0;
269
1.14k
  *tokPtr = XML_TOK_XML_DECL;
270
1.14k
  return 1;
271
1.14k
}
Unexecuted instantiation: xmltok.c:little2_checkPiTarget
Unexecuted instantiation: xmltok.c:big2_checkPiTarget
272
273
/* ptr points to character following "<?" */
274
275
static int PTRCALL
276
PREFIX(scanPi)(const ENCODING *enc, const char *ptr, const char *end,
277
37.1k
               const char **nextTokPtr) {
278
37.1k
  int tok;
279
37.1k
  const char *target = ptr;
280
37.1k
  REQUIRE_CHAR(enc, ptr, end);
281
37.1k
  switch (BYTE_TYPE(enc, ptr)) {
282
50.2k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
283
2
  default:
284
2
    *nextTokPtr = ptr;
285
2
    return XML_TOK_INVALID;
286
37.1k
  }
287
2.48M
  while (HAS_CHAR(enc, ptr, end)) {
288
2.48M
    switch (BYTE_TYPE(enc, ptr)) {
289
9.02M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
290
8.74k
    case BT_S:
291
10.1k
    case BT_CR:
292
13.5k
    case BT_LF:
293
13.5k
      if (! PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
294
3
        *nextTokPtr = ptr;
295
3
        return XML_TOK_INVALID;
296
3
      }
297
13.5k
      ptr += MINBPC(enc);
298
7.13M
      while (HAS_CHAR(enc, ptr, end)) {
299
7.13M
        switch (BYTE_TYPE(enc, ptr)) {
300
216k
          INVALID_CASES(ptr, nextTokPtr)
301
67.5k
        case BT_QUEST:
302
67.5k
          ptr += MINBPC(enc);
303
67.5k
          REQUIRE_CHAR(enc, ptr, end);
304
67.5k
          if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
305
13.3k
            *nextTokPtr = ptr + MINBPC(enc);
306
13.3k
            return tok;
307
13.3k
          }
308
54.2k
          break;
309
6.96M
        default:
310
6.96M
          ptr += MINBPC(enc);
311
6.96M
          break;
312
7.13M
        }
313
7.13M
      }
314
138
      return XML_TOK_PARTIAL;
315
23.4k
    case BT_QUEST:
316
23.4k
      if (! PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
317
3
        *nextTokPtr = ptr;
318
3
        return XML_TOK_INVALID;
319
3
      }
320
23.4k
      ptr += MINBPC(enc);
321
23.4k
      REQUIRE_CHAR(enc, ptr, end);
322
23.4k
      if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
323
23.4k
        *nextTokPtr = ptr + MINBPC(enc);
324
23.4k
        return tok;
325
23.4k
      }
326
      /* fall through */
327
33
    default:
328
33
      *nextTokPtr = ptr;
329
33
      return XML_TOK_INVALID;
330
2.48M
    }
331
2.48M
  }
332
64
  return XML_TOK_PARTIAL;
333
37.0k
}
xmltok.c:normal_scanPi
Line
Count
Source
277
37.1k
               const char **nextTokPtr) {
278
37.1k
  int tok;
279
37.1k
  const char *target = ptr;
280
37.1k
  REQUIRE_CHAR(enc, ptr, end);
281
37.1k
  switch (BYTE_TYPE(enc, ptr)) {
282
50.2k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
283
2
  default:
284
2
    *nextTokPtr = ptr;
285
2
    return XML_TOK_INVALID;
286
37.1k
  }
287
2.48M
  while (HAS_CHAR(enc, ptr, end)) {
288
2.48M
    switch (BYTE_TYPE(enc, ptr)) {
289
9.02M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
290
8.74k
    case BT_S:
291
10.1k
    case BT_CR:
292
13.5k
    case BT_LF:
293
13.5k
      if (! PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
294
3
        *nextTokPtr = ptr;
295
3
        return XML_TOK_INVALID;
296
3
      }
297
13.5k
      ptr += MINBPC(enc);
298
7.13M
      while (HAS_CHAR(enc, ptr, end)) {
299
7.13M
        switch (BYTE_TYPE(enc, ptr)) {
300
216k
          INVALID_CASES(ptr, nextTokPtr)
301
67.5k
        case BT_QUEST:
302
67.5k
          ptr += MINBPC(enc);
303
67.5k
          REQUIRE_CHAR(enc, ptr, end);
304
67.5k
          if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
305
13.3k
            *nextTokPtr = ptr + MINBPC(enc);
306
13.3k
            return tok;
307
13.3k
          }
308
54.2k
          break;
309
6.96M
        default:
310
6.96M
          ptr += MINBPC(enc);
311
6.96M
          break;
312
7.13M
        }
313
7.13M
      }
314
138
      return XML_TOK_PARTIAL;
315
23.4k
    case BT_QUEST:
316
23.4k
      if (! PREFIX(checkPiTarget)(enc, target, ptr, &tok)) {
317
3
        *nextTokPtr = ptr;
318
3
        return XML_TOK_INVALID;
319
3
      }
320
23.4k
      ptr += MINBPC(enc);
321
23.4k
      REQUIRE_CHAR(enc, ptr, end);
322
23.4k
      if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
323
23.4k
        *nextTokPtr = ptr + MINBPC(enc);
324
23.4k
        return tok;
325
23.4k
      }
326
      /* fall through */
327
33
    default:
328
33
      *nextTokPtr = ptr;
329
33
      return XML_TOK_INVALID;
330
2.48M
    }
331
2.48M
  }
332
64
  return XML_TOK_PARTIAL;
333
37.0k
}
Unexecuted instantiation: xmltok.c:little2_scanPi
Unexecuted instantiation: xmltok.c:big2_scanPi
334
335
static int PTRCALL
336
PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, const char *end,
337
1.41k
                         const char **nextTokPtr) {
338
1.41k
  static const char CDATA_LSQB[]
339
1.41k
      = {ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, ASCII_LSQB};
340
1.41k
  int i;
341
1.41k
  UNUSED_P(enc);
342
  /* CDATA[ */
343
1.41k
  REQUIRE_CHARS(enc, ptr, end, 6);
344
9.65k
  for (i = 0; i < 6; i++, ptr += MINBPC(enc)) {
345
8.30k
    if (! CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) {
346
54
      *nextTokPtr = ptr;
347
54
      return XML_TOK_INVALID;
348
54
    }
349
8.30k
  }
350
1.35k
  *nextTokPtr = ptr;
351
1.35k
  return XML_TOK_CDATA_SECT_OPEN;
352
1.40k
}
xmltok.c:normal_scanCdataSection
Line
Count
Source
337
1.41k
                         const char **nextTokPtr) {
338
1.41k
  static const char CDATA_LSQB[]
339
1.41k
      = {ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, ASCII_LSQB};
340
1.41k
  int i;
341
1.41k
  UNUSED_P(enc);
342
  /* CDATA[ */
343
1.41k
  REQUIRE_CHARS(enc, ptr, end, 6);
344
9.65k
  for (i = 0; i < 6; i++, ptr += MINBPC(enc)) {
345
8.30k
    if (! CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) {
346
54
      *nextTokPtr = ptr;
347
54
      return XML_TOK_INVALID;
348
54
    }
349
8.30k
  }
350
1.35k
  *nextTokPtr = ptr;
351
1.35k
  return XML_TOK_CDATA_SECT_OPEN;
352
1.40k
}
Unexecuted instantiation: xmltok.c:little2_scanCdataSection
Unexecuted instantiation: xmltok.c:big2_scanCdataSection
353
354
static int PTRCALL
355
PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
356
3.01M
                        const char **nextTokPtr) {
357
3.01M
  if (ptr >= end)
358
188
    return XML_TOK_NONE;
359
3.01M
  if (MINBPC(enc) > 1) {
360
0
    size_t n = end - ptr;
361
0
    if (n & (MINBPC(enc) - 1)) {
362
0
      n &= ~(MINBPC(enc) - 1);
363
0
      if (n == 0)
364
0
        return XML_TOK_PARTIAL;
365
0
      end = ptr + n;
366
0
    }
367
0
  }
368
3.01M
  switch (BYTE_TYPE(enc, ptr)) {
369
486k
  case BT_RSQB:
370
486k
    ptr += MINBPC(enc);
371
486k
    REQUIRE_CHAR(enc, ptr, end);
372
486k
    if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB))
373
210k
      break;
374
275k
    ptr += MINBPC(enc);
375
275k
    REQUIRE_CHAR(enc, ptr, end);
376
275k
    if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
377
274k
      ptr -= MINBPC(enc);
378
274k
      break;
379
274k
    }
380
1.20k
    *nextTokPtr = ptr + MINBPC(enc);
381
1.20k
    return XML_TOK_CDATA_SECT_CLOSE;
382
1.18M
  case BT_CR:
383
1.18M
    ptr += MINBPC(enc);
384
1.18M
    REQUIRE_CHAR(enc, ptr, end);
385
1.18M
    if (BYTE_TYPE(enc, ptr) == BT_LF)
386
172k
      ptr += MINBPC(enc);
387
1.18M
    *nextTokPtr = ptr;
388
1.18M
    return XML_TOK_DATA_NEWLINE;
389
616k
  case BT_LF:
390
616k
    *nextTokPtr = ptr + MINBPC(enc);
391
616k
    return XML_TOK_DATA_NEWLINE;
392
616k
    INVALID_CASES(ptr, nextTokPtr)
393
671k
  default:
394
671k
    ptr += MINBPC(enc);
395
671k
    break;
396
3.01M
  }
397
28.8M
  while (HAS_CHAR(enc, ptr, end)) {
398
28.8M
    switch (BYTE_TYPE(enc, ptr)) {
399
0
#  define LEAD_CASE(n)                                                         \
400
531k
  case BT_LEAD##n:                                                             \
401
531k
    if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) {                       \
402
15
      *nextTokPtr = ptr;                                                       \
403
15
      return XML_TOK_DATA_CHARS;                                               \
404
15
    }                                                                          \
405
531k
    ptr += n;                                                                  \
406
531k
    break;
407
250k
      LEAD_CASE(2)
408
243k
      LEAD_CASE(3)
409
36.7k
      LEAD_CASE(4)
410
0
#  undef LEAD_CASE
411
7
    case BT_NONXML:
412
9
    case BT_MALFORM:
413
13
    case BT_TRAIL:
414
538k
    case BT_CR:
415
781k
    case BT_LF:
416
1.21M
    case BT_RSQB:
417
1.21M
      *nextTokPtr = ptr;
418
1.21M
      return XML_TOK_DATA_CHARS;
419
27.1M
    default:
420
27.1M
      ptr += MINBPC(enc);
421
27.1M
      break;
422
28.8M
    }
423
28.8M
  }
424
65
  *nextTokPtr = ptr;
425
65
  return XML_TOK_DATA_CHARS;
426
1.21M
}
xmltok.c:normal_cdataSectionTok
Line
Count
Source
356
3.01M
                        const char **nextTokPtr) {
357
3.01M
  if (ptr >= end)
358
188
    return XML_TOK_NONE;
359
3.01M
  if (MINBPC(enc) > 1) {
360
0
    size_t n = end - ptr;
361
0
    if (n & (MINBPC(enc) - 1)) {
362
0
      n &= ~(MINBPC(enc) - 1);
363
0
      if (n == 0)
364
0
        return XML_TOK_PARTIAL;
365
0
      end = ptr + n;
366
0
    }
367
0
  }
368
3.01M
  switch (BYTE_TYPE(enc, ptr)) {
369
486k
  case BT_RSQB:
370
486k
    ptr += MINBPC(enc);
371
486k
    REQUIRE_CHAR(enc, ptr, end);
372
486k
    if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB))
373
210k
      break;
374
275k
    ptr += MINBPC(enc);
375
275k
    REQUIRE_CHAR(enc, ptr, end);
376
275k
    if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
377
274k
      ptr -= MINBPC(enc);
378
274k
      break;
379
274k
    }
380
1.20k
    *nextTokPtr = ptr + MINBPC(enc);
381
1.20k
    return XML_TOK_CDATA_SECT_CLOSE;
382
1.18M
  case BT_CR:
383
1.18M
    ptr += MINBPC(enc);
384
1.18M
    REQUIRE_CHAR(enc, ptr, end);
385
1.18M
    if (BYTE_TYPE(enc, ptr) == BT_LF)
386
172k
      ptr += MINBPC(enc);
387
1.18M
    *nextTokPtr = ptr;
388
1.18M
    return XML_TOK_DATA_NEWLINE;
389
616k
  case BT_LF:
390
616k
    *nextTokPtr = ptr + MINBPC(enc);
391
616k
    return XML_TOK_DATA_NEWLINE;
392
616k
    INVALID_CASES(ptr, nextTokPtr)
393
671k
  default:
394
671k
    ptr += MINBPC(enc);
395
671k
    break;
396
3.01M
  }
397
28.8M
  while (HAS_CHAR(enc, ptr, end)) {
398
28.8M
    switch (BYTE_TYPE(enc, ptr)) {
399
0
#  define LEAD_CASE(n)                                                         \
400
0
  case BT_LEAD##n:                                                             \
401
0
    if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) {                       \
402
0
      *nextTokPtr = ptr;                                                       \
403
0
      return XML_TOK_DATA_CHARS;                                               \
404
0
    }                                                                          \
405
0
    ptr += n;                                                                  \
406
0
    break;
407
250k
      LEAD_CASE(2)
408
243k
      LEAD_CASE(3)
409
36.7k
      LEAD_CASE(4)
410
0
#  undef LEAD_CASE
411
7
    case BT_NONXML:
412
9
    case BT_MALFORM:
413
13
    case BT_TRAIL:
414
538k
    case BT_CR:
415
781k
    case BT_LF:
416
1.21M
    case BT_RSQB:
417
1.21M
      *nextTokPtr = ptr;
418
1.21M
      return XML_TOK_DATA_CHARS;
419
27.1M
    default:
420
27.1M
      ptr += MINBPC(enc);
421
27.1M
      break;
422
28.8M
    }
423
28.8M
  }
424
65
  *nextTokPtr = ptr;
425
65
  return XML_TOK_DATA_CHARS;
426
1.21M
}
Unexecuted instantiation: xmltok.c:little2_cdataSectionTok
Unexecuted instantiation: xmltok.c:big2_cdataSectionTok
427
428
/* ptr points to character following "</" */
429
430
static int PTRCALL
431
PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, const char *end,
432
54.4k
                   const char **nextTokPtr) {
433
54.4k
  REQUIRE_CHAR(enc, ptr, end);
434
54.4k
  switch (BYTE_TYPE(enc, ptr)) {
435
65.0k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
436
8
  default:
437
8
    *nextTokPtr = ptr;
438
8
    return XML_TOK_INVALID;
439
54.4k
  }
440
283k
  while (HAS_CHAR(enc, ptr, end)) {
441
283k
    switch (BYTE_TYPE(enc, ptr)) {
442
665k
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
443
451
    case BT_S:
444
785
    case BT_CR:
445
1.35k
    case BT_LF:
446
16.3k
      for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
447
16.3k
        switch (BYTE_TYPE(enc, ptr)) {
448
12.6k
        case BT_S:
449
13.8k
        case BT_CR:
450
15.0k
        case BT_LF:
451
15.0k
          break;
452
1.30k
        case BT_GT:
453
1.30k
          *nextTokPtr = ptr + MINBPC(enc);
454
1.30k
          return XML_TOK_END_TAG;
455
4
        default:
456
4
          *nextTokPtr = ptr;
457
4
          return XML_TOK_INVALID;
458
16.3k
        }
459
16.3k
      }
460
48
      return XML_TOK_PARTIAL;
461
#  ifdef XML_NS
462
    case BT_COLON:
463
      /* no need to check qname syntax here,
464
         since end-tag must match exactly */
465
      ptr += MINBPC(enc);
466
      break;
467
#  endif
468
52.9k
    case BT_GT:
469
52.9k
      *nextTokPtr = ptr + MINBPC(enc);
470
52.9k
      return XML_TOK_END_TAG;
471
14
    default:
472
14
      *nextTokPtr = ptr;
473
14
      return XML_TOK_INVALID;
474
283k
    }
475
283k
  }
476
124
  return XML_TOK_PARTIAL;
477
54.4k
}
xmltok.c:normal_scanEndTag
Line
Count
Source
432
54.4k
                   const char **nextTokPtr) {
433
54.4k
  REQUIRE_CHAR(enc, ptr, end);
434
54.4k
  switch (BYTE_TYPE(enc, ptr)) {
435
65.0k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
436
8
  default:
437
8
    *nextTokPtr = ptr;
438
8
    return XML_TOK_INVALID;
439
54.4k
  }
440
283k
  while (HAS_CHAR(enc, ptr, end)) {
441
283k
    switch (BYTE_TYPE(enc, ptr)) {
442
665k
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
443
451
    case BT_S:
444
785
    case BT_CR:
445
1.35k
    case BT_LF:
446
16.3k
      for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
447
16.3k
        switch (BYTE_TYPE(enc, ptr)) {
448
12.6k
        case BT_S:
449
13.8k
        case BT_CR:
450
15.0k
        case BT_LF:
451
15.0k
          break;
452
1.30k
        case BT_GT:
453
1.30k
          *nextTokPtr = ptr + MINBPC(enc);
454
1.30k
          return XML_TOK_END_TAG;
455
4
        default:
456
4
          *nextTokPtr = ptr;
457
4
          return XML_TOK_INVALID;
458
16.3k
        }
459
16.3k
      }
460
48
      return XML_TOK_PARTIAL;
461
#  ifdef XML_NS
462
    case BT_COLON:
463
      /* no need to check qname syntax here,
464
         since end-tag must match exactly */
465
      ptr += MINBPC(enc);
466
      break;
467
#  endif
468
52.9k
    case BT_GT:
469
52.9k
      *nextTokPtr = ptr + MINBPC(enc);
470
52.9k
      return XML_TOK_END_TAG;
471
14
    default:
472
14
      *nextTokPtr = ptr;
473
14
      return XML_TOK_INVALID;
474
283k
    }
475
283k
  }
476
124
  return XML_TOK_PARTIAL;
477
54.4k
}
Unexecuted instantiation: xmltok.c:little2_scanEndTag
Unexecuted instantiation: xmltok.c:big2_scanEndTag
478
479
/* ptr points to character following "&#X" */
480
481
static int PTRCALL
482
PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, const char *end,
483
193k
                       const char **nextTokPtr) {
484
193k
  if (HAS_CHAR(enc, ptr, end)) {
485
193k
    switch (BYTE_TYPE(enc, ptr)) {
486
74.3k
    case BT_DIGIT:
487
193k
    case BT_HEX:
488
193k
      break;
489
7
    default:
490
7
      *nextTokPtr = ptr;
491
7
      return XML_TOK_INVALID;
492
193k
    }
493
696k
    for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
494
696k
      switch (BYTE_TYPE(enc, ptr)) {
495
352k
      case BT_DIGIT:
496
503k
      case BT_HEX:
497
503k
        break;
498
193k
      case BT_SEMI:
499
193k
        *nextTokPtr = ptr + MINBPC(enc);
500
193k
        return XML_TOK_CHAR_REF;
501
2
      default:
502
2
        *nextTokPtr = ptr;
503
2
        return XML_TOK_INVALID;
504
696k
      }
505
696k
    }
506
193k
  }
507
27
  return XML_TOK_PARTIAL;
508
193k
}
xmltok.c:normal_scanHexCharRef
Line
Count
Source
483
193k
                       const char **nextTokPtr) {
484
193k
  if (HAS_CHAR(enc, ptr, end)) {
485
193k
    switch (BYTE_TYPE(enc, ptr)) {
486
74.3k
    case BT_DIGIT:
487
193k
    case BT_HEX:
488
193k
      break;
489
7
    default:
490
7
      *nextTokPtr = ptr;
491
7
      return XML_TOK_INVALID;
492
193k
    }
493
696k
    for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
494
696k
      switch (BYTE_TYPE(enc, ptr)) {
495
352k
      case BT_DIGIT:
496
503k
      case BT_HEX:
497
503k
        break;
498
193k
      case BT_SEMI:
499
193k
        *nextTokPtr = ptr + MINBPC(enc);
500
193k
        return XML_TOK_CHAR_REF;
501
2
      default:
502
2
        *nextTokPtr = ptr;
503
2
        return XML_TOK_INVALID;
504
696k
      }
505
696k
    }
506
193k
  }
507
27
  return XML_TOK_PARTIAL;
508
193k
}
Unexecuted instantiation: xmltok.c:little2_scanHexCharRef
Unexecuted instantiation: xmltok.c:big2_scanHexCharRef
509
510
/* ptr points to character following "&#" */
511
512
static int PTRCALL
513
PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, const char *end,
514
200k
                    const char **nextTokPtr) {
515
200k
  if (HAS_CHAR(enc, ptr, end)) {
516
200k
    if (CHAR_MATCHES(enc, ptr, ASCII_x))
517
193k
      return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
518
7.44k
    switch (BYTE_TYPE(enc, ptr)) {
519
7.42k
    case BT_DIGIT:
520
7.42k
      break;
521
11
    default:
522
11
      *nextTokPtr = ptr;
523
11
      return XML_TOK_INVALID;
524
7.44k
    }
525
22.2k
    for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
526
22.2k
      switch (BYTE_TYPE(enc, ptr)) {
527
14.8k
      case BT_DIGIT:
528
14.8k
        break;
529
7.40k
      case BT_SEMI:
530
7.40k
        *nextTokPtr = ptr + MINBPC(enc);
531
7.40k
        return XML_TOK_CHAR_REF;
532
2
      default:
533
2
        *nextTokPtr = ptr;
534
2
        return XML_TOK_INVALID;
535
22.2k
      }
536
22.2k
    }
537
7.42k
  }
538
22
  return XML_TOK_PARTIAL;
539
200k
}
xmltok.c:normal_scanCharRef
Line
Count
Source
514
200k
                    const char **nextTokPtr) {
515
200k
  if (HAS_CHAR(enc, ptr, end)) {
516
200k
    if (CHAR_MATCHES(enc, ptr, ASCII_x))
517
193k
      return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
518
7.44k
    switch (BYTE_TYPE(enc, ptr)) {
519
7.42k
    case BT_DIGIT:
520
7.42k
      break;
521
11
    default:
522
11
      *nextTokPtr = ptr;
523
11
      return XML_TOK_INVALID;
524
7.44k
    }
525
22.2k
    for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
526
22.2k
      switch (BYTE_TYPE(enc, ptr)) {
527
14.8k
      case BT_DIGIT:
528
14.8k
        break;
529
7.40k
      case BT_SEMI:
530
7.40k
        *nextTokPtr = ptr + MINBPC(enc);
531
7.40k
        return XML_TOK_CHAR_REF;
532
2
      default:
533
2
        *nextTokPtr = ptr;
534
2
        return XML_TOK_INVALID;
535
22.2k
      }
536
22.2k
    }
537
7.42k
  }
538
22
  return XML_TOK_PARTIAL;
539
200k
}
Unexecuted instantiation: xmltok.c:little2_scanCharRef
Unexecuted instantiation: xmltok.c:big2_scanCharRef
540
541
/* ptr points to character following "&" */
542
543
static int PTRCALL
544
PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end,
545
379k
                const char **nextTokPtr) {
546
379k
  REQUIRE_CHAR(enc, ptr, end);
547
379k
  switch (BYTE_TYPE(enc, ptr)) {
548
88.4k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
549
200k
  case BT_NUM:
550
200k
    return PREFIX(scanCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
551
4
  default:
552
4
    *nextTokPtr = ptr;
553
4
    return XML_TOK_INVALID;
554
379k
  }
555
1.30M
  while (HAS_CHAR(enc, ptr, end)) {
556
1.30M
    switch (BYTE_TYPE(enc, ptr)) {
557
4.23M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
558
178k
    case BT_SEMI:
559
178k
      *nextTokPtr = ptr + MINBPC(enc);
560
178k
      return XML_TOK_ENTITY_REF;
561
11
    default:
562
11
      *nextTokPtr = ptr;
563
11
      return XML_TOK_INVALID;
564
1.30M
    }
565
1.30M
  }
566
92
  return XML_TOK_PARTIAL;
567
178k
}
xmltok.c:normal_scanRef
Line
Count
Source
545
379k
                const char **nextTokPtr) {
546
379k
  REQUIRE_CHAR(enc, ptr, end);
547
379k
  switch (BYTE_TYPE(enc, ptr)) {
548
88.4k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
549
200k
  case BT_NUM:
550
200k
    return PREFIX(scanCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
551
4
  default:
552
4
    *nextTokPtr = ptr;
553
4
    return XML_TOK_INVALID;
554
379k
  }
555
1.30M
  while (HAS_CHAR(enc, ptr, end)) {
556
1.30M
    switch (BYTE_TYPE(enc, ptr)) {
557
4.23M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
558
178k
    case BT_SEMI:
559
178k
      *nextTokPtr = ptr + MINBPC(enc);
560
178k
      return XML_TOK_ENTITY_REF;
561
11
    default:
562
11
      *nextTokPtr = ptr;
563
11
      return XML_TOK_INVALID;
564
1.30M
    }
565
1.30M
  }
566
92
  return XML_TOK_PARTIAL;
567
178k
}
Unexecuted instantiation: xmltok.c:little2_scanRef
Unexecuted instantiation: xmltok.c:big2_scanRef
568
569
/* ptr points to character following first character of attribute name */
570
571
static int PTRCALL
572
PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
573
145k
                 const char **nextTokPtr) {
574
#  ifdef XML_NS
575
  int hadColon = 0;
576
#  endif
577
4.61M
  while (HAS_CHAR(enc, ptr, end)) {
578
4.61M
    switch (BYTE_TYPE(enc, ptr)) {
579
2.62M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
580
#  ifdef XML_NS
581
    case BT_COLON:
582
      if (hadColon) {
583
        *nextTokPtr = ptr;
584
        return XML_TOK_INVALID;
585
      }
586
      hadColon = 1;
587
      ptr += MINBPC(enc);
588
      REQUIRE_CHAR(enc, ptr, end);
589
      switch (BYTE_TYPE(enc, ptr)) {
590
        CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
591
      default:
592
        *nextTokPtr = ptr;
593
        return XML_TOK_INVALID;
594
      }
595
      break;
596
#  endif
597
2.77k
    case BT_S:
598
19.1k
    case BT_CR:
599
20.1k
    case BT_LF:
600
38.8k
      for (;;) {
601
38.8k
        int t;
602
603
38.8k
        ptr += MINBPC(enc);
604
38.8k
        REQUIRE_CHAR(enc, ptr, end);
605
38.7k
        t = BYTE_TYPE(enc, ptr);
606
38.7k
        if (t == BT_EQUALS)
607
20.0k
          break;
608
18.6k
        switch (t) {
609
2.72k
        case BT_S:
610
3.76k
        case BT_LF:
611
18.6k
        case BT_CR:
612
18.6k
          break;
613
8
        default:
614
8
          *nextTokPtr = ptr;
615
8
          return XML_TOK_INVALID;
616
18.6k
        }
617
18.6k
      }
618
      /* fall through */
619
3.77M
    case BT_EQUALS: {
620
3.77M
      int open;
621
#  ifdef XML_NS
622
      hadColon = 0;
623
#  endif
624
3.84M
      for (;;) {
625
3.84M
        ptr += MINBPC(enc);
626
3.84M
        REQUIRE_CHAR(enc, ptr, end);
627
3.84M
        open = BYTE_TYPE(enc, ptr);
628
3.84M
        if (open == BT_QUOT || open == BT_APOS)
629
3.77M
          break;
630
69.9k
        switch (open) {
631
12.7k
        case BT_S:
632
25.6k
        case BT_LF:
633
69.9k
        case BT_CR:
634
69.9k
          break;
635
17
        default:
636
17
          *nextTokPtr = ptr;
637
17
          return XML_TOK_INVALID;
638
69.9k
        }
639
69.9k
      }
640
3.77M
      ptr += MINBPC(enc);
641
      /* in attribute value */
642
26.7M
      for (;;) {
643
26.7M
        int t;
644
26.7M
        REQUIRE_CHAR(enc, ptr, end);
645
26.7M
        t = BYTE_TYPE(enc, ptr);
646
26.7M
        if (t == open)
647
3.77M
          break;
648
22.9M
        switch (t) {
649
515k
          INVALID_CASES(ptr, nextTokPtr)
650
111k
        case BT_AMP: {
651
111k
          int tok = PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, &ptr);
652
111k
          if (tok <= 0) {
653
35
            if (tok == XML_TOK_INVALID)
654
15
              *nextTokPtr = ptr;
655
35
            return tok;
656
35
          }
657
110k
          break;
658
111k
        }
659
110k
        case BT_LT:
660
7
          *nextTokPtr = ptr;
661
7
          return XML_TOK_INVALID;
662
22.5M
        default:
663
22.5M
          ptr += MINBPC(enc);
664
22.5M
          break;
665
22.9M
        }
666
22.9M
      }
667
3.77M
      ptr += MINBPC(enc);
668
3.77M
      REQUIRE_CHAR(enc, ptr, end);
669
3.77M
      switch (BYTE_TYPE(enc, ptr)) {
670
1.96M
      case BT_S:
671
3.69M
      case BT_CR:
672
3.73M
      case BT_LF:
673
3.73M
        break;
674
29.6k
      case BT_SOL:
675
29.6k
        goto sol;
676
5.03k
      case BT_GT:
677
5.03k
        goto gt;
678
6
      default:
679
6
        *nextTokPtr = ptr;
680
6
        return XML_TOK_INVALID;
681
3.77M
      }
682
      /* ptr points to closing quote */
683
4.18M
      for (;;) {
684
4.18M
        ptr += MINBPC(enc);
685
4.18M
        REQUIRE_CHAR(enc, ptr, end);
686
4.18M
        switch (BYTE_TYPE(enc, ptr)) {
687
3.62M
          CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
688
326k
        case BT_S:
689
386k
        case BT_CR:
690
448k
        case BT_LF:
691
448k
          continue;
692
395
        case BT_GT:
693
5.43k
        gt:
694
5.43k
          *nextTokPtr = ptr + MINBPC(enc);
695
5.43k
          return XML_TOK_START_TAG_WITH_ATTS;
696
109k
        case BT_SOL:
697
139k
        sol:
698
139k
          ptr += MINBPC(enc);
699
139k
          REQUIRE_CHAR(enc, ptr, end);
700
139k
          if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
701
12
            *nextTokPtr = ptr;
702
12
            return XML_TOK_INVALID;
703
12
          }
704
139k
          *nextTokPtr = ptr + MINBPC(enc);
705
139k
          return XML_TOK_EMPTY_ELEMENT_WITH_ATTS;
706
3
        default:
707
3
          *nextTokPtr = ptr;
708
3
          return XML_TOK_INVALID;
709
4.18M
        }
710
3.62M
        break;
711
4.18M
      }
712
3.62M
      break;
713
3.73M
    }
714
3.62M
    default:
715
20
      *nextTokPtr = ptr;
716
20
      return XML_TOK_INVALID;
717
4.61M
    }
718
4.61M
  }
719
88
  return XML_TOK_PARTIAL;
720
145k
}
xmltok.c:normal_scanAtts
Line
Count
Source
573
145k
                 const char **nextTokPtr) {
574
#  ifdef XML_NS
575
  int hadColon = 0;
576
#  endif
577
4.61M
  while (HAS_CHAR(enc, ptr, end)) {
578
4.61M
    switch (BYTE_TYPE(enc, ptr)) {
579
2.62M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
580
#  ifdef XML_NS
581
    case BT_COLON:
582
      if (hadColon) {
583
        *nextTokPtr = ptr;
584
        return XML_TOK_INVALID;
585
      }
586
      hadColon = 1;
587
      ptr += MINBPC(enc);
588
      REQUIRE_CHAR(enc, ptr, end);
589
      switch (BYTE_TYPE(enc, ptr)) {
590
        CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
591
      default:
592
        *nextTokPtr = ptr;
593
        return XML_TOK_INVALID;
594
      }
595
      break;
596
#  endif
597
2.77k
    case BT_S:
598
19.1k
    case BT_CR:
599
20.1k
    case BT_LF:
600
38.8k
      for (;;) {
601
38.8k
        int t;
602
603
38.8k
        ptr += MINBPC(enc);
604
38.8k
        REQUIRE_CHAR(enc, ptr, end);
605
38.7k
        t = BYTE_TYPE(enc, ptr);
606
38.7k
        if (t == BT_EQUALS)
607
20.0k
          break;
608
18.6k
        switch (t) {
609
2.72k
        case BT_S:
610
3.76k
        case BT_LF:
611
18.6k
        case BT_CR:
612
18.6k
          break;
613
8
        default:
614
8
          *nextTokPtr = ptr;
615
8
          return XML_TOK_INVALID;
616
18.6k
        }
617
18.6k
      }
618
      /* fall through */
619
3.77M
    case BT_EQUALS: {
620
3.77M
      int open;
621
#  ifdef XML_NS
622
      hadColon = 0;
623
#  endif
624
3.84M
      for (;;) {
625
3.84M
        ptr += MINBPC(enc);
626
3.84M
        REQUIRE_CHAR(enc, ptr, end);
627
3.84M
        open = BYTE_TYPE(enc, ptr);
628
3.84M
        if (open == BT_QUOT || open == BT_APOS)
629
3.77M
          break;
630
69.9k
        switch (open) {
631
12.7k
        case BT_S:
632
25.6k
        case BT_LF:
633
69.9k
        case BT_CR:
634
69.9k
          break;
635
17
        default:
636
17
          *nextTokPtr = ptr;
637
17
          return XML_TOK_INVALID;
638
69.9k
        }
639
69.9k
      }
640
3.77M
      ptr += MINBPC(enc);
641
      /* in attribute value */
642
26.7M
      for (;;) {
643
26.7M
        int t;
644
26.7M
        REQUIRE_CHAR(enc, ptr, end);
645
26.7M
        t = BYTE_TYPE(enc, ptr);
646
26.7M
        if (t == open)
647
3.77M
          break;
648
22.9M
        switch (t) {
649
515k
          INVALID_CASES(ptr, nextTokPtr)
650
111k
        case BT_AMP: {
651
111k
          int tok = PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, &ptr);
652
111k
          if (tok <= 0) {
653
35
            if (tok == XML_TOK_INVALID)
654
15
              *nextTokPtr = ptr;
655
35
            return tok;
656
35
          }
657
110k
          break;
658
111k
        }
659
110k
        case BT_LT:
660
7
          *nextTokPtr = ptr;
661
7
          return XML_TOK_INVALID;
662
22.5M
        default:
663
22.5M
          ptr += MINBPC(enc);
664
22.5M
          break;
665
22.9M
        }
666
22.9M
      }
667
3.77M
      ptr += MINBPC(enc);
668
3.77M
      REQUIRE_CHAR(enc, ptr, end);
669
3.77M
      switch (BYTE_TYPE(enc, ptr)) {
670
1.96M
      case BT_S:
671
3.69M
      case BT_CR:
672
3.73M
      case BT_LF:
673
3.73M
        break;
674
29.6k
      case BT_SOL:
675
29.6k
        goto sol;
676
5.03k
      case BT_GT:
677
5.03k
        goto gt;
678
6
      default:
679
6
        *nextTokPtr = ptr;
680
6
        return XML_TOK_INVALID;
681
3.77M
      }
682
      /* ptr points to closing quote */
683
4.18M
      for (;;) {
684
4.18M
        ptr += MINBPC(enc);
685
4.18M
        REQUIRE_CHAR(enc, ptr, end);
686
4.18M
        switch (BYTE_TYPE(enc, ptr)) {
687
3.62M
          CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
688
326k
        case BT_S:
689
386k
        case BT_CR:
690
448k
        case BT_LF:
691
448k
          continue;
692
395
        case BT_GT:
693
5.43k
        gt:
694
5.43k
          *nextTokPtr = ptr + MINBPC(enc);
695
5.43k
          return XML_TOK_START_TAG_WITH_ATTS;
696
109k
        case BT_SOL:
697
139k
        sol:
698
139k
          ptr += MINBPC(enc);
699
139k
          REQUIRE_CHAR(enc, ptr, end);
700
139k
          if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
701
12
            *nextTokPtr = ptr;
702
12
            return XML_TOK_INVALID;
703
12
          }
704
139k
          *nextTokPtr = ptr + MINBPC(enc);
705
139k
          return XML_TOK_EMPTY_ELEMENT_WITH_ATTS;
706
3
        default:
707
3
          *nextTokPtr = ptr;
708
3
          return XML_TOK_INVALID;
709
4.18M
        }
710
3.62M
        break;
711
4.18M
      }
712
3.62M
      break;
713
3.73M
    }
714
3.62M
    default:
715
20
      *nextTokPtr = ptr;
716
20
      return XML_TOK_INVALID;
717
4.61M
    }
718
4.61M
  }
719
88
  return XML_TOK_PARTIAL;
720
145k
}
Unexecuted instantiation: xmltok.c:little2_scanAtts
Unexecuted instantiation: xmltok.c:big2_scanAtts
721
722
/* ptr points to character following "<" */
723
724
static int PTRCALL
725
PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end,
726
670k
               const char **nextTokPtr) {
727
#  ifdef XML_NS
728
  int hadColon;
729
#  endif
730
670k
  REQUIRE_CHAR(enc, ptr, end);
731
670k
  switch (BYTE_TYPE(enc, ptr)) {
732
551k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
733
18.3k
  case BT_EXCL:
734
18.3k
    ptr += MINBPC(enc);
735
18.3k
    REQUIRE_CHAR(enc, ptr, end);
736
18.3k
    switch (BYTE_TYPE(enc, ptr)) {
737
16.9k
    case BT_MINUS:
738
16.9k
      return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
739
1.41k
    case BT_LSQB:
740
1.41k
      return PREFIX(scanCdataSection)(enc, ptr + MINBPC(enc), end, nextTokPtr);
741
18.3k
    }
742
2
    *nextTokPtr = ptr;
743
2
    return XML_TOK_INVALID;
744
27.8k
  case BT_QUEST:
745
27.8k
    return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
746
54.4k
  case BT_SOL:
747
54.4k
    return PREFIX(scanEndTag)(enc, ptr + MINBPC(enc), end, nextTokPtr);
748
13
  default:
749
13
    *nextTokPtr = ptr;
750
13
    return XML_TOK_INVALID;
751
670k
  }
752
#  ifdef XML_NS
753
  hadColon = 0;
754
#  endif
755
  /* we have a start-tag */
756
10.2M
  while (HAS_CHAR(enc, ptr, end)) {
757
10.2M
    switch (BYTE_TYPE(enc, ptr)) {
758
38.0M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
759
#  ifdef XML_NS
760
    case BT_COLON:
761
      if (hadColon) {
762
        *nextTokPtr = ptr;
763
        return XML_TOK_INVALID;
764
      }
765
      hadColon = 1;
766
      ptr += MINBPC(enc);
767
      REQUIRE_CHAR(enc, ptr, end);
768
      switch (BYTE_TYPE(enc, ptr)) {
769
        CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
770
      default:
771
        *nextTokPtr = ptr;
772
        return XML_TOK_INVALID;
773
      }
774
      break;
775
#  endif
776
135k
    case BT_S:
777
148k
    case BT_CR:
778
153k
    case BT_LF: {
779
153k
      ptr += MINBPC(enc);
780
184k
      while (HAS_CHAR(enc, ptr, end)) {
781
184k
        switch (BYTE_TYPE(enc, ptr)) {
782
29.4k
          CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
783
588
        case BT_GT:
784
588
          goto gt;
785
6.79k
        case BT_SOL:
786
6.79k
          goto sol;
787
3.76k
        case BT_S:
788
31.1k
        case BT_CR:
789
31.8k
        case BT_LF:
790
31.8k
          ptr += MINBPC(enc);
791
31.8k
          continue;
792
10
        default:
793
10
          *nextTokPtr = ptr;
794
10
          return XML_TOK_INVALID;
795
184k
        }
796
145k
        return PREFIX(scanAtts)(enc, ptr, end, nextTokPtr);
797
184k
      }
798
66
      return XML_TOK_PARTIAL;
799
153k
    }
800
379k
    case BT_GT:
801
380k
    gt:
802
380k
      *nextTokPtr = ptr + MINBPC(enc);
803
380k
      return XML_TOK_START_TAG_NO_ATTS;
804
36.6k
    case BT_SOL:
805
43.4k
    sol:
806
43.4k
      ptr += MINBPC(enc);
807
43.4k
      REQUIRE_CHAR(enc, ptr, end);
808
43.3k
      if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
809
14
        *nextTokPtr = ptr;
810
14
        return XML_TOK_INVALID;
811
14
      }
812
43.3k
      *nextTokPtr = ptr + MINBPC(enc);
813
43.3k
      return XML_TOK_EMPTY_ELEMENT_NO_ATTS;
814
12
    default:
815
12
      *nextTokPtr = ptr;
816
12
      return XML_TOK_INVALID;
817
10.2M
    }
818
10.2M
  }
819
100
  return XML_TOK_PARTIAL;
820
569k
}
xmltok.c:normal_scanLt
Line
Count
Source
726
670k
               const char **nextTokPtr) {
727
#  ifdef XML_NS
728
  int hadColon;
729
#  endif
730
670k
  REQUIRE_CHAR(enc, ptr, end);
731
670k
  switch (BYTE_TYPE(enc, ptr)) {
732
551k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
733
18.3k
  case BT_EXCL:
734
18.3k
    ptr += MINBPC(enc);
735
18.3k
    REQUIRE_CHAR(enc, ptr, end);
736
18.3k
    switch (BYTE_TYPE(enc, ptr)) {
737
16.9k
    case BT_MINUS:
738
16.9k
      return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr);
739
1.41k
    case BT_LSQB:
740
1.41k
      return PREFIX(scanCdataSection)(enc, ptr + MINBPC(enc), end, nextTokPtr);
741
18.3k
    }
742
2
    *nextTokPtr = ptr;
743
2
    return XML_TOK_INVALID;
744
27.8k
  case BT_QUEST:
745
27.8k
    return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
746
54.4k
  case BT_SOL:
747
54.4k
    return PREFIX(scanEndTag)(enc, ptr + MINBPC(enc), end, nextTokPtr);
748
13
  default:
749
13
    *nextTokPtr = ptr;
750
13
    return XML_TOK_INVALID;
751
670k
  }
752
#  ifdef XML_NS
753
  hadColon = 0;
754
#  endif
755
  /* we have a start-tag */
756
10.2M
  while (HAS_CHAR(enc, ptr, end)) {
757
10.2M
    switch (BYTE_TYPE(enc, ptr)) {
758
38.0M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
759
#  ifdef XML_NS
760
    case BT_COLON:
761
      if (hadColon) {
762
        *nextTokPtr = ptr;
763
        return XML_TOK_INVALID;
764
      }
765
      hadColon = 1;
766
      ptr += MINBPC(enc);
767
      REQUIRE_CHAR(enc, ptr, end);
768
      switch (BYTE_TYPE(enc, ptr)) {
769
        CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
770
      default:
771
        *nextTokPtr = ptr;
772
        return XML_TOK_INVALID;
773
      }
774
      break;
775
#  endif
776
135k
    case BT_S:
777
148k
    case BT_CR:
778
153k
    case BT_LF: {
779
153k
      ptr += MINBPC(enc);
780
184k
      while (HAS_CHAR(enc, ptr, end)) {
781
184k
        switch (BYTE_TYPE(enc, ptr)) {
782
29.4k
          CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
783
588
        case BT_GT:
784
588
          goto gt;
785
6.79k
        case BT_SOL:
786
6.79k
          goto sol;
787
3.76k
        case BT_S:
788
31.1k
        case BT_CR:
789
31.8k
        case BT_LF:
790
31.8k
          ptr += MINBPC(enc);
791
31.8k
          continue;
792
10
        default:
793
10
          *nextTokPtr = ptr;
794
10
          return XML_TOK_INVALID;
795
184k
        }
796
145k
        return PREFIX(scanAtts)(enc, ptr, end, nextTokPtr);
797
184k
      }
798
66
      return XML_TOK_PARTIAL;
799
153k
    }
800
379k
    case BT_GT:
801
380k
    gt:
802
380k
      *nextTokPtr = ptr + MINBPC(enc);
803
380k
      return XML_TOK_START_TAG_NO_ATTS;
804
36.6k
    case BT_SOL:
805
43.4k
    sol:
806
43.4k
      ptr += MINBPC(enc);
807
43.4k
      REQUIRE_CHAR(enc, ptr, end);
808
43.3k
      if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
809
14
        *nextTokPtr = ptr;
810
14
        return XML_TOK_INVALID;
811
14
      }
812
43.3k
      *nextTokPtr = ptr + MINBPC(enc);
813
43.3k
      return XML_TOK_EMPTY_ELEMENT_NO_ATTS;
814
12
    default:
815
12
      *nextTokPtr = ptr;
816
12
      return XML_TOK_INVALID;
817
10.2M
    }
818
10.2M
  }
819
100
  return XML_TOK_PARTIAL;
820
569k
}
Unexecuted instantiation: xmltok.c:little2_scanLt
Unexecuted instantiation: xmltok.c:big2_scanLt
821
822
static int PTRCALL
823
PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end,
824
4.29M
                   const char **nextTokPtr) {
825
4.29M
  if (ptr >= end)
826
9.57k
    return XML_TOK_NONE;
827
4.28M
  if (MINBPC(enc) > 1) {
828
0
    size_t n = end - ptr;
829
0
    if (n & (MINBPC(enc) - 1)) {
830
0
      n &= ~(MINBPC(enc) - 1);
831
0
      if (n == 0)
832
0
        return XML_TOK_PARTIAL;
833
0
      end = ptr + n;
834
0
    }
835
0
  }
836
4.28M
  switch (BYTE_TYPE(enc, ptr)) {
837
670k
  case BT_LT:
838
670k
    return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr);
839
48.6k
  case BT_AMP:
840
48.6k
    return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
841
1.55M
  case BT_CR:
842
1.55M
    ptr += MINBPC(enc);
843
1.55M
    if (! HAS_CHAR(enc, ptr, end))
844
18
      return XML_TOK_TRAILING_CR;
845
1.55M
    if (BYTE_TYPE(enc, ptr) == BT_LF)
846
329k
      ptr += MINBPC(enc);
847
1.55M
    *nextTokPtr = ptr;
848
1.55M
    return XML_TOK_DATA_NEWLINE;
849
1.17M
  case BT_LF:
850
1.17M
    *nextTokPtr = ptr + MINBPC(enc);
851
1.17M
    return XML_TOK_DATA_NEWLINE;
852
39.6k
  case BT_RSQB:
853
39.6k
    ptr += MINBPC(enc);
854
39.6k
    if (! HAS_CHAR(enc, ptr, end))
855
12
      return XML_TOK_TRAILING_RSQB;
856
39.6k
    if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB))
857
13.8k
      break;
858
25.8k
    ptr += MINBPC(enc);
859
25.8k
    if (! HAS_CHAR(enc, ptr, end))
860
4
      return XML_TOK_TRAILING_RSQB;
861
25.8k
    if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
862
25.8k
      ptr -= MINBPC(enc);
863
25.8k
      break;
864
25.8k
    }
865
1
    *nextTokPtr = ptr;
866
1
    return XML_TOK_INVALID;
867
85.6k
    INVALID_CASES(ptr, nextTokPtr)
868
753k
  default:
869
753k
    ptr += MINBPC(enc);
870
753k
    break;
871
4.28M
  }
872
15.2M
  while (HAS_CHAR(enc, ptr, end)) {
873
15.2M
    switch (BYTE_TYPE(enc, ptr)) {
874
0
#  define LEAD_CASE(n)                                                         \
875
162k
  case BT_LEAD##n:                                                             \
876
162k
    if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) {                       \
877
22
      *nextTokPtr = ptr;                                                       \
878
22
      return XML_TOK_DATA_CHARS;                                               \
879
22
    }                                                                          \
880
162k
    ptr += n;                                                                  \
881
162k
    break;
882
85.7k
      LEAD_CASE(2)
883
37.8k
      LEAD_CASE(3)
884
38.9k
      LEAD_CASE(4)
885
0
#  undef LEAD_CASE
886
411k
    case BT_RSQB:
887
411k
      if (HAS_CHARS(enc, ptr, end, 2)) {
888
411k
        if (! CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) {
889
129k
          ptr += MINBPC(enc);
890
129k
          break;
891
129k
        }
892
281k
        if (HAS_CHARS(enc, ptr, end, 3)) {
893
281k
          if (! CHAR_MATCHES(enc, ptr + 2 * MINBPC(enc), ASCII_GT)) {
894
281k
            ptr += MINBPC(enc);
895
281k
            break;
896
281k
          }
897
1
          *nextTokPtr = ptr + 2 * MINBPC(enc);
898
1
          return XML_TOK_INVALID;
899
281k
        }
900
281k
      }
901
      /* fall through */
902
21.0k
    case BT_AMP:
903
134k
    case BT_LT:
904
134k
    case BT_NONXML:
905
134k
    case BT_MALFORM:
906
134k
    case BT_TRAIL:
907
590k
    case BT_CR:
908
828k
    case BT_LF:
909
828k
      *nextTokPtr = ptr;
910
828k
      return XML_TOK_DATA_CHARS;
911
13.8M
    default:
912
13.8M
      ptr += MINBPC(enc);
913
13.8M
      break;
914
15.2M
    }
915
15.2M
  }
916
7.80k
  *nextTokPtr = ptr;
917
7.80k
  return XML_TOK_DATA_CHARS;
918
835k
}
xmltok.c:normal_contentTok
Line
Count
Source
824
4.29M
                   const char **nextTokPtr) {
825
4.29M
  if (ptr >= end)
826
9.57k
    return XML_TOK_NONE;
827
4.28M
  if (MINBPC(enc) > 1) {
828
0
    size_t n = end - ptr;
829
0
    if (n & (MINBPC(enc) - 1)) {
830
0
      n &= ~(MINBPC(enc) - 1);
831
0
      if (n == 0)
832
0
        return XML_TOK_PARTIAL;
833
0
      end = ptr + n;
834
0
    }
835
0
  }
836
4.28M
  switch (BYTE_TYPE(enc, ptr)) {
837
670k
  case BT_LT:
838
670k
    return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr);
839
48.6k
  case BT_AMP:
840
48.6k
    return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
841
1.55M
  case BT_CR:
842
1.55M
    ptr += MINBPC(enc);
843
1.55M
    if (! HAS_CHAR(enc, ptr, end))
844
18
      return XML_TOK_TRAILING_CR;
845
1.55M
    if (BYTE_TYPE(enc, ptr) == BT_LF)
846
329k
      ptr += MINBPC(enc);
847
1.55M
    *nextTokPtr = ptr;
848
1.55M
    return XML_TOK_DATA_NEWLINE;
849
1.17M
  case BT_LF:
850
1.17M
    *nextTokPtr = ptr + MINBPC(enc);
851
1.17M
    return XML_TOK_DATA_NEWLINE;
852
39.6k
  case BT_RSQB:
853
39.6k
    ptr += MINBPC(enc);
854
39.6k
    if (! HAS_CHAR(enc, ptr, end))
855
12
      return XML_TOK_TRAILING_RSQB;
856
39.6k
    if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB))
857
13.8k
      break;
858
25.8k
    ptr += MINBPC(enc);
859
25.8k
    if (! HAS_CHAR(enc, ptr, end))
860
4
      return XML_TOK_TRAILING_RSQB;
861
25.8k
    if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) {
862
25.8k
      ptr -= MINBPC(enc);
863
25.8k
      break;
864
25.8k
    }
865
1
    *nextTokPtr = ptr;
866
1
    return XML_TOK_INVALID;
867
85.6k
    INVALID_CASES(ptr, nextTokPtr)
868
753k
  default:
869
753k
    ptr += MINBPC(enc);
870
753k
    break;
871
4.28M
  }
872
15.2M
  while (HAS_CHAR(enc, ptr, end)) {
873
15.2M
    switch (BYTE_TYPE(enc, ptr)) {
874
0
#  define LEAD_CASE(n)                                                         \
875
0
  case BT_LEAD##n:                                                             \
876
0
    if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) {                       \
877
0
      *nextTokPtr = ptr;                                                       \
878
0
      return XML_TOK_DATA_CHARS;                                               \
879
0
    }                                                                          \
880
0
    ptr += n;                                                                  \
881
0
    break;
882
85.7k
      LEAD_CASE(2)
883
37.8k
      LEAD_CASE(3)
884
38.9k
      LEAD_CASE(4)
885
0
#  undef LEAD_CASE
886
411k
    case BT_RSQB:
887
411k
      if (HAS_CHARS(enc, ptr, end, 2)) {
888
411k
        if (! CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) {
889
129k
          ptr += MINBPC(enc);
890
129k
          break;
891
129k
        }
892
281k
        if (HAS_CHARS(enc, ptr, end, 3)) {
893
281k
          if (! CHAR_MATCHES(enc, ptr + 2 * MINBPC(enc), ASCII_GT)) {
894
281k
            ptr += MINBPC(enc);
895
281k
            break;
896
281k
          }
897
1
          *nextTokPtr = ptr + 2 * MINBPC(enc);
898
1
          return XML_TOK_INVALID;
899
281k
        }
900
281k
      }
901
      /* fall through */
902
21.0k
    case BT_AMP:
903
134k
    case BT_LT:
904
134k
    case BT_NONXML:
905
134k
    case BT_MALFORM:
906
134k
    case BT_TRAIL:
907
590k
    case BT_CR:
908
828k
    case BT_LF:
909
828k
      *nextTokPtr = ptr;
910
828k
      return XML_TOK_DATA_CHARS;
911
13.8M
    default:
912
13.8M
      ptr += MINBPC(enc);
913
13.8M
      break;
914
15.2M
    }
915
15.2M
  }
916
7.80k
  *nextTokPtr = ptr;
917
7.80k
  return XML_TOK_DATA_CHARS;
918
835k
}
Unexecuted instantiation: xmltok.c:little2_contentTok
Unexecuted instantiation: xmltok.c:big2_contentTok
919
920
/* ptr points to character following "%" */
921
922
static int PTRCALL
923
PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end,
924
69.3k
                    const char **nextTokPtr) {
925
69.3k
  REQUIRE_CHAR(enc, ptr, end);
926
69.3k
  switch (BYTE_TYPE(enc, ptr)) {
927
103k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
928
1.25k
  case BT_S:
929
1.55k
  case BT_LF:
930
2.17k
  case BT_CR:
931
2.17k
  case BT_PERCNT:
932
2.17k
    *nextTokPtr = ptr;
933
2.17k
    return XML_TOK_PERCENT;
934
4
  default:
935
4
    *nextTokPtr = ptr;
936
4
    return XML_TOK_INVALID;
937
69.3k
  }
938
1.62M
  while (HAS_CHAR(enc, ptr, end)) {
939
1.62M
    switch (BYTE_TYPE(enc, ptr)) {
940
5.02M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
941
66.9k
    case BT_SEMI:
942
66.9k
      *nextTokPtr = ptr + MINBPC(enc);
943
66.9k
      return XML_TOK_PARAM_ENTITY_REF;
944
22
    default:
945
22
      *nextTokPtr = ptr;
946
22
      return XML_TOK_INVALID;
947
1.62M
    }
948
1.62M
  }
949
78
  return XML_TOK_PARTIAL;
950
67.1k
}
xmltok.c:normal_scanPercent
Line
Count
Source
924
69.3k
                    const char **nextTokPtr) {
925
69.3k
  REQUIRE_CHAR(enc, ptr, end);
926
69.3k
  switch (BYTE_TYPE(enc, ptr)) {
927
103k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
928
1.25k
  case BT_S:
929
1.55k
  case BT_LF:
930
2.17k
  case BT_CR:
931
2.17k
  case BT_PERCNT:
932
2.17k
    *nextTokPtr = ptr;
933
2.17k
    return XML_TOK_PERCENT;
934
4
  default:
935
4
    *nextTokPtr = ptr;
936
4
    return XML_TOK_INVALID;
937
69.3k
  }
938
1.62M
  while (HAS_CHAR(enc, ptr, end)) {
939
1.62M
    switch (BYTE_TYPE(enc, ptr)) {
940
5.02M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
941
66.9k
    case BT_SEMI:
942
66.9k
      *nextTokPtr = ptr + MINBPC(enc);
943
66.9k
      return XML_TOK_PARAM_ENTITY_REF;
944
22
    default:
945
22
      *nextTokPtr = ptr;
946
22
      return XML_TOK_INVALID;
947
1.62M
    }
948
1.62M
  }
949
78
  return XML_TOK_PARTIAL;
950
67.1k
}
Unexecuted instantiation: xmltok.c:little2_scanPercent
Unexecuted instantiation: xmltok.c:big2_scanPercent
951
952
static int PTRCALL
953
PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
954
61.2k
                      const char **nextTokPtr) {
955
61.2k
  REQUIRE_CHAR(enc, ptr, end);
956
61.2k
  switch (BYTE_TYPE(enc, ptr)) {
957
60.7k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
958
4
  default:
959
4
    *nextTokPtr = ptr;
960
4
    return XML_TOK_INVALID;
961
61.2k
  }
962
1.72M
  while (HAS_CHAR(enc, ptr, end)) {
963
1.72M
    switch (BYTE_TYPE(enc, ptr)) {
964
5.45M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
965
50.4k
    case BT_CR:
966
55.8k
    case BT_LF:
967
56.4k
    case BT_S:
968
56.8k
    case BT_RPAR:
969
60.5k
    case BT_GT:
970
60.5k
    case BT_PERCNT:
971
60.9k
    case BT_VERBAR:
972
60.9k
      *nextTokPtr = ptr;
973
60.9k
      return XML_TOK_POUND_NAME;
974
19
    default:
975
19
      *nextTokPtr = ptr;
976
19
      return XML_TOK_INVALID;
977
1.72M
    }
978
1.72M
  }
979
208
  return -XML_TOK_POUND_NAME;
980
61.2k
}
xmltok.c:normal_scanPoundName
Line
Count
Source
954
61.2k
                      const char **nextTokPtr) {
955
61.2k
  REQUIRE_CHAR(enc, ptr, end);
956
61.2k
  switch (BYTE_TYPE(enc, ptr)) {
957
60.7k
    CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
958
4
  default:
959
4
    *nextTokPtr = ptr;
960
4
    return XML_TOK_INVALID;
961
61.2k
  }
962
1.72M
  while (HAS_CHAR(enc, ptr, end)) {
963
1.72M
    switch (BYTE_TYPE(enc, ptr)) {
964
5.45M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
965
50.4k
    case BT_CR:
966
55.8k
    case BT_LF:
967
56.4k
    case BT_S:
968
56.8k
    case BT_RPAR:
969
60.5k
    case BT_GT:
970
60.5k
    case BT_PERCNT:
971
60.9k
    case BT_VERBAR:
972
60.9k
      *nextTokPtr = ptr;
973
60.9k
      return XML_TOK_POUND_NAME;
974
19
    default:
975
19
      *nextTokPtr = ptr;
976
19
      return XML_TOK_INVALID;
977
1.72M
    }
978
1.72M
  }
979
208
  return -XML_TOK_POUND_NAME;
980
61.2k
}
Unexecuted instantiation: xmltok.c:little2_scanPoundName
Unexecuted instantiation: xmltok.c:big2_scanPoundName
981
982
static int PTRCALL
983
PREFIX(scanLit)(int open, const ENCODING *enc, const char *ptr, const char *end,
984
37.1k
                const char **nextTokPtr) {
985
9.75M
  while (HAS_CHAR(enc, ptr, end)) {
986
9.75M
    int t = BYTE_TYPE(enc, ptr);
987
9.75M
    switch (t) {
988
288k
      INVALID_CASES(ptr, nextTokPtr)
989
10.3k
    case BT_QUOT:
990
170k
    case BT_APOS:
991
170k
      ptr += MINBPC(enc);
992
170k
      if (t != open)
993
133k
        break;
994
36.9k
      if (! HAS_CHAR(enc, ptr, end))
995
585
        return -XML_TOK_LITERAL;
996
36.4k
      *nextTokPtr = ptr;
997
36.4k
      switch (BYTE_TYPE(enc, ptr)) {
998
5.85k
      case BT_S:
999
9.34k
      case BT_CR:
1000
17.8k
      case BT_LF:
1001
36.0k
      case BT_GT:
1002
36.0k
      case BT_PERCNT:
1003
36.3k
      case BT_LSQB:
1004
36.3k
        return XML_TOK_LITERAL;
1005
17
      default:
1006
17
        return XML_TOK_INVALID;
1007
36.4k
      }
1008
9.43M
    default:
1009
9.43M
      ptr += MINBPC(enc);
1010
9.43M
      break;
1011
9.75M
    }
1012
9.75M
  }
1013
106
  return XML_TOK_PARTIAL;
1014
37.1k
}
xmltok.c:normal_scanLit
Line
Count
Source
984
37.1k
                const char **nextTokPtr) {
985
9.75M
  while (HAS_CHAR(enc, ptr, end)) {
986
9.75M
    int t = BYTE_TYPE(enc, ptr);
987
9.75M
    switch (t) {
988
288k
      INVALID_CASES(ptr, nextTokPtr)
989
10.3k
    case BT_QUOT:
990
170k
    case BT_APOS:
991
170k
      ptr += MINBPC(enc);
992
170k
      if (t != open)
993
133k
        break;
994
36.9k
      if (! HAS_CHAR(enc, ptr, end))
995
585
        return -XML_TOK_LITERAL;
996
36.4k
      *nextTokPtr = ptr;
997
36.4k
      switch (BYTE_TYPE(enc, ptr)) {
998
5.85k
      case BT_S:
999
9.34k
      case BT_CR:
1000
17.8k
      case BT_LF:
1001
36.0k
      case BT_GT:
1002
36.0k
      case BT_PERCNT:
1003
36.3k
      case BT_LSQB:
1004
36.3k
        return XML_TOK_LITERAL;
1005
17
      default:
1006
17
        return XML_TOK_INVALID;
1007
36.4k
      }
1008
9.43M
    default:
1009
9.43M
      ptr += MINBPC(enc);
1010
9.43M
      break;
1011
9.75M
    }
1012
9.75M
  }
1013
106
  return XML_TOK_PARTIAL;
1014
37.1k
}
Unexecuted instantiation: xmltok.c:little2_scanLit
Unexecuted instantiation: xmltok.c:big2_scanLit
1015
1016
static int PTRCALL
1017
PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
1018
4.64M
                  const char **nextTokPtr) {
1019
4.64M
  int tok;
1020
4.64M
  if (ptr >= end)
1021
7.98k
    return XML_TOK_NONE;
1022
4.63M
  if (MINBPC(enc) > 1) {
1023
239
    size_t n = end - ptr;
1024
239
    if (n & (MINBPC(enc) - 1)) {
1025
41
      n &= ~(MINBPC(enc) - 1);
1026
41
      if (n == 0)
1027
4
        return XML_TOK_PARTIAL;
1028
37
      end = ptr + n;
1029
37
    }
1030
239
  }
1031
4.63M
  switch (BYTE_TYPE(enc, ptr)) {
1032
7.77k
  case BT_QUOT:
1033
7.77k
    return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr);
1034
29.3k
  case BT_APOS:
1035
29.3k
    return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr);
1036
77.7k
  case BT_LT: {
1037
77.7k
    ptr += MINBPC(enc);
1038
77.7k
    REQUIRE_CHAR(enc, ptr, end);
1039
77.7k
    switch (BYTE_TYPE(enc, ptr)) {
1040
62.7k
    case BT_EXCL:
1041
62.7k
      return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1042
9.26k
    case BT_QUEST:
1043
9.26k
      return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1044
4.46k
    case BT_NMSTRT:
1045
5.67k
    case BT_HEX:
1046
5.67k
    case BT_NONASCII:
1047
5.70k
    case BT_LEAD2:
1048
5.74k
    case BT_LEAD3:
1049
5.75k
    case BT_LEAD4:
1050
5.75k
      *nextTokPtr = ptr - MINBPC(enc);
1051
5.75k
      return XML_TOK_INSTANCE_START;
1052
77.7k
    }
1053
15
    *nextTokPtr = ptr;
1054
15
    return XML_TOK_INVALID;
1055
77.7k
  }
1056
178k
  case BT_CR:
1057
178k
    if (ptr + MINBPC(enc) == end) {
1058
420
      *nextTokPtr = end;
1059
      /* indicate that this might be part of a CR/LF pair */
1060
420
      return -XML_TOK_PROLOG_S;
1061
420
    }
1062
    /* fall through */
1063
310k
  case BT_S:
1064
358k
  case BT_LF:
1065
403k
    for (;;) {
1066
403k
      ptr += MINBPC(enc);
1067
403k
      if (! HAS_CHAR(enc, ptr, end))
1068
254
        break;
1069
403k
      switch (BYTE_TYPE(enc, ptr)) {
1070
6.81k
      case BT_S:
1071
10.6k
      case BT_LF:
1072
10.6k
        break;
1073
34.7k
      case BT_CR:
1074
        /* don't split CR/LF pair */
1075
34.7k
        if (ptr + MINBPC(enc) != end)
1076
34.5k
          break;
1077
        /* fall through */
1078
358k
      default:
1079
358k
        *nextTokPtr = ptr;
1080
358k
        return XML_TOK_PROLOG_S;
1081
403k
      }
1082
403k
    }
1083
254
    *nextTokPtr = ptr;
1084
254
    return XML_TOK_PROLOG_S;
1085
69.3k
  case BT_PERCNT:
1086
69.3k
    return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1087
10.8k
  case BT_COMMA:
1088
10.8k
    *nextTokPtr = ptr + MINBPC(enc);
1089
10.8k
    return XML_TOK_COMMA;
1090
2.73k
  case BT_LSQB:
1091
2.73k
    *nextTokPtr = ptr + MINBPC(enc);
1092
2.73k
    return XML_TOK_OPEN_BRACKET;
1093
1.24k
  case BT_RSQB:
1094
1.24k
    ptr += MINBPC(enc);
1095
1.24k
    if (! HAS_CHAR(enc, ptr, end))
1096
3
      return -XML_TOK_CLOSE_BRACKET;
1097
1.24k
    if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
1098
28
      REQUIRE_CHARS(enc, ptr, end, 2);
1099
26
      if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) {
1100
1
        *nextTokPtr = ptr + 2 * MINBPC(enc);
1101
1
        return XML_TOK_COND_SECT_CLOSE;
1102
1
      }
1103
26
    }
1104
1.23k
    *nextTokPtr = ptr;
1105
1.23k
    return XML_TOK_CLOSE_BRACKET;
1106
3.35M
  case BT_LPAR:
1107
3.35M
    *nextTokPtr = ptr + MINBPC(enc);
1108
3.35M
    return XML_TOK_OPEN_PAREN;
1109
98.8k
  case BT_RPAR:
1110
98.8k
    ptr += MINBPC(enc);
1111
98.8k
    if (! HAS_CHAR(enc, ptr, end))
1112
99
      return -XML_TOK_CLOSE_PAREN;
1113
98.7k
    switch (BYTE_TYPE(enc, ptr)) {
1114
7.01k
    case BT_AST:
1115
7.01k
      *nextTokPtr = ptr + MINBPC(enc);
1116
7.01k
      return XML_TOK_CLOSE_PAREN_ASTERISK;
1117
5.65k
    case BT_QUEST:
1118
5.65k
      *nextTokPtr = ptr + MINBPC(enc);
1119
5.65k
      return XML_TOK_CLOSE_PAREN_QUESTION;
1120
7.45k
    case BT_PLUS:
1121
7.45k
      *nextTokPtr = ptr + MINBPC(enc);
1122
7.45k
      return XML_TOK_CLOSE_PAREN_PLUS;
1123
1.40k
    case BT_CR:
1124
4.98k
    case BT_LF:
1125
55.1k
    case BT_S:
1126
56.2k
    case BT_GT:
1127
62.7k
    case BT_COMMA:
1128
72.8k
    case BT_VERBAR:
1129
78.5k
    case BT_RPAR:
1130
78.5k
      *nextTokPtr = ptr;
1131
78.5k
      return XML_TOK_CLOSE_PAREN;
1132
98.7k
    }
1133
14
    *nextTokPtr = ptr;
1134
14
    return XML_TOK_INVALID;
1135
135k
  case BT_VERBAR:
1136
135k
    *nextTokPtr = ptr + MINBPC(enc);
1137
135k
    return XML_TOK_OR;
1138
56.0k
  case BT_GT:
1139
56.0k
    *nextTokPtr = ptr + MINBPC(enc);
1140
56.0k
    return XML_TOK_DECL_CLOSE;
1141
61.2k
  case BT_NUM:
1142
61.2k
    return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1143
0
#  define LEAD_CASE(n)                                                         \
1144
64
  case BT_LEAD##n:                                                             \
1145
11.4k
    if (end - ptr < n)                                                         \
1146
72
      return XML_TOK_PARTIAL_CHAR;                                             \
1147
11.3k
    if (IS_INVALID_CHAR(enc, ptr, n)) {                                        \
1148
93
      *nextTokPtr = ptr;                                                       \
1149
93
      return XML_TOK_INVALID;                                                  \
1150
93
    }                                                                          \
1151
11.3k
    if (IS_NMSTRT_CHAR(enc, ptr, n)) {                                         \
1152
8.30k
      ptr += n;                                                                \
1153
8.30k
      tok = XML_TOK_NAME;                                                      \
1154
8.30k
      break;                                                                   \
1155
8.30k
    }                                                                          \
1156
11.2k
    if (IS_NAME_CHAR(enc, ptr, n)) {                                           \
1157
2.91k
      ptr += n;                                                                \
1158
2.91k
      tok = XML_TOK_NMTOKEN;                                                   \
1159
2.91k
      break;                                                                   \
1160
2.91k
    }                                                                          \
1161
2.98k
    *nextTokPtr = ptr;                                                         \
1162
64
    return XML_TOK_INVALID;
1163
22.4k
    LEAD_CASE(2)
1164
14.4k
    LEAD_CASE(3)
1165
266
    LEAD_CASE(4)
1166
0
#  undef LEAD_CASE
1167
155k
  case BT_NMSTRT:
1168
249k
  case BT_HEX:
1169
249k
    tok = XML_TOK_NAME;
1170
249k
    ptr += MINBPC(enc);
1171
249k
    break;
1172
109k
  case BT_DIGIT:
1173
109k
  case BT_NAME:
1174
110k
  case BT_MINUS:
1175
#  ifdef XML_NS
1176
  case BT_COLON:
1177
#  endif
1178
110k
    tok = XML_TOK_NMTOKEN;
1179
110k
    ptr += MINBPC(enc);
1180
110k
    break;
1181
189
  case BT_NONASCII:
1182
189
    if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
1183
151
      ptr += MINBPC(enc);
1184
151
      tok = XML_TOK_NAME;
1185
151
      break;
1186
151
    }
1187
38
    if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
1188
14
      ptr += MINBPC(enc);
1189
14
      tok = XML_TOK_NMTOKEN;
1190
14
      break;
1191
14
    }
1192
    /* fall through */
1193
96
  default:
1194
96
    *nextTokPtr = ptr;
1195
96
    return XML_TOK_INVALID;
1196
4.63M
  }
1197
12.7M
  while (HAS_CHAR(enc, ptr, end)) {
1198
12.7M
    switch (BYTE_TYPE(enc, ptr)) {
1199
35.6M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1200
27.9k
    case BT_GT:
1201
99.9k
    case BT_RPAR:
1202
100k
    case BT_COMMA:
1203
216k
    case BT_VERBAR:
1204
219k
    case BT_LSQB:
1205
219k
    case BT_PERCNT:
1206
262k
    case BT_S:
1207
346k
    case BT_CR:
1208
364k
    case BT_LF:
1209
364k
      *nextTokPtr = ptr;
1210
364k
      return tok;
1211
#  ifdef XML_NS
1212
    case BT_COLON:
1213
      ptr += MINBPC(enc);
1214
      switch (tok) {
1215
      case XML_TOK_NAME:
1216
        REQUIRE_CHAR(enc, ptr, end);
1217
        tok = XML_TOK_PREFIXED_NAME;
1218
        switch (BYTE_TYPE(enc, ptr)) {
1219
          CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1220
        default:
1221
          tok = XML_TOK_NMTOKEN;
1222
          break;
1223
        }
1224
        break;
1225
      case XML_TOK_PREFIXED_NAME:
1226
        tok = XML_TOK_NMTOKEN;
1227
        break;
1228
      }
1229
      break;
1230
#  endif
1231
4.10k
    case BT_PLUS:
1232
4.10k
      if (tok == XML_TOK_NMTOKEN) {
1233
1
        *nextTokPtr = ptr;
1234
1
        return XML_TOK_INVALID;
1235
1
      }
1236
4.10k
      *nextTokPtr = ptr + MINBPC(enc);
1237
4.10k
      return XML_TOK_NAME_PLUS;
1238
919
    case BT_AST:
1239
919
      if (tok == XML_TOK_NMTOKEN) {
1240
1
        *nextTokPtr = ptr;
1241
1
        return XML_TOK_INVALID;
1242
1
      }
1243
918
      *nextTokPtr = ptr + MINBPC(enc);
1244
918
      return XML_TOK_NAME_ASTERISK;
1245
648
    case BT_QUEST:
1246
648
      if (tok == XML_TOK_NMTOKEN) {
1247
3
        *nextTokPtr = ptr;
1248
3
        return XML_TOK_INVALID;
1249
3
      }
1250
645
      *nextTokPtr = ptr + MINBPC(enc);
1251
645
      return XML_TOK_NAME_QUESTION;
1252
63
    default:
1253
63
      *nextTokPtr = ptr;
1254
63
      return XML_TOK_INVALID;
1255
12.7M
    }
1256
12.7M
  }
1257
719
  return -tok;
1258
371k
}
xmltok.c:normal_prologTok
Line
Count
Source
1018
4.64M
                  const char **nextTokPtr) {
1019
4.64M
  int tok;
1020
4.64M
  if (ptr >= end)
1021
7.98k
    return XML_TOK_NONE;
1022
4.63M
  if (MINBPC(enc) > 1) {
1023
0
    size_t n = end - ptr;
1024
0
    if (n & (MINBPC(enc) - 1)) {
1025
0
      n &= ~(MINBPC(enc) - 1);
1026
0
      if (n == 0)
1027
0
        return XML_TOK_PARTIAL;
1028
0
      end = ptr + n;
1029
0
    }
1030
0
  }
1031
4.63M
  switch (BYTE_TYPE(enc, ptr)) {
1032
7.77k
  case BT_QUOT:
1033
7.77k
    return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr);
1034
29.3k
  case BT_APOS:
1035
29.3k
    return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr);
1036
77.7k
  case BT_LT: {
1037
77.7k
    ptr += MINBPC(enc);
1038
77.7k
    REQUIRE_CHAR(enc, ptr, end);
1039
77.7k
    switch (BYTE_TYPE(enc, ptr)) {
1040
62.7k
    case BT_EXCL:
1041
62.7k
      return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1042
9.26k
    case BT_QUEST:
1043
9.26k
      return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1044
4.46k
    case BT_NMSTRT:
1045
5.67k
    case BT_HEX:
1046
5.67k
    case BT_NONASCII:
1047
5.70k
    case BT_LEAD2:
1048
5.74k
    case BT_LEAD3:
1049
5.75k
    case BT_LEAD4:
1050
5.75k
      *nextTokPtr = ptr - MINBPC(enc);
1051
5.75k
      return XML_TOK_INSTANCE_START;
1052
77.7k
    }
1053
15
    *nextTokPtr = ptr;
1054
15
    return XML_TOK_INVALID;
1055
77.7k
  }
1056
178k
  case BT_CR:
1057
178k
    if (ptr + MINBPC(enc) == end) {
1058
420
      *nextTokPtr = end;
1059
      /* indicate that this might be part of a CR/LF pair */
1060
420
      return -XML_TOK_PROLOG_S;
1061
420
    }
1062
    /* fall through */
1063
310k
  case BT_S:
1064
358k
  case BT_LF:
1065
403k
    for (;;) {
1066
403k
      ptr += MINBPC(enc);
1067
403k
      if (! HAS_CHAR(enc, ptr, end))
1068
254
        break;
1069
403k
      switch (BYTE_TYPE(enc, ptr)) {
1070
6.81k
      case BT_S:
1071
10.6k
      case BT_LF:
1072
10.6k
        break;
1073
34.7k
      case BT_CR:
1074
        /* don't split CR/LF pair */
1075
34.7k
        if (ptr + MINBPC(enc) != end)
1076
34.5k
          break;
1077
        /* fall through */
1078
358k
      default:
1079
358k
        *nextTokPtr = ptr;
1080
358k
        return XML_TOK_PROLOG_S;
1081
403k
      }
1082
403k
    }
1083
254
    *nextTokPtr = ptr;
1084
254
    return XML_TOK_PROLOG_S;
1085
69.3k
  case BT_PERCNT:
1086
69.3k
    return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1087
10.8k
  case BT_COMMA:
1088
10.8k
    *nextTokPtr = ptr + MINBPC(enc);
1089
10.8k
    return XML_TOK_COMMA;
1090
2.73k
  case BT_LSQB:
1091
2.73k
    *nextTokPtr = ptr + MINBPC(enc);
1092
2.73k
    return XML_TOK_OPEN_BRACKET;
1093
1.24k
  case BT_RSQB:
1094
1.24k
    ptr += MINBPC(enc);
1095
1.24k
    if (! HAS_CHAR(enc, ptr, end))
1096
3
      return -XML_TOK_CLOSE_BRACKET;
1097
1.24k
    if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
1098
28
      REQUIRE_CHARS(enc, ptr, end, 2);
1099
26
      if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) {
1100
1
        *nextTokPtr = ptr + 2 * MINBPC(enc);
1101
1
        return XML_TOK_COND_SECT_CLOSE;
1102
1
      }
1103
26
    }
1104
1.23k
    *nextTokPtr = ptr;
1105
1.23k
    return XML_TOK_CLOSE_BRACKET;
1106
3.35M
  case BT_LPAR:
1107
3.35M
    *nextTokPtr = ptr + MINBPC(enc);
1108
3.35M
    return XML_TOK_OPEN_PAREN;
1109
98.8k
  case BT_RPAR:
1110
98.8k
    ptr += MINBPC(enc);
1111
98.8k
    if (! HAS_CHAR(enc, ptr, end))
1112
99
      return -XML_TOK_CLOSE_PAREN;
1113
98.7k
    switch (BYTE_TYPE(enc, ptr)) {
1114
7.01k
    case BT_AST:
1115
7.01k
      *nextTokPtr = ptr + MINBPC(enc);
1116
7.01k
      return XML_TOK_CLOSE_PAREN_ASTERISK;
1117
5.65k
    case BT_QUEST:
1118
5.65k
      *nextTokPtr = ptr + MINBPC(enc);
1119
5.65k
      return XML_TOK_CLOSE_PAREN_QUESTION;
1120
7.45k
    case BT_PLUS:
1121
7.45k
      *nextTokPtr = ptr + MINBPC(enc);
1122
7.45k
      return XML_TOK_CLOSE_PAREN_PLUS;
1123
1.40k
    case BT_CR:
1124
4.98k
    case BT_LF:
1125
55.1k
    case BT_S:
1126
56.2k
    case BT_GT:
1127
62.7k
    case BT_COMMA:
1128
72.8k
    case BT_VERBAR:
1129
78.5k
    case BT_RPAR:
1130
78.5k
      *nextTokPtr = ptr;
1131
78.5k
      return XML_TOK_CLOSE_PAREN;
1132
98.7k
    }
1133
14
    *nextTokPtr = ptr;
1134
14
    return XML_TOK_INVALID;
1135
135k
  case BT_VERBAR:
1136
135k
    *nextTokPtr = ptr + MINBPC(enc);
1137
135k
    return XML_TOK_OR;
1138
56.0k
  case BT_GT:
1139
56.0k
    *nextTokPtr = ptr + MINBPC(enc);
1140
56.0k
    return XML_TOK_DECL_CLOSE;
1141
61.2k
  case BT_NUM:
1142
61.2k
    return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1143
0
#  define LEAD_CASE(n)                                                         \
1144
0
  case BT_LEAD##n:                                                             \
1145
0
    if (end - ptr < n)                                                         \
1146
0
      return XML_TOK_PARTIAL_CHAR;                                             \
1147
0
    if (IS_INVALID_CHAR(enc, ptr, n)) {                                        \
1148
0
      *nextTokPtr = ptr;                                                       \
1149
0
      return XML_TOK_INVALID;                                                  \
1150
0
    }                                                                          \
1151
0
    if (IS_NMSTRT_CHAR(enc, ptr, n)) {                                         \
1152
0
      ptr += n;                                                                \
1153
0
      tok = XML_TOK_NAME;                                                      \
1154
0
      break;                                                                   \
1155
0
    }                                                                          \
1156
0
    if (IS_NAME_CHAR(enc, ptr, n)) {                                           \
1157
0
      ptr += n;                                                                \
1158
0
      tok = XML_TOK_NMTOKEN;                                                   \
1159
0
      break;                                                                   \
1160
0
    }                                                                          \
1161
0
    *nextTokPtr = ptr;                                                         \
1162
0
    return XML_TOK_INVALID;
1163
22.4k
    LEAD_CASE(2)
1164
14.4k
    LEAD_CASE(3)
1165
180
    LEAD_CASE(4)
1166
0
#  undef LEAD_CASE
1167
155k
  case BT_NMSTRT:
1168
249k
  case BT_HEX:
1169
249k
    tok = XML_TOK_NAME;
1170
249k
    ptr += MINBPC(enc);
1171
249k
    break;
1172
109k
  case BT_DIGIT:
1173
109k
  case BT_NAME:
1174
110k
  case BT_MINUS:
1175
#  ifdef XML_NS
1176
  case BT_COLON:
1177
#  endif
1178
110k
    tok = XML_TOK_NMTOKEN;
1179
110k
    ptr += MINBPC(enc);
1180
110k
    break;
1181
0
  case BT_NONASCII:
1182
0
    if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
1183
0
      ptr += MINBPC(enc);
1184
0
      tok = XML_TOK_NAME;
1185
0
      break;
1186
0
    }
1187
0
    if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
1188
0
      ptr += MINBPC(enc);
1189
0
      tok = XML_TOK_NMTOKEN;
1190
0
      break;
1191
0
    }
1192
    /* fall through */
1193
61
  default:
1194
61
    *nextTokPtr = ptr;
1195
61
    return XML_TOK_INVALID;
1196
4.63M
  }
1197
12.3M
  while (HAS_CHAR(enc, ptr, end)) {
1198
12.3M
    switch (BYTE_TYPE(enc, ptr)) {
1199
33.7M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1200
27.9k
    case BT_GT:
1201
99.9k
    case BT_RPAR:
1202
100k
    case BT_COMMA:
1203
216k
    case BT_VERBAR:
1204
219k
    case BT_LSQB:
1205
219k
    case BT_PERCNT:
1206
262k
    case BT_S:
1207
346k
    case BT_CR:
1208
364k
    case BT_LF:
1209
364k
      *nextTokPtr = ptr;
1210
364k
      return tok;
1211
#  ifdef XML_NS
1212
    case BT_COLON:
1213
      ptr += MINBPC(enc);
1214
      switch (tok) {
1215
      case XML_TOK_NAME:
1216
        REQUIRE_CHAR(enc, ptr, end);
1217
        tok = XML_TOK_PREFIXED_NAME;
1218
        switch (BYTE_TYPE(enc, ptr)) {
1219
          CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1220
        default:
1221
          tok = XML_TOK_NMTOKEN;
1222
          break;
1223
        }
1224
        break;
1225
      case XML_TOK_PREFIXED_NAME:
1226
        tok = XML_TOK_NMTOKEN;
1227
        break;
1228
      }
1229
      break;
1230
#  endif
1231
4.10k
    case BT_PLUS:
1232
4.10k
      if (tok == XML_TOK_NMTOKEN) {
1233
1
        *nextTokPtr = ptr;
1234
1
        return XML_TOK_INVALID;
1235
1
      }
1236
4.10k
      *nextTokPtr = ptr + MINBPC(enc);
1237
4.10k
      return XML_TOK_NAME_PLUS;
1238
919
    case BT_AST:
1239
919
      if (tok == XML_TOK_NMTOKEN) {
1240
1
        *nextTokPtr = ptr;
1241
1
        return XML_TOK_INVALID;
1242
1
      }
1243
918
      *nextTokPtr = ptr + MINBPC(enc);
1244
918
      return XML_TOK_NAME_ASTERISK;
1245
648
    case BT_QUEST:
1246
648
      if (tok == XML_TOK_NMTOKEN) {
1247
3
        *nextTokPtr = ptr;
1248
3
        return XML_TOK_INVALID;
1249
3
      }
1250
645
      *nextTokPtr = ptr + MINBPC(enc);
1251
645
      return XML_TOK_NAME_QUESTION;
1252
45
    default:
1253
45
      *nextTokPtr = ptr;
1254
45
      return XML_TOK_INVALID;
1255
12.3M
    }
1256
12.3M
  }
1257
673
  return -tok;
1258
370k
}
xmltok.c:little2_prologTok
Line
Count
Source
1018
134
                  const char **nextTokPtr) {
1019
134
  int tok;
1020
134
  if (ptr >= end)
1021
2
    return XML_TOK_NONE;
1022
132
  if (MINBPC(enc) > 1) {
1023
132
    size_t n = end - ptr;
1024
132
    if (n & (MINBPC(enc) - 1)) {
1025
31
      n &= ~(MINBPC(enc) - 1);
1026
31
      if (n == 0)
1027
2
        return XML_TOK_PARTIAL;
1028
29
      end = ptr + n;
1029
29
    }
1030
132
  }
1031
130
  switch (BYTE_TYPE(enc, ptr)) {
1032
0
  case BT_QUOT:
1033
0
    return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr);
1034
0
  case BT_APOS:
1035
0
    return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr);
1036
0
  case BT_LT: {
1037
0
    ptr += MINBPC(enc);
1038
0
    REQUIRE_CHAR(enc, ptr, end);
1039
0
    switch (BYTE_TYPE(enc, ptr)) {
1040
0
    case BT_EXCL:
1041
0
      return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1042
0
    case BT_QUEST:
1043
0
      return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1044
0
    case BT_NMSTRT:
1045
0
    case BT_HEX:
1046
0
    case BT_NONASCII:
1047
0
    case BT_LEAD2:
1048
0
    case BT_LEAD3:
1049
0
    case BT_LEAD4:
1050
0
      *nextTokPtr = ptr - MINBPC(enc);
1051
0
      return XML_TOK_INSTANCE_START;
1052
0
    }
1053
0
    *nextTokPtr = ptr;
1054
0
    return XML_TOK_INVALID;
1055
0
  }
1056
0
  case BT_CR:
1057
0
    if (ptr + MINBPC(enc) == end) {
1058
0
      *nextTokPtr = end;
1059
      /* indicate that this might be part of a CR/LF pair */
1060
0
      return -XML_TOK_PROLOG_S;
1061
0
    }
1062
    /* fall through */
1063
0
  case BT_S:
1064
0
  case BT_LF:
1065
0
    for (;;) {
1066
0
      ptr += MINBPC(enc);
1067
0
      if (! HAS_CHAR(enc, ptr, end))
1068
0
        break;
1069
0
      switch (BYTE_TYPE(enc, ptr)) {
1070
0
      case BT_S:
1071
0
      case BT_LF:
1072
0
        break;
1073
0
      case BT_CR:
1074
        /* don't split CR/LF pair */
1075
0
        if (ptr + MINBPC(enc) != end)
1076
0
          break;
1077
        /* fall through */
1078
0
      default:
1079
0
        *nextTokPtr = ptr;
1080
0
        return XML_TOK_PROLOG_S;
1081
0
      }
1082
0
    }
1083
0
    *nextTokPtr = ptr;
1084
0
    return XML_TOK_PROLOG_S;
1085
0
  case BT_PERCNT:
1086
0
    return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1087
0
  case BT_COMMA:
1088
0
    *nextTokPtr = ptr + MINBPC(enc);
1089
0
    return XML_TOK_COMMA;
1090
0
  case BT_LSQB:
1091
0
    *nextTokPtr = ptr + MINBPC(enc);
1092
0
    return XML_TOK_OPEN_BRACKET;
1093
0
  case BT_RSQB:
1094
0
    ptr += MINBPC(enc);
1095
0
    if (! HAS_CHAR(enc, ptr, end))
1096
0
      return -XML_TOK_CLOSE_BRACKET;
1097
0
    if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
1098
0
      REQUIRE_CHARS(enc, ptr, end, 2);
1099
0
      if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) {
1100
0
        *nextTokPtr = ptr + 2 * MINBPC(enc);
1101
0
        return XML_TOK_COND_SECT_CLOSE;
1102
0
      }
1103
0
    }
1104
0
    *nextTokPtr = ptr;
1105
0
    return XML_TOK_CLOSE_BRACKET;
1106
0
  case BT_LPAR:
1107
0
    *nextTokPtr = ptr + MINBPC(enc);
1108
0
    return XML_TOK_OPEN_PAREN;
1109
0
  case BT_RPAR:
1110
0
    ptr += MINBPC(enc);
1111
0
    if (! HAS_CHAR(enc, ptr, end))
1112
0
      return -XML_TOK_CLOSE_PAREN;
1113
0
    switch (BYTE_TYPE(enc, ptr)) {
1114
0
    case BT_AST:
1115
0
      *nextTokPtr = ptr + MINBPC(enc);
1116
0
      return XML_TOK_CLOSE_PAREN_ASTERISK;
1117
0
    case BT_QUEST:
1118
0
      *nextTokPtr = ptr + MINBPC(enc);
1119
0
      return XML_TOK_CLOSE_PAREN_QUESTION;
1120
0
    case BT_PLUS:
1121
0
      *nextTokPtr = ptr + MINBPC(enc);
1122
0
      return XML_TOK_CLOSE_PAREN_PLUS;
1123
0
    case BT_CR:
1124
0
    case BT_LF:
1125
0
    case BT_S:
1126
0
    case BT_GT:
1127
0
    case BT_COMMA:
1128
0
    case BT_VERBAR:
1129
0
    case BT_RPAR:
1130
0
      *nextTokPtr = ptr;
1131
0
      return XML_TOK_CLOSE_PAREN;
1132
0
    }
1133
0
    *nextTokPtr = ptr;
1134
0
    return XML_TOK_INVALID;
1135
0
  case BT_VERBAR:
1136
0
    *nextTokPtr = ptr + MINBPC(enc);
1137
0
    return XML_TOK_OR;
1138
0
  case BT_GT:
1139
0
    *nextTokPtr = ptr + MINBPC(enc);
1140
0
    return XML_TOK_DECL_CLOSE;
1141
0
  case BT_NUM:
1142
0
    return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1143
0
#  define LEAD_CASE(n)                                                         \
1144
0
  case BT_LEAD##n:                                                             \
1145
0
    if (end - ptr < n)                                                         \
1146
0
      return XML_TOK_PARTIAL_CHAR;                                             \
1147
0
    if (IS_INVALID_CHAR(enc, ptr, n)) {                                        \
1148
0
      *nextTokPtr = ptr;                                                       \
1149
0
      return XML_TOK_INVALID;                                                  \
1150
0
    }                                                                          \
1151
0
    if (IS_NMSTRT_CHAR(enc, ptr, n)) {                                         \
1152
0
      ptr += n;                                                                \
1153
0
      tok = XML_TOK_NAME;                                                      \
1154
0
      break;                                                                   \
1155
0
    }                                                                          \
1156
0
    if (IS_NAME_CHAR(enc, ptr, n)) {                                           \
1157
0
      ptr += n;                                                                \
1158
0
      tok = XML_TOK_NMTOKEN;                                                   \
1159
0
      break;                                                                   \
1160
0
    }                                                                          \
1161
0
    *nextTokPtr = ptr;                                                         \
1162
0
    return XML_TOK_INVALID;
1163
0
    LEAD_CASE(2)
1164
0
    LEAD_CASE(3)
1165
38
    LEAD_CASE(4)
1166
0
#  undef LEAD_CASE
1167
0
  case BT_NMSTRT:
1168
0
  case BT_HEX:
1169
0
    tok = XML_TOK_NAME;
1170
0
    ptr += MINBPC(enc);
1171
0
    break;
1172
0
  case BT_DIGIT:
1173
0
  case BT_NAME:
1174
0
  case BT_MINUS:
1175
#  ifdef XML_NS
1176
  case BT_COLON:
1177
#  endif
1178
0
    tok = XML_TOK_NMTOKEN;
1179
0
    ptr += MINBPC(enc);
1180
0
    break;
1181
107
  case BT_NONASCII:
1182
107
    if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
1183
86
      ptr += MINBPC(enc);
1184
86
      tok = XML_TOK_NAME;
1185
86
      break;
1186
86
    }
1187
21
    if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
1188
8
      ptr += MINBPC(enc);
1189
8
      tok = XML_TOK_NMTOKEN;
1190
8
      break;
1191
8
    }
1192
    /* fall through */
1193
19
  default:
1194
19
    *nextTokPtr = ptr;
1195
19
    return XML_TOK_INVALID;
1196
130
  }
1197
381k
  while (HAS_CHAR(enc, ptr, end)) {
1198
381k
    switch (BYTE_TYPE(enc, ptr)) {
1199
1.90M
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1200
0
    case BT_GT:
1201
0
    case BT_RPAR:
1202
0
    case BT_COMMA:
1203
0
    case BT_VERBAR:
1204
0
    case BT_LSQB:
1205
0
    case BT_PERCNT:
1206
0
    case BT_S:
1207
0
    case BT_CR:
1208
0
    case BT_LF:
1209
0
      *nextTokPtr = ptr;
1210
0
      return tok;
1211
#  ifdef XML_NS
1212
    case BT_COLON:
1213
      ptr += MINBPC(enc);
1214
      switch (tok) {
1215
      case XML_TOK_NAME:
1216
        REQUIRE_CHAR(enc, ptr, end);
1217
        tok = XML_TOK_PREFIXED_NAME;
1218
        switch (BYTE_TYPE(enc, ptr)) {
1219
          CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1220
        default:
1221
          tok = XML_TOK_NMTOKEN;
1222
          break;
1223
        }
1224
        break;
1225
      case XML_TOK_PREFIXED_NAME:
1226
        tok = XML_TOK_NMTOKEN;
1227
        break;
1228
      }
1229
      break;
1230
#  endif
1231
0
    case BT_PLUS:
1232
0
      if (tok == XML_TOK_NMTOKEN) {
1233
0
        *nextTokPtr = ptr;
1234
0
        return XML_TOK_INVALID;
1235
0
      }
1236
0
      *nextTokPtr = ptr + MINBPC(enc);
1237
0
      return XML_TOK_NAME_PLUS;
1238
0
    case BT_AST:
1239
0
      if (tok == XML_TOK_NMTOKEN) {
1240
0
        *nextTokPtr = ptr;
1241
0
        return XML_TOK_INVALID;
1242
0
      }
1243
0
      *nextTokPtr = ptr + MINBPC(enc);
1244
0
      return XML_TOK_NAME_ASTERISK;
1245
0
    case BT_QUEST:
1246
0
      if (tok == XML_TOK_NMTOKEN) {
1247
0
        *nextTokPtr = ptr;
1248
0
        return XML_TOK_INVALID;
1249
0
      }
1250
0
      *nextTokPtr = ptr + MINBPC(enc);
1251
0
      return XML_TOK_NAME_QUESTION;
1252
9
    default:
1253
9
      *nextTokPtr = ptr;
1254
9
      return XML_TOK_INVALID;
1255
381k
    }
1256
381k
  }
1257
20
  return -tok;
1258
94
}
xmltok.c:big2_prologTok
Line
Count
Source
1018
109
                  const char **nextTokPtr) {
1019
109
  int tok;
1020
109
  if (ptr >= end)
1021
2
    return XML_TOK_NONE;
1022
107
  if (MINBPC(enc) > 1) {
1023
107
    size_t n = end - ptr;
1024
107
    if (n & (MINBPC(enc) - 1)) {
1025
10
      n &= ~(MINBPC(enc) - 1);
1026
10
      if (n == 0)
1027
2
        return XML_TOK_PARTIAL;
1028
8
      end = ptr + n;
1029
8
    }
1030
107
  }
1031
105
  switch (BYTE_TYPE(enc, ptr)) {
1032
0
  case BT_QUOT:
1033
0
    return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr);
1034
0
  case BT_APOS:
1035
0
    return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr);
1036
0
  case BT_LT: {
1037
0
    ptr += MINBPC(enc);
1038
0
    REQUIRE_CHAR(enc, ptr, end);
1039
0
    switch (BYTE_TYPE(enc, ptr)) {
1040
0
    case BT_EXCL:
1041
0
      return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1042
0
    case BT_QUEST:
1043
0
      return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1044
0
    case BT_NMSTRT:
1045
0
    case BT_HEX:
1046
0
    case BT_NONASCII:
1047
0
    case BT_LEAD2:
1048
0
    case BT_LEAD3:
1049
0
    case BT_LEAD4:
1050
0
      *nextTokPtr = ptr - MINBPC(enc);
1051
0
      return XML_TOK_INSTANCE_START;
1052
0
    }
1053
0
    *nextTokPtr = ptr;
1054
0
    return XML_TOK_INVALID;
1055
0
  }
1056
0
  case BT_CR:
1057
0
    if (ptr + MINBPC(enc) == end) {
1058
0
      *nextTokPtr = end;
1059
      /* indicate that this might be part of a CR/LF pair */
1060
0
      return -XML_TOK_PROLOG_S;
1061
0
    }
1062
    /* fall through */
1063
0
  case BT_S:
1064
0
  case BT_LF:
1065
0
    for (;;) {
1066
0
      ptr += MINBPC(enc);
1067
0
      if (! HAS_CHAR(enc, ptr, end))
1068
0
        break;
1069
0
      switch (BYTE_TYPE(enc, ptr)) {
1070
0
      case BT_S:
1071
0
      case BT_LF:
1072
0
        break;
1073
0
      case BT_CR:
1074
        /* don't split CR/LF pair */
1075
0
        if (ptr + MINBPC(enc) != end)
1076
0
          break;
1077
        /* fall through */
1078
0
      default:
1079
0
        *nextTokPtr = ptr;
1080
0
        return XML_TOK_PROLOG_S;
1081
0
      }
1082
0
    }
1083
0
    *nextTokPtr = ptr;
1084
0
    return XML_TOK_PROLOG_S;
1085
0
  case BT_PERCNT:
1086
0
    return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1087
0
  case BT_COMMA:
1088
0
    *nextTokPtr = ptr + MINBPC(enc);
1089
0
    return XML_TOK_COMMA;
1090
0
  case BT_LSQB:
1091
0
    *nextTokPtr = ptr + MINBPC(enc);
1092
0
    return XML_TOK_OPEN_BRACKET;
1093
0
  case BT_RSQB:
1094
0
    ptr += MINBPC(enc);
1095
0
    if (! HAS_CHAR(enc, ptr, end))
1096
0
      return -XML_TOK_CLOSE_BRACKET;
1097
0
    if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
1098
0
      REQUIRE_CHARS(enc, ptr, end, 2);
1099
0
      if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) {
1100
0
        *nextTokPtr = ptr + 2 * MINBPC(enc);
1101
0
        return XML_TOK_COND_SECT_CLOSE;
1102
0
      }
1103
0
    }
1104
0
    *nextTokPtr = ptr;
1105
0
    return XML_TOK_CLOSE_BRACKET;
1106
0
  case BT_LPAR:
1107
0
    *nextTokPtr = ptr + MINBPC(enc);
1108
0
    return XML_TOK_OPEN_PAREN;
1109
0
  case BT_RPAR:
1110
0
    ptr += MINBPC(enc);
1111
0
    if (! HAS_CHAR(enc, ptr, end))
1112
0
      return -XML_TOK_CLOSE_PAREN;
1113
0
    switch (BYTE_TYPE(enc, ptr)) {
1114
0
    case BT_AST:
1115
0
      *nextTokPtr = ptr + MINBPC(enc);
1116
0
      return XML_TOK_CLOSE_PAREN_ASTERISK;
1117
0
    case BT_QUEST:
1118
0
      *nextTokPtr = ptr + MINBPC(enc);
1119
0
      return XML_TOK_CLOSE_PAREN_QUESTION;
1120
0
    case BT_PLUS:
1121
0
      *nextTokPtr = ptr + MINBPC(enc);
1122
0
      return XML_TOK_CLOSE_PAREN_PLUS;
1123
0
    case BT_CR:
1124
0
    case BT_LF:
1125
0
    case BT_S:
1126
0
    case BT_GT:
1127
0
    case BT_COMMA:
1128
0
    case BT_VERBAR:
1129
0
    case BT_RPAR:
1130
0
      *nextTokPtr = ptr;
1131
0
      return XML_TOK_CLOSE_PAREN;
1132
0
    }
1133
0
    *nextTokPtr = ptr;
1134
0
    return XML_TOK_INVALID;
1135
0
  case BT_VERBAR:
1136
0
    *nextTokPtr = ptr + MINBPC(enc);
1137
0
    return XML_TOK_OR;
1138
0
  case BT_GT:
1139
0
    *nextTokPtr = ptr + MINBPC(enc);
1140
0
    return XML_TOK_DECL_CLOSE;
1141
0
  case BT_NUM:
1142
0
    return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1143
0
#  define LEAD_CASE(n)                                                         \
1144
0
  case BT_LEAD##n:                                                             \
1145
0
    if (end - ptr < n)                                                         \
1146
0
      return XML_TOK_PARTIAL_CHAR;                                             \
1147
0
    if (IS_INVALID_CHAR(enc, ptr, n)) {                                        \
1148
0
      *nextTokPtr = ptr;                                                       \
1149
0
      return XML_TOK_INVALID;                                                  \
1150
0
    }                                                                          \
1151
0
    if (IS_NMSTRT_CHAR(enc, ptr, n)) {                                         \
1152
0
      ptr += n;                                                                \
1153
0
      tok = XML_TOK_NAME;                                                      \
1154
0
      break;                                                                   \
1155
0
    }                                                                          \
1156
0
    if (IS_NAME_CHAR(enc, ptr, n)) {                                           \
1157
0
      ptr += n;                                                                \
1158
0
      tok = XML_TOK_NMTOKEN;                                                   \
1159
0
      break;                                                                   \
1160
0
    }                                                                          \
1161
0
    *nextTokPtr = ptr;                                                         \
1162
0
    return XML_TOK_INVALID;
1163
0
    LEAD_CASE(2)
1164
0
    LEAD_CASE(3)
1165
48
    LEAD_CASE(4)
1166
0
#  undef LEAD_CASE
1167
0
  case BT_NMSTRT:
1168
0
  case BT_HEX:
1169
0
    tok = XML_TOK_NAME;
1170
0
    ptr += MINBPC(enc);
1171
0
    break;
1172
0
  case BT_DIGIT:
1173
0
  case BT_NAME:
1174
0
  case BT_MINUS:
1175
#  ifdef XML_NS
1176
  case BT_COLON:
1177
#  endif
1178
0
    tok = XML_TOK_NMTOKEN;
1179
0
    ptr += MINBPC(enc);
1180
0
    break;
1181
82
  case BT_NONASCII:
1182
82
    if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
1183
65
      ptr += MINBPC(enc);
1184
65
      tok = XML_TOK_NAME;
1185
65
      break;
1186
65
    }
1187
17
    if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
1188
6
      ptr += MINBPC(enc);
1189
6
      tok = XML_TOK_NMTOKEN;
1190
6
      break;
1191
6
    }
1192
    /* fall through */
1193
16
  default:
1194
16
    *nextTokPtr = ptr;
1195
16
    return XML_TOK_INVALID;
1196
105
  }
1197
962
  while (HAS_CHAR(enc, ptr, end)) {
1198
962
    switch (BYTE_TYPE(enc, ptr)) {
1199
4.62k
      CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1200
0
    case BT_GT:
1201
0
    case BT_RPAR:
1202
0
    case BT_COMMA:
1203
0
    case BT_VERBAR:
1204
0
    case BT_LSQB:
1205
0
    case BT_PERCNT:
1206
0
    case BT_S:
1207
0
    case BT_CR:
1208
0
    case BT_LF:
1209
0
      *nextTokPtr = ptr;
1210
0
      return tok;
1211
#  ifdef XML_NS
1212
    case BT_COLON:
1213
      ptr += MINBPC(enc);
1214
      switch (tok) {
1215
      case XML_TOK_NAME:
1216
        REQUIRE_CHAR(enc, ptr, end);
1217
        tok = XML_TOK_PREFIXED_NAME;
1218
        switch (BYTE_TYPE(enc, ptr)) {
1219
          CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
1220
        default:
1221
          tok = XML_TOK_NMTOKEN;
1222
          break;
1223
        }
1224
        break;
1225
      case XML_TOK_PREFIXED_NAME:
1226
        tok = XML_TOK_NMTOKEN;
1227
        break;
1228
      }
1229
      break;
1230
#  endif
1231
0
    case BT_PLUS:
1232
0
      if (tok == XML_TOK_NMTOKEN) {
1233
0
        *nextTokPtr = ptr;
1234
0
        return XML_TOK_INVALID;
1235
0
      }
1236
0
      *nextTokPtr = ptr + MINBPC(enc);
1237
0
      return XML_TOK_NAME_PLUS;
1238
0
    case BT_AST:
1239
0
      if (tok == XML_TOK_NMTOKEN) {
1240
0
        *nextTokPtr = ptr;
1241
0
        return XML_TOK_INVALID;
1242
0
      }
1243
0
      *nextTokPtr = ptr + MINBPC(enc);
1244
0
      return XML_TOK_NAME_ASTERISK;
1245
0
    case BT_QUEST:
1246
0
      if (tok == XML_TOK_NMTOKEN) {
1247
0
        *nextTokPtr = ptr;
1248
0
        return XML_TOK_INVALID;
1249
0
      }
1250
0
      *nextTokPtr = ptr + MINBPC(enc);
1251
0
      return XML_TOK_NAME_QUESTION;
1252
9
    default:
1253
9
      *nextTokPtr = ptr;
1254
9
      return XML_TOK_INVALID;
1255
962
    }
1256
962
  }
1257
26
  return -tok;
1258
71
}
1259
1260
static int PTRCALL
1261
PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end,
1262
2.78M
                          const char **nextTokPtr) {
1263
2.78M
  const char *start;
1264
2.78M
  if (ptr >= end)
1265
107k
    return XML_TOK_NONE;
1266
2.67M
  else if (! HAS_CHAR(enc, ptr, end)) {
1267
    /* This line cannot be executed.  The incoming data has already
1268
     * been tokenized once, so incomplete characters like this have
1269
     * already been eliminated from the input.  Retaining the paranoia
1270
     * check is still valuable, however.
1271
     */
1272
0
    return XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */
1273
0
  }
1274
2.67M
  start = ptr;
1275
24.4M
  while (HAS_CHAR(enc, ptr, end)) {
1276
24.4M
    switch (BYTE_TYPE(enc, ptr)) {
1277
0
#  define LEAD_CASE(n)                                                         \
1278
319k
  case BT_LEAD##n:                                                             \
1279
319k
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1280
319k
    break;
1281
94.0k
      LEAD_CASE(2)
1282
122k
      LEAD_CASE(3)
1283
102k
      LEAD_CASE(4)
1284
0
#  undef LEAD_CASE
1285
286k
    case BT_AMP:
1286
286k
      if (ptr == start)
1287
219k
        return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1288
67.1k
      *nextTokPtr = ptr;
1289
67.1k
      return XML_TOK_DATA_CHARS;
1290
3
    case BT_LT:
1291
      /* this is for inside entity references */
1292
3
      *nextTokPtr = ptr;
1293
3
      return XML_TOK_INVALID;
1294
857k
    case BT_LF:
1295
857k
      if (ptr == start) {
1296
626k
        *nextTokPtr = ptr + MINBPC(enc);
1297
626k
        return XML_TOK_DATA_NEWLINE;
1298
626k
      }
1299
231k
      *nextTokPtr = ptr;
1300
231k
      return XML_TOK_DATA_CHARS;
1301
982k
    case BT_CR:
1302
982k
      if (ptr == start) {
1303
728k
        ptr += MINBPC(enc);
1304
728k
        if (! HAS_CHAR(enc, ptr, end))
1305
2.57k
          return XML_TOK_TRAILING_CR;
1306
725k
        if (BYTE_TYPE(enc, ptr) == BT_LF)
1307
170k
          ptr += MINBPC(enc);
1308
725k
        *nextTokPtr = ptr;
1309
725k
        return XML_TOK_DATA_NEWLINE;
1310
728k
      }
1311
253k
      *nextTokPtr = ptr;
1312
253k
      return XML_TOK_DATA_CHARS;
1313
471k
    case BT_S:
1314
471k
      if (ptr == start) {
1315
330k
        *nextTokPtr = ptr + MINBPC(enc);
1316
330k
        return XML_TOK_ATTRIBUTE_VALUE_S;
1317
330k
      }
1318
141k
      *nextTokPtr = ptr;
1319
141k
      return XML_TOK_DATA_CHARS;
1320
21.5M
    default:
1321
21.5M
      ptr += MINBPC(enc);
1322
21.5M
      break;
1323
24.4M
    }
1324
24.4M
  }
1325
79.5k
  *nextTokPtr = ptr;
1326
79.5k
  return XML_TOK_DATA_CHARS;
1327
2.67M
}
xmltok.c:normal_attributeValueTok
Line
Count
Source
1262
2.78M
                          const char **nextTokPtr) {
1263
2.78M
  const char *start;
1264
2.78M
  if (ptr >= end)
1265
107k
    return XML_TOK_NONE;
1266
2.67M
  else if (! HAS_CHAR(enc, ptr, end)) {
1267
    /* This line cannot be executed.  The incoming data has already
1268
     * been tokenized once, so incomplete characters like this have
1269
     * already been eliminated from the input.  Retaining the paranoia
1270
     * check is still valuable, however.
1271
     */
1272
0
    return XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */
1273
0
  }
1274
2.67M
  start = ptr;
1275
24.4M
  while (HAS_CHAR(enc, ptr, end)) {
1276
24.4M
    switch (BYTE_TYPE(enc, ptr)) {
1277
0
#  define LEAD_CASE(n)                                                         \
1278
0
  case BT_LEAD##n:                                                             \
1279
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1280
0
    break;
1281
94.0k
      LEAD_CASE(2)
1282
122k
      LEAD_CASE(3)
1283
102k
      LEAD_CASE(4)
1284
0
#  undef LEAD_CASE
1285
286k
    case BT_AMP:
1286
286k
      if (ptr == start)
1287
219k
        return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1288
67.1k
      *nextTokPtr = ptr;
1289
67.1k
      return XML_TOK_DATA_CHARS;
1290
3
    case BT_LT:
1291
      /* this is for inside entity references */
1292
3
      *nextTokPtr = ptr;
1293
3
      return XML_TOK_INVALID;
1294
857k
    case BT_LF:
1295
857k
      if (ptr == start) {
1296
626k
        *nextTokPtr = ptr + MINBPC(enc);
1297
626k
        return XML_TOK_DATA_NEWLINE;
1298
626k
      }
1299
231k
      *nextTokPtr = ptr;
1300
231k
      return XML_TOK_DATA_CHARS;
1301
982k
    case BT_CR:
1302
982k
      if (ptr == start) {
1303
728k
        ptr += MINBPC(enc);
1304
728k
        if (! HAS_CHAR(enc, ptr, end))
1305
2.57k
          return XML_TOK_TRAILING_CR;
1306
725k
        if (BYTE_TYPE(enc, ptr) == BT_LF)
1307
170k
          ptr += MINBPC(enc);
1308
725k
        *nextTokPtr = ptr;
1309
725k
        return XML_TOK_DATA_NEWLINE;
1310
728k
      }
1311
253k
      *nextTokPtr = ptr;
1312
253k
      return XML_TOK_DATA_CHARS;
1313
471k
    case BT_S:
1314
471k
      if (ptr == start) {
1315
330k
        *nextTokPtr = ptr + MINBPC(enc);
1316
330k
        return XML_TOK_ATTRIBUTE_VALUE_S;
1317
330k
      }
1318
141k
      *nextTokPtr = ptr;
1319
141k
      return XML_TOK_DATA_CHARS;
1320
21.5M
    default:
1321
21.5M
      ptr += MINBPC(enc);
1322
21.5M
      break;
1323
24.4M
    }
1324
24.4M
  }
1325
79.5k
  *nextTokPtr = ptr;
1326
79.5k
  return XML_TOK_DATA_CHARS;
1327
2.67M
}
Unexecuted instantiation: xmltok.c:little2_attributeValueTok
Unexecuted instantiation: xmltok.c:big2_attributeValueTok
1328
1329
static int PTRCALL
1330
PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end,
1331
0
                       const char **nextTokPtr) {
1332
0
  const char *start;
1333
0
  if (ptr >= end)
1334
0
    return XML_TOK_NONE;
1335
0
  else if (! HAS_CHAR(enc, ptr, end)) {
1336
    /* This line cannot be executed.  The incoming data has already
1337
     * been tokenized once, so incomplete characters like this have
1338
     * already been eliminated from the input.  Retaining the paranoia
1339
     * check is still valuable, however.
1340
     */
1341
0
    return XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */
1342
0
  }
1343
0
  start = ptr;
1344
0
  while (HAS_CHAR(enc, ptr, end)) {
1345
0
    switch (BYTE_TYPE(enc, ptr)) {
1346
0
#  define LEAD_CASE(n)                                                         \
1347
0
  case BT_LEAD##n:                                                             \
1348
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1349
0
    break;
1350
0
      LEAD_CASE(2)
1351
0
      LEAD_CASE(3)
1352
0
      LEAD_CASE(4)
1353
0
#  undef LEAD_CASE
1354
0
    case BT_AMP:
1355
0
      if (ptr == start)
1356
0
        return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1357
0
      *nextTokPtr = ptr;
1358
0
      return XML_TOK_DATA_CHARS;
1359
0
    case BT_PERCNT:
1360
0
      if (ptr == start) {
1361
0
        int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr);
1362
0
        return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok;
1363
0
      }
1364
0
      *nextTokPtr = ptr;
1365
0
      return XML_TOK_DATA_CHARS;
1366
0
    case BT_LF:
1367
0
      if (ptr == start) {
1368
0
        *nextTokPtr = ptr + MINBPC(enc);
1369
0
        return XML_TOK_DATA_NEWLINE;
1370
0
      }
1371
0
      *nextTokPtr = ptr;
1372
0
      return XML_TOK_DATA_CHARS;
1373
0
    case BT_CR:
1374
0
      if (ptr == start) {
1375
0
        ptr += MINBPC(enc);
1376
0
        if (! HAS_CHAR(enc, ptr, end))
1377
0
          return XML_TOK_TRAILING_CR;
1378
0
        if (BYTE_TYPE(enc, ptr) == BT_LF)
1379
0
          ptr += MINBPC(enc);
1380
0
        *nextTokPtr = ptr;
1381
0
        return XML_TOK_DATA_NEWLINE;
1382
0
      }
1383
0
      *nextTokPtr = ptr;
1384
0
      return XML_TOK_DATA_CHARS;
1385
0
    default:
1386
0
      ptr += MINBPC(enc);
1387
0
      break;
1388
0
    }
1389
0
  }
1390
0
  *nextTokPtr = ptr;
1391
0
  return XML_TOK_DATA_CHARS;
1392
0
}
Unexecuted instantiation: xmltok.c:normal_entityValueTok
Unexecuted instantiation: xmltok.c:little2_entityValueTok
Unexecuted instantiation: xmltok.c:big2_entityValueTok
1393
1394
#  ifdef XML_DTD
1395
1396
static int PTRCALL
1397
PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
1398
                         const char **nextTokPtr) {
1399
  int level = 0;
1400
  if (MINBPC(enc) > 1) {
1401
    size_t n = end - ptr;
1402
    if (n & (MINBPC(enc) - 1)) {
1403
      n &= ~(MINBPC(enc) - 1);
1404
      end = ptr + n;
1405
    }
1406
  }
1407
  while (HAS_CHAR(enc, ptr, end)) {
1408
    switch (BYTE_TYPE(enc, ptr)) {
1409
      INVALID_CASES(ptr, nextTokPtr)
1410
    case BT_LT:
1411
      ptr += MINBPC(enc);
1412
      REQUIRE_CHAR(enc, ptr, end);
1413
      if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) {
1414
        ptr += MINBPC(enc);
1415
        REQUIRE_CHAR(enc, ptr, end);
1416
        if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) {
1417
          ++level;
1418
          ptr += MINBPC(enc);
1419
        }
1420
      }
1421
      break;
1422
    case BT_RSQB:
1423
      ptr += MINBPC(enc);
1424
      REQUIRE_CHAR(enc, ptr, end);
1425
      if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) {
1426
        ptr += MINBPC(enc);
1427
        REQUIRE_CHAR(enc, ptr, end);
1428
        if (CHAR_MATCHES(enc, ptr, ASCII_GT)) {
1429
          ptr += MINBPC(enc);
1430
          if (level == 0) {
1431
            *nextTokPtr = ptr;
1432
            return XML_TOK_IGNORE_SECT;
1433
          }
1434
          --level;
1435
        }
1436
      }
1437
      break;
1438
    default:
1439
      ptr += MINBPC(enc);
1440
      break;
1441
    }
1442
  }
1443
  return XML_TOK_PARTIAL;
1444
}
1445
1446
#  endif /* XML_DTD */
1447
1448
static int PTRCALL
1449
PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
1450
3.75k
                   const char **badPtr) {
1451
3.75k
  ptr += MINBPC(enc);
1452
3.75k
  end -= MINBPC(enc);
1453
1.99M
  for (; HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
1454
1.99M
    switch (BYTE_TYPE(enc, ptr)) {
1455
725k
    case BT_DIGIT:
1456
1.15M
    case BT_HEX:
1457
1.16M
    case BT_MINUS:
1458
1.29M
    case BT_APOS:
1459
1.31M
    case BT_LPAR:
1460
1.43M
    case BT_RPAR:
1461
1.44M
    case BT_PLUS:
1462
1.45M
    case BT_COMMA:
1463
1.63M
    case BT_SOL:
1464
1.63M
    case BT_EQUALS:
1465
1.64M
    case BT_QUEST:
1466
1.65M
    case BT_CR:
1467
1.65M
    case BT_LF:
1468
1.65M
    case BT_SEMI:
1469
1.65M
    case BT_EXCL:
1470
1.66M
    case BT_AST:
1471
1.67M
    case BT_PERCNT:
1472
1.69M
    case BT_NUM:
1473
#  ifdef XML_NS
1474
    case BT_COLON:
1475
#  endif
1476
1.69M
      break;
1477
5.27k
    case BT_S:
1478
5.27k
      if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) {
1479
1
        *badPtr = ptr;
1480
1
        return 0;
1481
1
      }
1482
5.27k
      break;
1483
10.0k
    case BT_NAME:
1484
278k
    case BT_NMSTRT:
1485
278k
      if (! (BYTE_TO_ASCII(enc, ptr) & ~0x7f))
1486
278k
        break;
1487
      /* fall through */
1488
11.3k
    default:
1489
11.3k
      switch (BYTE_TO_ASCII(enc, ptr)) {
1490
3.00k
      case 0x24: /* $ */
1491
11.3k
      case 0x40: /* @ */
1492
11.3k
        break;
1493
7
      default:
1494
7
        *badPtr = ptr;
1495
7
        return 0;
1496
11.3k
      }
1497
11.3k
      break;
1498
1.99M
    }
1499
1.99M
  }
1500
3.74k
  return 1;
1501
3.75k
}
xmltok.c:normal_isPublicId
Line
Count
Source
1450
3.75k
                   const char **badPtr) {
1451
3.75k
  ptr += MINBPC(enc);
1452
3.75k
  end -= MINBPC(enc);
1453
1.99M
  for (; HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) {
1454
1.99M
    switch (BYTE_TYPE(enc, ptr)) {
1455
725k
    case BT_DIGIT:
1456
1.15M
    case BT_HEX:
1457
1.16M
    case BT_MINUS:
1458
1.29M
    case BT_APOS:
1459
1.31M
    case BT_LPAR:
1460
1.43M
    case BT_RPAR:
1461
1.44M
    case BT_PLUS:
1462
1.45M
    case BT_COMMA:
1463
1.63M
    case BT_SOL:
1464
1.63M
    case BT_EQUALS:
1465
1.64M
    case BT_QUEST:
1466
1.65M
    case BT_CR:
1467
1.65M
    case BT_LF:
1468
1.65M
    case BT_SEMI:
1469
1.65M
    case BT_EXCL:
1470
1.66M
    case BT_AST:
1471
1.67M
    case BT_PERCNT:
1472
1.69M
    case BT_NUM:
1473
#  ifdef XML_NS
1474
    case BT_COLON:
1475
#  endif
1476
1.69M
      break;
1477
5.27k
    case BT_S:
1478
5.27k
      if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) {
1479
1
        *badPtr = ptr;
1480
1
        return 0;
1481
1
      }
1482
5.27k
      break;
1483
10.0k
    case BT_NAME:
1484
278k
    case BT_NMSTRT:
1485
278k
      if (! (BYTE_TO_ASCII(enc, ptr) & ~0x7f))
1486
278k
        break;
1487
      /* fall through */
1488
11.3k
    default:
1489
11.3k
      switch (BYTE_TO_ASCII(enc, ptr)) {
1490
3.00k
      case 0x24: /* $ */
1491
11.3k
      case 0x40: /* @ */
1492
11.3k
        break;
1493
7
      default:
1494
7
        *badPtr = ptr;
1495
7
        return 0;
1496
11.3k
      }
1497
11.3k
      break;
1498
1.99M
    }
1499
1.99M
  }
1500
3.74k
  return 1;
1501
3.75k
}
Unexecuted instantiation: xmltok.c:little2_isPublicId
Unexecuted instantiation: xmltok.c:big2_isPublicId
1502
1503
/* This must only be called for a well-formed start-tag or empty
1504
   element tag.  Returns the number of attributes.  Pointers to the
1505
   first attsMax attributes are stored in atts.
1506
*/
1507
1508
static int PTRCALL
1509
PREFIX(getAtts)(const ENCODING *enc, const char *ptr, int attsMax,
1510
568k
                ATTRIBUTE *atts) {
1511
568k
  enum { other, inName, inValue } state = inName;
1512
568k
  int nAtts = 0;
1513
568k
  int open = 0; /* defined when state == inValue;
1514
                   initialization just to shut up compilers */
1515
1516
76.1M
  for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) {
1517
76.1M
    switch (BYTE_TYPE(enc, ptr)) {
1518
0
#  define START_NAME                                                           \
1519
39.2M
    if (state == other) {                                                      \
1520
7.37M
      if (nAtts < attsMax) {                                                   \
1521
3.77M
        atts[nAtts].name = ptr;                                                \
1522
3.77M
        atts[nAtts].normalized = 1;                                            \
1523
3.77M
      }                                                                        \
1524
7.37M
      state = inName;                                                          \
1525
7.37M
    }
1526
0
#  define LEAD_CASE(n)                                                         \
1527
452k
  case BT_LEAD##n: /* NOTE: The encoding has already been validated. */        \
1528
452k
    START_NAME ptr += (n - MINBPC(enc));                                       \
1529
452k
    break;
1530
178k
      LEAD_CASE(2)
1531
209k
      LEAD_CASE(3)
1532
63.4k
      LEAD_CASE(4)
1533
0
#  undef LEAD_CASE
1534
0
    case BT_NONASCII:
1535
36.7M
    case BT_NMSTRT:
1536
38.8M
    case BT_HEX:
1537
38.8M
      START_NAME
1538
38.8M
      break;
1539
0
#  undef START_NAME
1540
1.06M
    case BT_QUOT:
1541
1.06M
      if (state != inValue) {
1542
433k
        if (nAtts < attsMax)
1543
293k
          atts[nAtts].valuePtr = ptr + MINBPC(enc);
1544
433k
        state = inValue;
1545
433k
        open = BT_QUOT;
1546
633k
      } else if (open == BT_QUOT) {
1547
433k
        state = other;
1548
433k
        if (nAtts < attsMax)
1549
293k
          atts[nAtts].valueEnd = ptr;
1550
433k
        nAtts++;
1551
433k
      }
1552
1.06M
      break;
1553
14.0M
    case BT_APOS:
1554
14.0M
      if (state != inValue) {
1555
6.93M
        if (nAtts < attsMax)
1556
3.48M
          atts[nAtts].valuePtr = ptr + MINBPC(enc);
1557
6.93M
        state = inValue;
1558
6.93M
        open = BT_APOS;
1559
7.08M
      } else if (open == BT_APOS) {
1560
6.93M
        state = other;
1561
6.93M
        if (nAtts < attsMax)
1562
3.48M
          atts[nAtts].valueEnd = ptr;
1563
6.93M
        nAtts++;
1564
6.93M
      }
1565
14.0M
      break;
1566
112k
    case BT_AMP:
1567
112k
      if (nAtts < attsMax)
1568
110k
        atts[nAtts].normalized = 0;
1569
112k
      break;
1570
5.18M
    case BT_S:
1571
5.18M
      if (state == inName)
1572
139k
        state = other;
1573
5.04M
      else if (state == inValue && nAtts < attsMax && atts[nAtts].normalized
1574
5.04M
               && (ptr == atts[nAtts].valuePtr
1575
156k
                   || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE
1576
156k
                   || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE
1577
156k
                   || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open))
1578
150k
        atts[nAtts].normalized = 0;
1579
5.18M
      break;
1580
4.33M
    case BT_CR:
1581
5.27M
    case BT_LF:
1582
      /* This case ensures that the first attribute name is counted
1583
         Apart from that we could just change state on the quote. */
1584
5.27M
      if (state == inName)
1585
34.6k
        state = other;
1586
5.23M
      else if (state == inValue && nAtts < attsMax)
1587
1.39M
        atts[nAtts].normalized = 0;
1588
5.27M
      break;
1589
399k
    case BT_GT:
1590
597k
    case BT_SOL:
1591
597k
      if (state != inValue)
1592
568k
        return nAtts;
1593
28.7k
      break;
1594
10.6M
    default:
1595
10.6M
      break;
1596
76.1M
    }
1597
76.1M
  }
1598
  /* not reached */
1599
568k
}
xmltok.c:normal_getAtts
Line
Count
Source
1510
568k
                ATTRIBUTE *atts) {
1511
568k
  enum { other, inName, inValue } state = inName;
1512
568k
  int nAtts = 0;
1513
568k
  int open = 0; /* defined when state == inValue;
1514
                   initialization just to shut up compilers */
1515
1516
76.1M
  for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) {
1517
76.1M
    switch (BYTE_TYPE(enc, ptr)) {
1518
0
#  define START_NAME                                                           \
1519
0
    if (state == other) {                                                      \
1520
0
      if (nAtts < attsMax) {                                                   \
1521
0
        atts[nAtts].name = ptr;                                                \
1522
0
        atts[nAtts].normalized = 1;                                            \
1523
0
      }                                                                        \
1524
0
      state = inName;                                                          \
1525
0
    }
1526
0
#  define LEAD_CASE(n)                                                         \
1527
0
  case BT_LEAD##n: /* NOTE: The encoding has already been validated. */        \
1528
0
    START_NAME ptr += (n - MINBPC(enc));                                       \
1529
0
    break;
1530
178k
      LEAD_CASE(2)
1531
209k
      LEAD_CASE(3)
1532
63.4k
      LEAD_CASE(4)
1533
0
#  undef LEAD_CASE
1534
0
    case BT_NONASCII:
1535
36.7M
    case BT_NMSTRT:
1536
38.8M
    case BT_HEX:
1537
38.8M
      START_NAME
1538
38.8M
      break;
1539
0
#  undef START_NAME
1540
1.06M
    case BT_QUOT:
1541
1.06M
      if (state != inValue) {
1542
433k
        if (nAtts < attsMax)
1543
293k
          atts[nAtts].valuePtr = ptr + MINBPC(enc);
1544
433k
        state = inValue;
1545
433k
        open = BT_QUOT;
1546
633k
      } else if (open == BT_QUOT) {
1547
433k
        state = other;
1548
433k
        if (nAtts < attsMax)
1549
293k
          atts[nAtts].valueEnd = ptr;
1550
433k
        nAtts++;
1551
433k
      }
1552
1.06M
      break;
1553
14.0M
    case BT_APOS:
1554
14.0M
      if (state != inValue) {
1555
6.93M
        if (nAtts < attsMax)
1556
3.48M
          atts[nAtts].valuePtr = ptr + MINBPC(enc);
1557
6.93M
        state = inValue;
1558
6.93M
        open = BT_APOS;
1559
7.08M
      } else if (open == BT_APOS) {
1560
6.93M
        state = other;
1561
6.93M
        if (nAtts < attsMax)
1562
3.48M
          atts[nAtts].valueEnd = ptr;
1563
6.93M
        nAtts++;
1564
6.93M
      }
1565
14.0M
      break;
1566
112k
    case BT_AMP:
1567
112k
      if (nAtts < attsMax)
1568
110k
        atts[nAtts].normalized = 0;
1569
112k
      break;
1570
5.18M
    case BT_S:
1571
5.18M
      if (state == inName)
1572
139k
        state = other;
1573
5.04M
      else if (state == inValue && nAtts < attsMax && atts[nAtts].normalized
1574
5.04M
               && (ptr == atts[nAtts].valuePtr
1575
156k
                   || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE
1576
156k
                   || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE
1577
156k
                   || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open))
1578
150k
        atts[nAtts].normalized = 0;
1579
5.18M
      break;
1580
4.33M
    case BT_CR:
1581
5.27M
    case BT_LF:
1582
      /* This case ensures that the first attribute name is counted
1583
         Apart from that we could just change state on the quote. */
1584
5.27M
      if (state == inName)
1585
34.6k
        state = other;
1586
5.23M
      else if (state == inValue && nAtts < attsMax)
1587
1.39M
        atts[nAtts].normalized = 0;
1588
5.27M
      break;
1589
399k
    case BT_GT:
1590
597k
    case BT_SOL:
1591
597k
      if (state != inValue)
1592
568k
        return nAtts;
1593
28.7k
      break;
1594
10.6M
    default:
1595
10.6M
      break;
1596
76.1M
    }
1597
76.1M
  }
1598
  /* not reached */
1599
568k
}
Unexecuted instantiation: xmltok.c:little2_getAtts
Unexecuted instantiation: xmltok.c:big2_getAtts
1600
1601
static int PTRFASTCALL
1602
107k
PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) {
1603
107k
  int result = 0;
1604
  /* skip &# */
1605
107k
  UNUSED_P(enc);
1606
107k
  ptr += 2 * MINBPC(enc);
1607
107k
  if (CHAR_MATCHES(enc, ptr, ASCII_x)) {
1608
471k
    for (ptr += MINBPC(enc); ! CHAR_MATCHES(enc, ptr, ASCII_SEMI);
1609
369k
         ptr += MINBPC(enc)) {
1610
369k
      int c = BYTE_TO_ASCII(enc, ptr);
1611
369k
      switch (c) {
1612
4.17k
      case ASCII_0:
1613
33.7k
      case ASCII_1:
1614
75.1k
      case ASCII_2:
1615
81.1k
      case ASCII_3:
1616
129k
      case ASCII_4:
1617
165k
      case ASCII_5:
1618
167k
      case ASCII_6:
1619
187k
      case ASCII_7:
1620
215k
      case ASCII_8:
1621
224k
      case ASCII_9:
1622
224k
        result <<= 4;
1623
224k
        result |= (c - ASCII_0);
1624
224k
        break;
1625
35.8k
      case ASCII_A:
1626
40.7k
      case ASCII_B:
1627
43.5k
      case ASCII_C:
1628
49.4k
      case ASCII_D:
1629
52.6k
      case ASCII_E:
1630
74.0k
      case ASCII_F:
1631
74.0k
        result <<= 4;
1632
74.0k
        result += 10 + (c - ASCII_A);
1633
74.0k
        break;
1634
514
      case ASCII_a:
1635
18.4k
      case ASCII_b:
1636
20.3k
      case ASCII_c:
1637
55.3k
      case ASCII_d:
1638
56.6k
      case ASCII_e:
1639
71.0k
      case ASCII_f:
1640
71.0k
        result <<= 4;
1641
71.0k
        result += 10 + (c - ASCII_a);
1642
71.0k
        break;
1643
369k
      }
1644
369k
      if (result >= 0x110000)
1645
14
        return -1;
1646
369k
    }
1647
102k
  } else {
1648
19.8k
    for (; ! CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) {
1649
14.7k
      int c = BYTE_TO_ASCII(enc, ptr);
1650
14.7k
      result *= 10;
1651
14.7k
      result += (c - ASCII_0);
1652
14.7k
      if (result >= 0x110000)
1653
4
        return -1;
1654
14.7k
    }
1655
5.06k
  }
1656
107k
  return checkCharRefNumber(result);
1657
107k
}
xmltok.c:normal_charRefNumber
Line
Count
Source
1602
107k
PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) {
1603
107k
  int result = 0;
1604
  /* skip &# */
1605
107k
  UNUSED_P(enc);
1606
107k
  ptr += 2 * MINBPC(enc);
1607
107k
  if (CHAR_MATCHES(enc, ptr, ASCII_x)) {
1608
471k
    for (ptr += MINBPC(enc); ! CHAR_MATCHES(enc, ptr, ASCII_SEMI);
1609
369k
         ptr += MINBPC(enc)) {
1610
369k
      int c = BYTE_TO_ASCII(enc, ptr);
1611
369k
      switch (c) {
1612
4.17k
      case ASCII_0:
1613
33.7k
      case ASCII_1:
1614
75.1k
      case ASCII_2:
1615
81.1k
      case ASCII_3:
1616
129k
      case ASCII_4:
1617
165k
      case ASCII_5:
1618
167k
      case ASCII_6:
1619
187k
      case ASCII_7:
1620
215k
      case ASCII_8:
1621
224k
      case ASCII_9:
1622
224k
        result <<= 4;
1623
224k
        result |= (c - ASCII_0);
1624
224k
        break;
1625
35.8k
      case ASCII_A:
1626
40.7k
      case ASCII_B:
1627
43.5k
      case ASCII_C:
1628
49.4k
      case ASCII_D:
1629
52.6k
      case ASCII_E:
1630
74.0k
      case ASCII_F:
1631
74.0k
        result <<= 4;
1632
74.0k
        result += 10 + (c - ASCII_A);
1633
74.0k
        break;
1634
514
      case ASCII_a:
1635
18.4k
      case ASCII_b:
1636
20.3k
      case ASCII_c:
1637
55.3k
      case ASCII_d:
1638
56.6k
      case ASCII_e:
1639
71.0k
      case ASCII_f:
1640
71.0k
        result <<= 4;
1641
71.0k
        result += 10 + (c - ASCII_a);
1642
71.0k
        break;
1643
369k
      }
1644
369k
      if (result >= 0x110000)
1645
14
        return -1;
1646
369k
    }
1647
102k
  } else {
1648
19.8k
    for (; ! CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) {
1649
14.7k
      int c = BYTE_TO_ASCII(enc, ptr);
1650
14.7k
      result *= 10;
1651
14.7k
      result += (c - ASCII_0);
1652
14.7k
      if (result >= 0x110000)
1653
4
        return -1;
1654
14.7k
    }
1655
5.06k
  }
1656
107k
  return checkCharRefNumber(result);
1657
107k
}
Unexecuted instantiation: xmltok.c:little2_charRefNumber
Unexecuted instantiation: xmltok.c:big2_charRefNumber
1658
1659
static int PTRCALL
1660
PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr,
1661
172k
                             const char *end) {
1662
172k
  UNUSED_P(enc);
1663
172k
  switch ((end - ptr) / MINBPC(enc)) {
1664
13.2k
  case 2:
1665
13.2k
    if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) {
1666
3.09k
      switch (BYTE_TO_ASCII(enc, ptr)) {
1667
552
      case ASCII_l:
1668
552
        return ASCII_LT;
1669
172
      case ASCII_g:
1670
172
        return ASCII_GT;
1671
3.09k
      }
1672
3.09k
    }
1673
12.5k
    break;
1674
64.7k
  case 3:
1675
64.7k
    if (CHAR_MATCHES(enc, ptr, ASCII_a)) {
1676
52.5k
      ptr += MINBPC(enc);
1677
52.5k
      if (CHAR_MATCHES(enc, ptr, ASCII_m)) {
1678
51.0k
        ptr += MINBPC(enc);
1679
51.0k
        if (CHAR_MATCHES(enc, ptr, ASCII_p))
1680
50.8k
          return ASCII_AMP;
1681
51.0k
      }
1682
52.5k
    }
1683
13.9k
    break;
1684
18.8k
  case 4:
1685
18.8k
    switch (BYTE_TO_ASCII(enc, ptr)) {
1686
10.2k
    case ASCII_q:
1687
10.2k
      ptr += MINBPC(enc);
1688
10.2k
      if (CHAR_MATCHES(enc, ptr, ASCII_u)) {
1689
9.50k
        ptr += MINBPC(enc);
1690
9.50k
        if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
1691
8.22k
          ptr += MINBPC(enc);
1692
8.22k
          if (CHAR_MATCHES(enc, ptr, ASCII_t))
1693
7.90k
            return ASCII_QUOT;
1694
8.22k
        }
1695
9.50k
      }
1696
2.29k
      break;
1697
3.93k
    case ASCII_a:
1698
3.93k
      ptr += MINBPC(enc);
1699
3.93k
      if (CHAR_MATCHES(enc, ptr, ASCII_p)) {
1700
1.01k
        ptr += MINBPC(enc);
1701
1.01k
        if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
1702
570
          ptr += MINBPC(enc);
1703
570
          if (CHAR_MATCHES(enc, ptr, ASCII_s))
1704
233
            return ASCII_APOS;
1705
570
        }
1706
1.01k
      }
1707
3.70k
      break;
1708
18.8k
    }
1709
172k
  }
1710
113k
  return 0;
1711
172k
}
xmltok.c:normal_predefinedEntityName
Line
Count
Source
1661
172k
                             const char *end) {
1662
172k
  UNUSED_P(enc);
1663
172k
  switch ((end - ptr) / MINBPC(enc)) {
1664
13.2k
  case 2:
1665
13.2k
    if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) {
1666
3.09k
      switch (BYTE_TO_ASCII(enc, ptr)) {
1667
552
      case ASCII_l:
1668
552
        return ASCII_LT;
1669
172
      case ASCII_g:
1670
172
        return ASCII_GT;
1671
3.09k
      }
1672
3.09k
    }
1673
12.5k
    break;
1674
64.7k
  case 3:
1675
64.7k
    if (CHAR_MATCHES(enc, ptr, ASCII_a)) {
1676
52.5k
      ptr += MINBPC(enc);
1677
52.5k
      if (CHAR_MATCHES(enc, ptr, ASCII_m)) {
1678
51.0k
        ptr += MINBPC(enc);
1679
51.0k
        if (CHAR_MATCHES(enc, ptr, ASCII_p))
1680
50.8k
          return ASCII_AMP;
1681
51.0k
      }
1682
52.5k
    }
1683
13.9k
    break;
1684
18.8k
  case 4:
1685
18.8k
    switch (BYTE_TO_ASCII(enc, ptr)) {
1686
10.2k
    case ASCII_q:
1687
10.2k
      ptr += MINBPC(enc);
1688
10.2k
      if (CHAR_MATCHES(enc, ptr, ASCII_u)) {
1689
9.50k
        ptr += MINBPC(enc);
1690
9.50k
        if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
1691
8.22k
          ptr += MINBPC(enc);
1692
8.22k
          if (CHAR_MATCHES(enc, ptr, ASCII_t))
1693
7.90k
            return ASCII_QUOT;
1694
8.22k
        }
1695
9.50k
      }
1696
2.29k
      break;
1697
3.93k
    case ASCII_a:
1698
3.93k
      ptr += MINBPC(enc);
1699
3.93k
      if (CHAR_MATCHES(enc, ptr, ASCII_p)) {
1700
1.01k
        ptr += MINBPC(enc);
1701
1.01k
        if (CHAR_MATCHES(enc, ptr, ASCII_o)) {
1702
570
          ptr += MINBPC(enc);
1703
570
          if (CHAR_MATCHES(enc, ptr, ASCII_s))
1704
233
            return ASCII_APOS;
1705
570
        }
1706
1.01k
      }
1707
3.70k
      break;
1708
18.8k
    }
1709
172k
  }
1710
113k
  return 0;
1711
172k
}
Unexecuted instantiation: xmltok.c:little2_predefinedEntityName
Unexecuted instantiation: xmltok.c:big2_predefinedEntityName
1712
1713
static int PTRCALL
1714
PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1,
1715
246k
                         const char *end1, const char *ptr2) {
1716
246k
  UNUSED_P(enc);
1717
1.19M
  for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
1718
1.04M
    if (end1 - ptr1 < MINBPC(enc)) {
1719
      /* This line cannot be executed.  The incoming data has already
1720
       * been tokenized once, so incomplete characters like this have
1721
       * already been eliminated from the input.  Retaining the
1722
       * paranoia check is still valuable, however.
1723
       */
1724
53
      return 0; /* LCOV_EXCL_LINE */
1725
53
    }
1726
1.04M
    if (! CHAR_MATCHES(enc, ptr1, *ptr2))
1727
89.8k
      return 0;
1728
1.04M
  }
1729
156k
  return ptr1 == end1;
1730
246k
}
xmltok.c:normal_nameMatchesAscii
Line
Count
Source
1715
246k
                         const char *end1, const char *ptr2) {
1716
246k
  UNUSED_P(enc);
1717
1.19M
  for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
1718
1.04M
    if (end1 - ptr1 < MINBPC(enc)) {
1719
      /* This line cannot be executed.  The incoming data has already
1720
       * been tokenized once, so incomplete characters like this have
1721
       * already been eliminated from the input.  Retaining the
1722
       * paranoia check is still valuable, however.
1723
       */
1724
53
      return 0; /* LCOV_EXCL_LINE */
1725
53
    }
1726
1.04M
    if (! CHAR_MATCHES(enc, ptr1, *ptr2))
1727
89.8k
      return 0;
1728
1.04M
  }
1729
156k
  return ptr1 == end1;
1730
246k
}
Unexecuted instantiation: xmltok.c:little2_nameMatchesAscii
Unexecuted instantiation: xmltok.c:big2_nameMatchesAscii
1731
1732
static int PTRFASTCALL
1733
796k
PREFIX(nameLength)(const ENCODING *enc, const char *ptr) {
1734
796k
  const char *start = ptr;
1735
11.7M
  for (;;) {
1736
11.7M
    switch (BYTE_TYPE(enc, ptr)) {
1737
0
#  define LEAD_CASE(n)                                                         \
1738
108k
  case BT_LEAD##n:                                                             \
1739
108k
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1740
108k
    break;
1741
47.6k
      LEAD_CASE(2)
1742
60.3k
      LEAD_CASE(3)
1743
0
      LEAD_CASE(4)
1744
0
#  undef LEAD_CASE
1745
0
    case BT_NONASCII:
1746
9.81M
    case BT_NMSTRT:
1747
#  ifdef XML_NS
1748
    case BT_COLON:
1749
#  endif
1750
10.6M
    case BT_HEX:
1751
10.7M
    case BT_DIGIT:
1752
10.7M
    case BT_NAME:
1753
10.8M
    case BT_MINUS:
1754
10.8M
      ptr += MINBPC(enc);
1755
10.8M
      break;
1756
796k
    default:
1757
796k
      return (int)(ptr - start);
1758
11.7M
    }
1759
11.7M
  }
1760
796k
}
xmltok.c:normal_nameLength
Line
Count
Source
1733
796k
PREFIX(nameLength)(const ENCODING *enc, const char *ptr) {
1734
796k
  const char *start = ptr;
1735
11.7M
  for (;;) {
1736
11.7M
    switch (BYTE_TYPE(enc, ptr)) {
1737
0
#  define LEAD_CASE(n)                                                         \
1738
0
  case BT_LEAD##n:                                                             \
1739
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1740
0
    break;
1741
47.6k
      LEAD_CASE(2)
1742
60.3k
      LEAD_CASE(3)
1743
0
      LEAD_CASE(4)
1744
0
#  undef LEAD_CASE
1745
0
    case BT_NONASCII:
1746
9.81M
    case BT_NMSTRT:
1747
#  ifdef XML_NS
1748
    case BT_COLON:
1749
#  endif
1750
10.6M
    case BT_HEX:
1751
10.7M
    case BT_DIGIT:
1752
10.7M
    case BT_NAME:
1753
10.8M
    case BT_MINUS:
1754
10.8M
      ptr += MINBPC(enc);
1755
10.8M
      break;
1756
796k
    default:
1757
796k
      return (int)(ptr - start);
1758
11.7M
    }
1759
11.7M
  }
1760
796k
}
Unexecuted instantiation: xmltok.c:little2_nameLength
Unexecuted instantiation: xmltok.c:big2_nameLength
1761
1762
static const char *PTRFASTCALL
1763
0
PREFIX(skipS)(const ENCODING *enc, const char *ptr) {
1764
0
  for (;;) {
1765
0
    switch (BYTE_TYPE(enc, ptr)) {
1766
0
    case BT_LF:
1767
0
    case BT_CR:
1768
0
    case BT_S:
1769
0
      ptr += MINBPC(enc);
1770
0
      break;
1771
0
    default:
1772
0
      return ptr;
1773
0
    }
1774
0
  }
1775
0
}
Unexecuted instantiation: xmltok.c:normal_skipS
Unexecuted instantiation: xmltok.c:little2_skipS
Unexecuted instantiation: xmltok.c:big2_skipS
1776
1777
static void PTRCALL
1778
PREFIX(updatePosition)(const ENCODING *enc, const char *ptr, const char *end,
1779
19.1k
                       POSITION *pos) {
1780
126M
  while (HAS_CHAR(enc, ptr, end)) {
1781
126M
    switch (BYTE_TYPE(enc, ptr)) {
1782
0
#  define LEAD_CASE(n)                                                         \
1783
1.92M
  case BT_LEAD##n:                                                             \
1784
1.92M
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1785
1.92M
    pos->columnNumber++;                                                       \
1786
1.92M
    break;
1787
776k
      LEAD_CASE(2)
1788
901k
      LEAD_CASE(3)
1789
244k
      LEAD_CASE(4)
1790
0
#  undef LEAD_CASE
1791
3.00M
    case BT_LF:
1792
3.00M
      pos->columnNumber = 0;
1793
3.00M
      pos->lineNumber++;
1794
3.00M
      ptr += MINBPC(enc);
1795
3.00M
      break;
1796
4.42M
    case BT_CR:
1797
4.42M
      pos->lineNumber++;
1798
4.42M
      ptr += MINBPC(enc);
1799
4.42M
      if (HAS_CHAR(enc, ptr, end) && BYTE_TYPE(enc, ptr) == BT_LF)
1800
835k
        ptr += MINBPC(enc);
1801
4.42M
      pos->columnNumber = 0;
1802
4.42M
      break;
1803
117M
    default:
1804
117M
      ptr += MINBPC(enc);
1805
117M
      pos->columnNumber++;
1806
117M
      break;
1807
126M
    }
1808
126M
  }
1809
19.1k
}
xmltok.c:normal_updatePosition
Line
Count
Source
1779
18.7k
                       POSITION *pos) {
1780
126M
  while (HAS_CHAR(enc, ptr, end)) {
1781
126M
    switch (BYTE_TYPE(enc, ptr)) {
1782
0
#  define LEAD_CASE(n)                                                         \
1783
0
  case BT_LEAD##n:                                                             \
1784
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1785
0
    pos->columnNumber++;                                                       \
1786
0
    break;
1787
776k
      LEAD_CASE(2)
1788
901k
      LEAD_CASE(3)
1789
244k
      LEAD_CASE(4)
1790
0
#  undef LEAD_CASE
1791
3.00M
    case BT_LF:
1792
3.00M
      pos->columnNumber = 0;
1793
3.00M
      pos->lineNumber++;
1794
3.00M
      ptr += MINBPC(enc);
1795
3.00M
      break;
1796
4.42M
    case BT_CR:
1797
4.42M
      pos->lineNumber++;
1798
4.42M
      ptr += MINBPC(enc);
1799
4.42M
      if (HAS_CHAR(enc, ptr, end) && BYTE_TYPE(enc, ptr) == BT_LF)
1800
835k
        ptr += MINBPC(enc);
1801
4.42M
      pos->columnNumber = 0;
1802
4.42M
      break;
1803
117M
    default:
1804
117M
      ptr += MINBPC(enc);
1805
117M
      pos->columnNumber++;
1806
117M
      break;
1807
126M
    }
1808
126M
  }
1809
18.7k
}
xmltok.c:little2_updatePosition
Line
Count
Source
1779
243
                       POSITION *pos) {
1780
381k
  while (HAS_CHAR(enc, ptr, end)) {
1781
381k
    switch (BYTE_TYPE(enc, ptr)) {
1782
0
#  define LEAD_CASE(n)                                                         \
1783
0
  case BT_LEAD##n:                                                             \
1784
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1785
0
    pos->columnNumber++;                                                       \
1786
0
    break;
1787
0
      LEAD_CASE(2)
1788
0
      LEAD_CASE(3)
1789
0
      LEAD_CASE(4)
1790
0
#  undef LEAD_CASE
1791
0
    case BT_LF:
1792
0
      pos->columnNumber = 0;
1793
0
      pos->lineNumber++;
1794
0
      ptr += MINBPC(enc);
1795
0
      break;
1796
0
    case BT_CR:
1797
0
      pos->lineNumber++;
1798
0
      ptr += MINBPC(enc);
1799
0
      if (HAS_CHAR(enc, ptr, end) && BYTE_TYPE(enc, ptr) == BT_LF)
1800
0
        ptr += MINBPC(enc);
1801
0
      pos->columnNumber = 0;
1802
0
      break;
1803
381k
    default:
1804
381k
      ptr += MINBPC(enc);
1805
381k
      pos->columnNumber++;
1806
381k
      break;
1807
381k
    }
1808
381k
  }
1809
243
}
xmltok.c:big2_updatePosition
Line
Count
Source
1779
193
                       POSITION *pos) {
1780
646
  while (HAS_CHAR(enc, ptr, end)) {
1781
646
    switch (BYTE_TYPE(enc, ptr)) {
1782
0
#  define LEAD_CASE(n)                                                         \
1783
0
  case BT_LEAD##n:                                                             \
1784
0
    ptr += n; /* NOTE: The encoding has already been validated. */             \
1785
0
    pos->columnNumber++;                                                       \
1786
0
    break;
1787
0
      LEAD_CASE(2)
1788
0
      LEAD_CASE(3)
1789
0
      LEAD_CASE(4)
1790
0
#  undef LEAD_CASE
1791
0
    case BT_LF:
1792
0
      pos->columnNumber = 0;
1793
0
      pos->lineNumber++;
1794
0
      ptr += MINBPC(enc);
1795
0
      break;
1796
0
    case BT_CR:
1797
0
      pos->lineNumber++;
1798
0
      ptr += MINBPC(enc);
1799
0
      if (HAS_CHAR(enc, ptr, end) && BYTE_TYPE(enc, ptr) == BT_LF)
1800
0
        ptr += MINBPC(enc);
1801
0
      pos->columnNumber = 0;
1802
0
      break;
1803
646
    default:
1804
646
      ptr += MINBPC(enc);
1805
646
      pos->columnNumber++;
1806
646
      break;
1807
646
    }
1808
646
  }
1809
193
}
1810
1811
#  undef DO_LEAD_CASE
1812
#  undef MULTIBYTE_CASES
1813
#  undef INVALID_CASES
1814
#  undef CHECK_NAME_CASE
1815
#  undef CHECK_NAME_CASES
1816
#  undef CHECK_NMSTRT_CASE
1817
#  undef CHECK_NMSTRT_CASES
1818
1819
#endif /* XML_TOK_IMPL_C */