Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qbytearray.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | static const uchar latin1_uppercased[256] = { | - | ||||||||||||||||||
12 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, | - | ||||||||||||||||||
13 | 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, | - | ||||||||||||||||||
14 | 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, | - | ||||||||||||||||||
15 | 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, | - | ||||||||||||||||||
16 | 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, | - | ||||||||||||||||||
17 | 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, | - | ||||||||||||||||||
18 | 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, | - | ||||||||||||||||||
19 | 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, | - | ||||||||||||||||||
20 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, | - | ||||||||||||||||||
21 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, | - | ||||||||||||||||||
22 | 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, | - | ||||||||||||||||||
23 | 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, | - | ||||||||||||||||||
24 | 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, | - | ||||||||||||||||||
25 | 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, | - | ||||||||||||||||||
26 | 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, | - | ||||||||||||||||||
27 | 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff | - | ||||||||||||||||||
28 | }; | - | ||||||||||||||||||
29 | static const uchar latin1_lowercased[256] = { | - | ||||||||||||||||||
30 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, | - | ||||||||||||||||||
31 | 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, | - | ||||||||||||||||||
32 | 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, | - | ||||||||||||||||||
33 | 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, | - | ||||||||||||||||||
34 | 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f, | - | ||||||||||||||||||
35 | 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f, | - | ||||||||||||||||||
36 | 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f, | - | ||||||||||||||||||
37 | 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f, | - | ||||||||||||||||||
38 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, | - | ||||||||||||||||||
39 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, | - | ||||||||||||||||||
40 | 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, | - | ||||||||||||||||||
41 | 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, | - | ||||||||||||||||||
42 | 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, | - | ||||||||||||||||||
43 | 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xd7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xdf, | - | ||||||||||||||||||
44 | 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, | - | ||||||||||||||||||
45 | 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff | - | ||||||||||||||||||
46 | }; | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | int qFindByteArray( | - | ||||||||||||||||||
49 | const char *haystack0, int haystackLen, int from, | - | ||||||||||||||||||
50 | const char *needle0, int needleLen); | - | ||||||||||||||||||
int qAllocMoresize_t qCalculateBlockSize(int allocsize_t elementCount, int extrasize_t elementSize, size_t headerSize) noexcept | ||||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | unsigned count = unsigned(elementCount); | - | ||||||||||||||||||
54 | unsigned size = unsigned(elementSize); | - | ||||||||||||||||||
55 | unsigned header = unsigned(headerSize); | - | ||||||||||||||||||
56 | ((!(alloc >= 0 && extra >= 0 && extra <= MaxAllocSizeelementSize)) ? qt_assert("alloc >= 0 && extra >= 0 && extra <= MaxAllocSize""elementSize",__FILE__,127172) : qt_noop()); | - | ||||||||||||||||||
57 | ((!(alloc <= MaxAllocSize - extrasize == elementSize)) ? qt_assert_xqt_assert("qAllocMore", "Requested size is"size too== large!"elementSize",__FILE__,128173) : qt_noop()); | - | ||||||||||||||||||
58 | unsigned nalloc = qNextPowerOfTwo(alloc + extra);((!(nalloc > unsigned(alloc + extra)))header == headerSize)) ? qt_assert("nalloc > unsigned(alloc"header +== extra)"headerSize",__FILE__,132174) : qt_noop()); | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | if (__builtin_expect(!!(count != elementCount), false)
| 1-114251311 | ||||||||||||||||||
61 | return executed 1 time by 1 test: nallocstd::numeric_limits<size_t>::max();return std::numeric_limits<size_t>::max(); Executed by:
executed 1 time by 1 test: return std::numeric_limits<size_t>::max(); Executed by:
| 1 | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | unsigned bytes; | - | ||||||||||||||||||
64 | if (__builtin_expect(!!(mul_overflow(size, count, &bytes)), false)
| 2-114251309 | ||||||||||||||||||
65 | __builtin_expect(!!(add_overflow(bytes, header, &bytes)), false)
| 1-114251308 | ||||||||||||||||||
66 | return executed 3 times by 1 test: std::numeric_limits<size_t>::max();return std::numeric_limits<size_t>::max(); Executed by:
executed 3 times by 1 test: return std::numeric_limits<size_t>::max(); Executed by:
| 3 | ||||||||||||||||||
67 | if (__builtin_expect(!!(int(bytes) < 0), false)
| 13-114251295 | ||||||||||||||||||
68 | return executed 13 times by 1 test: std::numeric_limits<size_t>::max();return std::numeric_limits<size_t>::max(); Executed by:
executed 13 times by 1 test: return std::numeric_limits<size_t>::max(); Executed by:
| 13 | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | return executed 114250814 times by 781 tests: bytes;return bytes; Executed by:
executed 114250814 times by 781 tests: return bytes; Executed by:
| 114250814 | ||||||||||||||||||
71 | } | - | ||||||||||||||||||
72 | CalculateGrowingBlockSizeResult | - | ||||||||||||||||||
73 | qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t headerSize) noexcept | - | ||||||||||||||||||
74 | { | - | ||||||||||||||||||
75 | CalculateGrowingBlockSizeResult result = { | - | ||||||||||||||||||
76 | std::numeric_limits<size_t>::max(),std::numeric_limits<size_t>::max() | - | ||||||||||||||||||
77 | }; | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | unsigned bytes = unsigned(qCalculateBlockSize(elementCount, elementSize, headerSize)); | - | ||||||||||||||||||
80 | if (int(bytes) < 0
| 10-30345637 | ||||||||||||||||||
81 | return executed 10 times by 1 test: result;return result; Executed by:
executed 10 times by 1 test: return result; Executed by:
| 10 | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | unsigned morebytes = qNextPowerOfTwo(bytes); | - | ||||||||||||||||||
84 | if (__builtin_expect(!!(int(morebytes) < 0), false)
| 444-30345193 | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | - | |||||||||||||||||||
87 | bytes += (morebytes - extrabytes) / 2; | - | ||||||||||||||||||
88 | } executed 444 times by 1 test: else {end of block Executed by:
| 444 | ||||||||||||||||||
89 | bytes = morebytes; | - | ||||||||||||||||||
90 | } executed 30345193 times by 724 tests: end of block Executed by:
| 30345193 | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | result.elementCount = (bytes - unsigned(headerSize)) / unsigned(elementSize); | - | ||||||||||||||||||
93 | result.size = bytes; | - | ||||||||||||||||||
94 | return executed 30345637 times by 724 tests: resultreturn result; Executed by:
executed 30345637 times by 724 tests: return result; Executed by:
executed 30345637 times by 724 tests: ;return result; Executed by:
executed 30345637 times by 724 tests: return result; Executed by:
| 30345637 | ||||||||||||||||||
95 | } | - | ||||||||||||||||||
96 | char *qstrdup(const char *src) | - | ||||||||||||||||||
97 | { | - | ||||||||||||||||||
98 | if (!src) | - | ||||||||||||||||||
99 | return 0; | - | ||||||||||||||||||
100 | char *dst = new char[strlen(src) + 1]; | - | ||||||||||||||||||
101 | return qstrcpy(dst, src); | - | ||||||||||||||||||
102 | } | - | ||||||||||||||||||
103 | char *qstrcpy(char *dst, const char *src) | - | ||||||||||||||||||
104 | { | - | ||||||||||||||||||
105 | if (!src) | - | ||||||||||||||||||
106 | return 0; | - | ||||||||||||||||||
107 | return strcpy(dst, src); | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | } | - | ||||||||||||||||||
110 | char *qstrncpy(char *dst, const char *src, uint len) | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | if (!src || !dst) | - | ||||||||||||||||||
113 | return 0; | - | ||||||||||||||||||
114 | if (len > 0) { | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | - | |||||||||||||||||||
117 | - | |||||||||||||||||||
118 | strncpy(dst, src, len); | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | dst[len-1] = '\0'; | - | ||||||||||||||||||
121 | } | - | ||||||||||||||||||
122 | return dst; | - | ||||||||||||||||||
123 | } | - | ||||||||||||||||||
124 | int qstrcmp(const char *str1, const char *str2) | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | return (str1 && str2) ? strcmp(str1, str2) | - | ||||||||||||||||||
127 | : (str1 ? 1 : (str2 ? -1 : 0)); | - | ||||||||||||||||||
128 | } | - | ||||||||||||||||||
129 | int qstricmp(const char *str1, const char *str2) | - | ||||||||||||||||||
130 | { | - | ||||||||||||||||||
131 | const uchar *s1 = reinterpret_cast<const uchar *>(str1); | - | ||||||||||||||||||
132 | const uchar *s2 = reinterpret_cast<const uchar *>(str2); | - | ||||||||||||||||||
133 | int res; | - | ||||||||||||||||||
134 | uchar c; | - | ||||||||||||||||||
135 | if (!s1 || !s2) | - | ||||||||||||||||||
136 | return s1 ? 1 : (s2 ? -1 : 0); | - | ||||||||||||||||||
137 | for (; !(res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]); s1++, s2++) | - | ||||||||||||||||||
138 | if (!c) | - | ||||||||||||||||||
139 | break; | - | ||||||||||||||||||
140 | return res; | - | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | int qstrnicmp(const char *str1, const char *str2, uint len) | - | ||||||||||||||||||
143 | { | - | ||||||||||||||||||
144 | const uchar *s1 = reinterpret_cast<const uchar *>(str1); | - | ||||||||||||||||||
145 | const uchar *s2 = reinterpret_cast<const uchar *>(str2); | - | ||||||||||||||||||
146 | int res; | - | ||||||||||||||||||
147 | uchar c; | - | ||||||||||||||||||
148 | if (!s1 || !s2) | - | ||||||||||||||||||
149 | return s1 ? 1 : (s2 ? -1 : 0); | - | ||||||||||||||||||
150 | for (; len--; s1++, s2++) { | - | ||||||||||||||||||
151 | if ((res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2])) | - | ||||||||||||||||||
152 | return res; | - | ||||||||||||||||||
153 | if (!c) | - | ||||||||||||||||||
154 | break; | - | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | return 0; | - | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | - | |||||||||||||||||||
160 | - | |||||||||||||||||||
161 | - | |||||||||||||||||||
162 | int qstrcmp(const QByteArray &str1, const char *str2) | - | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | if (!str2) | - | ||||||||||||||||||
165 | return str1.isEmpty() ? 0 : +1; | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | const char *str1data = str1.constData(); | - | ||||||||||||||||||
168 | const char *str1end = str1data + str1.length(); | - | ||||||||||||||||||
169 | for ( ; str1data < str1end && *str2; ++str1data, ++str2) { | - | ||||||||||||||||||
170 | int diff = int(uchar(*str1data)) - uchar(*str2); | - | ||||||||||||||||||
171 | if (diff) | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | return diff; | - | ||||||||||||||||||
174 | } | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | - | |||||||||||||||||||
177 | if (*str2 != '\0') | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | return -1; | - | ||||||||||||||||||
180 | if (str1data < str1end) | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | return +1; | - | ||||||||||||||||||
183 | return 0; | - | ||||||||||||||||||
184 | } | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | - | |||||||||||||||||||
187 | - | |||||||||||||||||||
188 | - | |||||||||||||||||||
189 | int qstrcmp(const QByteArray &str1, const QByteArray &str2) | - | ||||||||||||||||||
190 | { | - | ||||||||||||||||||
191 | int l1 = str1.length(); | - | ||||||||||||||||||
192 | int l2 = str2.length(); | - | ||||||||||||||||||
193 | int ret = memcmp(str1.constData(), str2.constData(), qMin(l1, l2)); | - | ||||||||||||||||||
194 | if (ret != 0) | - | ||||||||||||||||||
195 | return ret; | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | - | |||||||||||||||||||
198 | - | |||||||||||||||||||
199 | return l1 - l2; | - | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | static const quint16 crc_tbl[16] = { | - | ||||||||||||||||||
202 | 0x0000, 0x1081, 0x2102, 0x3183, | - | ||||||||||||||||||
203 | 0x4204, 0x5285, 0x6306, 0x7387, | - | ||||||||||||||||||
204 | 0x8408, 0x9489, 0xa50a, 0xb58b, | - | ||||||||||||||||||
205 | 0xc60c, 0xd68d, 0xe70e, 0xf78f | - | ||||||||||||||||||
206 | }; | - | ||||||||||||||||||
207 | quint16 qChecksum(const char *data, uint len) | - | ||||||||||||||||||
208 | { | - | ||||||||||||||||||
209 | quint16 crc = 0xffff; | - | ||||||||||||||||||
210 | uchar c; | - | ||||||||||||||||||
211 | const uchar *p = reinterpret_cast<const uchar *>(data); | - | ||||||||||||||||||
212 | while (len--) { | - | ||||||||||||||||||
213 | c = *p++; | - | ||||||||||||||||||
214 | crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; | - | ||||||||||||||||||
215 | c >>= 4; | - | ||||||||||||||||||
216 | crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; | - | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | return ~crc & 0xffff; | - | ||||||||||||||||||
219 | } | - | ||||||||||||||||||
220 | QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel) | - | ||||||||||||||||||
221 | { | - | ||||||||||||||||||
222 | if (nbytes == 0) { | - | ||||||||||||||||||
223 | return QByteArray(4, '\0'); | - | ||||||||||||||||||
224 | } | - | ||||||||||||||||||
225 | if (!data) { | - | ||||||||||||||||||
226 | QMessageLogger(__FILE__, 504599, __PRETTY_FUNCTION__).warning("qCompress: Data is null"); | - | ||||||||||||||||||
227 | return QByteArray(); | - | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | if (compressionLevel < -1 || compressionLevel > 9) | - | ||||||||||||||||||
230 | compressionLevel = -1; | - | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | ulong len = nbytes + nbytes / 100 + 13; | - | ||||||||||||||||||
233 | QByteArray bazip; | - | ||||||||||||||||||
234 | int res; | - | ||||||||||||||||||
235 | do { | - | ||||||||||||||||||
236 | bazip.resize(len + 4); | - | ||||||||||||||||||
237 | res = ::compress2((uchar*)bazip.data()+4, &len, data, nbytes, compressionLevel); | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | switch (res) { | - | ||||||||||||||||||
240 | case 0: | - | ||||||||||||||||||
241 | bazip.resize(len + 4); | - | ||||||||||||||||||
242 | bazip[0] = (nbytes & 0xff000000) >> 24; | - | ||||||||||||||||||
243 | bazip[1] = (nbytes & 0x00ff0000) >> 16; | - | ||||||||||||||||||
244 | bazip[2] = (nbytes & 0x0000ff00) >> 8; | - | ||||||||||||||||||
245 | bazip[3] = (nbytes & 0x000000ff); | - | ||||||||||||||||||
246 | break; | - | ||||||||||||||||||
247 | case (-4): | - | ||||||||||||||||||
248 | QMessageLogger(__FILE__, 526621, __PRETTY_FUNCTION__).warning("qCompress: Z_MEM_ERROR: Not enough memory"); | - | ||||||||||||||||||
249 | bazip.resize(0); | - | ||||||||||||||||||
250 | break; | - | ||||||||||||||||||
251 | case (-5): | - | ||||||||||||||||||
252 | len *= 2; | - | ||||||||||||||||||
253 | break; | - | ||||||||||||||||||
254 | } | - | ||||||||||||||||||
255 | } while (res == (-5)); | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | return bazip; | - | ||||||||||||||||||
258 | } | - | ||||||||||||||||||
259 | QByteArray qUncompress(const uchar* data, int nbytes) | - | ||||||||||||||||||
260 | { | - | ||||||||||||||||||
261 | if (!data) { | - | ||||||||||||||||||
262 | QMessageLogger(__FILE__, 574669, __PRETTY_FUNCTION__).warning("qUncompress: Data is null"); | - | ||||||||||||||||||
263 | return QByteArray(); | - | ||||||||||||||||||
264 | } | - | ||||||||||||||||||
265 | if (nbytes <= 4) { | - | ||||||||||||||||||
266 | if (nbytes < 4 || (data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0)) | - | ||||||||||||||||||
267 | QMessageLogger(__FILE__, 579674, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted"); | - | ||||||||||||||||||
268 | return QByteArray(); | - | ||||||||||||||||||
269 | } | - | ||||||||||||||||||
270 | ulong expectedSize = uint((data[0] << 24) | (data[1] << 16) | | - | ||||||||||||||||||
271 | (data[2] << 8) | (data[3] )); | - | ||||||||||||||||||
272 | ulong len = qMax(expectedSize, 1ul); | - | ||||||||||||||||||
273 | QScopedPointer<QByteArray::Data, QScopedPointerPodDeleter> d; | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | for(;;) { | - | ||||||||||||||||||
276 | ulong alloc = len; | - | ||||||||||||||||||
277 | if (len >= (1u << 31u) - sizeof(QByteArray::Data)) { | - | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | QMessageLogger(__FILE__, 591686, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted"); | - | ||||||||||||||||||
280 | return QByteArray(); | - | ||||||||||||||||||
281 | } | - | ||||||||||||||||||
282 | QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + alloc + 1)); | - | ||||||||||||||||||
283 | if (!p) { | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | QMessageLogger(__FILE__, 597692, __PRETTY_FUNCTION__).warning("qUncompress: could not allocate enough memory to uncompress data"); | - | ||||||||||||||||||
286 | return QByteArray(); | - | ||||||||||||||||||
287 | } | - | ||||||||||||||||||
288 | d.take(); | - | ||||||||||||||||||
289 | d.reset(p); | - | ||||||||||||||||||
290 | d->offset = sizeof(QByteArrayData); | - | ||||||||||||||||||
291 | d->size = 0; | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | int res = ::uncompress((uchar*)d->data(), &len, | - | ||||||||||||||||||
294 | data+4, nbytes-4); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | switch (res) { | - | ||||||||||||||||||
297 | case 0: | - | ||||||||||||||||||
298 | if (len != alloc) { | - | ||||||||||||||||||
299 | if (len >= (1u << 31u) - sizeof(QByteArray::Data)) { | - | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | QMessageLogger(__FILE__, 613708, __PRETTY_FUNCTION__).warning("qUncompress: Input data is corrupted"); | - | ||||||||||||||||||
302 | return QByteArray(); | - | ||||||||||||||||||
303 | } | - | ||||||||||||||||||
304 | QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + len + 1)); | - | ||||||||||||||||||
305 | if (!p) { | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | QMessageLogger(__FILE__, 619714, __PRETTY_FUNCTION__).warning("qUncompress: could not allocate enough memory to uncompress data"); | - | ||||||||||||||||||
308 | return QByteArray(); | - | ||||||||||||||||||
309 | } | - | ||||||||||||||||||
310 | d.take(); | - | ||||||||||||||||||
311 | d.reset(p); | - | ||||||||||||||||||
312 | } | - | ||||||||||||||||||
313 | d->ref.initializeOwned(); | - | ||||||||||||||||||
314 | d->size = len; | - | ||||||||||||||||||
315 | d->alloc = uint(len) + 1u; | - | ||||||||||||||||||
316 | d->capacityReserved = false; | - | ||||||||||||||||||
317 | d->offset = sizeof(QByteArrayData); | - | ||||||||||||||||||
318 | d->data()[len] = 0; | - | ||||||||||||||||||
319 | - | |||||||||||||||||||
320 | { | - | ||||||||||||||||||
321 | QByteArrayDataPtr dataPtr = { d.take() }; | - | ||||||||||||||||||
322 | return QByteArray(dataPtr); | - | ||||||||||||||||||
323 | } | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | case (-4): | - | ||||||||||||||||||
326 | QMessageLogger(__FILE__, 638733, __PRETTY_FUNCTION__).warning("qUncompress: Z_MEM_ERROR: Not enough memory"); | - | ||||||||||||||||||
327 | return QByteArray(); | - | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | case (-5): | - | ||||||||||||||||||
330 | len *= 2; | - | ||||||||||||||||||
331 | continue; | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | case (-3): | - | ||||||||||||||||||
334 | QMessageLogger(__FILE__, 646741, __PRETTY_FUNCTION__).warning("qUncompress: Z_DATA_ERROR: Input data is corrupted"); | - | ||||||||||||||||||
335 | return QByteArray(); | - | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | } | - | ||||||||||||||||||
338 | } | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | - | |||||||||||||||||||
341 | static inline bool qIsUpper(char c) | - | ||||||||||||||||||
342 | { | - | ||||||||||||||||||
343 | return c >= 'A' && c <= 'Z'; | - | ||||||||||||||||||
344 | } | - | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | static inline char qToLower(char c) | - | ||||||||||||||||||
347 | { | - | ||||||||||||||||||
348 | if (c >= 'A' && c <= 'Z') | - | ||||||||||||||||||
349 | return c - 'A' + 'a'; | - | ||||||||||||||||||
350 | else | - | ||||||||||||||||||
351 | return c; | - | ||||||||||||||||||
352 | } | - | ||||||||||||||||||
353 | QByteArray &QByteArray::operator=(const QByteArray & other) noexcept | - | ||||||||||||||||||
354 | { | - | ||||||||||||||||||
355 | other.d->ref.ref(); | - | ||||||||||||||||||
356 | if (!d->ref.deref()
| 118697-795264 | ||||||||||||||||||
357 | Data::deallocate(d); executed 118697 times by 77 tests: Data::deallocate(d); Executed by:
| 118697 | ||||||||||||||||||
358 | d = other.d; | - | ||||||||||||||||||
359 | return executed 913961 times by 422 tests: *this;return *this; Executed by:
executed 913961 times by 422 tests: return *this; Executed by:
| 913961 | ||||||||||||||||||
360 | } | - | ||||||||||||||||||
361 | QByteArray &QByteArray::operator=(const char *str) | - | ||||||||||||||||||
362 | { | - | ||||||||||||||||||
363 | Data *x; | - | ||||||||||||||||||
364 | if (!str) { | - | ||||||||||||||||||
365 | x = Data::sharedNull(); | - | ||||||||||||||||||
366 | } else if (!*str) { | - | ||||||||||||||||||
367 | x = Data::allocate(0); | - | ||||||||||||||||||
368 | } else { | - | ||||||||||||||||||
369 | const int len = int(strlen(str)); | - | ||||||||||||||||||
370 | const uint fullLen = len + 1; | - | ||||||||||||||||||
371 | if (d->ref.isShared() || fullLen > d->alloc | - | ||||||||||||||||||
372 | || (len < d->size && fullLen < uint(d->alloc >> 1))) | - | ||||||||||||||||||
373 | reallocData(fullLen, d->detachFlags()); | - | ||||||||||||||||||
374 | x = d; | - | ||||||||||||||||||
375 | memcpy(x->data(), str, fullLen); | - | ||||||||||||||||||
376 | x->size = len; | - | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | x->ref.ref(); | - | ||||||||||||||||||
379 | if (!d->ref.deref()) | - | ||||||||||||||||||
380 | Data::deallocate(d); | - | ||||||||||||||||||
381 | d = x; | - | ||||||||||||||||||
382 | return *this; | - | ||||||||||||||||||
383 | } | - | ||||||||||||||||||
384 | void QByteArray::truncate(int pos) | - | ||||||||||||||||||
385 | { | - | ||||||||||||||||||
386 | if (pos < d->size) | - | ||||||||||||||||||
387 | resize(pos); | - | ||||||||||||||||||
388 | } | - | ||||||||||||||||||
389 | void QByteArray::chop(int n) | - | ||||||||||||||||||
390 | { | - | ||||||||||||||||||
391 | if (n > 0) | - | ||||||||||||||||||
392 | resize(d->size - n); | - | ||||||||||||||||||
393 | } | - | ||||||||||||||||||
394 | QByteArray::QByteArray(const char *data, int size) | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | if (!data) { | - | ||||||||||||||||||
397 | d = Data::sharedNull(); | - | ||||||||||||||||||
398 | } else { | - | ||||||||||||||||||
399 | if (size < 0) | - | ||||||||||||||||||
400 | size = int(strlen(data)); | - | ||||||||||||||||||
401 | if (!size) { | - | ||||||||||||||||||
402 | d = Data::allocate(0); | - | ||||||||||||||||||
403 | } else { | - | ||||||||||||||||||
404 | d = Data::allocate(uint(size) + 1u); | - | ||||||||||||||||||
405 | do { if (!(d)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
406 | d->size = size; | - | ||||||||||||||||||
407 | memcpy(d->data(), data, size); | - | ||||||||||||||||||
408 | d->data()[size] = '\0'; | - | ||||||||||||||||||
409 | } | - | ||||||||||||||||||
410 | } | - | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | QByteArray::QByteArray(int size, char ch) | - | ||||||||||||||||||
413 | { | - | ||||||||||||||||||
414 | if (size <= 0) { | - | ||||||||||||||||||
415 | d = Data::allocate(0); | - | ||||||||||||||||||
416 | } else { | - | ||||||||||||||||||
417 | d = Data::allocate(uint(size) + 1u); | - | ||||||||||||||||||
418 | do { if (!(d)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
419 | d->size = size; | - | ||||||||||||||||||
420 | memset(d->data(), ch, size); | - | ||||||||||||||||||
421 | d->data()[size] = '\0'; | - | ||||||||||||||||||
422 | } | - | ||||||||||||||||||
423 | } | - | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | - | |||||||||||||||||||
426 | - | |||||||||||||||||||
427 | - | |||||||||||||||||||
428 | - | |||||||||||||||||||
429 | - | |||||||||||||||||||
430 | - | |||||||||||||||||||
431 | QByteArray::QByteArray(int size, Qt::Initialization) | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | d = Data::allocate(uint(size) + 1u); | - | ||||||||||||||||||
434 | do { if (!(d)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
435 | d->size = size; | - | ||||||||||||||||||
436 | d->data()[size] = '\0'; | - | ||||||||||||||||||
437 | } | - | ||||||||||||||||||
438 | void QByteArray::resize(int size) | - | ||||||||||||||||||
439 | { | - | ||||||||||||||||||
440 | if (size < 0) | - | ||||||||||||||||||
441 | size = 0; | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | if (((d)->offset != sizeof(QByteArrayData)) && !d->ref.isShared() && size < d->size) { | - | ||||||||||||||||||
444 | d->size = size; | - | ||||||||||||||||||
445 | return; | - | ||||||||||||||||||
446 | } | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | if (size == 0 && !d->capacityReserved) { | - | ||||||||||||||||||
449 | Data *x = Data::allocate(0); | - | ||||||||||||||||||
450 | if (!d->ref.deref()) | - | ||||||||||||||||||
451 | Data::deallocate(d); | - | ||||||||||||||||||
452 | d = x; | - | ||||||||||||||||||
453 | } else if (d->size == 0 && d->ref.isStatic()) { | - | ||||||||||||||||||
454 | Data *x = Data::allocate(uint(size) + 1u); | - | ||||||||||||||||||
455 | do { if (!(x)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
456 | x->size = size; | - | ||||||||||||||||||
457 | x->data()[size] = '\0'; | - | ||||||||||||||||||
458 | d = x; | - | ||||||||||||||||||
459 | } else { | - | ||||||||||||||||||
460 | if (d->ref.isShared() || uint(size) + 1u > d->alloc | - | ||||||||||||||||||
461 | || (!d->capacityReserved && size < d->size | - | ||||||||||||||||||
462 | && uint(size) + 1u < uint(d->alloc >> 1))) | - | ||||||||||||||||||
463 | reallocData(uint(size) + 1u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
464 | if (d->alloc) { | - | ||||||||||||||||||
465 | d->size = size; | - | ||||||||||||||||||
466 | d->data()[size] = '\0'; | - | ||||||||||||||||||
467 | } | - | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | } | - | ||||||||||||||||||
470 | QByteArray &QByteArray::fill(char ch, int size) | - | ||||||||||||||||||
471 | { | - | ||||||||||||||||||
472 | resize(size < 0 ? d->size : size); | - | ||||||||||||||||||
473 | if (d->size) | - | ||||||||||||||||||
474 | memset(d->data(), ch, d->size); | - | ||||||||||||||||||
475 | return *this; | - | ||||||||||||||||||
476 | } | - | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) | - | ||||||||||||||||||
479 | { | - | ||||||||||||||||||
480 | if (d->ref.isShared()
| 5-1652549 | ||||||||||||||||||
481 | Data *x = Data::allocate(alloc, options); | - | ||||||||||||||||||
482 | do { if (!(x)
never executed: } while (0);qBadAlloc(); | 0-1652554 | ||||||||||||||||||
483 | x->size = qMin(int(alloc) - 1, d->size); | - | ||||||||||||||||||
484 | ::memcpy(x->data(), d->data(), x->size); | - | ||||||||||||||||||
485 | x->data()[x->size] = '\0'; | - | ||||||||||||||||||
486 | if (!d->ref.deref()
| 5-1652549 | ||||||||||||||||||
487 | Data::deallocate(d); executed 5 times by 3 tests: Data::deallocate(d); Executed by:
| 5 | ||||||||||||||||||
488 | d = x; | - | ||||||||||||||||||
489 | } executed 1652554 times by 421 tests: else {end of block Executed by:
| 1652554 | ||||||||||||||||||
490 | size_t blockSize; | - | ||||||||||||||||||
491 | if (options & Data::Grow
| 41870-1485537 | ||||||||||||||||||
492 | ifauto r = qCalculateGrowingBlockSize(alloc> MaxByteArraySize) | - | ||||||||||||||||||
qBadAlloc();, sizeof(QChar), sizeof(Data)); | ||||||||||||||||||||
493 | blockSize = r.size; | - | ||||||||||||||||||
494 | alloc = qAllocMoreuint(r.elementCount); | - | ||||||||||||||||||
495 | } executed 1485537 times by 438 tests: else {end of block Executed by:
| 1485537 | ||||||||||||||||||
496 | blockSize = qCalculateBlockSize(alloc, sizeof(QChar), sizeof(Data)); | - | ||||||||||||||||||
497 | } executed 41870 times by 56 tests: end of block Executed by:
| 41870 | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + allocblockSize)); | - | ||||||||||||||||||
500 | do { if (!(x)
never executed: } while (0);qBadAlloc(); | 0-1527407 | ||||||||||||||||||
501 | x->alloc = alloc; | - | ||||||||||||||||||
502 | x->capacityReserved = (
| 11097-1516310 | ||||||||||||||||||
503 | d = x; | - | ||||||||||||||||||
504 | } executed 1527407 times by 438 tests: end of block Executed by:
| 1527407 | ||||||||||||||||||
505 | } | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | void QByteArray::expand(int i) | - | ||||||||||||||||||
508 | { | - | ||||||||||||||||||
509 | resize(qMax(i + 1, d->size)); | - | ||||||||||||||||||
510 | } | - | ||||||||||||||||||
511 | QByteArray QByteArray::nulTerminated() const | - | ||||||||||||||||||
512 | { | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | if (!((d)->offset != sizeof(QByteArrayData))) | - | ||||||||||||||||||
515 | return *this; | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | QByteArray copy(*this); | - | ||||||||||||||||||
518 | copy.detach(); | - | ||||||||||||||||||
519 | return copy; | - | ||||||||||||||||||
520 | } | - | ||||||||||||||||||
521 | QByteArray &QByteArray::prepend(const QByteArray &ba) | - | ||||||||||||||||||
522 | { | - | ||||||||||||||||||
523 | if (d->size == 0 && d->ref.isStatic() && !((ba.d)->offset != sizeof(QByteArrayData))) { | - | ||||||||||||||||||
524 | *this = ba; | - | ||||||||||||||||||
525 | } else if (ba.d->size != 0) { | - | ||||||||||||||||||
526 | QByteArray tmp = *this; | - | ||||||||||||||||||
527 | *this = ba; | - | ||||||||||||||||||
528 | append(tmp); | - | ||||||||||||||||||
529 | } | - | ||||||||||||||||||
530 | return *this; | - | ||||||||||||||||||
531 | } | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | - | |||||||||||||||||||
534 | - | |||||||||||||||||||
535 | - | |||||||||||||||||||
536 | - | |||||||||||||||||||
537 | - | |||||||||||||||||||
538 | - | |||||||||||||||||||
539 | QByteArray &QByteArray::prepend(const char *str) | - | ||||||||||||||||||
540 | { | - | ||||||||||||||||||
541 | return prepend(str, qstrlen(str)); | - | ||||||||||||||||||
542 | } | - | ||||||||||||||||||
543 | QByteArray &QByteArray::prepend(const char *str, int len) | - | ||||||||||||||||||
544 | { | - | ||||||||||||||||||
545 | if (str) { | - | ||||||||||||||||||
546 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) | - | ||||||||||||||||||
547 | reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
548 | memmove(d->data()+len, d->data(), d->size); | - | ||||||||||||||||||
549 | memcpy(d->data(), str, len); | - | ||||||||||||||||||
550 | d->size += len; | - | ||||||||||||||||||
551 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
552 | } | - | ||||||||||||||||||
553 | return *this; | - | ||||||||||||||||||
554 | } | - | ||||||||||||||||||
555 | QByteArray &QByteArray::prepend(char ch) | - | ||||||||||||||||||
556 | { | - | ||||||||||||||||||
557 | if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) | - | ||||||||||||||||||
558 | reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
559 | memmove(d->data()+1, d->data(), d->size); | - | ||||||||||||||||||
560 | d->data()[0] = ch; | - | ||||||||||||||||||
561 | ++d->size; | - | ||||||||||||||||||
562 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
563 | return *this; | - | ||||||||||||||||||
564 | } | - | ||||||||||||||||||
565 | QByteArray &QByteArray::append(const QByteArray &ba) | - | ||||||||||||||||||
566 | { | - | ||||||||||||||||||
567 | if (d->size == 0 && d->ref.isStatic() && !((ba.d)->offset != sizeof(QByteArrayData))) { | - | ||||||||||||||||||
568 | *this = ba; | - | ||||||||||||||||||
569 | } else if (ba.d->size != 0) { | - | ||||||||||||||||||
570 | if (d->ref.isShared() || uint(d->size + ba.d->size) + 1u > d->alloc) | - | ||||||||||||||||||
571 | reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
572 | memcpy(d->data() + d->size, ba.d->data(), ba.d->size); | - | ||||||||||||||||||
573 | d->size += ba.d->size; | - | ||||||||||||||||||
574 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
575 | } | - | ||||||||||||||||||
576 | return *this; | - | ||||||||||||||||||
577 | } | - | ||||||||||||||||||
578 | QByteArray& QByteArray::append(const char *str) | - | ||||||||||||||||||
579 | { | - | ||||||||||||||||||
580 | if (str) { | - | ||||||||||||||||||
581 | const int len = int(strlen(str)); | - | ||||||||||||||||||
582 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) | - | ||||||||||||||||||
583 | reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
584 | memcpy(d->data() + d->size, str, len + 1); | - | ||||||||||||||||||
585 | d->size += len; | - | ||||||||||||||||||
586 | } | - | ||||||||||||||||||
587 | return *this; | - | ||||||||||||||||||
588 | } | - | ||||||||||||||||||
589 | QByteArray &QByteArray::append(const char *str, int len) | - | ||||||||||||||||||
590 | { | - | ||||||||||||||||||
591 | if (len < 0) | - | ||||||||||||||||||
592 | len = qstrlen(str); | - | ||||||||||||||||||
593 | if (str && len) { | - | ||||||||||||||||||
594 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) | - | ||||||||||||||||||
595 | reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
596 | memcpy(d->data() + d->size, str, len); | - | ||||||||||||||||||
597 | d->size += len; | - | ||||||||||||||||||
598 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
599 | } | - | ||||||||||||||||||
600 | return *this; | - | ||||||||||||||||||
601 | } | - | ||||||||||||||||||
602 | QByteArray& QByteArray::append(char ch) | - | ||||||||||||||||||
603 | { | - | ||||||||||||||||||
604 | if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) | - | ||||||||||||||||||
605 | reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); | - | ||||||||||||||||||
606 | d->data()[d->size++] = ch; | - | ||||||||||||||||||
607 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
608 | return *this; | - | ||||||||||||||||||
609 | } | - | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | - | |||||||||||||||||||
612 | - | |||||||||||||||||||
613 | - | |||||||||||||||||||
614 | - | |||||||||||||||||||
615 | - | |||||||||||||||||||
616 | static inline QByteArray &qbytearray_insert(QByteArray *ba, | - | ||||||||||||||||||
617 | int pos, const char *arr, int len) | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | ((!(pos >= 0)) ? qt_assert("pos >= 0",__FILE__,18521970) : qt_noop()); | - | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | if (pos < 0 || len <= 0 || arr == 0) | - | ||||||||||||||||||
622 | return *ba; | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | int oldsize = ba->size(); | - | ||||||||||||||||||
625 | ba->resize(qMax(pos, oldsize) + len); | - | ||||||||||||||||||
626 | char *dst = ba->data(); | - | ||||||||||||||||||
627 | if (pos > oldsize) | - | ||||||||||||||||||
628 | ::memset(dst + oldsize, 0x20, pos - oldsize); | - | ||||||||||||||||||
629 | else | - | ||||||||||||||||||
630 | ::memmove(dst + pos + len, dst + pos, oldsize - pos); | - | ||||||||||||||||||
631 | memcpy(dst + pos, arr, len); | - | ||||||||||||||||||
632 | return *ba; | - | ||||||||||||||||||
633 | } | - | ||||||||||||||||||
634 | QByteArray &QByteArray::insert(int i, const QByteArray &ba) | - | ||||||||||||||||||
635 | { | - | ||||||||||||||||||
636 | QByteArray copy(ba); | - | ||||||||||||||||||
637 | return qbytearray_insert(this, i, copy.d->data(), copy.d->size); | - | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | QByteArray &QByteArray::insert(int i, const char *str) | - | ||||||||||||||||||
640 | { | - | ||||||||||||||||||
641 | return qbytearray_insert(this, i, str, qstrlen(str)); | - | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | QByteArray &QByteArray::insert(int i, const char *str, int len) | - | ||||||||||||||||||
644 | { | - | ||||||||||||||||||
645 | return qbytearray_insert(this, i, str, len); | - | ||||||||||||||||||
646 | } | - | ||||||||||||||||||
647 | QByteArray &QByteArray::insert(int i, char ch) | - | ||||||||||||||||||
648 | { | - | ||||||||||||||||||
649 | return qbytearray_insert(this, i, &ch, 1); | - | ||||||||||||||||||
650 | } | - | ||||||||||||||||||
651 | QByteArray &QByteArray::insert(int i, int count, char ch) | - | ||||||||||||||||||
652 | { | - | ||||||||||||||||||
653 | if (i < 0
| 1-46 | ||||||||||||||||||
654 | return executed 19 times by 1 test: *this;return *this; Executed by:
executed 19 times by 1 test: return *this; Executed by:
| 19 | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | int oldsize = size(); | - | ||||||||||||||||||
657 | resize(qMax(i, oldsize) + count); | - | ||||||||||||||||||
658 | char *dst = d->data(); | - | ||||||||||||||||||
659 | if (i > oldsize
| 1-27 | ||||||||||||||||||
660 | :: executed 1 time by 1 test: memset(dst + oldsize, 0x20, i - oldsize);::memset(dst + oldsize, 0x20, i - oldsize); Executed by:
executed 1 time by 1 test: ::memset(dst + oldsize, 0x20, i - oldsize); Executed by:
| 1 | ||||||||||||||||||
661 | else if (i < oldsize
| 9-18 | ||||||||||||||||||
662 | :: executed 18 times by 1 test: memmove(dst + i + count, dst + i, oldsize - i);::memmove(dst + i + count, dst + i, oldsize - i); Executed by:
executed 18 times by 1 test: ::memmove(dst + i + count, dst + i, oldsize - i); Executed by:
| 18 | ||||||||||||||||||
663 | ::memset(dst + i, ch, count); | - | ||||||||||||||||||
664 | return executed 28 times by 1 test: return *this; Executed by:
executed 28 times by 1 test: *this;return *this; Executed by:
executed 28 times by 1 test: return *this; Executed by:
| 28 | ||||||||||||||||||
665 | } | - | ||||||||||||||||||
666 | QByteArray &QByteArray::remove(int pos, int len) | - | ||||||||||||||||||
667 | { | - | ||||||||||||||||||
668 | if (len <= 0 || uint(pos) >= uint(d->size)) | - | ||||||||||||||||||
669 | return *this; | - | ||||||||||||||||||
670 | detach(); | - | ||||||||||||||||||
671 | if (len >= d->size - pos) { | - | ||||||||||||||||||
672 | resize(pos); | - | ||||||||||||||||||
673 | } else { | - | ||||||||||||||||||
674 | memmove(d->data() + pos, d->data() + pos + len, d->size - pos - len); | - | ||||||||||||||||||
675 | resize(d->size - len); | - | ||||||||||||||||||
676 | } | - | ||||||||||||||||||
677 | return *this; | - | ||||||||||||||||||
678 | } | - | ||||||||||||||||||
679 | QByteArray &QByteArray::replace(int pos, int len, const QByteArray &after) | - | ||||||||||||||||||
680 | { | - | ||||||||||||||||||
681 | if (len == after.d->size && (pos + len <= d->size)) { | - | ||||||||||||||||||
682 | detach(); | - | ||||||||||||||||||
683 | memmove(d->data() + pos, after.d->data(), len*sizeof(char)); | - | ||||||||||||||||||
684 | return *this; | - | ||||||||||||||||||
685 | } else { | - | ||||||||||||||||||
686 | QByteArray copy(after); | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | remove(pos, len); | - | ||||||||||||||||||
689 | return insert(pos, copy); | - | ||||||||||||||||||
690 | } | - | ||||||||||||||||||
691 | } | - | ||||||||||||||||||
692 | QByteArray &QByteArray::replace(int pos, int len, const char *after) | - | ||||||||||||||||||
693 | { | - | ||||||||||||||||||
694 | return replace(pos,len,after,qstrlen(after)); | - | ||||||||||||||||||
695 | } | - | ||||||||||||||||||
696 | QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen) | - | ||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | if (len == alen && (pos + len <= d->size)) { | - | ||||||||||||||||||
699 | detach(); | - | ||||||||||||||||||
700 | memcpy(d->data() + pos, after, len*sizeof(char)); | - | ||||||||||||||||||
701 | return *this; | - | ||||||||||||||||||
702 | } else { | - | ||||||||||||||||||
703 | remove(pos, len); | - | ||||||||||||||||||
704 | return qbytearray_insert(this, pos, after, alen); | - | ||||||||||||||||||
705 | } | - | ||||||||||||||||||
706 | } | - | ||||||||||||||||||
707 | QByteArray &QByteArray::replace(const QByteArray &before, const QByteArray &after) | - | ||||||||||||||||||
708 | { | - | ||||||||||||||||||
709 | if (isNull() || before.d == after.d) | - | ||||||||||||||||||
710 | return *this; | - | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | QByteArray aft = after; | - | ||||||||||||||||||
713 | if (after.d == d) | - | ||||||||||||||||||
714 | aft.detach(); | - | ||||||||||||||||||
715 | - | |||||||||||||||||||
716 | return replace(before.constData(), before.size(), aft.constData(), aft.size()); | - | ||||||||||||||||||
717 | } | - | ||||||||||||||||||
718 | QByteArray &QByteArray::replace(const char *c, const QByteArray &after) | - | ||||||||||||||||||
719 | { | - | ||||||||||||||||||
720 | QByteArray aft = after; | - | ||||||||||||||||||
721 | if (after.d == d) | - | ||||||||||||||||||
722 | aft.detach(); | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | return replace(c, qstrlen(c), aft.constData(), aft.size()); | - | ||||||||||||||||||
725 | } | - | ||||||||||||||||||
726 | QByteArray &QByteArray::replace(const char *before, int bsize, const char *after, int asize) | - | ||||||||||||||||||
727 | { | - | ||||||||||||||||||
728 | if (isNull() || (before == after && bsize == asize)) | - | ||||||||||||||||||
729 | return *this; | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | - | |||||||||||||||||||
732 | const char *a = after; | - | ||||||||||||||||||
733 | const char *b = before; | - | ||||||||||||||||||
734 | if (after >= d->data() && after < d->data() + d->size) { | - | ||||||||||||||||||
735 | char *copy = (char *)malloc(asize); | - | ||||||||||||||||||
736 | do { if (!(copy)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
737 | memcpy(copy, after, asize); | - | ||||||||||||||||||
738 | a = copy; | - | ||||||||||||||||||
739 | } | - | ||||||||||||||||||
740 | if (before >= d->data() && before < d->data() + d->size) { | - | ||||||||||||||||||
741 | char *copy = (char *)malloc(bsize); | - | ||||||||||||||||||
742 | do { if (!(copy)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
743 | memcpy(copy, before, bsize); | - | ||||||||||||||||||
744 | b = copy; | - | ||||||||||||||||||
745 | } | - | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | QByteArrayMatcher matcher(before, bsize); | - | ||||||||||||||||||
748 | int index = 0; | - | ||||||||||||||||||
749 | int len = d->size; | - | ||||||||||||||||||
750 | char *d = data(); | - | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | if (bsize == asize) { | - | ||||||||||||||||||
753 | if (bsize) { | - | ||||||||||||||||||
754 | while ((index = matcher.indexIn(*this, index)) != -1) { | - | ||||||||||||||||||
755 | memcpy(d + index, after, asize); | - | ||||||||||||||||||
756 | index += bsize; | - | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | } | - | ||||||||||||||||||
759 | } else if (asize < bsize) { | - | ||||||||||||||||||
760 | uint to = 0; | - | ||||||||||||||||||
761 | uint movestart = 0; | - | ||||||||||||||||||
762 | uint num = 0; | - | ||||||||||||||||||
763 | while ((index = matcher.indexIn(*this, index)) != -1) { | - | ||||||||||||||||||
764 | if (num) { | - | ||||||||||||||||||
765 | int msize = index - movestart; | - | ||||||||||||||||||
766 | if (msize > 0) { | - | ||||||||||||||||||
767 | memmove(d + to, d + movestart, msize); | - | ||||||||||||||||||
768 | to += msize; | - | ||||||||||||||||||
769 | } | - | ||||||||||||||||||
770 | } else { | - | ||||||||||||||||||
771 | to = index; | - | ||||||||||||||||||
772 | } | - | ||||||||||||||||||
773 | if (asize) { | - | ||||||||||||||||||
774 | memcpy(d + to, after, asize); | - | ||||||||||||||||||
775 | to += asize; | - | ||||||||||||||||||
776 | } | - | ||||||||||||||||||
777 | index += bsize; | - | ||||||||||||||||||
778 | movestart = index; | - | ||||||||||||||||||
779 | num++; | - | ||||||||||||||||||
780 | } | - | ||||||||||||||||||
781 | if (num) { | - | ||||||||||||||||||
782 | int msize = len - movestart; | - | ||||||||||||||||||
783 | if (msize > 0) | - | ||||||||||||||||||
784 | memmove(d + to, d + movestart, msize); | - | ||||||||||||||||||
785 | resize(len - num*(bsize-asize)); | - | ||||||||||||||||||
786 | } | - | ||||||||||||||||||
787 | } else { | - | ||||||||||||||||||
788 | - | |||||||||||||||||||
789 | - | |||||||||||||||||||
790 | while (index != -1) { | - | ||||||||||||||||||
791 | uint indices[4096]; | - | ||||||||||||||||||
792 | uint pos = 0; | - | ||||||||||||||||||
793 | while(pos < 4095) { | - | ||||||||||||||||||
794 | index = matcher.indexIn(*this, index); | - | ||||||||||||||||||
795 | if (index == -1) | - | ||||||||||||||||||
796 | break; | - | ||||||||||||||||||
797 | indices[pos++] = index; | - | ||||||||||||||||||
798 | index += bsize; | - | ||||||||||||||||||
799 | - | |||||||||||||||||||
800 | if (!bsize) | - | ||||||||||||||||||
801 | index++; | - | ||||||||||||||||||
802 | } | - | ||||||||||||||||||
803 | if (!pos) | - | ||||||||||||||||||
804 | break; | - | ||||||||||||||||||
805 | - | |||||||||||||||||||
806 | - | |||||||||||||||||||
807 | int adjust = pos*(asize-bsize); | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | if (index != -1) | - | ||||||||||||||||||
810 | index += adjust; | - | ||||||||||||||||||
811 | int newlen = len + adjust; | - | ||||||||||||||||||
812 | int moveend = len; | - | ||||||||||||||||||
813 | if (newlen > len) { | - | ||||||||||||||||||
814 | resize(newlen); | - | ||||||||||||||||||
815 | len = newlen; | - | ||||||||||||||||||
816 | } | - | ||||||||||||||||||
817 | d = this->d->data(); | - | ||||||||||||||||||
818 | - | |||||||||||||||||||
819 | while(pos) { | - | ||||||||||||||||||
820 | pos--; | - | ||||||||||||||||||
821 | int movestart = indices[pos] + bsize; | - | ||||||||||||||||||
822 | int insertstart = indices[pos] + pos*(asize-bsize); | - | ||||||||||||||||||
823 | int moveto = insertstart + asize; | - | ||||||||||||||||||
824 | memmove(d + moveto, d + movestart, (moveend - movestart)); | - | ||||||||||||||||||
825 | if (asize) | - | ||||||||||||||||||
826 | memcpy(d + insertstart, after, asize); | - | ||||||||||||||||||
827 | moveend = movestart - bsize; | - | ||||||||||||||||||
828 | } | - | ||||||||||||||||||
829 | } | - | ||||||||||||||||||
830 | } | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | if (a != after) | - | ||||||||||||||||||
833 | ::free(const_cast<char *>(a)); | - | ||||||||||||||||||
834 | if (b != before) | - | ||||||||||||||||||
835 | ::free(const_cast<char *>(b)); | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | - | |||||||||||||||||||
838 | return *this; | - | ||||||||||||||||||
839 | } | - | ||||||||||||||||||
840 | QByteArray &QByteArray::replace(char before, const QByteArray &after) | - | ||||||||||||||||||
841 | { | - | ||||||||||||||||||
842 | char b[2] = { before, '\0' }; | - | ||||||||||||||||||
843 | QByteArray cb = fromRawData(b, 1); | - | ||||||||||||||||||
844 | return replace(cb, after); | - | ||||||||||||||||||
845 | } | - | ||||||||||||||||||
846 | QByteArray &QByteArray::replace(char before, char after) | - | ||||||||||||||||||
847 | { | - | ||||||||||||||||||
848 | if (d->size) { | - | ||||||||||||||||||
849 | char *i = data(); | - | ||||||||||||||||||
850 | char *e = i + d->size; | - | ||||||||||||||||||
851 | for (; i != e; ++i) | - | ||||||||||||||||||
852 | if (*i == before) | - | ||||||||||||||||||
853 | * i = after; | - | ||||||||||||||||||
854 | } | - | ||||||||||||||||||
855 | return *this; | - | ||||||||||||||||||
856 | } | - | ||||||||||||||||||
857 | QList<QByteArray> QByteArray::split(char sep) const | - | ||||||||||||||||||
858 | { | - | ||||||||||||||||||
859 | QList<QByteArray> list; | - | ||||||||||||||||||
860 | int start = 0; | - | ||||||||||||||||||
861 | int end; | - | ||||||||||||||||||
862 | while ((end = indexOf(sep, start)) != -1) { | - | ||||||||||||||||||
863 | list.append(mid(start, end - start)); | - | ||||||||||||||||||
864 | start = end + 1; | - | ||||||||||||||||||
865 | } | - | ||||||||||||||||||
866 | list.append(mid(start)); | - | ||||||||||||||||||
867 | return list; | - | ||||||||||||||||||
868 | } | - | ||||||||||||||||||
869 | QByteArray QByteArray::repeated(int times) const | - | ||||||||||||||||||
870 | { | - | ||||||||||||||||||
871 | if (d->size == 0) | - | ||||||||||||||||||
872 | return *this; | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | if (times <= 1) { | - | ||||||||||||||||||
875 | if (times == 1) | - | ||||||||||||||||||
876 | return *this; | - | ||||||||||||||||||
877 | return QByteArray(); | - | ||||||||||||||||||
878 | } | - | ||||||||||||||||||
879 | - | |||||||||||||||||||
880 | const int resultSize = times * d->size; | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | QByteArray result; | - | ||||||||||||||||||
883 | result.reserve(resultSize); | - | ||||||||||||||||||
884 | if (result.d->alloc != uint(resultSize) + 1u) | - | ||||||||||||||||||
885 | return QByteArray(); | - | ||||||||||||||||||
886 | - | |||||||||||||||||||
887 | memcpy(result.d->data(), d->data(), d->size); | - | ||||||||||||||||||
888 | - | |||||||||||||||||||
889 | int sizeSoFar = d->size; | - | ||||||||||||||||||
890 | char *end = result.d->data() + sizeSoFar; | - | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | const int halfResultSize = resultSize >> 1; | - | ||||||||||||||||||
893 | while (sizeSoFar <= halfResultSize) { | - | ||||||||||||||||||
894 | memcpy(end, result.d->data(), sizeSoFar); | - | ||||||||||||||||||
895 | end += sizeSoFar; | - | ||||||||||||||||||
896 | sizeSoFar <<= 1; | - | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | memcpy(end, result.d->data(), resultSize - sizeSoFar); | - | ||||||||||||||||||
899 | result.d->data()[resultSize] = '\0'; | - | ||||||||||||||||||
900 | result.d->size = resultSize; | - | ||||||||||||||||||
901 | return result; | - | ||||||||||||||||||
902 | } | - | ||||||||||||||||||
903 | int QByteArray::indexOf(const QByteArray &ba, int from) const | - | ||||||||||||||||||
904 | { | - | ||||||||||||||||||
905 | const int ol = ba.d->size; | - | ||||||||||||||||||
906 | if (ol == 0) | - | ||||||||||||||||||
907 | return from; | - | ||||||||||||||||||
908 | if (ol == 1) | - | ||||||||||||||||||
909 | return indexOf(*ba.d->data(), from); | - | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | const int l = d->size; | - | ||||||||||||||||||
912 | if (from > d->size || ol + from > l) | - | ||||||||||||||||||
913 | return -1; | - | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | return qFindByteArray(d->data(), d->size, from, ba.d->data(), ol); | - | ||||||||||||||||||
916 | } | - | ||||||||||||||||||
917 | int QByteArray::indexOf(const char *c, int from) const | - | ||||||||||||||||||
918 | { | - | ||||||||||||||||||
919 | const int ol = qstrlen(c); | - | ||||||||||||||||||
920 | if (ol == 1) | - | ||||||||||||||||||
921 | return indexOf(*c, from); | - | ||||||||||||||||||
922 | - | |||||||||||||||||||
923 | const int l = d->size; | - | ||||||||||||||||||
924 | if (from > d->size || ol + from > l) | - | ||||||||||||||||||
925 | return -1; | - | ||||||||||||||||||
926 | if (ol == 0) | - | ||||||||||||||||||
927 | return from; | - | ||||||||||||||||||
928 | - | |||||||||||||||||||
929 | return qFindByteArray(d->data(), d->size, from, c, ol); | - | ||||||||||||||||||
930 | } | - | ||||||||||||||||||
931 | int QByteArray::indexOf(char ch, int from) const | - | ||||||||||||||||||
932 | { | - | ||||||||||||||||||
933 | if (from < 0) | - | ||||||||||||||||||
934 | from = qMax(from + d->size, 0); | - | ||||||||||||||||||
935 | if (from < d->size) { | - | ||||||||||||||||||
936 | const char *n = d->data() + from - 1; | - | ||||||||||||||||||
937 | const char *e = d->data() + d->size; | - | ||||||||||||||||||
938 | while (++n != e) | - | ||||||||||||||||||
939 | if (*n == ch) | - | ||||||||||||||||||
940 | return n - d->data(); | - | ||||||||||||||||||
941 | } | - | ||||||||||||||||||
942 | return -1; | - | ||||||||||||||||||
943 | } | - | ||||||||||||||||||
944 | - | |||||||||||||||||||
945 | - | |||||||||||||||||||
946 | static int lastIndexOfHelper(const char *haystack, int l, const char *needle, int ol, int from) | - | ||||||||||||||||||
947 | { | - | ||||||||||||||||||
948 | int delta = l - ol; | - | ||||||||||||||||||
949 | if (from < 0) | - | ||||||||||||||||||
950 | from = delta; | - | ||||||||||||||||||
951 | if (from < 0 || from > l) | - | ||||||||||||||||||
952 | return -1; | - | ||||||||||||||||||
953 | if (from > delta) | - | ||||||||||||||||||
954 | from = delta; | - | ||||||||||||||||||
955 | - | |||||||||||||||||||
956 | const char *end = haystack; | - | ||||||||||||||||||
957 | haystack += from; | - | ||||||||||||||||||
958 | const uint ol_minus_1 = ol - 1; | - | ||||||||||||||||||
959 | const char *n = needle + ol_minus_1; | - | ||||||||||||||||||
960 | const char *h = haystack + ol_minus_1; | - | ||||||||||||||||||
961 | uint hashNeedle = 0, hashHaystack = 0; | - | ||||||||||||||||||
962 | int idx; | - | ||||||||||||||||||
963 | for (idx = 0; idx < ol; ++idx) { | - | ||||||||||||||||||
964 | hashNeedle = ((hashNeedle<<1) + *(n-idx)); | - | ||||||||||||||||||
965 | hashHaystack = ((hashHaystack<<1) + *(h-idx)); | - | ||||||||||||||||||
966 | } | - | ||||||||||||||||||
967 | hashHaystack -= *haystack; | - | ||||||||||||||||||
968 | while (haystack >= end) { | - | ||||||||||||||||||
969 | hashHaystack += *haystack; | - | ||||||||||||||||||
970 | if (hashHaystack == hashNeedle && memcmp(needle, haystack, ol) == 0) | - | ||||||||||||||||||
971 | return haystack - end; | - | ||||||||||||||||||
972 | --haystack; | - | ||||||||||||||||||
973 | if (ol_minus_1 < sizeof(uint) * 8) hashHaystack -= (*(haystack + ol)) << ol_minus_1; hashHaystack <<= 1; | - | ||||||||||||||||||
974 | } | - | ||||||||||||||||||
975 | return -1; | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | } | - | ||||||||||||||||||
978 | int QByteArray::lastIndexOf(const QByteArray &ba, int from) const | - | ||||||||||||||||||
979 | { | - | ||||||||||||||||||
980 | const int ol = ba.d->size; | - | ||||||||||||||||||
981 | if (ol == 1) | - | ||||||||||||||||||
982 | return lastIndexOf(*ba.d->data(), from); | - | ||||||||||||||||||
983 | - | |||||||||||||||||||
984 | return lastIndexOfHelper(d->data(), d->size, ba.d->data(), ol, from); | - | ||||||||||||||||||
985 | } | - | ||||||||||||||||||
986 | int QByteArray::lastIndexOf(const char *str, int from) const | - | ||||||||||||||||||
987 | { | - | ||||||||||||||||||
988 | const int ol = qstrlen(str); | - | ||||||||||||||||||
989 | if (ol == 1) | - | ||||||||||||||||||
990 | return lastIndexOf(*str, from); | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | return lastIndexOfHelper(d->data(), d->size, str, ol, from); | - | ||||||||||||||||||
993 | } | - | ||||||||||||||||||
994 | int QByteArray::lastIndexOf(char ch, int from) const | - | ||||||||||||||||||
995 | { | - | ||||||||||||||||||
996 | if (from < 0) | - | ||||||||||||||||||
997 | from += d->size; | - | ||||||||||||||||||
998 | else if (from > d->size) | - | ||||||||||||||||||
999 | from = d->size-1; | - | ||||||||||||||||||
1000 | if (from >= 0) { | - | ||||||||||||||||||
1001 | const char *b = d->data(); | - | ||||||||||||||||||
1002 | const char *n = d->data() + from + 1; | - | ||||||||||||||||||
1003 | while (n-- != b) | - | ||||||||||||||||||
1004 | if (*n == ch) | - | ||||||||||||||||||
1005 | return n - b; | - | ||||||||||||||||||
1006 | } | - | ||||||||||||||||||
1007 | return -1; | - | ||||||||||||||||||
1008 | } | - | ||||||||||||||||||
1009 | int QByteArray::count(const QByteArray &ba) const | - | ||||||||||||||||||
1010 | { | - | ||||||||||||||||||
1011 | int num = 0; | - | ||||||||||||||||||
1012 | int i = -1; | - | ||||||||||||||||||
1013 | if (d->size > 500 && ba.d->size > 5) { | - | ||||||||||||||||||
1014 | QByteArrayMatcher matcher(ba); | - | ||||||||||||||||||
1015 | while ((i = matcher.indexIn(*this, i + 1)) != -1) | - | ||||||||||||||||||
1016 | ++num; | - | ||||||||||||||||||
1017 | } else { | - | ||||||||||||||||||
1018 | while ((i = indexOf(ba, i + 1)) != -1) | - | ||||||||||||||||||
1019 | ++num; | - | ||||||||||||||||||
1020 | } | - | ||||||||||||||||||
1021 | return num; | - | ||||||||||||||||||
1022 | } | - | ||||||||||||||||||
1023 | int QByteArray::count(const char *str) const | - | ||||||||||||||||||
1024 | { | - | ||||||||||||||||||
1025 | return count(fromRawData(str, qstrlen(str))); | - | ||||||||||||||||||
1026 | } | - | ||||||||||||||||||
1027 | int QByteArray::count(char ch) const | - | ||||||||||||||||||
1028 | { | - | ||||||||||||||||||
1029 | int num = 0; | - | ||||||||||||||||||
1030 | const char *i = d->data() + d->size; | - | ||||||||||||||||||
1031 | const char *b = d->data(); | - | ||||||||||||||||||
1032 | while (i != b) | - | ||||||||||||||||||
1033 | if (*--i == ch) | - | ||||||||||||||||||
1034 | ++num; | - | ||||||||||||||||||
1035 | return num; | - | ||||||||||||||||||
1036 | } | - | ||||||||||||||||||
1037 | bool QByteArray::startsWith(const QByteArray &ba) const | - | ||||||||||||||||||
1038 | { | - | ||||||||||||||||||
1039 | if (d == ba.d || ba.d->size == 0) | - | ||||||||||||||||||
1040 | return true; | - | ||||||||||||||||||
1041 | if (d->size < ba.d->size) | - | ||||||||||||||||||
1042 | return false; | - | ||||||||||||||||||
1043 | return memcmp(d->data(), ba.d->data(), ba.d->size) == 0; | - | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | - | |||||||||||||||||||
1047 | - | |||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | bool QByteArray::startsWith(const char *str) const | - | ||||||||||||||||||
1052 | { | - | ||||||||||||||||||
1053 | if (!str || !*str) | - | ||||||||||||||||||
1054 | return true; | - | ||||||||||||||||||
1055 | const int len = int(strlen(str)); | - | ||||||||||||||||||
1056 | if (d->size < len) | - | ||||||||||||||||||
1057 | return false; | - | ||||||||||||||||||
1058 | return qstrncmp(d->data(), str, len) == 0; | - | ||||||||||||||||||
1059 | } | - | ||||||||||||||||||
1060 | - | |||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | - | |||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | bool QByteArray::startsWith(char ch) const | - | ||||||||||||||||||
1067 | { | - | ||||||||||||||||||
1068 | if (d->size == 0) | - | ||||||||||||||||||
1069 | return false; | - | ||||||||||||||||||
1070 | return d->data()[0] == ch; | - | ||||||||||||||||||
1071 | } | - | ||||||||||||||||||
1072 | bool QByteArray::endsWith(const QByteArray &ba) const | - | ||||||||||||||||||
1073 | { | - | ||||||||||||||||||
1074 | if (d == ba.d || ba.d->size == 0) | - | ||||||||||||||||||
1075 | return true; | - | ||||||||||||||||||
1076 | if (d->size < ba.d->size) | - | ||||||||||||||||||
1077 | return false; | - | ||||||||||||||||||
1078 | return memcmp(d->data() + d->size - ba.d->size, ba.d->data(), ba.d->size) == 0; | - | ||||||||||||||||||
1079 | } | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | - | |||||||||||||||||||
1085 | - | |||||||||||||||||||
1086 | bool QByteArray::endsWith(const char *str) const | - | ||||||||||||||||||
1087 | { | - | ||||||||||||||||||
1088 | if (!str || !*str) | - | ||||||||||||||||||
1089 | return true; | - | ||||||||||||||||||
1090 | const int len = int(strlen(str)); | - | ||||||||||||||||||
1091 | if (d->size < len) | - | ||||||||||||||||||
1092 | return false; | - | ||||||||||||||||||
1093 | return qstrncmp(d->data() + d->size - len, str, len) == 0; | - | ||||||||||||||||||
1094 | } | - | ||||||||||||||||||
1095 | - | |||||||||||||||||||
1096 | - | |||||||||||||||||||
1097 | - | |||||||||||||||||||
1098 | - | |||||||||||||||||||
1099 | - | |||||||||||||||||||
1100 | - | |||||||||||||||||||
1101 | bool QByteArray::endsWith(char ch) const | - | ||||||||||||||||||
1102 | { | - | ||||||||||||||||||
1103 | if (d->size == 0) | - | ||||||||||||||||||
1104 | return false; | - | ||||||||||||||||||
1105 | return d->data()[d->size - 1] == ch; | - | ||||||||||||||||||
1106 | } | - | ||||||||||||||||||
1107 | QByteArray QByteArray::left(int len) const | - | ||||||||||||||||||
1108 | { | - | ||||||||||||||||||
1109 | if (len >= d->size) | - | ||||||||||||||||||
1110 | return *this; | - | ||||||||||||||||||
1111 | if (len < 0) | - | ||||||||||||||||||
1112 | len = 0; | - | ||||||||||||||||||
1113 | return QByteArray(d->data(), len); | - | ||||||||||||||||||
1114 | } | - | ||||||||||||||||||
1115 | QByteArray QByteArray::right(int len) const | - | ||||||||||||||||||
1116 | { | - | ||||||||||||||||||
1117 | if (len >= d->size) | - | ||||||||||||||||||
1118 | return *this; | - | ||||||||||||||||||
1119 | if (len < 0) | - | ||||||||||||||||||
1120 | len = 0; | - | ||||||||||||||||||
1121 | return QByteArray(d->data() + d->size - len, len); | - | ||||||||||||||||||
1122 | } | - | ||||||||||||||||||
1123 | QByteArray QByteArray::mid(int pos, int len) const | - | ||||||||||||||||||
1124 | { | - | ||||||||||||||||||
1125 | using namespace QtPrivate; | - | ||||||||||||||||||
1126 | switch (QContainerImplHelper::mid(size(), &pos, &len)) { | - | ||||||||||||||||||
1127 | case QContainerImplHelper::Null: | - | ||||||||||||||||||
1128 | return QByteArray(); | - | ||||||||||||||||||
1129 | case QContainerImplHelper::Empty: | - | ||||||||||||||||||
1130 | { | - | ||||||||||||||||||
1131 | QByteArrayDataPtr empty = { Data::allocate(0) }; | - | ||||||||||||||||||
1132 | return QByteArray(empty); | - | ||||||||||||||||||
1133 | } | - | ||||||||||||||||||
1134 | case QContainerImplHelper::Full: | - | ||||||||||||||||||
1135 | return *this; | - | ||||||||||||||||||
1136 | case QContainerImplHelper::Subset: | - | ||||||||||||||||||
1137 | return QByteArray(d->data() + pos, len); | - | ||||||||||||||||||
1138 | } | - | ||||||||||||||||||
1139 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,28052950) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||||||||
1140 | return QByteArray(); | - | ||||||||||||||||||
1141 | } | - | ||||||||||||||||||
1142 | template <typename T> | - | ||||||||||||||||||
1143 | __attribute__((noinline)) | - | ||||||||||||||||||
1144 | static QByteArray toCase_template(T &input, const uchar * table) | - | ||||||||||||||||||
1145 | { | - | ||||||||||||||||||
1146 | - | |||||||||||||||||||
1147 | const char *orig_begin = input.constBegin(); | - | ||||||||||||||||||
1148 | const char *firstBad = orig_begin; | - | ||||||||||||||||||
1149 | const char *e = input.constEnd(); | - | ||||||||||||||||||
1150 | for ( ; firstBad != e ; ++firstBad) { | - | ||||||||||||||||||
1151 | uchar ch = uchar(*firstBad); | - | ||||||||||||||||||
1152 | uchar converted = table[ch]; | - | ||||||||||||||||||
1153 | if (ch != converted) | - | ||||||||||||||||||
1154 | break; | - | ||||||||||||||||||
1155 | } | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | if (firstBad == e) | - | ||||||||||||||||||
1158 | return std::move(input); | - | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | - | |||||||||||||||||||
1161 | QByteArray s = std::move(input); | - | ||||||||||||||||||
1162 | char *b = s.begin(); | - | ||||||||||||||||||
1163 | char *p = b + (firstBad - orig_begin); | - | ||||||||||||||||||
1164 | e = b + s.size(); | - | ||||||||||||||||||
1165 | for ( ; p != e; ++p) { | - | ||||||||||||||||||
1166 | *p = char(uchar(table[uchar(*p)])); | - | ||||||||||||||||||
1167 | } | - | ||||||||||||||||||
1168 | return s; | - | ||||||||||||||||||
1169 | } | - | ||||||||||||||||||
1170 | - | |||||||||||||||||||
1171 | QByteArray QByteArray::toLower_helper(const QByteArray &a) | - | ||||||||||||||||||
1172 | { | - | ||||||||||||||||||
1173 | return toCase_template(a, latin1_lowercased); | - | ||||||||||||||||||
1174 | } | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | QByteArray QByteArray::toLower_helper(QByteArray &a) | - | ||||||||||||||||||
1177 | { | - | ||||||||||||||||||
1178 | return toCase_template(a, latin1_lowercased); | - | ||||||||||||||||||
1179 | } | - | ||||||||||||||||||
1180 | QByteArray QByteArray::toUpper_helper(const QByteArray &a) | - | ||||||||||||||||||
1181 | { | - | ||||||||||||||||||
1182 | return toCase_template(a, latin1_uppercased); | - | ||||||||||||||||||
1183 | } | - | ||||||||||||||||||
1184 | - | |||||||||||||||||||
1185 | QByteArray QByteArray::toUpper_helper(QByteArray &a) | - | ||||||||||||||||||
1186 | { | - | ||||||||||||||||||
1187 | return toCase_template(a, latin1_uppercased); | - | ||||||||||||||||||
1188 | } | - | ||||||||||||||||||
1189 | void QByteArray::clear() | - | ||||||||||||||||||
1190 | { | - | ||||||||||||||||||
1191 | if (!d->ref.deref()) | - | ||||||||||||||||||
1192 | Data::deallocate(d); | - | ||||||||||||||||||
1193 | d = Data::sharedNull(); | - | ||||||||||||||||||
1194 | } | - | ||||||||||||||||||
1195 | QDataStream &operator<<(QDataStream &out, const QByteArray &ba) | - | ||||||||||||||||||
1196 | { | - | ||||||||||||||||||
1197 | if (ba.isNull() && out.version() >= 6) { | - | ||||||||||||||||||
1198 | out << (quint32)0xffffffff; | - | ||||||||||||||||||
1199 | return out; | - | ||||||||||||||||||
1200 | } | - | ||||||||||||||||||
1201 | return out.writeBytes(ba.constData(), ba.size()); | - | ||||||||||||||||||
1202 | } | - | ||||||||||||||||||
1203 | QDataStream &operator>>(QDataStream &in, QByteArray &ba) | - | ||||||||||||||||||
1204 | { | - | ||||||||||||||||||
1205 | ba.clear(); | - | ||||||||||||||||||
1206 | quint32 len; | - | ||||||||||||||||||
1207 | in >> len; | - | ||||||||||||||||||
1208 | if (len == 0xffffffff) | - | ||||||||||||||||||
1209 | return in; | - | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | const quint32 Step = 1024 * 1024; | - | ||||||||||||||||||
1212 | quint32 allocated = 0; | - | ||||||||||||||||||
1213 | - | |||||||||||||||||||
1214 | do { | - | ||||||||||||||||||
1215 | int blockSize = qMin(Step, len - allocated); | - | ||||||||||||||||||
1216 | ba.resize(allocated + blockSize); | - | ||||||||||||||||||
1217 | if (in.readRawData(ba.data() + allocated, blockSize) != blockSize) { | - | ||||||||||||||||||
1218 | ba.clear(); | - | ||||||||||||||||||
1219 | in.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||||||||
1220 | return in; | - | ||||||||||||||||||
1221 | } | - | ||||||||||||||||||
1222 | allocated += blockSize; | - | ||||||||||||||||||
1223 | } while (allocated < len); | - | ||||||||||||||||||
1224 | - | |||||||||||||||||||
1225 | return in; | - | ||||||||||||||||||
1226 | } | - | ||||||||||||||||||
1227 | QByteArray QByteArray::simplified_helper(const QByteArray &a) | - | ||||||||||||||||||
1228 | { | - | ||||||||||||||||||
1229 | return QStringAlgorithms<const QByteArray>::simplified_helper(a); | - | ||||||||||||||||||
1230 | } | - | ||||||||||||||||||
1231 | - | |||||||||||||||||||
1232 | QByteArray QByteArray::simplified_helper(QByteArray &a) | - | ||||||||||||||||||
1233 | { | - | ||||||||||||||||||
1234 | return QStringAlgorithms<QByteArray>::simplified_helper(a); | - | ||||||||||||||||||
1235 | } | - | ||||||||||||||||||
1236 | QByteArray QByteArray::trimmed_helper(const QByteArray &a) | - | ||||||||||||||||||
1237 | { | - | ||||||||||||||||||
1238 | return QStringAlgorithms<const QByteArray>::trimmed_helper(a); | - | ||||||||||||||||||
1239 | } | - | ||||||||||||||||||
1240 | - | |||||||||||||||||||
1241 | QByteArray QByteArray::trimmed_helper(QByteArray &a) | - | ||||||||||||||||||
1242 | { | - | ||||||||||||||||||
1243 | return QStringAlgorithms<QByteArray>::trimmed_helper(a); | - | ||||||||||||||||||
1244 | } | - | ||||||||||||||||||
1245 | QByteArray QByteArray::leftJustified(int width, char fill, bool truncate) const | - | ||||||||||||||||||
1246 | { | - | ||||||||||||||||||
1247 | QByteArray result; | - | ||||||||||||||||||
1248 | int len = d->size; | - | ||||||||||||||||||
1249 | int padlen = width - len; | - | ||||||||||||||||||
1250 | if (padlen > 0) { | - | ||||||||||||||||||
1251 | result.resize(len+padlen); | - | ||||||||||||||||||
1252 | if (len) | - | ||||||||||||||||||
1253 | memcpy(result.d->data(), d->data(), len); | - | ||||||||||||||||||
1254 | memset(result.d->data()+len, fill, padlen); | - | ||||||||||||||||||
1255 | } else { | - | ||||||||||||||||||
1256 | if (truncate) | - | ||||||||||||||||||
1257 | result = left(width); | - | ||||||||||||||||||
1258 | else | - | ||||||||||||||||||
1259 | result = *this; | - | ||||||||||||||||||
1260 | } | - | ||||||||||||||||||
1261 | return result; | - | ||||||||||||||||||
1262 | } | - | ||||||||||||||||||
1263 | QByteArray QByteArray::rightJustified(int width, char fill, bool truncate) const | - | ||||||||||||||||||
1264 | { | - | ||||||||||||||||||
1265 | QByteArray result; | - | ||||||||||||||||||
1266 | int len = d->size; | - | ||||||||||||||||||
1267 | int padlen = width - len; | - | ||||||||||||||||||
1268 | if (padlen > 0) { | - | ||||||||||||||||||
1269 | result.resize(len+padlen); | - | ||||||||||||||||||
1270 | if (len) | - | ||||||||||||||||||
1271 | memcpy(result.d->data()+padlen, data(), len); | - | ||||||||||||||||||
1272 | memset(result.d->data(), fill, padlen); | - | ||||||||||||||||||
1273 | } else { | - | ||||||||||||||||||
1274 | if (truncate) | - | ||||||||||||||||||
1275 | result = left(width); | - | ||||||||||||||||||
1276 | else | - | ||||||||||||||||||
1277 | result = *this; | - | ||||||||||||||||||
1278 | } | - | ||||||||||||||||||
1279 | return result; | - | ||||||||||||||||||
1280 | } | - | ||||||||||||||||||
1281 | - | |||||||||||||||||||
1282 | bool QByteArray::isNull() const { return d == QArrayData::sharedNull(); } | - | ||||||||||||||||||
1283 | - | |||||||||||||||||||
1284 | static qlonglong toIntegral_helper(const char *data, bool *ok, int base, qlonglong) | - | ||||||||||||||||||
1285 | { | - | ||||||||||||||||||
1286 | return QLocaleData::bytearrayToLongLong(data, base, ok); | - | ||||||||||||||||||
1287 | } | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | static qulonglong toIntegral_helper(const char *data, bool *ok, int base, qulonglong) | - | ||||||||||||||||||
1290 | { | - | ||||||||||||||||||
1291 | return QLocaleData::bytearrayToUnsLongLong(data, base, ok); | - | ||||||||||||||||||
1292 | } | - | ||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | template <typename T> static inline | - | ||||||||||||||||||
1295 | T toIntegral_helper(const char *data, bool *ok, int base) | - | ||||||||||||||||||
1296 | { | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | const bool isUnsigned = T(0) < T(-1); | - | ||||||||||||||||||
1299 | typedef typename QtPrivate::QConditional<isUnsigned, qulonglong, qlonglong>::Type Int64; | - | ||||||||||||||||||
1300 | Int64 val = toIntegral_helper(data, ok, base, Int64()); | - | ||||||||||||||||||
1301 | if (T(val) != val) { | - | ||||||||||||||||||
1302 | if (ok) | - | ||||||||||||||||||
1303 | *ok = false; | - | ||||||||||||||||||
1304 | val = 0; | - | ||||||||||||||||||
1305 | } | - | ||||||||||||||||||
1306 | return T(val); | - | ||||||||||||||||||
1307 | } | - | ||||||||||||||||||
1308 | qlonglong QByteArray::toLongLong(bool *ok, int base) const | - | ||||||||||||||||||
1309 | { | - | ||||||||||||||||||
1310 | return toIntegral_helper<qlonglong>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1311 | } | - | ||||||||||||||||||
1312 | qulonglong QByteArray::toULongLong(bool *ok, int base) const | - | ||||||||||||||||||
1313 | { | - | ||||||||||||||||||
1314 | return toIntegral_helper<qulonglong>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1315 | } | - | ||||||||||||||||||
1316 | int QByteArray::toInt(bool *ok, int base) const | - | ||||||||||||||||||
1317 | { | - | ||||||||||||||||||
1318 | return toIntegral_helper<int>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1319 | } | - | ||||||||||||||||||
1320 | uint QByteArray::toUInt(bool *ok, int base) const | - | ||||||||||||||||||
1321 | { | - | ||||||||||||||||||
1322 | return toIntegral_helper<uint>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1323 | } | - | ||||||||||||||||||
1324 | long QByteArray::toLong(bool *ok, int base) const | - | ||||||||||||||||||
1325 | { | - | ||||||||||||||||||
1326 | return toIntegral_helper<long>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1327 | } | - | ||||||||||||||||||
1328 | ulong QByteArray::toULong(bool *ok, int base) const | - | ||||||||||||||||||
1329 | { | - | ||||||||||||||||||
1330 | return toIntegral_helper<ulong>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1331 | } | - | ||||||||||||||||||
1332 | short QByteArray::toShort(bool *ok, int base) const | - | ||||||||||||||||||
1333 | { | - | ||||||||||||||||||
1334 | return toIntegral_helper<short>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1335 | } | - | ||||||||||||||||||
1336 | ushort QByteArray::toUShort(bool *ok, int base) const | - | ||||||||||||||||||
1337 | { | - | ||||||||||||||||||
1338 | return toIntegral_helper<ushort>(nulTerminated().constData(), ok, base); | - | ||||||||||||||||||
1339 | } | - | ||||||||||||||||||
1340 | double QByteArray::toDouble(bool *ok) const | - | ||||||||||||||||||
1341 | { | - | ||||||||||||||||||
1342 | return QLocaleData::bytearrayToDouble(QByteArray nulled = nulTerminated().(); | - | ||||||||||||||||||
1343 | bool nonNullOk = false; | - | ||||||||||||||||||
1344 | int processed = 0; | - | ||||||||||||||||||
1345 | double d = asciiToDouble(nulled.constData(), oknulled.length(), nonNullOk, processed); | - | ||||||||||||||||||
1346 | if (ok
| 0-184 | ||||||||||||||||||
1347 | * executed 184 times by 3 tests: ok = nonNullOk;*ok = nonNullOk; Executed by:
executed 184 times by 3 tests: *ok = nonNullOk; Executed by:
| 184 | ||||||||||||||||||
1348 | return executed 184 times by 3 tests: d;return d; Executed by:
executed 184 times by 3 tests: return d; Executed by:
| 184 | ||||||||||||||||||
1349 | } | - | ||||||||||||||||||
1350 | float QByteArray::toFloat(bool *ok) const | - | ||||||||||||||||||
1351 | { | - | ||||||||||||||||||
1352 | return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); | - | ||||||||||||||||||
1353 | } | - | ||||||||||||||||||
1354 | QByteArray QByteArray::toBase64() const | - | ||||||||||||||||||
1355 | { | - | ||||||||||||||||||
1356 | return toBase64(Base64Encoding); | - | ||||||||||||||||||
1357 | } | - | ||||||||||||||||||
1358 | QByteArray QByteArray::toBase64(Base64Options options) const | - | ||||||||||||||||||
1359 | { | - | ||||||||||||||||||
1360 | const char alphabet_base64[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef" | - | ||||||||||||||||||
1361 | "ghijklmn" "opqrstuv" "wxyz0123" "456789+/"; | - | ||||||||||||||||||
1362 | const char alphabet_base64url[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef" | - | ||||||||||||||||||
1363 | "ghijklmn" "opqrstuv" "wxyz0123" "456789-_"; | - | ||||||||||||||||||
1364 | const char *const alphabet = options & Base64UrlEncoding ? alphabet_base64url : alphabet_base64; | - | ||||||||||||||||||
1365 | const char padchar = '='; | - | ||||||||||||||||||
1366 | int padlen = 0; | - | ||||||||||||||||||
1367 | - | |||||||||||||||||||
1368 | QByteArray tmp((d->size + 2) / 3 * 4, Qt::Uninitialized); | - | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | int i = 0; | - | ||||||||||||||||||
1371 | char *out = tmp.data(); | - | ||||||||||||||||||
1372 | while (i < d->size) { | - | ||||||||||||||||||
1373 | - | |||||||||||||||||||
1374 | int chunk = 0; | - | ||||||||||||||||||
1375 | chunk |= int(uchar(d->data()[i++])) << 16; | - | ||||||||||||||||||
1376 | if (i == d->size) { | - | ||||||||||||||||||
1377 | padlen = 2; | - | ||||||||||||||||||
1378 | } else { | - | ||||||||||||||||||
1379 | chunk |= int(uchar(d->data()[i++])) << 8; | - | ||||||||||||||||||
1380 | if (i == d->size) | - | ||||||||||||||||||
1381 | padlen = 1; | - | ||||||||||||||||||
1382 | else | - | ||||||||||||||||||
1383 | chunk |= int(uchar(data()[i++])); | - | ||||||||||||||||||
1384 | } | - | ||||||||||||||||||
1385 | - | |||||||||||||||||||
1386 | int j = (chunk & 0x00fc0000) >> 18; | - | ||||||||||||||||||
1387 | int k = (chunk & 0x0003f000) >> 12; | - | ||||||||||||||||||
1388 | int l = (chunk & 0x00000fc0) >> 6; | - | ||||||||||||||||||
1389 | int m = (chunk & 0x0000003f); | - | ||||||||||||||||||
1390 | *out++ = alphabet[j]; | - | ||||||||||||||||||
1391 | *out++ = alphabet[k]; | - | ||||||||||||||||||
1392 | - | |||||||||||||||||||
1393 | if (padlen > 1) { | - | ||||||||||||||||||
1394 | if ((options & OmitTrailingEquals) == 0) | - | ||||||||||||||||||
1395 | *out++ = padchar; | - | ||||||||||||||||||
1396 | } else { | - | ||||||||||||||||||
1397 | *out++ = alphabet[l]; | - | ||||||||||||||||||
1398 | } | - | ||||||||||||||||||
1399 | if (padlen > 0) { | - | ||||||||||||||||||
1400 | if ((options & OmitTrailingEquals) == 0) | - | ||||||||||||||||||
1401 | *out++ = padchar; | - | ||||||||||||||||||
1402 | } else { | - | ||||||||||||||||||
1403 | *out++ = alphabet[m]; | - | ||||||||||||||||||
1404 | } | - | ||||||||||||||||||
1405 | } | - | ||||||||||||||||||
1406 | ((!((options & OmitTrailingEquals) || (out == tmp.size() + tmp.data()))) ? qt_assert("(options & OmitTrailingEquals) || (out == tmp.size() + tmp.data())",__FILE__,37483899) : qt_noop()); | - | ||||||||||||||||||
1407 | if (options & OmitTrailingEquals) | - | ||||||||||||||||||
1408 | tmp.truncate(out - tmp.data()); | - | ||||||||||||||||||
1409 | return tmp; | - | ||||||||||||||||||
1410 | } | - | ||||||||||||||||||
1411 | static char *qulltoa2(char *p, qulonglong n, int base) | - | ||||||||||||||||||
1412 | { | - | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | - | |||||||||||||||||||
1416 | - | |||||||||||||||||||
1417 | - | |||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | const char b = 'a' - 10; | - | ||||||||||||||||||
1420 | do { | - | ||||||||||||||||||
1421 | const int c = n % base; | - | ||||||||||||||||||
1422 | n /= base; | - | ||||||||||||||||||
1423 | *--p = c + (c < 10 ? '0' : b); | - | ||||||||||||||||||
1424 | } while (n); | - | ||||||||||||||||||
1425 | - | |||||||||||||||||||
1426 | return p; | - | ||||||||||||||||||
1427 | } | - | ||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | - | |||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | - | |||||||||||||||||||
1434 | QByteArray &QByteArray::setNum(qlonglong n, int base) | - | ||||||||||||||||||
1435 | { | - | ||||||||||||||||||
1436 | const int buffsize = 66; | - | ||||||||||||||||||
1437 | char buff[buffsize]; | - | ||||||||||||||||||
1438 | char *p; | - | ||||||||||||||||||
1439 | - | |||||||||||||||||||
1440 | if (n < 0 && base == 10) { | - | ||||||||||||||||||
1441 | p = qulltoa2(buff + buffsize, qulonglong(-(1 + n)) + 1, base); | - | ||||||||||||||||||
1442 | *--p = '-'; | - | ||||||||||||||||||
1443 | } else { | - | ||||||||||||||||||
1444 | p = qulltoa2(buff + buffsize, qulonglong(n), base); | - | ||||||||||||||||||
1445 | } | - | ||||||||||||||||||
1446 | - | |||||||||||||||||||
1447 | clear(); | - | ||||||||||||||||||
1448 | append(p, buffsize - (p - buff)); | - | ||||||||||||||||||
1449 | return *this; | - | ||||||||||||||||||
1450 | } | - | ||||||||||||||||||
1451 | - | |||||||||||||||||||
1452 | - | |||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | - | |||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | - | |||||||||||||||||||
1457 | - | |||||||||||||||||||
1458 | QByteArray &QByteArray::setNum(qulonglong n, int base) | - | ||||||||||||||||||
1459 | { | - | ||||||||||||||||||
1460 | const int buffsize = 66; | - | ||||||||||||||||||
1461 | char buff[buffsize]; | - | ||||||||||||||||||
1462 | char *p = qulltoa2(buff + buffsize, n, base); | - | ||||||||||||||||||
1463 | - | |||||||||||||||||||
1464 | clear(); | - | ||||||||||||||||||
1465 | append(p, buffsize - (p - buff)); | - | ||||||||||||||||||
1466 | return *this; | - | ||||||||||||||||||
1467 | } | - | ||||||||||||||||||
1468 | QByteArray &QByteArray::setNum(double n, char f, int prec) | - | ||||||||||||||||||
1469 | { | - | ||||||||||||||||||
1470 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
1471 | uint flags = 0QLocaleData::ZeroPadExponent; | - | ||||||||||||||||||
1472 | - | |||||||||||||||||||
1473 | if (qIsUpper(f)
| 0-265 | ||||||||||||||||||
1474 | flags |= QLocaleData::CapitalEorX; never executed: flags |= QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
1475 | f = qToLower(f); | - | ||||||||||||||||||
1476 | - | |||||||||||||||||||
1477 | switch (f) { | - | ||||||||||||||||||
1478 | case never executed: 'f':case 'f': never executed: case 'f': | 0 | ||||||||||||||||||
1479 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
1480 | break; never executed: break; | 0 | ||||||||||||||||||
1481 | case never executed: 'e':case 'e': never executed: case 'e': | 0 | ||||||||||||||||||
1482 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||
1483 | break; never executed: break; | 0 | ||||||||||||||||||
1484 | case executed 265 times by 4 tests: 'g':case 'g': Executed by:
executed 265 times by 4 tests: case 'g': Executed by:
| 265 | ||||||||||||||||||
1485 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||
1486 | break; executed 265 times by 4 tests: break; Executed by:
| 265 | ||||||||||||||||||
1487 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
1488 | - | |||||||||||||||||||
1489 | - | |||||||||||||||||||
1490 | - | |||||||||||||||||||
1491 | break; never executed: break; | 0 | ||||||||||||||||||
1492 | } | - | ||||||||||||||||||
1493 | - | |||||||||||||||||||
1494 | *this = QLocaleData::c()->doubleToString(n, prec, form, -1, flags).toLatin1(); | - | ||||||||||||||||||
1495 | return executed 265 times by 4 tests: *this;return *this; Executed by:
executed 265 times by 4 tests: return *this; Executed by:
| 265 | ||||||||||||||||||
1496 | } | - | ||||||||||||||||||
1497 | QByteArray QByteArray::number(int n, int base) | - | ||||||||||||||||||
1498 | { | - | ||||||||||||||||||
1499 | QByteArray s; | - | ||||||||||||||||||
1500 | s.setNum(n, base); | - | ||||||||||||||||||
1501 | return s; | - | ||||||||||||||||||
1502 | } | - | ||||||||||||||||||
1503 | - | |||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | - | |||||||||||||||||||
1506 | - | |||||||||||||||||||
1507 | - | |||||||||||||||||||
1508 | - | |||||||||||||||||||
1509 | QByteArray QByteArray::number(uint n, int base) | - | ||||||||||||||||||
1510 | { | - | ||||||||||||||||||
1511 | QByteArray s; | - | ||||||||||||||||||
1512 | s.setNum(n, base); | - | ||||||||||||||||||
1513 | return s; | - | ||||||||||||||||||
1514 | } | - | ||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | - | |||||||||||||||||||
1517 | - | |||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | - | |||||||||||||||||||
1521 | QByteArray QByteArray::number(qlonglong n, int base) | - | ||||||||||||||||||
1522 | { | - | ||||||||||||||||||
1523 | QByteArray s; | - | ||||||||||||||||||
1524 | s.setNum(n, base); | - | ||||||||||||||||||
1525 | return s; | - | ||||||||||||||||||
1526 | } | - | ||||||||||||||||||
1527 | - | |||||||||||||||||||
1528 | - | |||||||||||||||||||
1529 | - | |||||||||||||||||||
1530 | - | |||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | - | |||||||||||||||||||
1533 | QByteArray QByteArray::number(qulonglong n, int base) | - | ||||||||||||||||||
1534 | { | - | ||||||||||||||||||
1535 | QByteArray s; | - | ||||||||||||||||||
1536 | s.setNum(n, base); | - | ||||||||||||||||||
1537 | return s; | - | ||||||||||||||||||
1538 | } | - | ||||||||||||||||||
1539 | QByteArray QByteArray::number(double n, char f, int prec) | - | ||||||||||||||||||
1540 | { | - | ||||||||||||||||||
1541 | QByteArray s; | - | ||||||||||||||||||
1542 | s.setNum(n, f, prec); | - | ||||||||||||||||||
1543 | return s; | - | ||||||||||||||||||
1544 | } | - | ||||||||||||||||||
1545 | QByteArray QByteArray::fromRawData(const char *data, int size) | - | ||||||||||||||||||
1546 | { | - | ||||||||||||||||||
1547 | Data *x; | - | ||||||||||||||||||
1548 | if (!data) { | - | ||||||||||||||||||
1549 | x = Data::sharedNull(); | - | ||||||||||||||||||
1550 | } else if (!size) { | - | ||||||||||||||||||
1551 | x = Data::allocate(0); | - | ||||||||||||||||||
1552 | } else { | - | ||||||||||||||||||
1553 | x = Data::fromRawData(data, size); | - | ||||||||||||||||||
1554 | do { if (!(x)) qBadAlloc(); } while (0); | - | ||||||||||||||||||
1555 | } | - | ||||||||||||||||||
1556 | QByteArrayDataPtr dataPtr = { x }; | - | ||||||||||||||||||
1557 | return QByteArray(dataPtr); | - | ||||||||||||||||||
1558 | } | - | ||||||||||||||||||
1559 | QByteArray &QByteArray::setRawData(const char *data, uint size) | - | ||||||||||||||||||
1560 | { | - | ||||||||||||||||||
1561 | if (d->ref.isShared() || d->alloc) { | - | ||||||||||||||||||
1562 | *this = fromRawData(data, size); | - | ||||||||||||||||||
1563 | } else { | - | ||||||||||||||||||
1564 | if (data) { | - | ||||||||||||||||||
1565 | d->size = size; | - | ||||||||||||||||||
1566 | d->offset = data - reinterpret_cast<char *>(d); | - | ||||||||||||||||||
1567 | } else { | - | ||||||||||||||||||
1568 | d->offset = sizeof(QByteArrayData); | - | ||||||||||||||||||
1569 | d->size = 0; | - | ||||||||||||||||||
1570 | *d->data() = 0; | - | ||||||||||||||||||
1571 | } | - | ||||||||||||||||||
1572 | } | - | ||||||||||||||||||
1573 | return *this; | - | ||||||||||||||||||
1574 | } | - | ||||||||||||||||||
1575 | QByteArray QByteArray::fromBase64(const QByteArray &base64) | - | ||||||||||||||||||
1576 | { | - | ||||||||||||||||||
1577 | return fromBase64(base64, Base64Encoding); | - | ||||||||||||||||||
1578 | } | - | ||||||||||||||||||
1579 | QByteArray QByteArray::fromBase64(const QByteArray &base64, Base64Options options) | - | ||||||||||||||||||
1580 | { | - | ||||||||||||||||||
1581 | unsigned int buf = 0; | - | ||||||||||||||||||
1582 | int nbits = 0; | - | ||||||||||||||||||
1583 | QByteArray tmp((base64.size() * 3) / 4, Qt::Uninitialized); | - | ||||||||||||||||||
1584 | - | |||||||||||||||||||
1585 | int offset = 0; | - | ||||||||||||||||||
1586 | for (int i = 0; i < base64.size(); ++i) { | - | ||||||||||||||||||
1587 | int ch = base64.at(i); | - | ||||||||||||||||||
1588 | int d; | - | ||||||||||||||||||
1589 | - | |||||||||||||||||||
1590 | if (ch >= 'A' && ch <= 'Z') | - | ||||||||||||||||||
1591 | d = ch - 'A'; | - | ||||||||||||||||||
1592 | else if (ch >= 'a' && ch <= 'z') | - | ||||||||||||||||||
1593 | d = ch - 'a' + 26; | - | ||||||||||||||||||
1594 | else if (ch >= '0' && ch <= '9') | - | ||||||||||||||||||
1595 | d = ch - '0' + 52; | - | ||||||||||||||||||
1596 | else if (ch == '+' && (options & Base64UrlEncoding) == 0) | - | ||||||||||||||||||
1597 | d = 62; | - | ||||||||||||||||||
1598 | else if (ch == '-' && (options & Base64UrlEncoding) != 0) | - | ||||||||||||||||||
1599 | d = 62; | - | ||||||||||||||||||
1600 | else if (ch == '/' && (options & Base64UrlEncoding) == 0) | - | ||||||||||||||||||
1601 | d = 63; | - | ||||||||||||||||||
1602 | else if (ch == '_' && (options & Base64UrlEncoding) != 0) | - | ||||||||||||||||||
1603 | d = 63; | - | ||||||||||||||||||
1604 | else | - | ||||||||||||||||||
1605 | d = -1; | - | ||||||||||||||||||
1606 | - | |||||||||||||||||||
1607 | if (d != -1) { | - | ||||||||||||||||||
1608 | buf = (buf << 6) | d; | - | ||||||||||||||||||
1609 | nbits += 6; | - | ||||||||||||||||||
1610 | if (nbits >= 8) { | - | ||||||||||||||||||
1611 | nbits -= 8; | - | ||||||||||||||||||
1612 | tmp[offset++] = buf >> nbits; | - | ||||||||||||||||||
1613 | buf &= (1 << nbits) - 1; | - | ||||||||||||||||||
1614 | } | - | ||||||||||||||||||
1615 | } | - | ||||||||||||||||||
1616 | } | - | ||||||||||||||||||
1617 | - | |||||||||||||||||||
1618 | tmp.truncate(offset); | - | ||||||||||||||||||
1619 | return tmp; | - | ||||||||||||||||||
1620 | } | - | ||||||||||||||||||
1621 | QByteArray QByteArray::fromHex(const QByteArray &hexEncoded) | - | ||||||||||||||||||
1622 | { | - | ||||||||||||||||||
1623 | QByteArray res((hexEncoded.size() + 1)/ 2, Qt::Uninitialized); | - | ||||||||||||||||||
1624 | uchar *result = (uchar *)res.data() + res.size(); | - | ||||||||||||||||||
1625 | - | |||||||||||||||||||
1626 | bool odd_digit = true; | - | ||||||||||||||||||
1627 | for (int i = hexEncoded.size() - 1; i >= 0; --i) { | - | ||||||||||||||||||
1628 | uchar ch = uchar(hexEncoded.at(i)); | - | ||||||||||||||||||
1629 | int tmp = QtMiscUtils::fromHex(ch); | - | ||||||||||||||||||
1630 | if (tmp == -1) | - | ||||||||||||||||||
1631 | continue; | - | ||||||||||||||||||
1632 | if (odd_digit) { | - | ||||||||||||||||||
1633 | --result; | - | ||||||||||||||||||
1634 | *result = tmp; | - | ||||||||||||||||||
1635 | odd_digit = false; | - | ||||||||||||||||||
1636 | } else { | - | ||||||||||||||||||
1637 | *result |= tmp << 4; | - | ||||||||||||||||||
1638 | odd_digit = true; | - | ||||||||||||||||||
1639 | } | - | ||||||||||||||||||
1640 | } | - | ||||||||||||||||||
1641 | - | |||||||||||||||||||
1642 | res.remove(0, result - (const uchar *)res.constData()); | - | ||||||||||||||||||
1643 | return res; | - | ||||||||||||||||||
1644 | } | - | ||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | - | |||||||||||||||||||
1649 | - | |||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | - | |||||||||||||||||||
1652 | QByteArray QByteArray::toHex() const | - | ||||||||||||||||||
1653 | { | - | ||||||||||||||||||
1654 | QByteArray hex(d->size * 2, Qt::Uninitialized); | - | ||||||||||||||||||
1655 | char *hexData = hex.data(); | - | ||||||||||||||||||
1656 | const uchar *data = (const uchar *)d->data(); | - | ||||||||||||||||||
1657 | for (int i = 0; i < d->size; ++i) { | - | ||||||||||||||||||
1658 | hexData[i*2] = QtMiscUtils::toHexLower(data[i] >> 4); | - | ||||||||||||||||||
1659 | hexData[i*2+1] = QtMiscUtils::toHexLower(data[i] & 0xf); | - | ||||||||||||||||||
1660 | } | - | ||||||||||||||||||
1661 | return hex; | - | ||||||||||||||||||
1662 | } | - | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | static void q_fromPercentEncoding(QByteArray *ba, char percent) | - | ||||||||||||||||||
1665 | { | - | ||||||||||||||||||
1666 | if (ba->isEmpty()) | - | ||||||||||||||||||
1667 | return; | - | ||||||||||||||||||
1668 | - | |||||||||||||||||||
1669 | char *data = ba->data(); | - | ||||||||||||||||||
1670 | const char *inputPtr = data; | - | ||||||||||||||||||
1671 | - | |||||||||||||||||||
1672 | int i = 0; | - | ||||||||||||||||||
1673 | int len = ba->count(); | - | ||||||||||||||||||
1674 | int outlen = 0; | - | ||||||||||||||||||
1675 | int a, b; | - | ||||||||||||||||||
1676 | char c; | - | ||||||||||||||||||
1677 | while (i < len) { | - | ||||||||||||||||||
1678 | c = inputPtr[i]; | - | ||||||||||||||||||
1679 | if (c == percent && i + 2 < len) { | - | ||||||||||||||||||
1680 | a = inputPtr[++i]; | - | ||||||||||||||||||
1681 | b = inputPtr[++i]; | - | ||||||||||||||||||
1682 | - | |||||||||||||||||||
1683 | if (a >= '0' && a <= '9') a -= '0'; | - | ||||||||||||||||||
1684 | else if (a >= 'a' && a <= 'f') a = a - 'a' + 10; | - | ||||||||||||||||||
1685 | else if (a >= 'A' && a <= 'F') a = a - 'A' + 10; | - | ||||||||||||||||||
1686 | - | |||||||||||||||||||
1687 | if (b >= '0' && b <= '9') b -= '0'; | - | ||||||||||||||||||
1688 | else if (b >= 'a' && b <= 'f') b = b - 'a' + 10; | - | ||||||||||||||||||
1689 | else if (b >= 'A' && b <= 'F') b = b - 'A' + 10; | - | ||||||||||||||||||
1690 | - | |||||||||||||||||||
1691 | *data++ = (char)((a << 4) | b); | - | ||||||||||||||||||
1692 | } else { | - | ||||||||||||||||||
1693 | *data++ = c; | - | ||||||||||||||||||
1694 | } | - | ||||||||||||||||||
1695 | - | |||||||||||||||||||
1696 | ++i; | - | ||||||||||||||||||
1697 | ++outlen; | - | ||||||||||||||||||
1698 | } | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | if (outlen != len) | - | ||||||||||||||||||
1701 | ba->truncate(outlen); | - | ||||||||||||||||||
1702 | } | - | ||||||||||||||||||
1703 | - | |||||||||||||||||||
1704 | void q_fromPercentEncoding(QByteArray *ba) | - | ||||||||||||||||||
1705 | { | - | ||||||||||||||||||
1706 | q_fromPercentEncoding(ba, '%'); | - | ||||||||||||||||||
1707 | } | - | ||||||||||||||||||
1708 | QByteArray QByteArray::fromPercentEncoding(const QByteArray &input, char percent) | - | ||||||||||||||||||
1709 | { | - | ||||||||||||||||||
1710 | if (input.isNull()) | - | ||||||||||||||||||
1711 | return QByteArray(); | - | ||||||||||||||||||
1712 | if (input.isEmpty()) | - | ||||||||||||||||||
1713 | return QByteArray(input.data(), 0); | - | ||||||||||||||||||
1714 | - | |||||||||||||||||||
1715 | QByteArray tmp = input; | - | ||||||||||||||||||
1716 | q_fromPercentEncoding(&tmp, percent); | - | ||||||||||||||||||
1717 | return tmp; | - | ||||||||||||||||||
1718 | } | - | ||||||||||||||||||
1719 | static inline bool q_strchr(const char str[], char chr) | - | ||||||||||||||||||
1720 | { | - | ||||||||||||||||||
1721 | if (!str) return false; | - | ||||||||||||||||||
1722 | - | |||||||||||||||||||
1723 | const char *ptr = str; | - | ||||||||||||||||||
1724 | char c; | - | ||||||||||||||||||
1725 | while ((c = *ptr++)) | - | ||||||||||||||||||
1726 | if (c == chr) | - | ||||||||||||||||||
1727 | return true; | - | ||||||||||||||||||
1728 | return false; | - | ||||||||||||||||||
1729 | } | - | ||||||||||||||||||
1730 | - | |||||||||||||||||||
1731 | static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent) | - | ||||||||||||||||||
1732 | { | - | ||||||||||||||||||
1733 | if (ba->isEmpty()) | - | ||||||||||||||||||
1734 | return; | - | ||||||||||||||||||
1735 | - | |||||||||||||||||||
1736 | QByteArray input = *ba; | - | ||||||||||||||||||
1737 | int len = input.count(); | - | ||||||||||||||||||
1738 | const char *inputData = input.constData(); | - | ||||||||||||||||||
1739 | char *output = 0; | - | ||||||||||||||||||
1740 | int length = 0; | - | ||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | for (int i = 0; i < len; ++i) { | - | ||||||||||||||||||
1743 | unsigned char c = *inputData++; | - | ||||||||||||||||||
1744 | if (((c >= 0x61 && c <= 0x7A) | - | ||||||||||||||||||
1745 | || (c >= 0x41 && c <= 0x5A) | - | ||||||||||||||||||
1746 | || (c >= 0x30 && c <= 0x39) | - | ||||||||||||||||||
1747 | || c == 0x2D | - | ||||||||||||||||||
1748 | || c == 0x2E | - | ||||||||||||||||||
1749 | || c == 0x5F | - | ||||||||||||||||||
1750 | || c == 0x7E | - | ||||||||||||||||||
1751 | || q_strchr(dontEncode, c)) | - | ||||||||||||||||||
1752 | && !q_strchr(alsoEncode, c)) { | - | ||||||||||||||||||
1753 | if (output) | - | ||||||||||||||||||
1754 | output[length] = c; | - | ||||||||||||||||||
1755 | ++length; | - | ||||||||||||||||||
1756 | } else { | - | ||||||||||||||||||
1757 | if (!output) { | - | ||||||||||||||||||
1758 | - | |||||||||||||||||||
1759 | ba->resize(len*3); | - | ||||||||||||||||||
1760 | output = ba->data(); | - | ||||||||||||||||||
1761 | } | - | ||||||||||||||||||
1762 | output[length++] = percent; | - | ||||||||||||||||||
1763 | output[length++] = QtMiscUtils::toHexUpper((c & 0xf0) >> 4); | - | ||||||||||||||||||
1764 | output[length++] = QtMiscUtils::toHexUpper(c & 0xf); | - | ||||||||||||||||||
1765 | } | - | ||||||||||||||||||
1766 | } | - | ||||||||||||||||||
1767 | if (output) | - | ||||||||||||||||||
1768 | ba->truncate(length); | - | ||||||||||||||||||
1769 | } | - | ||||||||||||||||||
1770 | - | |||||||||||||||||||
1771 | void q_toPercentEncoding(QByteArray *ba, const char *exclude, const char *include) | - | ||||||||||||||||||
1772 | { | - | ||||||||||||||||||
1773 | q_toPercentEncoding(ba, exclude, include, '%'); | - | ||||||||||||||||||
1774 | } | - | ||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | void q_normalizePercentEncoding(QByteArray *ba, const char *exclude) | - | ||||||||||||||||||
1777 | { | - | ||||||||||||||||||
1778 | q_fromPercentEncoding(ba, '%'); | - | ||||||||||||||||||
1779 | q_toPercentEncoding(ba, exclude, 0, '%'); | - | ||||||||||||||||||
1780 | } | - | ||||||||||||||||||
1781 | QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteArray &include, | - | ||||||||||||||||||
1782 | char percent) const | - | ||||||||||||||||||
1783 | { | - | ||||||||||||||||||
1784 | if (isNull()) | - | ||||||||||||||||||
1785 | return QByteArray(); | - | ||||||||||||||||||
1786 | if (isEmpty()) | - | ||||||||||||||||||
1787 | return QByteArray(data(), 0); | - | ||||||||||||||||||
1788 | - | |||||||||||||||||||
1789 | QByteArray include2 = include; | - | ||||||||||||||||||
1790 | if (percent != '%') | - | ||||||||||||||||||
1791 | if ((percent >= 0x61 && percent <= 0x7A) | - | ||||||||||||||||||
1792 | || (percent >= 0x41 && percent <= 0x5A) | - | ||||||||||||||||||
1793 | || (percent >= 0x30 && percent <= 0x39) | - | ||||||||||||||||||
1794 | || percent == 0x2D | - | ||||||||||||||||||
1795 | || percent == 0x2E | - | ||||||||||||||||||
1796 | || percent == 0x5F | - | ||||||||||||||||||
1797 | || percent == 0x7E) | - | ||||||||||||||||||
1798 | include2 += percent; | - | ||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | QByteArray result = *this; | - | ||||||||||||||||||
1801 | q_toPercentEncoding(&result, exclude.nulTerminated().constData(), include2.nulTerminated().constData(), percent); | - | ||||||||||||||||||
1802 | - | |||||||||||||||||||
1803 | return result; | - | ||||||||||||||||||
1804 | } | - | ||||||||||||||||||
1805 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |