1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qstring.h>
5
6#include "qxmlutils_p.h"
7
8#include <private/qtools_p.h>
9
10QT_BEGIN_NAMESPACE
11
12using namespace QtMiscUtils;
13
14/* TODO:
15 * - isNameChar() doesn't have to be public, it's only needed in
16 * qdom.cpp -- refactor fixedXmlName() to use isNCName()
17 * - A lot of functions can be inlined.
18 */
19
20class QXmlCharRange
21{
22public:
23 ushort min;
24 ushort max;
25};
26typedef const QXmlCharRange *RangeIter;
27
28/*!
29 Performs a binary search between \a begin and \a end inclusive, to check whether \a
30 c is contained. Remember that the QXmlCharRange instances must be in numeric order.
31 */
32bool QXmlUtils::rangeContains(RangeIter begin, RangeIter end, const QChar c)
33{
34 const ushort cp(c.unicode());
35
36 // check the first two ranges "manually" as characters in that
37 // range are checked very often and we avoid the binary search below.
38
39 if (cp <= begin->max)
40 return cp >= begin->min;
41
42 ++begin;
43
44 if (begin == end)
45 return false;
46
47 if (cp <= begin->max)
48 return cp >= begin->min;
49
50 while (begin != end) {
51 qptrdiff delta = (end - begin) / 2;
52 RangeIter mid = begin + delta;
53
54 if (mid->min > cp)
55 end = mid;
56 else if (mid->max < cp)
57 begin = mid;
58 else
59 return true;
60
61 if (delta == 0)
62 break;
63 }
64
65 return false;
66}
67
68// [85] BaseChar ::= ...
69
70static const QXmlCharRange g_base_begin[] =
71{
72 {.min: 0x0041, .max: 0x005A}, {.min: 0x0061, .max: 0x007A}, {.min: 0x00C0, .max: 0x00D6}, {.min: 0x00D8, .max: 0x00F6}, {.min: 0x00F8, .max: 0x00FF},
73 {.min: 0x0100, .max: 0x0131}, {.min: 0x0134, .max: 0x013E}, {.min: 0x0141, .max: 0x0148}, {.min: 0x014A, .max: 0x017E}, {.min: 0x0180, .max: 0x01C3},
74 {.min: 0x01CD, .max: 0x01F0}, {.min: 0x01F4, .max: 0x01F5}, {.min: 0x01FA, .max: 0x0217}, {.min: 0x0250, .max: 0x02A8}, {.min: 0x02BB, .max: 0x02C1},
75 {.min: 0x0386, .max: 0x0386}, {.min: 0x0388, .max: 0x038A}, {.min: 0x038C, .max: 0x038C}, {.min: 0x038E, .max: 0x03A1}, {.min: 0x03A3, .max: 0x03CE},
76 {.min: 0x03D0, .max: 0x03D6}, {.min: 0x03DA, .max: 0x03DA}, {.min: 0x03DC, .max: 0x03DC}, {.min: 0x03DE, .max: 0x03DE}, {.min: 0x03E0, .max: 0x03E0},
77 {.min: 0x03E2, .max: 0x03F3}, {.min: 0x0401, .max: 0x040C}, {.min: 0x040E, .max: 0x044F}, {.min: 0x0451, .max: 0x045C}, {.min: 0x045E, .max: 0x0481},
78 {.min: 0x0490, .max: 0x04C4}, {.min: 0x04C7, .max: 0x04C8}, {.min: 0x04CB, .max: 0x04CC}, {.min: 0x04D0, .max: 0x04EB}, {.min: 0x04EE, .max: 0x04F5},
79 {.min: 0x04F8, .max: 0x04F9}, {.min: 0x0531, .max: 0x0556}, {.min: 0x0559, .max: 0x0559}, {.min: 0x0561, .max: 0x0586}, {.min: 0x05D0, .max: 0x05EA},
80 {.min: 0x05F0, .max: 0x05F2}, {.min: 0x0621, .max: 0x063A}, {.min: 0x0641, .max: 0x064A}, {.min: 0x0671, .max: 0x06B7}, {.min: 0x06BA, .max: 0x06BE},
81 {.min: 0x06C0, .max: 0x06CE}, {.min: 0x06D0, .max: 0x06D3}, {.min: 0x06D5, .max: 0x06D5}, {.min: 0x06E5, .max: 0x06E6}, {.min: 0x0905, .max: 0x0939},
82 {.min: 0x093D, .max: 0x093D}, {.min: 0x0958, .max: 0x0961}, {.min: 0x0985, .max: 0x098C}, {.min: 0x098F, .max: 0x0990}, {.min: 0x0993, .max: 0x09A8},
83 {.min: 0x09AA, .max: 0x09B0}, {.min: 0x09B2, .max: 0x09B2}, {.min: 0x09B6, .max: 0x09B9}, {.min: 0x09DC, .max: 0x09DD}, {.min: 0x09DF, .max: 0x09E1},
84 {.min: 0x09F0, .max: 0x09F1}, {.min: 0x0A05, .max: 0x0A0A}, {.min: 0x0A0F, .max: 0x0A10}, {.min: 0x0A13, .max: 0x0A28}, {.min: 0x0A2A, .max: 0x0A30},
85 {.min: 0x0A32, .max: 0x0A33}, {.min: 0x0A35, .max: 0x0A36}, {.min: 0x0A38, .max: 0x0A39}, {.min: 0x0A59, .max: 0x0A5C}, {.min: 0x0A5E, .max: 0x0A5E},
86 {.min: 0x0A72, .max: 0x0A74}, {.min: 0x0A85, .max: 0x0A8B}, {.min: 0x0A8D, .max: 0x0A8D}, {.min: 0x0A8F, .max: 0x0A91}, {.min: 0x0A93, .max: 0x0AA8},
87 {.min: 0x0AAA, .max: 0x0AB0}, {.min: 0x0AB2, .max: 0x0AB3}, {.min: 0x0AB5, .max: 0x0AB9}, {.min: 0x0ABD, .max: 0x0ABD}, {.min: 0x0AE0, .max: 0x0AE0},
88 {.min: 0x0B05, .max: 0x0B0C}, {.min: 0x0B0F, .max: 0x0B10}, {.min: 0x0B13, .max: 0x0B28}, {.min: 0x0B2A, .max: 0x0B30}, {.min: 0x0B32, .max: 0x0B33},
89 {.min: 0x0B36, .max: 0x0B39}, {.min: 0x0B3D, .max: 0x0B3D}, {.min: 0x0B5C, .max: 0x0B5D}, {.min: 0x0B5F, .max: 0x0B61}, {.min: 0x0B85, .max: 0x0B8A},
90 {.min: 0x0B8E, .max: 0x0B90}, {.min: 0x0B92, .max: 0x0B95}, {.min: 0x0B99, .max: 0x0B9A}, {.min: 0x0B9C, .max: 0x0B9C}, {.min: 0x0B9E, .max: 0x0B9F},
91 {.min: 0x0BA3, .max: 0x0BA4}, {.min: 0x0BA8, .max: 0x0BAA}, {.min: 0x0BAE, .max: 0x0BB5}, {.min: 0x0BB7, .max: 0x0BB9}, {.min: 0x0C05, .max: 0x0C0C},
92 {.min: 0x0C0E, .max: 0x0C10}, {.min: 0x0C12, .max: 0x0C28}, {.min: 0x0C2A, .max: 0x0C33}, {.min: 0x0C35, .max: 0x0C39}, {.min: 0x0C60, .max: 0x0C61},
93 {.min: 0x0C85, .max: 0x0C8C}, {.min: 0x0C8E, .max: 0x0C90}, {.min: 0x0C92, .max: 0x0CA8}, {.min: 0x0CAA, .max: 0x0CB3}, {.min: 0x0CB5, .max: 0x0CB9},
94 {.min: 0x0CDE, .max: 0x0CDE}, {.min: 0x0CE0, .max: 0x0CE1}, {.min: 0x0D05, .max: 0x0D0C}, {.min: 0x0D0E, .max: 0x0D10}, {.min: 0x0D12, .max: 0x0D28},
95 {.min: 0x0D2A, .max: 0x0D39}, {.min: 0x0D60, .max: 0x0D61}, {.min: 0x0E01, .max: 0x0E2E}, {.min: 0x0E30, .max: 0x0E30}, {.min: 0x0E32, .max: 0x0E33},
96 {.min: 0x0E40, .max: 0x0E45}, {.min: 0x0E81, .max: 0x0E82}, {.min: 0x0E84, .max: 0x0E84}, {.min: 0x0E87, .max: 0x0E88}, {.min: 0x0E8A, .max: 0x0E8A},
97 {.min: 0x0E8D, .max: 0x0E8D}, {.min: 0x0E94, .max: 0x0E97}, {.min: 0x0E99, .max: 0x0E9F}, {.min: 0x0EA1, .max: 0x0EA3}, {.min: 0x0EA5, .max: 0x0EA5},
98 {.min: 0x0EA7, .max: 0x0EA7}, {.min: 0x0EAA, .max: 0x0EAB}, {.min: 0x0EAD, .max: 0x0EAE}, {.min: 0x0EB0, .max: 0x0EB0}, {.min: 0x0EB2, .max: 0x0EB3},
99 {.min: 0x0EBD, .max: 0x0EBD}, {.min: 0x0EC0, .max: 0x0EC4}, {.min: 0x0F40, .max: 0x0F47}, {.min: 0x0F49, .max: 0x0F69}, {.min: 0x10A0, .max: 0x10C5},
100 {.min: 0x10D0, .max: 0x10F6}, {.min: 0x1100, .max: 0x1100}, {.min: 0x1102, .max: 0x1103}, {.min: 0x1105, .max: 0x1107}, {.min: 0x1109, .max: 0x1109},
101 {.min: 0x110B, .max: 0x110C}, {.min: 0x110E, .max: 0x1112}, {.min: 0x113C, .max: 0x113C}, {.min: 0x113E, .max: 0x113E}, {.min: 0x1140, .max: 0x1140},
102 {.min: 0x114C, .max: 0x114C}, {.min: 0x114E, .max: 0x114E}, {.min: 0x1150, .max: 0x1150}, {.min: 0x1154, .max: 0x1155}, {.min: 0x1159, .max: 0x1159},
103 {.min: 0x115F, .max: 0x1161}, {.min: 0x1163, .max: 0x1163}, {.min: 0x1165, .max: 0x1165}, {.min: 0x1167, .max: 0x1167}, {.min: 0x1169, .max: 0x1169},
104 {.min: 0x116D, .max: 0x116E}, {.min: 0x1172, .max: 0x1173}, {.min: 0x1175, .max: 0x1175}, {.min: 0x119E, .max: 0x119E}, {.min: 0x11A8, .max: 0x11A8},
105 {.min: 0x11AB, .max: 0x11AB}, {.min: 0x11AE, .max: 0x11AF}, {.min: 0x11B7, .max: 0x11B8}, {.min: 0x11BA, .max: 0x11BA}, {.min: 0x11BC, .max: 0x11C2},
106 {.min: 0x11EB, .max: 0x11EB}, {.min: 0x11F0, .max: 0x11F0}, {.min: 0x11F9, .max: 0x11F9}, {.min: 0x1E00, .max: 0x1E9B}, {.min: 0x1EA0, .max: 0x1EF9},
107 {.min: 0x1F00, .max: 0x1F15}, {.min: 0x1F18, .max: 0x1F1D}, {.min: 0x1F20, .max: 0x1F45}, {.min: 0x1F48, .max: 0x1F4D}, {.min: 0x1F50, .max: 0x1F57},
108 {.min: 0x1F59, .max: 0x1F59}, {.min: 0x1F5B, .max: 0x1F5B}, {.min: 0x1F5D, .max: 0x1F5D}, {.min: 0x1F5F, .max: 0x1F7D}, {.min: 0x1F80, .max: 0x1FB4},
109 {.min: 0x1FB6, .max: 0x1FBC}, {.min: 0x1FBE, .max: 0x1FBE}, {.min: 0x1FC2, .max: 0x1FC4}, {.min: 0x1FC6, .max: 0x1FCC}, {.min: 0x1FD0, .max: 0x1FD3},
110 {.min: 0x1FD6, .max: 0x1FDB}, {.min: 0x1FE0, .max: 0x1FEC}, {.min: 0x1FF2, .max: 0x1FF4}, {.min: 0x1FF6, .max: 0x1FFC}, {.min: 0x2126, .max: 0x2126},
111 {.min: 0x212A, .max: 0x212B}, {.min: 0x212E, .max: 0x212E}, {.min: 0x2180, .max: 0x2182}, {.min: 0x3041, .max: 0x3094}, {.min: 0x30A1, .max: 0x30FA},
112 {.min: 0x3105, .max: 0x312C}, {.min: 0xAC00, .max: 0xD7A3}
113};
114static const RangeIter g_base_end = g_base_begin + sizeof(g_base_begin) / sizeof(QXmlCharRange);
115
116static const QXmlCharRange g_ideographic_begin[] =
117{
118 {.min: 0x3007, .max: 0x3007}, {.min: 0x3021, .max: 0x3029}, {.min: 0x4E00, .max: 0x9FA5}
119};
120static const RangeIter g_ideographic_end = g_ideographic_begin + sizeof(g_ideographic_begin) / sizeof(QXmlCharRange);
121
122bool QXmlUtils::isIdeographic(const QChar c)
123{
124 return rangeContains(begin: g_ideographic_begin, end: g_ideographic_end, c);
125}
126
127static const QXmlCharRange g_combining_begin[] =
128{
129 {.min: 0x0300, .max: 0x0345}, {.min: 0x0360, .max: 0x0361}, {.min: 0x0483, .max: 0x0486}, {.min: 0x0591, .max: 0x05A1}, {.min: 0x05A3, .max: 0x05B9},
130 {.min: 0x05BB, .max: 0x05BD}, {.min: 0x05BF, .max: 0x05BF}, {.min: 0x05C1, .max: 0x05C2}, {.min: 0x05C4, .max: 0x05C4}, {.min: 0x064B, .max: 0x0652},
131 {.min: 0x0670, .max: 0x0670}, {.min: 0x06D6, .max: 0x06DC}, {.min: 0x06DD, .max: 0x06DF}, {.min: 0x06E0, .max: 0x06E4}, {.min: 0x06E7, .max: 0x06E8},
132 {.min: 0x06EA, .max: 0x06ED}, {.min: 0x0901, .max: 0x0903}, {.min: 0x093C, .max: 0x093C}, {.min: 0x093E, .max: 0x094C}, {.min: 0x094D, .max: 0x094D},
133 {.min: 0x0951, .max: 0x0954}, {.min: 0x0962, .max: 0x0963}, {.min: 0x0981, .max: 0x0983}, {.min: 0x09BC, .max: 0x09BC}, {.min: 0x09BE, .max: 0x09BE},
134 {.min: 0x09BF, .max: 0x09BF}, {.min: 0x09C0, .max: 0x09C4}, {.min: 0x09C7, .max: 0x09C8}, {.min: 0x09CB, .max: 0x09CD}, {.min: 0x09D7, .max: 0x09D7},
135 {.min: 0x09E2, .max: 0x09E3}, {.min: 0x0A02, .max: 0x0A02}, {.min: 0x0A3C, .max: 0x0A3C}, {.min: 0x0A3E, .max: 0x0A3E}, {.min: 0x0A3F, .max: 0x0A3F},
136 {.min: 0x0A40, .max: 0x0A42}, {.min: 0x0A47, .max: 0x0A48}, {.min: 0x0A4B, .max: 0x0A4D}, {.min: 0x0A70, .max: 0x0A71}, {.min: 0x0A81, .max: 0x0A83},
137 {.min: 0x0ABC, .max: 0x0ABC}, {.min: 0x0ABE, .max: 0x0AC5}, {.min: 0x0AC7, .max: 0x0AC9}, {.min: 0x0ACB, .max: 0x0ACD}, {.min: 0x0B01, .max: 0x0B03},
138 {.min: 0x0B3C, .max: 0x0B3C}, {.min: 0x0B3E, .max: 0x0B43}, {.min: 0x0B47, .max: 0x0B48}, {.min: 0x0B4B, .max: 0x0B4D}, {.min: 0x0B56, .max: 0x0B57},
139 {.min: 0x0B82, .max: 0x0B83}, {.min: 0x0BBE, .max: 0x0BC2}, {.min: 0x0BC6, .max: 0x0BC8}, {.min: 0x0BCA, .max: 0x0BCD}, {.min: 0x0BD7, .max: 0x0BD7},
140 {.min: 0x0C01, .max: 0x0C03}, {.min: 0x0C3E, .max: 0x0C44}, {.min: 0x0C46, .max: 0x0C48}, {.min: 0x0C4A, .max: 0x0C4D}, {.min: 0x0C55, .max: 0x0C56},
141 {.min: 0x0C82, .max: 0x0C83}, {.min: 0x0CBE, .max: 0x0CC4}, {.min: 0x0CC6, .max: 0x0CC8}, {.min: 0x0CCA, .max: 0x0CCD}, {.min: 0x0CD5, .max: 0x0CD6},
142 {.min: 0x0D02, .max: 0x0D03}, {.min: 0x0D3E, .max: 0x0D43}, {.min: 0x0D46, .max: 0x0D48}, {.min: 0x0D4A, .max: 0x0D4D}, {.min: 0x0D57, .max: 0x0D57},
143 {.min: 0x0E31, .max: 0x0E31}, {.min: 0x0E34, .max: 0x0E3A}, {.min: 0x0E47, .max: 0x0E4E}, {.min: 0x0EB1, .max: 0x0EB1}, {.min: 0x0EB4, .max: 0x0EB9},
144 {.min: 0x0EBB, .max: 0x0EBC}, {.min: 0x0EC8, .max: 0x0ECD}, {.min: 0x0F18, .max: 0x0F19}, {.min: 0x0F35, .max: 0x0F35}, {.min: 0x0F37, .max: 0x0F37},
145 {.min: 0x0F39, .max: 0x0F39}, {.min: 0x0F3E, .max: 0x0F3E}, {.min: 0x0F3F, .max: 0x0F3F}, {.min: 0x0F71, .max: 0x0F84}, {.min: 0x0F86, .max: 0x0F8B},
146 {.min: 0x0F90, .max: 0x0F95}, {.min: 0x0F97, .max: 0x0F97}, {.min: 0x0F99, .max: 0x0FAD}, {.min: 0x0FB1, .max: 0x0FB7}, {.min: 0x0FB9, .max: 0x0FB9},
147 {.min: 0x20D0, .max: 0x20DC}, {.min: 0x20E1, .max: 0x20E1}, {.min: 0x302A, .max: 0x302F}, {.min: 0x3099, .max: 0x3099}, {.min: 0x309A, .max: 0x309A}
148};
149static const RangeIter g_combining_end = g_combining_begin + sizeof(g_combining_begin) / sizeof(QXmlCharRange);
150
151bool QXmlUtils::isCombiningChar(const QChar c)
152{
153 return rangeContains(begin: g_combining_begin, end: g_combining_end, c);
154}
155
156// [88] Digit ::= ...
157static const QXmlCharRange g_digit_begin[] =
158{
159 {.min: 0x0030, .max: 0x0039}, {.min: 0x0660, .max: 0x0669}, {.min: 0x06F0, .max: 0x06F9}, {.min: 0x0966, .max: 0x096F}, {.min: 0x09E6, .max: 0x09EF},
160 {.min: 0x0A66, .max: 0x0A6F}, {.min: 0x0AE6, .max: 0x0AEF}, {.min: 0x0B66, .max: 0x0B6F}, {.min: 0x0BE7, .max: 0x0BEF}, {.min: 0x0C66, .max: 0x0C6F},
161 {.min: 0x0CE6, .max: 0x0CEF}, {.min: 0x0D66, .max: 0x0D6F}, {.min: 0x0E50, .max: 0x0E59}, {.min: 0x0ED0, .max: 0x0ED9}, {.min: 0x0F20, .max: 0x0F29}
162};
163static const RangeIter g_digit_end = g_digit_begin + sizeof(g_digit_begin) / sizeof(QXmlCharRange);
164
165bool QXmlUtils::isDigit(const QChar c)
166{
167 return rangeContains(begin: g_digit_begin, end: g_digit_end, c);
168}
169
170// [89] Extender ::= ...
171static const QXmlCharRange g_extender_begin[] =
172{
173 {.min: 0x00B7, .max: 0x00B7}, {.min: 0x02D0, .max: 0x02D0}, {.min: 0x02D1, .max: 0x02D1}, {.min: 0x0387, .max: 0x0387}, {.min: 0x0640, .max: 0x0640},
174 {.min: 0x0E46, .max: 0x0E46}, {.min: 0x0EC6, .max: 0x0EC6}, {.min: 0x3005, .max: 0x3005}, {.min: 0x3031, .max: 0x3035}, {.min: 0x309D, .max: 0x309E},
175 {.min: 0x30FC, .max: 0x30FE}
176};
177static const RangeIter g_extender_end = g_extender_begin + sizeof(g_extender_begin) / sizeof(QXmlCharRange);
178
179bool QXmlUtils::isExtender(const QChar c)
180{
181 return rangeContains(begin: g_extender_begin, end: g_extender_end, c);
182}
183
184bool QXmlUtils::isBaseChar(const QChar c)
185{
186 return rangeContains(begin: g_base_begin, end: g_base_end, c);
187}
188
189/*!
190 \internal
191
192 Determines whether \a encName is a valid instance of production [81]EncName in the XML 1.0
193 specification. If it is, true is returned, otherwise false.
194
195 \sa {http://www.w3.org/TR/REC-xml/#NT-EncName},
196 {Extensible Markup Language (XML) 1.0 (Fourth Edition), [81] EncName}
197 */
198bool QXmlUtils::isEncName(QStringView encName)
199{
200 // Valid encoding names are given by "[A-Za-z][A-Za-z0-9._\\-]*"
201 if (encName.isEmpty())
202 return false;
203 const auto first = encName.front().unicode();
204 if (!(isAsciiLower(c: first) || isAsciiUpper(c: first)))
205 return false;
206 for (QChar ch : encName.mid(pos: 1)) {
207 const auto cp = ch.unicode();
208 if (isAsciiLetterOrNumber(c: cp) || cp == '.' || cp == '_' || cp == '-')
209 continue;
210 return false;
211 }
212 return true;
213}
214
215/*!
216 \internal
217
218 Determines whether \a c is a valid instance of production [84]Letter in the XML 1.0
219 specification. If it is, true is returned, otherwise false.
220
221 \sa {http://www.w3.org/TR/REC-xml/#NT-Letter},
222 {Extensible Markup Language (XML) 1.0 (Fourth Edition), [84] Letter}
223 */
224bool QXmlUtils::isLetter(const QChar c)
225{
226 return isBaseChar(c) || isIdeographic(c);
227}
228
229/*!
230 \internal
231
232 Determines whether \a c is a valid instance of production [2]Char in the XML 1.0
233 specification. If it is, true is returned, otherwise false.
234
235 \sa {http://www.w3.org/TR/REC-xml/#NT-Char},
236 {Extensible Markup Language (XML) 1.0 (Fourth Edition), [2] Char}
237 */
238bool QXmlUtils::isChar(const char32_t c)
239{
240 // The valid range is defined by https://www.w3.org/TR/REC-xml/#NT-Char as following:
241 // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
242 return (c >= 0x0020 && c <= 0xD7FF)
243 || c == 0x0009
244 || c == 0x000A
245 || c == 0x000D
246 || (c >= 0xE000 && c <= 0xFFFD)
247 || (c >= 0x10000 && c <= 0x10FFFF);
248}
249
250/*!
251 \internal
252
253 Determines whether \a c is a valid instance of
254 production [4]NameChar in the XML 1.0 specification. If it
255 is, true is returned, otherwise false.
256
257 \sa {http://www.w3.org/TR/REC-xml/#NT-NameChar},
258 {Extensible Markup Language (XML) 1.0 (Fourth Edition), [4] NameChar}
259 */
260bool QXmlUtils::isNameChar(const QChar c)
261{
262 return isBaseChar(c)
263 || isDigit(c)
264 || c.unicode() == '.'
265 || c.unicode() == '-'
266 || c.unicode() == '_'
267 || c.unicode() == ':'
268 || isCombiningChar(c)
269 || isIdeographic(c)
270 || isExtender(c);
271}
272
273/*!
274 \internal
275
276 Determines whether \a c is a valid instance of
277 production [12] PubidLiteral in the XML 1.0 specification. If it
278 is, true is returned, otherwise false.
279
280 \sa {http://www.w3.org/TR/REC-xml/#NT-PubidLiteral},
281 {Extensible Markup Language (XML) 1.0 (Fourth Edition), [12] PubidLiteral}
282 */
283bool QXmlUtils::isPublicID(QStringView candidate)
284{
285 for (QChar ch : candidate) {
286 const ushort cp = ch.unicode();
287
288 if (isAsciiLetterOrNumber(c: cp))
289 continue;
290
291 switch (cp)
292 {
293 /* Fallthrough all these. */
294 case 0x20:
295 case 0x0D:
296 case 0x0A:
297 case '-':
298 case '\'':
299 case '(':
300 case ')':
301 case '+':
302 case ',':
303 case '.':
304 case '/':
305 case ':':
306 case '=':
307 case '?':
308 case ';':
309 case '!':
310 case '*':
311 case '#':
312 case '@':
313 case '$':
314 case '_':
315 case '%':
316 continue;
317 default:
318 return false;
319 }
320 }
321
322 return true;
323}
324
325/*!
326 \internal
327
328 Determines whether \a c is a valid instance of
329 production [4]NCName in the XML 1.0 Namespaces specification. If it
330 is, true is returned, otherwise false.
331
332 \sa {http://www.w3.org/TR/REC-xml-names/#NT-NCName},
333 {W3CNamespaces in XML 1.0 (Second Edition), [4] NCName}
334 */
335bool QXmlUtils::isNCName(QStringView ncName)
336{
337 if (ncName.isEmpty())
338 return false;
339
340 const QChar first(ncName.at(n: 0));
341
342 if (!QXmlUtils::isLetter(c: first) && first.unicode() != '_' && first.unicode() != ':')
343 return false;
344
345 for (QChar at : ncName) {
346 if (!QXmlUtils::isNameChar(c: at) || at == u':')
347 return false;
348 }
349
350 return true;
351}
352
353QT_END_NAMESPACE
354

source code of qtbase/src/corelib/serialization/qxmlutils.cpp