Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qtextstream.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | //#define QTEXTSTREAM_DEBUG | - | ||||||||||||||||||||||||
35 | static const int QTEXTSTREAM_BUFFERSIZE = 16384; | - | ||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | /*! | - | ||||||||||||||||||||||||
38 | \class QTextStream | - | ||||||||||||||||||||||||
39 | \inmodule QtCore | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | \brief The QTextStream class provides a convenient interface for | - | ||||||||||||||||||||||||
42 | reading and writing text. | - | ||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||
44 | \ingroup io | - | ||||||||||||||||||||||||
45 | \ingroup string-processing | - | ||||||||||||||||||||||||
46 | \reentrant | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | QTextStream can operate on a QIODevice, a QByteArray or a | - | ||||||||||||||||||||||||
49 | QString. Using QTextStream's streaming operators, you can | - | ||||||||||||||||||||||||
50 | conveniently read and write words, lines and numbers. For | - | ||||||||||||||||||||||||
51 | generating text, QTextStream supports formatting options for field | - | ||||||||||||||||||||||||
52 | padding and alignment, and formatting of numbers. Example: | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | \snippet code/src_corelib_io_qtextstream.cpp 0 | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | It's also common to use QTextStream to read console input and write | - | ||||||||||||||||||||||||
57 | console output. QTextStream is locale aware, and will automatically decode | - | ||||||||||||||||||||||||
58 | standard input using the correct codec. Example: | - | ||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | \snippet code/src_corelib_io_qtextstream.cpp 1 | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | Besides using QTextStream's constructors, you can also set the | - | ||||||||||||||||||||||||
63 | device or string QTextStream operates on by calling setDevice() or | - | ||||||||||||||||||||||||
64 | setString(). You can seek to a position by calling seek(), and | - | ||||||||||||||||||||||||
65 | atEnd() will return true when there is no data left to be read. If | - | ||||||||||||||||||||||||
66 | you call flush(), QTextStream will empty all data from its write | - | ||||||||||||||||||||||||
67 | buffer into the device and call flush() on the device. | - | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | Internally, QTextStream uses a Unicode based buffer, and | - | ||||||||||||||||||||||||
70 | QTextCodec is used by QTextStream to automatically support | - | ||||||||||||||||||||||||
71 | different character sets. By default, QTextCodec::codecForLocale() | - | ||||||||||||||||||||||||
72 | is used for reading and writing, but you can also set the codec by | - | ||||||||||||||||||||||||
73 | calling setCodec(). Automatic Unicode detection is also | - | ||||||||||||||||||||||||
74 | supported. When this feature is enabled (the default behavior), | - | ||||||||||||||||||||||||
75 | QTextStream will detect the UTF-16 or the UTF-32 BOM (Byte Order Mark) and | - | ||||||||||||||||||||||||
76 | switch to the appropriate UTF codec when reading. QTextStream | - | ||||||||||||||||||||||||
77 | does not write a BOM by default, but you can enable this by calling | - | ||||||||||||||||||||||||
78 | setGenerateByteOrderMark(true). When QTextStream operates on a QString | - | ||||||||||||||||||||||||
79 | directly, the codec is disabled. | - | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | There are three general ways to use QTextStream when reading text | - | ||||||||||||||||||||||||
82 | files: | - | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | \list | - | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | \li Chunk by chunk, by calling readLine() or readAll(). | - | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | \li Word by word. QTextStream supports streaming into \l {QString}s, | - | ||||||||||||||||||||||||
89 | \l {QByteArray}s and char* buffers. Words are delimited by space, and | - | ||||||||||||||||||||||||
90 | leading white space is automatically skipped. | - | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | \li Character by character, by streaming into QChar or char types. | - | ||||||||||||||||||||||||
93 | This method is often used for convenient input handling when | - | ||||||||||||||||||||||||
94 | parsing files, independent of character encoding and end-of-line | - | ||||||||||||||||||||||||
95 | semantics. To skip white space, call skipWhiteSpace(). | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | \endlist | - | ||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | Since the text stream uses a buffer, you should not read from | - | ||||||||||||||||||||||||
100 | the stream using the implementation of a superclass. For instance, | - | ||||||||||||||||||||||||
101 | if you have a QFile and read from it directly using | - | ||||||||||||||||||||||||
102 | QFile::readLine() instead of using the stream, the text stream's | - | ||||||||||||||||||||||||
103 | internal position will be out of sync with the file's position. | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | By default, when reading numbers from a stream of text, | - | ||||||||||||||||||||||||
106 | QTextStream will automatically detect the number's base | - | ||||||||||||||||||||||||
107 | representation. For example, if the number starts with "0x", it is | - | ||||||||||||||||||||||||
108 | assumed to be in hexadecimal form. If it starts with the digits | - | ||||||||||||||||||||||||
109 | 1-9, it is assumed to be in decimal form, and so on. You can set | - | ||||||||||||||||||||||||
110 | the integer base, thereby disabling the automatic detection, by | - | ||||||||||||||||||||||||
111 | calling setIntegerBase(). Example: | - | ||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | \snippet code/src_corelib_io_qtextstream.cpp 2 | - | ||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | QTextStream supports many formatting options for generating text. | - | ||||||||||||||||||||||||
116 | You can set the field width and pad character by calling | - | ||||||||||||||||||||||||
117 | setFieldWidth() and setPadChar(). Use setFieldAlignment() to set | - | ||||||||||||||||||||||||
118 | the alignment within each field. For real numbers, call | - | ||||||||||||||||||||||||
119 | setRealNumberNotation() and setRealNumberPrecision() to set the | - | ||||||||||||||||||||||||
120 | notation (SmartNotation, ScientificNotation, FixedNotation) and precision in | - | ||||||||||||||||||||||||
121 | digits of the generated number. Some extra number formatting | - | ||||||||||||||||||||||||
122 | options are also available through setNumberFlags(). | - | ||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | \target QTextStream manipulators | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | Like \c <iostream> in the standard C++ library, QTextStream also | - | ||||||||||||||||||||||||
127 | defines several global manipulator functions: | - | ||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | \table | - | ||||||||||||||||||||||||
130 | \header \li Manipulator \li Description | - | ||||||||||||||||||||||||
131 | \row \li \c bin \li Same as setIntegerBase(2). | - | ||||||||||||||||||||||||
132 | \row \li \c oct \li Same as setIntegerBase(8). | - | ||||||||||||||||||||||||
133 | \row \li \c dec \li Same as setIntegerBase(10). | - | ||||||||||||||||||||||||
134 | \row \li \c hex \li Same as setIntegerBase(16). | - | ||||||||||||||||||||||||
135 | \row \li \c showbase \li Same as setNumberFlags(numberFlags() | ShowBase). | - | ||||||||||||||||||||||||
136 | \row \li \c forcesign \li Same as setNumberFlags(numberFlags() | ForceSign). | - | ||||||||||||||||||||||||
137 | \row \li \c forcepoint \li Same as setNumberFlags(numberFlags() | ForcePoint). | - | ||||||||||||||||||||||||
138 | \row \li \c noshowbase \li Same as setNumberFlags(numberFlags() & ~ShowBase). | - | ||||||||||||||||||||||||
139 | \row \li \c noforcesign \li Same as setNumberFlags(numberFlags() & ~ForceSign). | - | ||||||||||||||||||||||||
140 | \row \li \c noforcepoint \li Same as setNumberFlags(numberFlags() & ~ForcePoint). | - | ||||||||||||||||||||||||
141 | \row \li \c uppercasebase \li Same as setNumberFlags(numberFlags() | UppercaseBase). | - | ||||||||||||||||||||||||
142 | \row \li \c uppercasedigits \li Same as setNumberFlags(numberFlags() | UppercaseDigits). | - | ||||||||||||||||||||||||
143 | \row \li \c lowercasebase \li Same as setNumberFlags(numberFlags() & ~UppercaseBase). | - | ||||||||||||||||||||||||
144 | \row \li \c lowercasedigits \li Same as setNumberFlags(numberFlags() & ~UppercaseDigits). | - | ||||||||||||||||||||||||
145 | \row \li \c fixed \li Same as setRealNumberNotation(FixedNotation). | - | ||||||||||||||||||||||||
146 | \row \li \c scientific \li Same as setRealNumberNotation(ScientificNotation). | - | ||||||||||||||||||||||||
147 | \row \li \c left \li Same as setFieldAlignment(AlignLeft). | - | ||||||||||||||||||||||||
148 | \row \li \c right \li Same as setFieldAlignment(AlignRight). | - | ||||||||||||||||||||||||
149 | \row \li \c center \li Same as setFieldAlignment(AlignCenter). | - | ||||||||||||||||||||||||
150 | \row \li \c endl \li Same as operator<<('\\n') and flush(). | - | ||||||||||||||||||||||||
151 | \row \li \c flush \li Same as flush(). | - | ||||||||||||||||||||||||
152 | \row \li \c reset \li Same as reset(). | - | ||||||||||||||||||||||||
153 | \row \li \c ws \li Same as skipWhiteSpace(). | - | ||||||||||||||||||||||||
154 | \row \li \c bom \li Same as setGenerateByteOrderMark(true). | - | ||||||||||||||||||||||||
155 | \endtable | - | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | In addition, Qt provides three global manipulators that take a | - | ||||||||||||||||||||||||
158 | parameter: qSetFieldWidth(), qSetPadChar(), and | - | ||||||||||||||||||||||||
159 | qSetRealNumberPrecision(). | - | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | \sa QDataStream, QIODevice, QFile, QBuffer, QTcpSocket, {Text Codecs Example} | - | ||||||||||||||||||||||||
162 | */ | - | ||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | /*! \enum QTextStream::RealNumberNotation | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | This enum specifies which notations to use for expressing \c | - | ||||||||||||||||||||||||
167 | float and \c double as strings. | - | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | \value ScientificNotation Scientific notation (\c{printf()}'s \c %e flag). | - | ||||||||||||||||||||||||
170 | \value FixedNotation Fixed-point notation (\c{printf()}'s \c %f flag). | - | ||||||||||||||||||||||||
171 | \value SmartNotation Scientific or fixed-point notation, depending on which makes most sense (\c{printf()}'s \c %g flag). | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | \sa setRealNumberNotation() | - | ||||||||||||||||||||||||
174 | */ | - | ||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||
176 | /*! \enum QTextStream::FieldAlignment | - | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | This enum specifies how to align text in fields when the field is | - | ||||||||||||||||||||||||
179 | wider than the text that occupies it. | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | \value AlignLeft Pad on the right side of fields. | - | ||||||||||||||||||||||||
182 | \value AlignRight Pad on the left side of fields. | - | ||||||||||||||||||||||||
183 | \value AlignCenter Pad on both sides of field. | - | ||||||||||||||||||||||||
184 | \value AlignAccountingStyle Same as AlignRight, except that the | - | ||||||||||||||||||||||||
185 | sign of a number is flush left. | - | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | \sa setFieldAlignment() | - | ||||||||||||||||||||||||
188 | */ | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | /*! \enum QTextStream::NumberFlag | - | ||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | This enum specifies various flags that can be set to affect the | - | ||||||||||||||||||||||||
193 | output of integers, \c{float}s, and \c{double}s. | - | ||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | \value ShowBase Show the base as a prefix if the base | - | ||||||||||||||||||||||||
196 | is 16 ("0x"), 8 ("0"), or 2 ("0b"). | - | ||||||||||||||||||||||||
197 | \value ForcePoint Always put the decimal separator in numbers, even if | - | ||||||||||||||||||||||||
198 | there are no decimals. | - | ||||||||||||||||||||||||
199 | \value ForceSign Always put the sign in numbers, even for positive numbers. | - | ||||||||||||||||||||||||
200 | \value UppercaseBase Use uppercase versions of base prefixes ("0X", "0B"). | - | ||||||||||||||||||||||||
201 | \value UppercaseDigits Use uppercase letters for expressing | - | ||||||||||||||||||||||||
202 | digits 10 to 35 instead of lowercase. | - | ||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | \sa setNumberFlags() | - | ||||||||||||||||||||||||
205 | */ | - | ||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||
207 | /*! \enum QTextStream::Status | - | ||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||
209 | This enum describes the current status of the text stream. | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | \value Ok The text stream is operating normally. | - | ||||||||||||||||||||||||
212 | \value ReadPastEnd The text stream has read past the end of the | - | ||||||||||||||||||||||||
213 | data in the underlying device. | - | ||||||||||||||||||||||||
214 | \value ReadCorruptData The text stream has read corrupt data. | - | ||||||||||||||||||||||||
215 | \value WriteFailed The text stream cannot write to the underlying device. | - | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | \sa status() | - | ||||||||||||||||||||||||
218 | */ | - | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | #include "qtextstream.h" | - | ||||||||||||||||||||||||
221 | #include "private/qtextstream_p.h" | - | ||||||||||||||||||||||||
222 | #include "qbuffer.h" | - | ||||||||||||||||||||||||
223 | #include "qfile.h" | - | ||||||||||||||||||||||||
224 | #include "qnumeric.h" | - | ||||||||||||||||||||||||
225 | #include "qvarlengtharray.h" | - | ||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||
227 | #ifndef Q_OS_WINCE | - | ||||||||||||||||||||||||
228 | #include <locale.h> | - | ||||||||||||||||||||||||
229 | #endif | - | ||||||||||||||||||||||||
230 | #include "private/qlocale_p.h" | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | #include <stdlib.h> | - | ||||||||||||||||||||||||
233 | #include <limits.h> | - | ||||||||||||||||||||||||
234 | #include <new> | - | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | #if defined QTEXTSTREAM_DEBUG | - | ||||||||||||||||||||||||
237 | #include <ctype.h> | - | ||||||||||||||||||||||||
238 | #include "private/qtools_p.h" | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | // Returns a human readable representation of the first \a len | - | ||||||||||||||||||||||||
243 | // characters in \a data. | - | ||||||||||||||||||||||||
244 | static QByteArray qt_prettyDebug(const char *data, int len, int maxSize) | - | ||||||||||||||||||||||||
245 | { | - | ||||||||||||||||||||||||
246 | if (!data) return "(null)"; | - | ||||||||||||||||||||||||
247 | QByteArray out; | - | ||||||||||||||||||||||||
248 | for (int i = 0; i < len; ++i) { | - | ||||||||||||||||||||||||
249 | char c = data[i]; | - | ||||||||||||||||||||||||
250 | if (isprint(int(uchar(c)))) { | - | ||||||||||||||||||||||||
251 | out += c; | - | ||||||||||||||||||||||||
252 | } else switch (c) { | - | ||||||||||||||||||||||||
253 | case '\n': out += "\\n"; break; | - | ||||||||||||||||||||||||
254 | case '\r': out += "\\r"; break; | - | ||||||||||||||||||||||||
255 | case '\t': out += "\\t"; break; | - | ||||||||||||||||||||||||
256 | default: { | - | ||||||||||||||||||||||||
257 | const char buf[] = { | - | ||||||||||||||||||||||||
258 | '\\', | - | ||||||||||||||||||||||||
259 | 'x', | - | ||||||||||||||||||||||||
260 | QtMiscUtils::toHexLower(uchar(c) / 16), | - | ||||||||||||||||||||||||
261 | QtMiscUtils::toHexLower(uchar(c) % 16), | - | ||||||||||||||||||||||||
262 | 0 | - | ||||||||||||||||||||||||
263 | }; | - | ||||||||||||||||||||||||
264 | out += buf; | - | ||||||||||||||||||||||||
265 | } | - | ||||||||||||||||||||||||
266 | } | - | ||||||||||||||||||||||||
267 | } | - | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | if (len < maxSize) | - | ||||||||||||||||||||||||
270 | out += "..."; | - | ||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||
272 | return out; | - | ||||||||||||||||||||||||
273 | } | - | ||||||||||||||||||||||||
274 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | #endif | - | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | // A precondition macro | - | ||||||||||||||||||||||||
279 | #define Q_VOID | - | ||||||||||||||||||||||||
280 | #define CHECK_VALID_STREAM(x) do { \ | - | ||||||||||||||||||||||||
281 | if (!d->string && !d->device) { \ | - | ||||||||||||||||||||||||
282 | qWarning("QTextStream: No device"); \ | - | ||||||||||||||||||||||||
283 | return x; \ | - | ||||||||||||||||||||||||
284 | } } while (0) | - | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | // Base implementations of operator>> for ints and reals | - | ||||||||||||||||||||||||
287 | #define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type) do { \ | - | ||||||||||||||||||||||||
288 | Q_D(QTextStream); \ | - | ||||||||||||||||||||||||
289 | CHECK_VALID_STREAM(*this); \ | - | ||||||||||||||||||||||||
290 | qulonglong tmp; \ | - | ||||||||||||||||||||||||
291 | switch (d->getNumber(&tmp)) { \ | - | ||||||||||||||||||||||||
292 | case QTextStreamPrivate::npsOk: \ | - | ||||||||||||||||||||||||
293 | i = (type)tmp; \ | - | ||||||||||||||||||||||||
294 | break; \ | - | ||||||||||||||||||||||||
295 | case QTextStreamPrivate::npsMissingDigit: \ | - | ||||||||||||||||||||||||
296 | case QTextStreamPrivate::npsInvalidPrefix: \ | - | ||||||||||||||||||||||||
297 | i = (type)0; \ | - | ||||||||||||||||||||||||
298 | setStatus(atEnd() ? QTextStream::ReadPastEnd : QTextStream::ReadCorruptData); \ | - | ||||||||||||||||||||||||
299 | break; \ | - | ||||||||||||||||||||||||
300 | } \ | - | ||||||||||||||||||||||||
301 | return *this; } while (0) | - | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | #define IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(type) do { \ | - | ||||||||||||||||||||||||
304 | Q_D(QTextStream); \ | - | ||||||||||||||||||||||||
305 | CHECK_VALID_STREAM(*this); \ | - | ||||||||||||||||||||||||
306 | double tmp; \ | - | ||||||||||||||||||||||||
307 | if (d->getReal(&tmp)) { \ | - | ||||||||||||||||||||||||
308 | f = (type)tmp; \ | - | ||||||||||||||||||||||||
309 | } else { \ | - | ||||||||||||||||||||||||
310 | f = (type)0; \ | - | ||||||||||||||||||||||||
311 | setStatus(atEnd() ? QTextStream::ReadPastEnd : QTextStream::ReadCorruptData); \ | - | ||||||||||||||||||||||||
312 | } \ | - | ||||||||||||||||||||||||
313 | return *this; } while (0) | - | ||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||
315 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||
317 | //------------------------------------------------------------------- | - | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | /*! | - | ||||||||||||||||||||||||
320 | \internal | - | ||||||||||||||||||||||||
321 | */ | - | ||||||||||||||||||||||||
322 | QTextStreamPrivate::QTextStreamPrivate(QTextStream *q_ptr) | - | ||||||||||||||||||||||||
323 | : | - | ||||||||||||||||||||||||
324 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
325 | readConverterSavedState(0), | - | ||||||||||||||||||||||||
326 | #endif | - | ||||||||||||||||||||||||
327 | readConverterSavedStateOffset(0), | - | ||||||||||||||||||||||||
328 | locale(QLocale::c()) | - | ||||||||||||||||||||||||
329 | { | - | ||||||||||||||||||||||||
330 | this->q_ptr = q_ptr; | - | ||||||||||||||||||||||||
331 | reset(); | - | ||||||||||||||||||||||||
332 | } executed 78681 times by 98 tests: end of block Executed by:
| 78681 | ||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||
334 | /*! | - | ||||||||||||||||||||||||
335 | \internal | - | ||||||||||||||||||||||||
336 | */ | - | ||||||||||||||||||||||||
337 | QTextStreamPrivate::~QTextStreamPrivate() | - | ||||||||||||||||||||||||
338 | { | - | ||||||||||||||||||||||||
339 | if (deleteDevice) {
| 845-77990 | ||||||||||||||||||||||||
340 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
341 | device->blockSignals(true); | - | ||||||||||||||||||||||||
342 | #endif | - | ||||||||||||||||||||||||
343 | delete device; | - | ||||||||||||||||||||||||
344 | } executed 845 times by 8 tests: end of block Executed by:
| 845 | ||||||||||||||||||||||||
345 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
346 | delete readConverterSavedState; | - | ||||||||||||||||||||||||
347 | #endif | - | ||||||||||||||||||||||||
348 | } executed 78835 times by 98 tests: end of block Executed by:
| 78835 | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
351 | static void resetCodecConverterStateHelper(QTextCodec::ConverterState *state) | - | ||||||||||||||||||||||||
352 | { | - | ||||||||||||||||||||||||
353 | state->~ConverterState(); | - | ||||||||||||||||||||||||
354 | new (state) QTextCodec::ConverterState; | - | ||||||||||||||||||||||||
355 | } executed 588423 times by 98 tests: end of block Executed by:
| 588423 | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | static void copyConverterStateHelper(QTextCodec::ConverterState *dest, | - | ||||||||||||||||||||||||
358 | const QTextCodec::ConverterState *src) | - | ||||||||||||||||||||||||
359 | { | - | ||||||||||||||||||||||||
360 | // ### QTextCodec::ConverterState's copy constructors and assignments are | - | ||||||||||||||||||||||||
361 | // private. This function copies the structure manually. | - | ||||||||||||||||||||||||
362 | Q_ASSERT(!src->d); | - | ||||||||||||||||||||||||
363 | dest->flags = src->flags; | - | ||||||||||||||||||||||||
364 | dest->invalidChars = src->invalidChars; | - | ||||||||||||||||||||||||
365 | dest->state_data[0] = src->state_data[0]; | - | ||||||||||||||||||||||||
366 | dest->state_data[1] = src->state_data[1]; | - | ||||||||||||||||||||||||
367 | dest->state_data[2] = src->state_data[2]; | - | ||||||||||||||||||||||||
368 | } executed 2698 times by 16 tests: end of block Executed by:
| 2698 | ||||||||||||||||||||||||
369 | #endif | - | ||||||||||||||||||||||||
370 | - | |||||||||||||||||||||||||
371 | void QTextStreamPrivate::Params::reset() | - | ||||||||||||||||||||||||
372 | { | - | ||||||||||||||||||||||||
373 | realNumberPrecision = 6; | - | ||||||||||||||||||||||||
374 | integerBase = 0; | - | ||||||||||||||||||||||||
375 | fieldWidth = 0; | - | ||||||||||||||||||||||||
376 | padChar = QLatin1Char(' '); | - | ||||||||||||||||||||||||
377 | fieldAlignment = QTextStream::AlignRight; | - | ||||||||||||||||||||||||
378 | realNumberNotation = QTextStream::SmartNotation; | - | ||||||||||||||||||||||||
379 | numberFlags = 0; | - | ||||||||||||||||||||||||
380 | } executed 92953 times by 98 tests: end of block Executed by:
| 92953 | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | /*! | - | ||||||||||||||||||||||||
383 | \internal | - | ||||||||||||||||||||||||
384 | */ | - | ||||||||||||||||||||||||
385 | void QTextStreamPrivate::reset() | - | ||||||||||||||||||||||||
386 | { | - | ||||||||||||||||||||||||
387 | params.reset(); | - | ||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||
389 | device = 0; | - | ||||||||||||||||||||||||
390 | deleteDevice = false; | - | ||||||||||||||||||||||||
391 | string = 0; | - | ||||||||||||||||||||||||
392 | stringOffset = 0; | - | ||||||||||||||||||||||||
393 | stringOpenMode = QIODevice::NotOpen; | - | ||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||
395 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
396 | readBufferStartDevicePos = 0; | - | ||||||||||||||||||||||||
397 | lastTokenSize = 0; | - | ||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||
399 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
400 | codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||||||||
401 | resetCodecConverterStateHelper(&readConverterState); | - | ||||||||||||||||||||||||
402 | resetCodecConverterStateHelper(&writeConverterState); | - | ||||||||||||||||||||||||
403 | delete readConverterSavedState; | - | ||||||||||||||||||||||||
404 | readConverterSavedState = 0; | - | ||||||||||||||||||||||||
405 | writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
406 | autoDetectUnicode = true; | - | ||||||||||||||||||||||||
407 | #endif | - | ||||||||||||||||||||||||
408 | } executed 78853 times by 98 tests: end of block Executed by:
| 78853 | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | /*! | - | ||||||||||||||||||||||||
411 | \internal | - | ||||||||||||||||||||||||
412 | */ | - | ||||||||||||||||||||||||
413 | bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) | - | ||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||
415 | // no buffer next to the QString itself; this function should only | - | ||||||||||||||||||||||||
416 | // be called internally, for devices. | - | ||||||||||||||||||||||||
417 | Q_ASSERT(!string); | - | ||||||||||||||||||||||||
418 | Q_ASSERT(device); | - | ||||||||||||||||||||||||
419 | - | |||||||||||||||||||||||||
420 | // handle text translation and bypass the Text flag in the device. | - | ||||||||||||||||||||||||
421 | bool textModeEnabled = device->isTextModeEnabled(); | - | ||||||||||||||||||||||||
422 | if (textModeEnabled)
| 2563-41040053 | ||||||||||||||||||||||||
423 | device->setTextModeEnabled(false); executed 41040053 times by 6 tests: device->setTextModeEnabled(false); Executed by:
| 41040053 | ||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||
425 | // read raw data into a temporary buffer | - | ||||||||||||||||||||||||
426 | char buf[QTEXTSTREAM_BUFFERSIZE]; | - | ||||||||||||||||||||||||
427 | qint64 bytesRead = 0; | - | ||||||||||||||||||||||||
428 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
429 | // On Windows, there is no non-blocking stdin - so we fall back to reading | - | ||||||||||||||||||||||||
430 | // lines instead. If there is no QOBJECT, we read lines for all sequential | - | ||||||||||||||||||||||||
431 | // devices; otherwise, we read lines only for stdin. | - | ||||||||||||||||||||||||
432 | QFile *file = 0; | - | ||||||||||||||||||||||||
433 | Q_UNUSED(file); | - | ||||||||||||||||||||||||
434 | if (device->isSequential() | - | ||||||||||||||||||||||||
435 | #if !defined(QT_NO_QOBJECT) | - | ||||||||||||||||||||||||
436 | && (file = qobject_cast<QFile *>(device)) && file->handle() == 0 | - | ||||||||||||||||||||||||
437 | #endif | - | ||||||||||||||||||||||||
438 | ) { | - | ||||||||||||||||||||||||
439 | if (maxBytes != -1) | - | ||||||||||||||||||||||||
440 | bytesRead = device->readLine(buf, qMin<qint64>(sizeof(buf), maxBytes)); | - | ||||||||||||||||||||||||
441 | else | - | ||||||||||||||||||||||||
442 | bytesRead = device->readLine(buf, sizeof(buf)); | - | ||||||||||||||||||||||||
443 | } else | - | ||||||||||||||||||||||||
444 | #endif | - | ||||||||||||||||||||||||
445 | { | - | ||||||||||||||||||||||||
446 | if (maxBytes != -1)
| 7322-41035294 | ||||||||||||||||||||||||
447 | bytesRead = device->read(buf, qMin<qint64>(sizeof(buf), maxBytes)); executed 41035294 times by 1 test: bytesRead = device->read(buf, qMin<qint64>(sizeof(buf), maxBytes)); Executed by:
| 41035294 | ||||||||||||||||||||||||
448 | else | - | ||||||||||||||||||||||||
449 | bytesRead = device->read(buf, sizeof(buf)); executed 7322 times by 17 tests: bytesRead = device->read(buf, sizeof(buf)); Executed by:
| 7322 | ||||||||||||||||||||||||
450 | } | - | ||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||
452 | // reset the Text flag. | - | ||||||||||||||||||||||||
453 | if (textModeEnabled)
| 2563-41040053 | ||||||||||||||||||||||||
454 | device->setTextModeEnabled(true); executed 41040053 times by 6 tests: device->setTextModeEnabled(true); Executed by:
| 41040053 | ||||||||||||||||||||||||
455 | - | |||||||||||||||||||||||||
456 | if (bytesRead <= 0)
| 2523-41040093 | ||||||||||||||||||||||||
457 | return false; executed 2523 times by 7 tests: return false; Executed by:
| 2523 | ||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
460 | // codec auto detection, explicitly defaults to locale encoding if the | - | ||||||||||||||||||||||||
461 | // codec has been set to 0. | - | ||||||||||||||||||||||||
462 | if (!codec || autoDetectUnicode) {
| 0-41040093 | ||||||||||||||||||||||||
463 | autoDetectUnicode = false; | - | ||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||
465 | codec = QTextCodec::codecForUtfText(QByteArray::fromRawData(buf, bytesRead), codec); | - | ||||||||||||||||||||||||
466 | if (!codec) {
| 0-4547 | ||||||||||||||||||||||||
467 | codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||||||||
468 | writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
469 | } never executed: end of block | 0 | ||||||||||||||||||||||||
470 | } executed 4547 times by 17 tests: end of block Executed by:
| 4547 | ||||||||||||||||||||||||
471 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
472 | qDebug("QTextStreamPrivate::fillReadBuffer(), using %s codec", | - | ||||||||||||||||||||||||
473 | codec ? codec->name().constData() : "no"); | - | ||||||||||||||||||||||||
474 | #endif | - | ||||||||||||||||||||||||
475 | #endif | - | ||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||
477 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
478 | qDebug("QTextStreamPrivate::fillReadBuffer(), device->read(\"%s\", %d) == %d", | - | ||||||||||||||||||||||||
479 | qt_prettyDebug(buf, qMin(32,int(bytesRead)) , int(bytesRead)).constData(), int(sizeof(buf)), int(bytesRead)); | - | ||||||||||||||||||||||||
480 | #endif | - | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | int oldReadBufferSize = readBuffer.size(); | - | ||||||||||||||||||||||||
483 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
484 | // convert to unicode | - | ||||||||||||||||||||||||
485 | readBuffer += Q_LIKELY(codec) ? codec->toUnicode(buf, bytesRead, &readConverterState)
| 0-41040093 | ||||||||||||||||||||||||
486 | : QString::fromLatin1(buf, bytesRead); | - | ||||||||||||||||||||||||
487 | #else | - | ||||||||||||||||||||||||
488 | readBuffer += QString::fromLatin1(buf, bytesRead); | - | ||||||||||||||||||||||||
489 | #endif | - | ||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||
491 | // remove all '\r\n' in the string. | - | ||||||||||||||||||||||||
492 | if (readBuffer.size() > oldReadBufferSize && textModeEnabled) {
| 682-41039411 | ||||||||||||||||||||||||
493 | QChar CR = QLatin1Char('\r'); | - | ||||||||||||||||||||||||
494 | QChar *writePtr = readBuffer.data() + oldReadBufferSize; | - | ||||||||||||||||||||||||
495 | QChar *readPtr = readBuffer.data() + oldReadBufferSize; | - | ||||||||||||||||||||||||
496 | QChar *endPtr = readBuffer.data() + readBuffer.size(); | - | ||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||
498 | int n = oldReadBufferSize; | - | ||||||||||||||||||||||||
499 | if (readPtr < endPtr) {
| 0-41037818 | ||||||||||||||||||||||||
500 | // Cut-off to avoid unnecessary self-copying. | - | ||||||||||||||||||||||||
501 | while (*readPtr++ != CR) {
| 110-63893758 | ||||||||||||||||||||||||
502 | ++n; | - | ||||||||||||||||||||||||
503 | if (++writePtr == endPtr)
| 22856050-41037708 | ||||||||||||||||||||||||
504 | break; executed 41037708 times by 6 tests: break; Executed by:
| 41037708 | ||||||||||||||||||||||||
505 | } executed 22856050 times by 6 tests: end of block Executed by:
| 22856050 | ||||||||||||||||||||||||
506 | } executed 41037818 times by 6 tests: end of block Executed by:
| 41037818 | ||||||||||||||||||||||||
507 | while (readPtr < endPtr) {
| 146620-41037818 | ||||||||||||||||||||||||
508 | QChar ch = *readPtr++; | - | ||||||||||||||||||||||||
509 | if (ch != CR) {
| 22205-124415 | ||||||||||||||||||||||||
510 | *writePtr++ = ch; | - | ||||||||||||||||||||||||
511 | } else { executed 124415 times by 1 test: end of block Executed by:
| 124415 | ||||||||||||||||||||||||
512 | if (n < readBufferOffset)
| 0-22205 | ||||||||||||||||||||||||
513 | --readBufferOffset; never executed: --readBufferOffset; | 0 | ||||||||||||||||||||||||
514 | --bytesRead; | - | ||||||||||||||||||||||||
515 | } executed 22205 times by 1 test: end of block Executed by:
| 22205 | ||||||||||||||||||||||||
516 | ++n; | - | ||||||||||||||||||||||||
517 | } executed 146620 times by 1 test: end of block Executed by:
| 146620 | ||||||||||||||||||||||||
518 | readBuffer.resize(writePtr - readBuffer.data()); | - | ||||||||||||||||||||||||
519 | } executed 41037818 times by 6 tests: end of block Executed by:
| 41037818 | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
522 | qDebug("QTextStreamPrivate::fillReadBuffer() read %d bytes from device. readBuffer = [%s]", int(bytesRead), | - | ||||||||||||||||||||||||
523 | qt_prettyDebug(readBuffer.toLatin1(), readBuffer.size(), readBuffer.size()).data()); | - | ||||||||||||||||||||||||
524 | #endif | - | ||||||||||||||||||||||||
525 | return true; executed 41040093 times by 17 tests: return true; Executed by:
| 41040093 | ||||||||||||||||||||||||
526 | } | - | ||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||
528 | /*! | - | ||||||||||||||||||||||||
529 | \internal | - | ||||||||||||||||||||||||
530 | */ | - | ||||||||||||||||||||||||
531 | void QTextStreamPrivate::resetReadBuffer() | - | ||||||||||||||||||||||||
532 | { | - | ||||||||||||||||||||||||
533 | readBuffer.clear(); | - | ||||||||||||||||||||||||
534 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
535 | readBufferStartDevicePos = (device ? device->pos() : 0);
| 1-214481 | ||||||||||||||||||||||||
536 | } executed 214482 times by 1 test: end of block Executed by:
| 214482 | ||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||
538 | /*! | - | ||||||||||||||||||||||||
539 | \internal | - | ||||||||||||||||||||||||
540 | */ | - | ||||||||||||||||||||||||
541 | void QTextStreamPrivate::flushWriteBuffer() | - | ||||||||||||||||||||||||
542 | { | - | ||||||||||||||||||||||||
543 | // no buffer next to the QString itself; this function should only | - | ||||||||||||||||||||||||
544 | // be called internally, for devices. | - | ||||||||||||||||||||||||
545 | if (string || !device)
| 13-241565 | ||||||||||||||||||||||||
546 | return; executed 48610 times by 7 tests: return; Executed by:
| 48610 | ||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||
548 | // Stream went bye-bye already. Appending further data may succeed again, | - | ||||||||||||||||||||||||
549 | // but would create a corrupted stream anyway. | - | ||||||||||||||||||||||||
550 | if (status != QTextStream::Ok)
| 3-241549 | ||||||||||||||||||||||||
551 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||
553 | if (writeBuffer.isEmpty())
| 26664-214885 | ||||||||||||||||||||||||
554 | return; executed 214885 times by 6 tests: return; Executed by:
| 214885 | ||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||
556 | #if defined (Q_OS_WIN) | - | ||||||||||||||||||||||||
557 | // handle text translation and bypass the Text flag in the device. | - | ||||||||||||||||||||||||
558 | bool textModeEnabled = device->isTextModeEnabled(); | - | ||||||||||||||||||||||||
559 | if (textModeEnabled) { | - | ||||||||||||||||||||||||
560 | device->setTextModeEnabled(false); | - | ||||||||||||||||||||||||
561 | writeBuffer.replace(QLatin1Char('\n'), QLatin1String("\r\n")); | - | ||||||||||||||||||||||||
562 | } | - | ||||||||||||||||||||||||
563 | #endif | - | ||||||||||||||||||||||||
564 | - | |||||||||||||||||||||||||
565 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
566 | if (!codec)
| 1-26663 | ||||||||||||||||||||||||
567 | codec = QTextCodec::codecForLocale(); executed 1 time by 1 test: codec = QTextCodec::codecForLocale(); Executed by:
| 1 | ||||||||||||||||||||||||
568 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
569 | qDebug("QTextStreamPrivate::flushWriteBuffer(), using %s codec (%s generating BOM)", | - | ||||||||||||||||||||||||
570 | codec ? codec->name().constData() : "no", | - | ||||||||||||||||||||||||
571 | !codec || (writeConverterState.flags & QTextCodec::IgnoreHeader) ? "not" : ""); | - | ||||||||||||||||||||||||
572 | #endif | - | ||||||||||||||||||||||||
573 | - | |||||||||||||||||||||||||
574 | // convert from unicode to raw data | - | ||||||||||||||||||||||||
575 | // codec might be null if we're already inside global destructors (QTestCodec::codecForLocale returned null) | - | ||||||||||||||||||||||||
576 | QByteArray data = Q_LIKELY(codec) ? codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState)
| 1-26663 | ||||||||||||||||||||||||
577 | : writeBuffer.toLatin1(); | - | ||||||||||||||||||||||||
578 | #else | - | ||||||||||||||||||||||||
579 | QByteArray data = writeBuffer.toLatin1(); | - | ||||||||||||||||||||||||
580 | #endif | - | ||||||||||||||||||||||||
581 | writeBuffer.clear(); | - | ||||||||||||||||||||||||
582 | - | |||||||||||||||||||||||||
583 | // write raw data to the device | - | ||||||||||||||||||||||||
584 | qint64 bytesWritten = device->write(data); | - | ||||||||||||||||||||||||
585 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
586 | qDebug("QTextStreamPrivate::flushWriteBuffer(), device->write(\"%s\") == %d", | - | ||||||||||||||||||||||||
587 | qt_prettyDebug(data.constData(), qMin(data.size(),32), data.size()).constData(), int(bytesWritten)); | - | ||||||||||||||||||||||||
588 | #endif | - | ||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||
590 | #if defined (Q_OS_WIN) | - | ||||||||||||||||||||||||
591 | // reset the text flag | - | ||||||||||||||||||||||||
592 | if (textModeEnabled) | - | ||||||||||||||||||||||||
593 | device->setTextModeEnabled(true); | - | ||||||||||||||||||||||||
594 | #endif | - | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | if (bytesWritten <= 0) {
| 2-26662 | ||||||||||||||||||||||||
597 | status = QTextStream::WriteFailed; | - | ||||||||||||||||||||||||
598 | return; executed 2 times by 2 tests: return; Executed by:
| 2 | ||||||||||||||||||||||||
599 | } | - | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | // flush the file | - | ||||||||||||||||||||||||
602 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
603 | QFileDevice *file = qobject_cast<QFileDevice *>(device); | - | ||||||||||||||||||||||||
604 | bool flushed = !file || file->flush();
| 0-15832 | ||||||||||||||||||||||||
605 | #else | - | ||||||||||||||||||||||||
606 | bool flushed = true; | - | ||||||||||||||||||||||||
607 | #endif | - | ||||||||||||||||||||||||
608 | - | |||||||||||||||||||||||||
609 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
610 | qDebug("QTextStreamPrivate::flushWriteBuffer() wrote %d bytes", | - | ||||||||||||||||||||||||
611 | int(bytesWritten)); | - | ||||||||||||||||||||||||
612 | #endif | - | ||||||||||||||||||||||||
613 | if (!flushed || bytesWritten != qint64(data.size()))
| 0-26662 | ||||||||||||||||||||||||
614 | status = QTextStream::WriteFailed; never executed: status = QTextStream::WriteFailed; | 0 | ||||||||||||||||||||||||
615 | } executed 26662 times by 17 tests: end of block Executed by:
| 26662 | ||||||||||||||||||||||||
616 | - | |||||||||||||||||||||||||
617 | QString QTextStreamPrivate::read(int maxlen) | - | ||||||||||||||||||||||||
618 | { | - | ||||||||||||||||||||||||
619 | QString ret; | - | ||||||||||||||||||||||||
620 | if (string) {
| 5-1871 | ||||||||||||||||||||||||
621 | lastTokenSize = qMin(maxlen, string->size() - stringOffset); | - | ||||||||||||||||||||||||
622 | ret = string->mid(stringOffset, lastTokenSize); | - | ||||||||||||||||||||||||
623 | } else { executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
624 | while (readBuffer.size() - readBufferOffset < maxlen && fillReadBuffer()) ; executed 1867 times by 2 tests: ; Executed by:
| 7-3731 | ||||||||||||||||||||||||
625 | lastTokenSize = qMin(maxlen, readBuffer.size() - readBufferOffset); | - | ||||||||||||||||||||||||
626 | ret = readBuffer.mid(readBufferOffset, lastTokenSize); | - | ||||||||||||||||||||||||
627 | } executed 1871 times by 2 tests: end of block Executed by:
| 1871 | ||||||||||||||||||||||||
628 | consumeLastToken(); | - | ||||||||||||||||||||||||
629 | - | |||||||||||||||||||||||||
630 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
631 | qDebug("QTextStreamPrivate::read() maxlen = %d, token length = %d", maxlen, ret.length()); | - | ||||||||||||||||||||||||
632 | #endif | - | ||||||||||||||||||||||||
633 | return ret; executed 1876 times by 2 tests: return ret; Executed by:
| 1876 | ||||||||||||||||||||||||
634 | } | - | ||||||||||||||||||||||||
635 | - | |||||||||||||||||||||||||
636 | /*! | - | ||||||||||||||||||||||||
637 | \internal | - | ||||||||||||||||||||||||
638 | - | |||||||||||||||||||||||||
639 | Scans no more than \a maxlen QChars in the current buffer for the | - | ||||||||||||||||||||||||
640 | first \a delimiter. Stores a pointer to the start offset of the | - | ||||||||||||||||||||||||
641 | token in \a ptr, and the length in QChars in \a length. | - | ||||||||||||||||||||||||
642 | */ | - | ||||||||||||||||||||||||
643 | bool QTextStreamPrivate::scan(const QChar **ptr, int *length, int maxlen, TokenDelimiter delimiter) | - | ||||||||||||||||||||||||
644 | { | - | ||||||||||||||||||||||||
645 | int totalSize = 0; | - | ||||||||||||||||||||||||
646 | int delimSize = 0; | - | ||||||||||||||||||||||||
647 | bool consumeDelimiter = false; | - | ||||||||||||||||||||||||
648 | bool foundToken = false; | - | ||||||||||||||||||||||||
649 | int startOffset = device ? readBufferOffset : stringOffset;
| 24207-183757 | ||||||||||||||||||||||||
650 | QChar lastChar; | - | ||||||||||||||||||||||||
651 | - | |||||||||||||||||||||||||
652 | bool canStillReadFromDevice = true; | - | ||||||||||||||||||||||||
653 | do { | - | ||||||||||||||||||||||||
654 | int endOffset; | - | ||||||||||||||||||||||||
655 | const QChar *chPtr; | - | ||||||||||||||||||||||||
656 | if (device) {
| 24207-186688 | ||||||||||||||||||||||||
657 | chPtr = readBuffer.constData(); | - | ||||||||||||||||||||||||
658 | endOffset = readBuffer.size(); | - | ||||||||||||||||||||||||
659 | } else { executed 186688 times by 16 tests: end of block Executed by:
| 186688 | ||||||||||||||||||||||||
660 | chPtr = string->constData(); | - | ||||||||||||||||||||||||
661 | endOffset = string->size(); | - | ||||||||||||||||||||||||
662 | } executed 24207 times by 4 tests: end of block Executed by:
| 24207 | ||||||||||||||||||||||||
663 | chPtr += startOffset; | - | ||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||
665 | for (; !foundToken && startOffset < endOffset && (!maxlen || totalSize < maxlen); ++startOffset) {
| 10-4219026 | ||||||||||||||||||||||||
666 | const QChar ch = *chPtr++; | - | ||||||||||||||||||||||||
667 | ++totalSize; | - | ||||||||||||||||||||||||
668 | - | |||||||||||||||||||||||||
669 | switch (delimiter) { | - | ||||||||||||||||||||||||
670 | case Space: executed 5982 times by 4 tests: case Space: Executed by:
| 5982 | ||||||||||||||||||||||||
671 | if (ch.isSpace()) {
| 424-5558 | ||||||||||||||||||||||||
672 | foundToken = true; | - | ||||||||||||||||||||||||
673 | delimSize = 1; | - | ||||||||||||||||||||||||
674 | } executed 424 times by 3 tests: end of block Executed by:
| 424 | ||||||||||||||||||||||||
675 | break; executed 5982 times by 4 tests: break; Executed by:
| 5982 | ||||||||||||||||||||||||
676 | case NotSpace: executed 63851 times by 4 tests: case NotSpace: Executed by:
| 63851 | ||||||||||||||||||||||||
677 | if (!ch.isSpace()) {
| 22940-40911 | ||||||||||||||||||||||||
678 | foundToken = true; | - | ||||||||||||||||||||||||
679 | delimSize = 1; | - | ||||||||||||||||||||||||
680 | } executed 22940 times by 4 tests: end of block Executed by:
| 22940 | ||||||||||||||||||||||||
681 | break; executed 63851 times by 4 tests: break; Executed by:
| 63851 | ||||||||||||||||||||||||
682 | case EndOfLine: executed 4145979 times by 14 tests: case EndOfLine: Executed by:
| 4145979 | ||||||||||||||||||||||||
683 | if (ch == QLatin1Char('\n')) {
| 184317-3961028 | ||||||||||||||||||||||||
684 | foundToken = true; | - | ||||||||||||||||||||||||
685 | delimSize = (lastChar == QLatin1Char('\r')) ? 2 : 1;
| 75386-108931 | ||||||||||||||||||||||||
686 | consumeDelimiter = true; | - | ||||||||||||||||||||||||
687 | } executed 184317 times by 13 tests: end of block Executed by:
| 184317 | ||||||||||||||||||||||||
688 | lastChar = ch; | - | ||||||||||||||||||||||||
689 | break; executed 4145979 times by 14 tests: break; Executed by:
| 4145979 | ||||||||||||||||||||||||
690 | } | - | ||||||||||||||||||||||||
691 | } executed 4215812 times by 17 tests: end of block Executed by:
| 4215812 | ||||||||||||||||||||||||
692 | } while (!foundToken executed 210895 times by 17 tests: end of block Executed by:
| 3214-210895 | ||||||||||||||||||||||||
693 | && (!maxlen || totalSize < maxlen)
| 12-3186 | ||||||||||||||||||||||||
694 | && (device && (canStillReadFromDevice = fillReadBuffer())));
| 28-3174 | ||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||
696 | if (totalSize == 0) {
| 79-207885 | ||||||||||||||||||||||||
697 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
698 | qDebug("QTextStreamPrivate::scan() reached the end of input."); | - | ||||||||||||||||||||||||
699 | #endif | - | ||||||||||||||||||||||||
700 | return false; executed 79 times by 1 test: return false; Executed by:
| 79 | ||||||||||||||||||||||||
701 | } | - | ||||||||||||||||||||||||
702 | - | |||||||||||||||||||||||||
703 | // if we find a '\r' at the end of the data when reading lines, | - | ||||||||||||||||||||||||
704 | // don't make it part of the line. | - | ||||||||||||||||||||||||
705 | if (delimiter == EndOfLine && totalSize > 0 && !foundToken) {
| 0-184393 | ||||||||||||||||||||||||
706 | if (((string && stringOffset + totalSize == string->size()) || (device && device->atEnd()))
| 2-55 | ||||||||||||||||||||||||
707 | && lastChar == QLatin1Char('\r')) {
| 11-58 | ||||||||||||||||||||||||
708 | consumeDelimiter = true; | - | ||||||||||||||||||||||||
709 | ++delimSize; | - | ||||||||||||||||||||||||
710 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||||||||
711 | } executed 76 times by 4 tests: end of block Executed by:
| 76 | ||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | // set the read offset and length of the token | - | ||||||||||||||||||||||||
714 | if (length)
| 23039-184846 | ||||||||||||||||||||||||
715 | *length = totalSize - delimSize; executed 184846 times by 17 tests: *length = totalSize - delimSize; Executed by:
| 184846 | ||||||||||||||||||||||||
716 | if (ptr)
| 23039-184846 | ||||||||||||||||||||||||
717 | *ptr = readPtr(); executed 184846 times by 17 tests: *ptr = readPtr(); Executed by:
| 184846 | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | // update last token size. the callee will call consumeLastToken() when | - | ||||||||||||||||||||||||
720 | // done. | - | ||||||||||||||||||||||||
721 | lastTokenSize = totalSize; | - | ||||||||||||||||||||||||
722 | if (!consumeDelimiter)
| 23557-184328 | ||||||||||||||||||||||||
723 | lastTokenSize -= delimSize; executed 23557 times by 7 tests: lastTokenSize -= delimSize; Executed by:
| 23557 | ||||||||||||||||||||||||
724 | - | |||||||||||||||||||||||||
725 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
726 | qDebug("QTextStreamPrivate::scan(%p, %p, %d, %x) token length = %d, delimiter = %d", | - | ||||||||||||||||||||||||
727 | ptr, length, maxlen, (int)delimiter, totalSize - delimSize, delimSize); | - | ||||||||||||||||||||||||
728 | #endif | - | ||||||||||||||||||||||||
729 | return true; executed 207885 times by 17 tests: return true; Executed by:
| 207885 | ||||||||||||||||||||||||
730 | } | - | ||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | /*! | - | ||||||||||||||||||||||||
733 | \internal | - | ||||||||||||||||||||||||
734 | */ | - | ||||||||||||||||||||||||
735 | inline const QChar *QTextStreamPrivate::readPtr() const | - | ||||||||||||||||||||||||
736 | { | - | ||||||||||||||||||||||||
737 | Q_ASSERT(readBufferOffset <= readBuffer.size()); | - | ||||||||||||||||||||||||
738 | if (string)
| 24368-230094 | ||||||||||||||||||||||||
739 | return string->constData() + stringOffset; executed 24368 times by 4 tests: return string->constData() + stringOffset; Executed by:
| 24368 | ||||||||||||||||||||||||
740 | return readBuffer.constData() + readBufferOffset; executed 230094 times by 16 tests: return readBuffer.constData() + readBufferOffset; Executed by:
| 230094 | ||||||||||||||||||||||||
741 | } | - | ||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||
743 | /*! | - | ||||||||||||||||||||||||
744 | \internal | - | ||||||||||||||||||||||||
745 | */ | - | ||||||||||||||||||||||||
746 | inline void QTextStreamPrivate::consumeLastToken() | - | ||||||||||||||||||||||||
747 | { | - | ||||||||||||||||||||||||
748 | if (lastTokenSize)
| 867-208110 | ||||||||||||||||||||||||
749 | consume(lastTokenSize); executed 208110 times by 18 tests: consume(lastTokenSize); Executed by:
| 208110 | ||||||||||||||||||||||||
750 | lastTokenSize = 0; | - | ||||||||||||||||||||||||
751 | } executed 208977 times by 18 tests: end of block Executed by:
| 208977 | ||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||
753 | /*! | - | ||||||||||||||||||||||||
754 | \internal | - | ||||||||||||||||||||||||
755 | */ | - | ||||||||||||||||||||||||
756 | inline void QTextStreamPrivate::consume(int size) | - | ||||||||||||||||||||||||
757 | { | - | ||||||||||||||||||||||||
758 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
759 | qDebug("QTextStreamPrivate::consume(%d)", size); | - | ||||||||||||||||||||||||
760 | #endif | - | ||||||||||||||||||||||||
761 | if (string) {
| 24412-253314 | ||||||||||||||||||||||||
762 | stringOffset += size; | - | ||||||||||||||||||||||||
763 | if (stringOffset > string->size())
| 0-24412 | ||||||||||||||||||||||||
764 | stringOffset = string->size(); never executed: stringOffset = string->size(); | 0 | ||||||||||||||||||||||||
765 | } else { executed 24412 times by 4 tests: end of block Executed by:
| 24412 | ||||||||||||||||||||||||
766 | readBufferOffset += size; | - | ||||||||||||||||||||||||
767 | if (readBufferOffset >= readBuffer.size()) {
| 2698-250616 | ||||||||||||||||||||||||
768 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
769 | readBuffer.clear(); | - | ||||||||||||||||||||||||
770 | saveConverterState(device->pos()); | - | ||||||||||||||||||||||||
771 | } else if (readBufferOffset > QTEXTSTREAM_BUFFERSIZE) { executed 2698 times by 16 tests: end of block Executed by:
| 1301-249315 | ||||||||||||||||||||||||
772 | readBuffer = readBuffer.remove(0,readBufferOffset); | - | ||||||||||||||||||||||||
773 | readConverterSavedStateOffset += readBufferOffset; | - | ||||||||||||||||||||||||
774 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
775 | } executed 1301 times by 3 tests: end of block Executed by:
| 1301 | ||||||||||||||||||||||||
776 | } executed 253314 times by 17 tests: end of block Executed by:
| 253314 | ||||||||||||||||||||||||
777 | } | - | ||||||||||||||||||||||||
778 | - | |||||||||||||||||||||||||
779 | /*! | - | ||||||||||||||||||||||||
780 | \internal | - | ||||||||||||||||||||||||
781 | */ | - | ||||||||||||||||||||||||
782 | inline void QTextStreamPrivate::saveConverterState(qint64 newPos) | - | ||||||||||||||||||||||||
783 | { | - | ||||||||||||||||||||||||
784 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
785 | if (readConverterState.d) {
| 0-2698 | ||||||||||||||||||||||||
786 | // converter cannot be copied, so don't save anything | - | ||||||||||||||||||||||||
787 | // don't update readBufferStartDevicePos either | - | ||||||||||||||||||||||||
788 | return; never executed: return; | 0 | ||||||||||||||||||||||||
789 | } | - | ||||||||||||||||||||||||
790 | - | |||||||||||||||||||||||||
791 | if (!readConverterSavedState)
| 32-2666 | ||||||||||||||||||||||||
792 | readConverterSavedState = new QTextCodec::ConverterState; executed 2666 times by 16 tests: readConverterSavedState = new QTextCodec::ConverterState; Executed by:
| 2666 | ||||||||||||||||||||||||
793 | copyConverterStateHelper(readConverterSavedState, &readConverterState); | - | ||||||||||||||||||||||||
794 | #endif | - | ||||||||||||||||||||||||
795 | - | |||||||||||||||||||||||||
796 | readBufferStartDevicePos = newPos; | - | ||||||||||||||||||||||||
797 | readConverterSavedStateOffset = 0; | - | ||||||||||||||||||||||||
798 | } executed 2698 times by 16 tests: end of block Executed by:
| 2698 | ||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||
800 | /*! | - | ||||||||||||||||||||||||
801 | \internal | - | ||||||||||||||||||||||||
802 | */ | - | ||||||||||||||||||||||||
803 | inline void QTextStreamPrivate::restoreToSavedConverterState() | - | ||||||||||||||||||||||||
804 | { | - | ||||||||||||||||||||||||
805 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
806 | if (readConverterSavedState) {
| 0-1775 | ||||||||||||||||||||||||
807 | // we have a saved state | - | ||||||||||||||||||||||||
808 | // that means the converter can be copied | - | ||||||||||||||||||||||||
809 | copyConverterStateHelper(&readConverterState, readConverterSavedState); | - | ||||||||||||||||||||||||
810 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
811 | // the only state we could save was the initial | - | ||||||||||||||||||||||||
812 | // so reset to that | - | ||||||||||||||||||||||||
813 | resetCodecConverterStateHelper(&readConverterState); | - | ||||||||||||||||||||||||
814 | } executed 1775 times by 1 test: end of block Executed by:
| 1775 | ||||||||||||||||||||||||
815 | #endif | - | ||||||||||||||||||||||||
816 | } | - | ||||||||||||||||||||||||
817 | - | |||||||||||||||||||||||||
818 | /*! | - | ||||||||||||||||||||||||
819 | \internal | - | ||||||||||||||||||||||||
820 | */ | - | ||||||||||||||||||||||||
821 | void QTextStreamPrivate::write(const QChar *data, int len) | - | ||||||||||||||||||||||||
822 | { | - | ||||||||||||||||||||||||
823 | if (string) {
| 37490-160957 | ||||||||||||||||||||||||
824 | // ### What about seek()?? | - | ||||||||||||||||||||||||
825 | string->append(data, len); | - | ||||||||||||||||||||||||
826 | } else { executed 160957 times by 81 tests: end of block Executed by:
| 160957 | ||||||||||||||||||||||||
827 | writeBuffer.append(data, len); | - | ||||||||||||||||||||||||
828 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 4-37486 | ||||||||||||||||||||||||
829 | flushWriteBuffer(); executed 4 times by 2 tests: flushWriteBuffer(); Executed by:
| 4 | ||||||||||||||||||||||||
830 | } executed 37490 times by 13 tests: end of block Executed by:
| 37490 | ||||||||||||||||||||||||
831 | } | - | ||||||||||||||||||||||||
832 | - | |||||||||||||||||||||||||
833 | /*! | - | ||||||||||||||||||||||||
834 | \internal | - | ||||||||||||||||||||||||
835 | */ | - | ||||||||||||||||||||||||
836 | inline void QTextStreamPrivate::write(QChar ch) | - | ||||||||||||||||||||||||
837 | { | - | ||||||||||||||||||||||||
838 | if (string) {
| 63096-93254 | ||||||||||||||||||||||||
839 | // ### What about seek()?? | - | ||||||||||||||||||||||||
840 | string->append(ch); | - | ||||||||||||||||||||||||
841 | } else { executed 93254 times by 77 tests: end of block Executed by:
| 93254 | ||||||||||||||||||||||||
842 | writeBuffer += ch; | - | ||||||||||||||||||||||||
843 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 0-63096 | ||||||||||||||||||||||||
844 | flushWriteBuffer(); never executed: flushWriteBuffer(); | 0 | ||||||||||||||||||||||||
845 | } executed 63096 times by 11 tests: end of block Executed by:
| 63096 | ||||||||||||||||||||||||
846 | } | - | ||||||||||||||||||||||||
847 | - | |||||||||||||||||||||||||
848 | /*! | - | ||||||||||||||||||||||||
849 | \internal | - | ||||||||||||||||||||||||
850 | */ | - | ||||||||||||||||||||||||
851 | void QTextStreamPrivate::write(QLatin1String data) | - | ||||||||||||||||||||||||
852 | { | - | ||||||||||||||||||||||||
853 | if (string) {
| 26241-41270 | ||||||||||||||||||||||||
854 | // ### What about seek()?? | - | ||||||||||||||||||||||||
855 | string->append(data); | - | ||||||||||||||||||||||||
856 | } else { executed 41270 times by 19 tests: end of block Executed by:
| 41270 | ||||||||||||||||||||||||
857 | writeBuffer += data; | - | ||||||||||||||||||||||||
858 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 0-26241 | ||||||||||||||||||||||||
859 | flushWriteBuffer(); never executed: flushWriteBuffer(); | 0 | ||||||||||||||||||||||||
860 | } executed 26241 times by 14 tests: end of block Executed by:
| 26241 | ||||||||||||||||||||||||
861 | } | - | ||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||
863 | /*! | - | ||||||||||||||||||||||||
864 | \internal | - | ||||||||||||||||||||||||
865 | */ | - | ||||||||||||||||||||||||
866 | inline bool QTextStreamPrivate::getChar(QChar *ch) | - | ||||||||||||||||||||||||
867 | { | - | ||||||||||||||||||||||||
868 | if ((string && stringOffset == string->size())
| 11-69793 | ||||||||||||||||||||||||
869 | || (device && readBuffer.isEmpty() && !fillReadBuffer())) {
| 1-69793 | ||||||||||||||||||||||||
870 | if (ch)
| 0-427 | ||||||||||||||||||||||||
871 | *ch = 0; executed 427 times by 2 tests: *ch = 0; Executed by:
| 427 | ||||||||||||||||||||||||
872 | return false; executed 427 times by 2 tests: return false; Executed by:
| 427 | ||||||||||||||||||||||||
873 | } | - | ||||||||||||||||||||||||
874 | if (ch)
| 0-69616 | ||||||||||||||||||||||||
875 | *ch = *readPtr(); executed 69616 times by 3 tests: *ch = *readPtr(); Executed by:
| 69616 | ||||||||||||||||||||||||
876 | consume(1); | - | ||||||||||||||||||||||||
877 | return true; executed 69616 times by 3 tests: return true; Executed by:
| 69616 | ||||||||||||||||||||||||
878 | } | - | ||||||||||||||||||||||||
879 | - | |||||||||||||||||||||||||
880 | /*! | - | ||||||||||||||||||||||||
881 | \internal | - | ||||||||||||||||||||||||
882 | */ | - | ||||||||||||||||||||||||
883 | inline void QTextStreamPrivate::ungetChar(QChar ch) | - | ||||||||||||||||||||||||
884 | { | - | ||||||||||||||||||||||||
885 | if (string) {
| 51-39049 | ||||||||||||||||||||||||
886 | if (stringOffset == 0)
| 0-51 | ||||||||||||||||||||||||
887 | string->prepend(ch); never executed: string->prepend(ch); | 0 | ||||||||||||||||||||||||
888 | else | - | ||||||||||||||||||||||||
889 | (*string)[--stringOffset] = ch; executed 51 times by 2 tests: (*string)[--stringOffset] = ch; Executed by:
| 51 | ||||||||||||||||||||||||
890 | return; executed 51 times by 2 tests: return; Executed by:
| 51 | ||||||||||||||||||||||||
891 | } | - | ||||||||||||||||||||||||
892 | - | |||||||||||||||||||||||||
893 | if (readBufferOffset == 0) {
| 45-39004 | ||||||||||||||||||||||||
894 | readBuffer.prepend(ch); | - | ||||||||||||||||||||||||
895 | return; executed 45 times by 2 tests: return; Executed by:
| 45 | ||||||||||||||||||||||||
896 | } | - | ||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||
898 | readBuffer[--readBufferOffset] = ch; | - | ||||||||||||||||||||||||
899 | } executed 39004 times by 2 tests: end of block Executed by:
| 39004 | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | /*! | - | ||||||||||||||||||||||||
902 | \internal | - | ||||||||||||||||||||||||
903 | */ | - | ||||||||||||||||||||||||
904 | inline void QTextStreamPrivate::putChar(QChar ch) | - | ||||||||||||||||||||||||
905 | { | - | ||||||||||||||||||||||||
906 | if (params.fieldWidth > 0)
| 2004-156350 | ||||||||||||||||||||||||
907 | putString(&ch, 1); executed 2004 times by 2 tests: putString(&ch, 1); Executed by:
| 2004 | ||||||||||||||||||||||||
908 | else | - | ||||||||||||||||||||||||
909 | write(ch); executed 156350 times by 85 tests: write(ch); Executed by:
| 156350 | ||||||||||||||||||||||||
910 | } | - | ||||||||||||||||||||||||
911 | - | |||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | /*! | - | ||||||||||||||||||||||||
914 | \internal | - | ||||||||||||||||||||||||
915 | */ | - | ||||||||||||||||||||||||
916 | QTextStreamPrivate::PaddingResult QTextStreamPrivate::padding(int len) const | - | ||||||||||||||||||||||||
917 | { | - | ||||||||||||||||||||||||
918 | Q_ASSERT(params.fieldWidth > len); // calling padding() when no padding is needed is an error | - | ||||||||||||||||||||||||
919 | - | |||||||||||||||||||||||||
920 | // Do NOT break NRVO in this function or kittens will die! | - | ||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||
922 | PaddingResult result; | - | ||||||||||||||||||||||||
923 | - | |||||||||||||||||||||||||
924 | const int padSize = params.fieldWidth - len; | - | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | result.padding.resize(padSize); | - | ||||||||||||||||||||||||
927 | std::fill_n(result.padding.begin(), padSize, params.padChar); | - | ||||||||||||||||||||||||
928 | - | |||||||||||||||||||||||||
929 | switch (params.fieldAlignment) { | - | ||||||||||||||||||||||||
930 | case QTextStream::AlignLeft: never executed: case QTextStream::AlignLeft: | 0 | ||||||||||||||||||||||||
931 | result.left = 0; | - | ||||||||||||||||||||||||
932 | result.right = padSize; | - | ||||||||||||||||||||||||
933 | break; never executed: break; | 0 | ||||||||||||||||||||||||
934 | case QTextStream::AlignRight: executed 2235 times by 4 tests: case QTextStream::AlignRight: Executed by:
| 2235 | ||||||||||||||||||||||||
935 | case QTextStream::AlignAccountingStyle: executed 4 times by 1 test: case QTextStream::AlignAccountingStyle: Executed by:
| 4 | ||||||||||||||||||||||||
936 | result.left = padSize; | - | ||||||||||||||||||||||||
937 | result.right = 0; | - | ||||||||||||||||||||||||
938 | break; executed 2239 times by 4 tests: break; Executed by:
| 2239 | ||||||||||||||||||||||||
939 | case QTextStream::AlignCenter: never executed: case QTextStream::AlignCenter: | 0 | ||||||||||||||||||||||||
940 | result.left = padSize/2; | - | ||||||||||||||||||||||||
941 | result.right = padSize - padSize/2; | - | ||||||||||||||||||||||||
942 | break; never executed: break; | 0 | ||||||||||||||||||||||||
943 | } | - | ||||||||||||||||||||||||
944 | - | |||||||||||||||||||||||||
945 | return result; executed 2239 times by 4 tests: return result; Executed by:
| 2239 | ||||||||||||||||||||||||
946 | } | - | ||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||
948 | /*! | - | ||||||||||||||||||||||||
949 | \internal | - | ||||||||||||||||||||||||
950 | */ | - | ||||||||||||||||||||||||
951 | void QTextStreamPrivate::putString(const QChar *data, int len, bool number) | - | ||||||||||||||||||||||||
952 | { | - | ||||||||||||||||||||||||
953 | if (Q_UNLIKELY(params.fieldWidth > len)) {
| 2237-147691 | ||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | // handle padding: | - | ||||||||||||||||||||||||
956 | - | |||||||||||||||||||||||||
957 | const PaddingResult pad = padding(len); | - | ||||||||||||||||||||||||
958 | - | |||||||||||||||||||||||||
959 | if (params.fieldAlignment == QTextStream::AlignAccountingStyle && number) {
| 0-2235 | ||||||||||||||||||||||||
960 | const QChar sign = len > 0 ? data[0] : QChar();
| 0-2 | ||||||||||||||||||||||||
961 | if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
| 0-2 | ||||||||||||||||||||||||
962 | // write the sign before the padding, then skip it later | - | ||||||||||||||||||||||||
963 | write(&sign, 1); | - | ||||||||||||||||||||||||
964 | ++data; | - | ||||||||||||||||||||||||
965 | --len; | - | ||||||||||||||||||||||||
966 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
967 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
968 | - | |||||||||||||||||||||||||
969 | write(pad.padding.constData(), pad.left); | - | ||||||||||||||||||||||||
970 | write(data, len); | - | ||||||||||||||||||||||||
971 | write(pad.padding.constData(), pad.right); | - | ||||||||||||||||||||||||
972 | } else { executed 2237 times by 4 tests: end of block Executed by:
| 2237 | ||||||||||||||||||||||||
973 | write(data, len); | - | ||||||||||||||||||||||||
974 | } executed 147879 times by 88 tests: end of block Executed by:
| 147879 | ||||||||||||||||||||||||
975 | } | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | /*! | - | ||||||||||||||||||||||||
978 | \internal | - | ||||||||||||||||||||||||
979 | */ | - | ||||||||||||||||||||||||
980 | void QTextStreamPrivate::putString(QLatin1String data, bool number) | - | ||||||||||||||||||||||||
981 | { | - | ||||||||||||||||||||||||
982 | if (Q_UNLIKELY(params.fieldWidth > data.size())) {
| 2-67509 | ||||||||||||||||||||||||
983 | - | |||||||||||||||||||||||||
984 | // handle padding | - | ||||||||||||||||||||||||
985 | - | |||||||||||||||||||||||||
986 | const PaddingResult pad = padding(data.size()); | - | ||||||||||||||||||||||||
987 | - | |||||||||||||||||||||||||
988 | if (params.fieldAlignment == QTextStream::AlignAccountingStyle && number) {
| 0-2 | ||||||||||||||||||||||||
989 | const QChar sign = data.size() > 0 ? QLatin1Char(*data.data()) : QChar();
| 0 | ||||||||||||||||||||||||
990 | if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
| 0 | ||||||||||||||||||||||||
991 | // write the sign before the padding, then skip it later | - | ||||||||||||||||||||||||
992 | write(&sign, 1); | - | ||||||||||||||||||||||||
993 | data = QLatin1String(data.data() + 1, data.size() - 1); | - | ||||||||||||||||||||||||
994 | } never executed: end of block | 0 | ||||||||||||||||||||||||
995 | } never executed: end of block | 0 | ||||||||||||||||||||||||
996 | - | |||||||||||||||||||||||||
997 | write(pad.padding.constData(), pad.left); | - | ||||||||||||||||||||||||
998 | write(data); | - | ||||||||||||||||||||||||
999 | write(pad.padding.constData(), pad.right); | - | ||||||||||||||||||||||||
1000 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1001 | write(data); | - | ||||||||||||||||||||||||
1002 | } executed 67509 times by 30 tests: end of block Executed by:
| 67509 | ||||||||||||||||||||||||
1003 | } | - | ||||||||||||||||||||||||
1004 | - | |||||||||||||||||||||||||
1005 | /*! | - | ||||||||||||||||||||||||
1006 | Constructs a QTextStream. Before you can use it for reading or | - | ||||||||||||||||||||||||
1007 | writing, you must assign a device or a string. | - | ||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||
1009 | \sa setDevice(), setString() | - | ||||||||||||||||||||||||
1010 | */ | - | ||||||||||||||||||||||||
1011 | QTextStream::QTextStream() | - | ||||||||||||||||||||||||
1012 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1013 | { | - | ||||||||||||||||||||||||
1014 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1015 | qDebug("QTextStream::QTextStream()"); | - | ||||||||||||||||||||||||
1016 | #endif | - | ||||||||||||||||||||||||
1017 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1018 | d->status = Ok; | - | ||||||||||||||||||||||||
1019 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | /*! | - | ||||||||||||||||||||||||
1022 | Constructs a QTextStream that operates on \a device. | - | ||||||||||||||||||||||||
1023 | */ | - | ||||||||||||||||||||||||
1024 | QTextStream::QTextStream(QIODevice *device) | - | ||||||||||||||||||||||||
1025 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1026 | { | - | ||||||||||||||||||||||||
1027 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1028 | qDebug("QTextStream::QTextStream(QIODevice *device == *%p)", | - | ||||||||||||||||||||||||
1029 | device); | - | ||||||||||||||||||||||||
1030 | #endif | - | ||||||||||||||||||||||||
1031 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1032 | d->device = device; | - | ||||||||||||||||||||||||
1033 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1034 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
1035 | #endif | - | ||||||||||||||||||||||||
1036 | d->status = Ok; | - | ||||||||||||||||||||||||
1037 | } executed 2874 times by 22 tests: end of block Executed by:
| 2874 | ||||||||||||||||||||||||
1038 | - | |||||||||||||||||||||||||
1039 | /*! | - | ||||||||||||||||||||||||
1040 | Constructs a QTextStream that operates on \a string, using \a | - | ||||||||||||||||||||||||
1041 | openMode to define the open mode. | - | ||||||||||||||||||||||||
1042 | */ | - | ||||||||||||||||||||||||
1043 | QTextStream::QTextStream(QString *string, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
1044 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1045 | { | - | ||||||||||||||||||||||||
1046 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1047 | qDebug("QTextStream::QTextStream(QString *string == *%p, openMode = %d)", | - | ||||||||||||||||||||||||
1048 | string, int(openMode)); | - | ||||||||||||||||||||||||
1049 | #endif | - | ||||||||||||||||||||||||
1050 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1051 | d->string = string; | - | ||||||||||||||||||||||||
1052 | d->stringOpenMode = openMode; | - | ||||||||||||||||||||||||
1053 | d->status = Ok; | - | ||||||||||||||||||||||||
1054 | } executed 75100 times by 82 tests: end of block Executed by:
| 75100 | ||||||||||||||||||||||||
1055 | - | |||||||||||||||||||||||||
1056 | /*! | - | ||||||||||||||||||||||||
1057 | Constructs a QTextStream that operates on \a array, using \a | - | ||||||||||||||||||||||||
1058 | openMode to define the open mode. Internally, the array is wrapped | - | ||||||||||||||||||||||||
1059 | by a QBuffer. | - | ||||||||||||||||||||||||
1060 | */ | - | ||||||||||||||||||||||||
1061 | QTextStream::QTextStream(QByteArray *array, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
1062 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1063 | { | - | ||||||||||||||||||||||||
1064 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1065 | qDebug("QTextStream::QTextStream(QByteArray *array == *%p, openMode = %d)", | - | ||||||||||||||||||||||||
1066 | array, int(openMode)); | - | ||||||||||||||||||||||||
1067 | #endif | - | ||||||||||||||||||||||||
1068 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1069 | d->device = new QBuffer(array); | - | ||||||||||||||||||||||||
1070 | d->device->open(openMode); | - | ||||||||||||||||||||||||
1071 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
1072 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1073 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
1074 | #endif | - | ||||||||||||||||||||||||
1075 | d->status = Ok; | - | ||||||||||||||||||||||||
1076 | } executed 830 times by 6 tests: end of block Executed by:
| 830 | ||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||
1078 | /*! | - | ||||||||||||||||||||||||
1079 | Constructs a QTextStream that operates on \a array, using \a | - | ||||||||||||||||||||||||
1080 | openMode to define the open mode. The array is accessed as | - | ||||||||||||||||||||||||
1081 | read-only, regardless of the values in \a openMode. | - | ||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||
1083 | This constructor is convenient for working on constant | - | ||||||||||||||||||||||||
1084 | strings. Example: | - | ||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||
1086 | \snippet code/src_corelib_io_qtextstream.cpp 3 | - | ||||||||||||||||||||||||
1087 | */ | - | ||||||||||||||||||||||||
1088 | QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
1089 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1090 | { | - | ||||||||||||||||||||||||
1091 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1092 | qDebug("QTextStream::QTextStream(const QByteArray &array == *(%p), openMode = %d)", | - | ||||||||||||||||||||||||
1093 | &array, int(openMode)); | - | ||||||||||||||||||||||||
1094 | #endif | - | ||||||||||||||||||||||||
1095 | QBuffer *buffer = new QBuffer; | - | ||||||||||||||||||||||||
1096 | buffer->setData(array); | - | ||||||||||||||||||||||||
1097 | buffer->open(openMode); | - | ||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||
1099 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1100 | d->device = buffer; | - | ||||||||||||||||||||||||
1101 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
1102 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1103 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
1104 | #endif | - | ||||||||||||||||||||||||
1105 | d->status = Ok; | - | ||||||||||||||||||||||||
1106 | } executed 16 times by 3 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
1107 | - | |||||||||||||||||||||||||
1108 | /*! | - | ||||||||||||||||||||||||
1109 | Constructs a QTextStream that operates on \a fileHandle, using \a | - | ||||||||||||||||||||||||
1110 | openMode to define the open mode. Internally, a QFile is created | - | ||||||||||||||||||||||||
1111 | to handle the FILE pointer. | - | ||||||||||||||||||||||||
1112 | - | |||||||||||||||||||||||||
1113 | This constructor is useful for working directly with the common | - | ||||||||||||||||||||||||
1114 | FILE based input and output streams: stdin, stdout and stderr. Example: | - | ||||||||||||||||||||||||
1115 | - | |||||||||||||||||||||||||
1116 | \snippet code/src_corelib_io_qtextstream.cpp 4 | - | ||||||||||||||||||||||||
1117 | */ | - | ||||||||||||||||||||||||
1118 | - | |||||||||||||||||||||||||
1119 | QTextStream::QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
1120 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
1121 | { | - | ||||||||||||||||||||||||
1122 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1123 | qDebug("QTextStream::QTextStream(FILE *fileHandle = %p, openMode = %d)", | - | ||||||||||||||||||||||||
1124 | fileHandle, int(openMode)); | - | ||||||||||||||||||||||||
1125 | #endif | - | ||||||||||||||||||||||||
1126 | QFile *file = new QFile; | - | ||||||||||||||||||||||||
1127 | file->open(fileHandle, openMode); | - | ||||||||||||||||||||||||
1128 | - | |||||||||||||||||||||||||
1129 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1130 | d->device = file; | - | ||||||||||||||||||||||||
1131 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
1132 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1133 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
1134 | #endif | - | ||||||||||||||||||||||||
1135 | d->status = Ok; | - | ||||||||||||||||||||||||
1136 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1137 | - | |||||||||||||||||||||||||
1138 | /*! | - | ||||||||||||||||||||||||
1139 | Destroys the QTextStream. | - | ||||||||||||||||||||||||
1140 | - | |||||||||||||||||||||||||
1141 | If the stream operates on a device, flush() will be called | - | ||||||||||||||||||||||||
1142 | implicitly. Otherwise, the device is unaffected. | - | ||||||||||||||||||||||||
1143 | */ | - | ||||||||||||||||||||||||
1144 | QTextStream::~QTextStream() | - | ||||||||||||||||||||||||
1145 | { | - | ||||||||||||||||||||||||
1146 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1147 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
1148 | qDebug("QTextStream::~QTextStream()"); | - | ||||||||||||||||||||||||
1149 | #endif | - | ||||||||||||||||||||||||
1150 | if (!d->writeBuffer.isEmpty())
| 21-78814 | ||||||||||||||||||||||||
1151 | d->flushWriteBuffer(); executed 21 times by 4 tests: d->flushWriteBuffer(); Executed by:
| 21 | ||||||||||||||||||||||||
1152 | } executed 78835 times by 98 tests: end of block Executed by:
| 78835 | ||||||||||||||||||||||||
1153 | - | |||||||||||||||||||||||||
1154 | /*! | - | ||||||||||||||||||||||||
1155 | Resets QTextStream's formatting options, bringing it back to its | - | ||||||||||||||||||||||||
1156 | original constructed state. The device, string and any buffered | - | ||||||||||||||||||||||||
1157 | data is left untouched. | - | ||||||||||||||||||||||||
1158 | */ | - | ||||||||||||||||||||||||
1159 | void QTextStream::reset() | - | ||||||||||||||||||||||||
1160 | { | - | ||||||||||||||||||||||||
1161 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1162 | - | |||||||||||||||||||||||||
1163 | d->params.reset(); | - | ||||||||||||||||||||||||
1164 | } executed 924 times by 13 tests: end of block Executed by:
| 924 | ||||||||||||||||||||||||
1165 | - | |||||||||||||||||||||||||
1166 | /*! | - | ||||||||||||||||||||||||
1167 | Flushes any buffered data waiting to be written to the device. | - | ||||||||||||||||||||||||
1168 | - | |||||||||||||||||||||||||
1169 | If QTextStream operates on a string, this function does nothing. | - | ||||||||||||||||||||||||
1170 | */ | - | ||||||||||||||||||||||||
1171 | void QTextStream::flush() | - | ||||||||||||||||||||||||
1172 | { | - | ||||||||||||||||||||||||
1173 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1174 | d->flushWriteBuffer(); | - | ||||||||||||||||||||||||
1175 | } executed 75666 times by 21 tests: end of block Executed by:
| 75666 | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | /*! | - | ||||||||||||||||||||||||
1178 | Seeks to the position \a pos in the device. Returns \c true on | - | ||||||||||||||||||||||||
1179 | success; otherwise returns \c false. | - | ||||||||||||||||||||||||
1180 | */ | - | ||||||||||||||||||||||||
1181 | bool QTextStream::seek(qint64 pos) | - | ||||||||||||||||||||||||
1182 | { | - | ||||||||||||||||||||||||
1183 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1184 | d->lastTokenSize = 0; | - | ||||||||||||||||||||||||
1185 | - | |||||||||||||||||||||||||
1186 | if (d->device) {
| 47-214471 | ||||||||||||||||||||||||
1187 | // Empty the write buffer | - | ||||||||||||||||||||||||
1188 | d->flushWriteBuffer(); | - | ||||||||||||||||||||||||
1189 | if (!d->device->seek(pos))
| 0-214471 | ||||||||||||||||||||||||
1190 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1191 | d->resetReadBuffer(); | - | ||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||
1193 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
1194 | // Reset the codec converter states. | - | ||||||||||||||||||||||||
1195 | resetCodecConverterStateHelper(&d->readConverterState); | - | ||||||||||||||||||||||||
1196 | resetCodecConverterStateHelper(&d->writeConverterState); | - | ||||||||||||||||||||||||
1197 | delete d->readConverterSavedState; | - | ||||||||||||||||||||||||
1198 | d->readConverterSavedState = 0; | - | ||||||||||||||||||||||||
1199 | d->writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
1200 | #endif | - | ||||||||||||||||||||||||
1201 | return true; executed 214471 times by 1 test: return true; Executed by:
| 214471 | ||||||||||||||||||||||||
1202 | } | - | ||||||||||||||||||||||||
1203 | - | |||||||||||||||||||||||||
1204 | // string | - | ||||||||||||||||||||||||
1205 | if (d->string && pos <= d->string->size()) {
| 0-47 | ||||||||||||||||||||||||
1206 | d->stringOffset = int(pos); | - | ||||||||||||||||||||||||
1207 | return true; executed 47 times by 1 test: return true; Executed by:
| 47 | ||||||||||||||||||||||||
1208 | } | - | ||||||||||||||||||||||||
1209 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1210 | } | - | ||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||
1212 | /*! | - | ||||||||||||||||||||||||
1213 | \since 4.2 | - | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | Returns the device position corresponding to the current position of the | - | ||||||||||||||||||||||||
1216 | stream, or -1 if an error occurs (e.g., if there is no device or string, | - | ||||||||||||||||||||||||
1217 | or if there's a device error). | - | ||||||||||||||||||||||||
1218 | - | |||||||||||||||||||||||||
1219 | Because QTextStream is buffered, this function may have to | - | ||||||||||||||||||||||||
1220 | seek the device to reconstruct a valid device position. This | - | ||||||||||||||||||||||||
1221 | operation can be expensive, so you may want to avoid calling this | - | ||||||||||||||||||||||||
1222 | function in a tight loop. | - | ||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||
1224 | \sa seek() | - | ||||||||||||||||||||||||
1225 | */ | - | ||||||||||||||||||||||||
1226 | qint64 QTextStream::pos() const | - | ||||||||||||||||||||||||
1227 | { | - | ||||||||||||||||||||||||
1228 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1229 | if (d->device) {
| 36-216444 | ||||||||||||||||||||||||
1230 | // Cutoff | - | ||||||||||||||||||||||||
1231 | if (d->readBuffer.isEmpty())
| 1775-214669 | ||||||||||||||||||||||||
1232 | return d->device->pos(); executed 214669 times by 1 test: return d->device->pos(); Executed by:
| 214669 | ||||||||||||||||||||||||
1233 | if (d->device->isSequential())
| 0-1775 | ||||||||||||||||||||||||
1234 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1235 | - | |||||||||||||||||||||||||
1236 | // Seek the device | - | ||||||||||||||||||||||||
1237 | if (!d->device->seek(d->readBufferStartDevicePos))
| 0-1775 | ||||||||||||||||||||||||
1238 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||
1240 | // Reset the read buffer | - | ||||||||||||||||||||||||
1241 | QTextStreamPrivate *thatd = const_cast<QTextStreamPrivate *>(d); | - | ||||||||||||||||||||||||
1242 | thatd->readBuffer.clear(); | - | ||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||
1244 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
1245 | thatd->restoreToSavedConverterState(); | - | ||||||||||||||||||||||||
1246 | if (d->readBufferStartDevicePos == 0)
| 15-1760 | ||||||||||||||||||||||||
1247 | thatd->autoDetectUnicode = true; executed 1760 times by 1 test: thatd->autoDetectUnicode = true; Executed by:
| 1760 | ||||||||||||||||||||||||
1248 | #endif | - | ||||||||||||||||||||||||
1249 | - | |||||||||||||||||||||||||
1250 | // Rewind the device to get to the current position Ensure that | - | ||||||||||||||||||||||||
1251 | // readBufferOffset is unaffected by fillReadBuffer() | - | ||||||||||||||||||||||||
1252 | int oldReadBufferOffset = d->readBufferOffset + d->readConverterSavedStateOffset; | - | ||||||||||||||||||||||||
1253 | while (d->readBuffer.size() < oldReadBufferOffset) {
| 1775-41035294 | ||||||||||||||||||||||||
1254 | if (!thatd->fillReadBuffer(1))
| 0-41035294 | ||||||||||||||||||||||||
1255 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
1256 | } executed 41035294 times by 1 test: end of block Executed by:
| 41035294 | ||||||||||||||||||||||||
1257 | thatd->readBufferOffset = oldReadBufferOffset; | - | ||||||||||||||||||||||||
1258 | thatd->readConverterSavedStateOffset = 0; | - | ||||||||||||||||||||||||
1259 | - | |||||||||||||||||||||||||
1260 | // Return the device position. | - | ||||||||||||||||||||||||
1261 | return d->device->pos(); executed 1775 times by 1 test: return d->device->pos(); Executed by:
| 1775 | ||||||||||||||||||||||||
1262 | } | - | ||||||||||||||||||||||||
1263 | - | |||||||||||||||||||||||||
1264 | if (d->string)
| 0-36 | ||||||||||||||||||||||||
1265 | return d->stringOffset; executed 36 times by 1 test: return d->stringOffset; Executed by:
| 36 | ||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||
1267 | qWarning("QTextStream::pos: no device"); | - | ||||||||||||||||||||||||
1268 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
1269 | } | - | ||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||
1271 | /*! | - | ||||||||||||||||||||||||
1272 | Reads and discards whitespace from the stream until either a | - | ||||||||||||||||||||||||
1273 | non-space character is detected, or until atEnd() returns | - | ||||||||||||||||||||||||
1274 | true. This function is useful when reading a stream character by | - | ||||||||||||||||||||||||
1275 | character. | - | ||||||||||||||||||||||||
1276 | - | |||||||||||||||||||||||||
1277 | Whitespace characters are all characters for which | - | ||||||||||||||||||||||||
1278 | QChar::isSpace() returns \c true. | - | ||||||||||||||||||||||||
1279 | - | |||||||||||||||||||||||||
1280 | \sa operator>>() | - | ||||||||||||||||||||||||
1281 | */ | - | ||||||||||||||||||||||||
1282 | void QTextStream::skipWhiteSpace() | - | ||||||||||||||||||||||||
1283 | { | - | ||||||||||||||||||||||||
1284 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1285 | CHECK_VALID_STREAM(Q_VOID); never executed: return ;
| 0-405 | ||||||||||||||||||||||||
1286 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
1287 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
1288 | } executed 408 times by 2 tests: end of block Executed by:
| 408 | ||||||||||||||||||||||||
1289 | - | |||||||||||||||||||||||||
1290 | /*! | - | ||||||||||||||||||||||||
1291 | Sets the current device to \a device. If a device has already been | - | ||||||||||||||||||||||||
1292 | assigned, QTextStream will call flush() before the old device is | - | ||||||||||||||||||||||||
1293 | replaced. | - | ||||||||||||||||||||||||
1294 | - | |||||||||||||||||||||||||
1295 | \note This function resets locale to the default locale ('C') | - | ||||||||||||||||||||||||
1296 | and codec to the default codec, QTextCodec::codecForLocale(). | - | ||||||||||||||||||||||||
1297 | - | |||||||||||||||||||||||||
1298 | \sa device(), setString() | - | ||||||||||||||||||||||||
1299 | */ | - | ||||||||||||||||||||||||
1300 | void QTextStream::setDevice(QIODevice *device) | - | ||||||||||||||||||||||||
1301 | { | - | ||||||||||||||||||||||||
1302 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1303 | flush(); | - | ||||||||||||||||||||||||
1304 | if (d->deleteDevice) {
| 1-10 | ||||||||||||||||||||||||
1305 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1306 | d->deviceClosedNotifier.disconnect(); | - | ||||||||||||||||||||||||
1307 | #endif | - | ||||||||||||||||||||||||
1308 | delete d->device; | - | ||||||||||||||||||||||||
1309 | d->deleteDevice = false; | - | ||||||||||||||||||||||||
1310 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
1311 | - | |||||||||||||||||||||||||
1312 | d->reset(); | - | ||||||||||||||||||||||||
1313 | d->status = Ok; | - | ||||||||||||||||||||||||
1314 | d->device = device; | - | ||||||||||||||||||||||||
1315 | d->resetReadBuffer(); | - | ||||||||||||||||||||||||
1316 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1317 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
1318 | #endif | - | ||||||||||||||||||||||||
1319 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||||||||
1320 | - | |||||||||||||||||||||||||
1321 | /*! | - | ||||||||||||||||||||||||
1322 | Returns the current device associated with the QTextStream, | - | ||||||||||||||||||||||||
1323 | or 0 if no device has been assigned. | - | ||||||||||||||||||||||||
1324 | - | |||||||||||||||||||||||||
1325 | \sa setDevice(), string() | - | ||||||||||||||||||||||||
1326 | */ | - | ||||||||||||||||||||||||
1327 | QIODevice *QTextStream::device() const | - | ||||||||||||||||||||||||
1328 | { | - | ||||||||||||||||||||||||
1329 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1330 | return d->device; executed 3 times by 1 test: return d->device; Executed by:
| 3 | ||||||||||||||||||||||||
1331 | } | - | ||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||
1333 | /*! | - | ||||||||||||||||||||||||
1334 | Sets the current string to \a string, using the given \a | - | ||||||||||||||||||||||||
1335 | openMode. If a device has already been assigned, QTextStream will | - | ||||||||||||||||||||||||
1336 | call flush() before replacing it. | - | ||||||||||||||||||||||||
1337 | - | |||||||||||||||||||||||||
1338 | \sa string(), setDevice() | - | ||||||||||||||||||||||||
1339 | */ | - | ||||||||||||||||||||||||
1340 | void QTextStream::setString(QString *string, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
1341 | { | - | ||||||||||||||||||||||||
1342 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1343 | flush(); | - | ||||||||||||||||||||||||
1344 | if (d->deleteDevice) {
| 0-7 | ||||||||||||||||||||||||
1345 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
1346 | d->deviceClosedNotifier.disconnect(); | - | ||||||||||||||||||||||||
1347 | d->device->blockSignals(true); | - | ||||||||||||||||||||||||
1348 | #endif | - | ||||||||||||||||||||||||
1349 | delete d->device; | - | ||||||||||||||||||||||||
1350 | d->deleteDevice = false; | - | ||||||||||||||||||||||||
1351 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1352 | - | |||||||||||||||||||||||||
1353 | d->reset(); | - | ||||||||||||||||||||||||
1354 | d->status = Ok; | - | ||||||||||||||||||||||||
1355 | d->string = string; | - | ||||||||||||||||||||||||
1356 | d->stringOpenMode = openMode; | - | ||||||||||||||||||||||||
1357 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
1358 | - | |||||||||||||||||||||||||
1359 | /*! | - | ||||||||||||||||||||||||
1360 | Returns the current string assigned to the QTextStream, or 0 if no | - | ||||||||||||||||||||||||
1361 | string has been assigned. | - | ||||||||||||||||||||||||
1362 | - | |||||||||||||||||||||||||
1363 | \sa setString(), device() | - | ||||||||||||||||||||||||
1364 | */ | - | ||||||||||||||||||||||||
1365 | QString *QTextStream::string() const | - | ||||||||||||||||||||||||
1366 | { | - | ||||||||||||||||||||||||
1367 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1368 | return d->string; executed 1 time by 1 test: return d->string; Executed by:
| 1 | ||||||||||||||||||||||||
1369 | } | - | ||||||||||||||||||||||||
1370 | - | |||||||||||||||||||||||||
1371 | /*! | - | ||||||||||||||||||||||||
1372 | Sets the field alignment to \a mode. When used together with | - | ||||||||||||||||||||||||
1373 | setFieldWidth(), this function allows you to generate formatted | - | ||||||||||||||||||||||||
1374 | output with text aligned to the left, to the right or center | - | ||||||||||||||||||||||||
1375 | aligned. | - | ||||||||||||||||||||||||
1376 | - | |||||||||||||||||||||||||
1377 | \sa fieldAlignment(), setFieldWidth() | - | ||||||||||||||||||||||||
1378 | */ | - | ||||||||||||||||||||||||
1379 | void QTextStream::setFieldAlignment(FieldAlignment mode) | - | ||||||||||||||||||||||||
1380 | { | - | ||||||||||||||||||||||||
1381 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1382 | d->params.fieldAlignment = mode; | - | ||||||||||||||||||||||||
1383 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||||||||
1384 | - | |||||||||||||||||||||||||
1385 | /*! | - | ||||||||||||||||||||||||
1386 | Returns the current field alignment. | - | ||||||||||||||||||||||||
1387 | - | |||||||||||||||||||||||||
1388 | \sa setFieldAlignment(), fieldWidth() | - | ||||||||||||||||||||||||
1389 | */ | - | ||||||||||||||||||||||||
1390 | QTextStream::FieldAlignment QTextStream::fieldAlignment() const | - | ||||||||||||||||||||||||
1391 | { | - | ||||||||||||||||||||||||
1392 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1393 | return d->params.fieldAlignment; executed 4 times by 1 test: return d->params.fieldAlignment; Executed by:
| 4 | ||||||||||||||||||||||||
1394 | } | - | ||||||||||||||||||||||||
1395 | - | |||||||||||||||||||||||||
1396 | /*! | - | ||||||||||||||||||||||||
1397 | Sets the pad character to \a ch. The default value is the ASCII | - | ||||||||||||||||||||||||
1398 | space character (' '), or QChar(0x20). This character is used to | - | ||||||||||||||||||||||||
1399 | fill in the space in fields when generating text. | - | ||||||||||||||||||||||||
1400 | - | |||||||||||||||||||||||||
1401 | Example: | - | ||||||||||||||||||||||||
1402 | - | |||||||||||||||||||||||||
1403 | \snippet code/src_corelib_io_qtextstream.cpp 5 | - | ||||||||||||||||||||||||
1404 | - | |||||||||||||||||||||||||
1405 | The string \c s contains: | - | ||||||||||||||||||||||||
1406 | - | |||||||||||||||||||||||||
1407 | \snippet code/src_corelib_io_qtextstream.cpp 6 | - | ||||||||||||||||||||||||
1408 | - | |||||||||||||||||||||||||
1409 | \sa padChar(), setFieldWidth() | - | ||||||||||||||||||||||||
1410 | */ | - | ||||||||||||||||||||||||
1411 | void QTextStream::setPadChar(QChar ch) | - | ||||||||||||||||||||||||
1412 | { | - | ||||||||||||||||||||||||
1413 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1414 | d->params.padChar = ch; | - | ||||||||||||||||||||||||
1415 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||||||||
1416 | - | |||||||||||||||||||||||||
1417 | /*! | - | ||||||||||||||||||||||||
1418 | Returns the current pad character. | - | ||||||||||||||||||||||||
1419 | - | |||||||||||||||||||||||||
1420 | \sa setPadChar(), setFieldWidth() | - | ||||||||||||||||||||||||
1421 | */ | - | ||||||||||||||||||||||||
1422 | QChar QTextStream::padChar() const | - | ||||||||||||||||||||||||
1423 | { | - | ||||||||||||||||||||||||
1424 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1425 | return d->params.padChar; executed 2 times by 1 test: return d->params.padChar; Executed by:
| 2 | ||||||||||||||||||||||||
1426 | } | - | ||||||||||||||||||||||||
1427 | - | |||||||||||||||||||||||||
1428 | /*! | - | ||||||||||||||||||||||||
1429 | Sets the current field width to \a width. If \a width is 0 (the | - | ||||||||||||||||||||||||
1430 | default), the field width is equal to the length of the generated | - | ||||||||||||||||||||||||
1431 | text. | - | ||||||||||||||||||||||||
1432 | - | |||||||||||||||||||||||||
1433 | \note The field width applies to every element appended to this | - | ||||||||||||||||||||||||
1434 | stream after this function has been called (e.g., it also pads | - | ||||||||||||||||||||||||
1435 | endl). This behavior is different from similar classes in the STL, | - | ||||||||||||||||||||||||
1436 | where the field width only applies to the next element. | - | ||||||||||||||||||||||||
1437 | - | |||||||||||||||||||||||||
1438 | \sa fieldWidth(), setPadChar() | - | ||||||||||||||||||||||||
1439 | */ | - | ||||||||||||||||||||||||
1440 | void QTextStream::setFieldWidth(int width) | - | ||||||||||||||||||||||||
1441 | { | - | ||||||||||||||||||||||||
1442 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1443 | d->params.fieldWidth = width; | - | ||||||||||||||||||||||||
1444 | } executed 31 times by 4 tests: end of block Executed by:
| 31 | ||||||||||||||||||||||||
1445 | - | |||||||||||||||||||||||||
1446 | /*! | - | ||||||||||||||||||||||||
1447 | Returns the current field width. | - | ||||||||||||||||||||||||
1448 | - | |||||||||||||||||||||||||
1449 | \sa setFieldWidth() | - | ||||||||||||||||||||||||
1450 | */ | - | ||||||||||||||||||||||||
1451 | int QTextStream::fieldWidth() const | - | ||||||||||||||||||||||||
1452 | { | - | ||||||||||||||||||||||||
1453 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1454 | return d->params.fieldWidth; executed 3 times by 1 test: return d->params.fieldWidth; Executed by:
| 3 | ||||||||||||||||||||||||
1455 | } | - | ||||||||||||||||||||||||
1456 | - | |||||||||||||||||||||||||
1457 | /*! | - | ||||||||||||||||||||||||
1458 | Sets the current number flags to \a flags. \a flags is a set of | - | ||||||||||||||||||||||||
1459 | flags from the NumberFlag enum, and describes options for | - | ||||||||||||||||||||||||
1460 | formatting generated code (e.g., whether or not to always write | - | ||||||||||||||||||||||||
1461 | the base or sign of a number). | - | ||||||||||||||||||||||||
1462 | - | |||||||||||||||||||||||||
1463 | \sa numberFlags(), setIntegerBase(), setRealNumberNotation() | - | ||||||||||||||||||||||||
1464 | */ | - | ||||||||||||||||||||||||
1465 | void QTextStream::setNumberFlags(NumberFlags flags) | - | ||||||||||||||||||||||||
1466 | { | - | ||||||||||||||||||||||||
1467 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1468 | d->params.numberFlags = flags; | - | ||||||||||||||||||||||||
1469 | } executed 103 times by 4 tests: end of block Executed by:
| 103 | ||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||
1471 | /*! | - | ||||||||||||||||||||||||
1472 | Returns the current number flags. | - | ||||||||||||||||||||||||
1473 | - | |||||||||||||||||||||||||
1474 | \sa setNumberFlags(), integerBase(), realNumberNotation() | - | ||||||||||||||||||||||||
1475 | */ | - | ||||||||||||||||||||||||
1476 | QTextStream::NumberFlags QTextStream::numberFlags() const | - | ||||||||||||||||||||||||
1477 | { | - | ||||||||||||||||||||||||
1478 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1479 | return d->params.numberFlags; executed 1624 times by 10 tests: return d->params.numberFlags; Executed by:
| 1624 | ||||||||||||||||||||||||
1480 | } | - | ||||||||||||||||||||||||
1481 | - | |||||||||||||||||||||||||
1482 | /*! | - | ||||||||||||||||||||||||
1483 | Sets the base of integers to \a base, both for reading and for | - | ||||||||||||||||||||||||
1484 | generating numbers. \a base can be either 2 (binary), 8 (octal), | - | ||||||||||||||||||||||||
1485 | 10 (decimal) or 16 (hexadecimal). If \a base is 0, QTextStream | - | ||||||||||||||||||||||||
1486 | will attempt to detect the base by inspecting the data on the | - | ||||||||||||||||||||||||
1487 | stream. When generating numbers, QTextStream assumes base is 10 | - | ||||||||||||||||||||||||
1488 | unless the base has been set explicitly. | - | ||||||||||||||||||||||||
1489 | - | |||||||||||||||||||||||||
1490 | \sa integerBase(), QString::number(), setNumberFlags() | - | ||||||||||||||||||||||||
1491 | */ | - | ||||||||||||||||||||||||
1492 | void QTextStream::setIntegerBase(int base) | - | ||||||||||||||||||||||||
1493 | { | - | ||||||||||||||||||||||||
1494 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1495 | d->params.integerBase = base; | - | ||||||||||||||||||||||||
1496 | } executed 240 times by 7 tests: end of block Executed by:
| 240 | ||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||
1498 | /*! | - | ||||||||||||||||||||||||
1499 | Returns the current base of integers. 0 means that the base is | - | ||||||||||||||||||||||||
1500 | detected when reading, or 10 (decimal) when generating numbers. | - | ||||||||||||||||||||||||
1501 | - | |||||||||||||||||||||||||
1502 | \sa setIntegerBase(), QString::number(), numberFlags() | - | ||||||||||||||||||||||||
1503 | */ | - | ||||||||||||||||||||||||
1504 | int QTextStream::integerBase() const | - | ||||||||||||||||||||||||
1505 | { | - | ||||||||||||||||||||||||
1506 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1507 | return d->params.integerBase; executed 3 times by 1 test: return d->params.integerBase; Executed by:
| 3 | ||||||||||||||||||||||||
1508 | } | - | ||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||
1510 | /*! | - | ||||||||||||||||||||||||
1511 | Sets the real number notation to \a notation (SmartNotation, | - | ||||||||||||||||||||||||
1512 | FixedNotation, ScientificNotation). When reading and generating | - | ||||||||||||||||||||||||
1513 | numbers, QTextStream uses this value to detect the formatting of | - | ||||||||||||||||||||||||
1514 | real numbers. | - | ||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | \sa realNumberNotation(), setRealNumberPrecision(), setNumberFlags(), setIntegerBase() | - | ||||||||||||||||||||||||
1517 | */ | - | ||||||||||||||||||||||||
1518 | void QTextStream::setRealNumberNotation(RealNumberNotation notation) | - | ||||||||||||||||||||||||
1519 | { | - | ||||||||||||||||||||||||
1520 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1521 | d->params.realNumberNotation = notation; | - | ||||||||||||||||||||||||
1522 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||
1524 | /*! | - | ||||||||||||||||||||||||
1525 | Returns the current real number notation. | - | ||||||||||||||||||||||||
1526 | - | |||||||||||||||||||||||||
1527 | \sa setRealNumberNotation(), realNumberPrecision(), numberFlags(), integerBase() | - | ||||||||||||||||||||||||
1528 | */ | - | ||||||||||||||||||||||||
1529 | QTextStream::RealNumberNotation QTextStream::realNumberNotation() const | - | ||||||||||||||||||||||||
1530 | { | - | ||||||||||||||||||||||||
1531 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1532 | return d->params.realNumberNotation; executed 309 times by 9 tests: return d->params.realNumberNotation; Executed by:
| 309 | ||||||||||||||||||||||||
1533 | } | - | ||||||||||||||||||||||||
1534 | - | |||||||||||||||||||||||||
1535 | /*! | - | ||||||||||||||||||||||||
1536 | Sets the precision of real numbers to \a precision. This value | - | ||||||||||||||||||||||||
1537 | describes the number of fraction digits QTextStream should | - | ||||||||||||||||||||||||
1538 | write when generating real numbers. | - | ||||||||||||||||||||||||
1539 | - | |||||||||||||||||||||||||
1540 | The precision cannot be a negative value. The default value is 6. | - | ||||||||||||||||||||||||
1541 | - | |||||||||||||||||||||||||
1542 | \sa realNumberPrecision(), setRealNumberNotation() | - | ||||||||||||||||||||||||
1543 | */ | - | ||||||||||||||||||||||||
1544 | void QTextStream::setRealNumberPrecision(int precision) | - | ||||||||||||||||||||||||
1545 | { | - | ||||||||||||||||||||||||
1546 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1547 | if (precision < 0) {
| 2-10 | ||||||||||||||||||||||||
1548 | qWarning("QTextStream::setRealNumberPrecision: Invalid precision (%d)", precision); | - | ||||||||||||||||||||||||
1549 | d->params.realNumberPrecision = 6; | - | ||||||||||||||||||||||||
1550 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
1551 | } | - | ||||||||||||||||||||||||
1552 | d->params.realNumberPrecision = precision; | - | ||||||||||||||||||||||||
1553 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||
1555 | /*! | - | ||||||||||||||||||||||||
1556 | Returns the current real number precision, or the number of fraction | - | ||||||||||||||||||||||||
1557 | digits QTextStream will write when generating real numbers. | - | ||||||||||||||||||||||||
1558 | - | |||||||||||||||||||||||||
1559 | \sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase() | - | ||||||||||||||||||||||||
1560 | */ | - | ||||||||||||||||||||||||
1561 | int QTextStream::realNumberPrecision() const | - | ||||||||||||||||||||||||
1562 | { | - | ||||||||||||||||||||||||
1563 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1564 | return d->params.realNumberPrecision; executed 3 times by 1 test: return d->params.realNumberPrecision; Executed by:
| 3 | ||||||||||||||||||||||||
1565 | } | - | ||||||||||||||||||||||||
1566 | - | |||||||||||||||||||||||||
1567 | /*! | - | ||||||||||||||||||||||||
1568 | Returns the status of the text stream. | - | ||||||||||||||||||||||||
1569 | - | |||||||||||||||||||||||||
1570 | \sa QTextStream::Status, setStatus(), resetStatus() | - | ||||||||||||||||||||||||
1571 | */ | - | ||||||||||||||||||||||||
1572 | - | |||||||||||||||||||||||||
1573 | QTextStream::Status QTextStream::status() const | - | ||||||||||||||||||||||||
1574 | { | - | ||||||||||||||||||||||||
1575 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1576 | return d->status; executed 17141 times by 4 tests: return d->status; Executed by:
| 17141 | ||||||||||||||||||||||||
1577 | } | - | ||||||||||||||||||||||||
1578 | - | |||||||||||||||||||||||||
1579 | /*! | - | ||||||||||||||||||||||||
1580 | \since 4.1 | - | ||||||||||||||||||||||||
1581 | - | |||||||||||||||||||||||||
1582 | Resets the status of the text stream. | - | ||||||||||||||||||||||||
1583 | - | |||||||||||||||||||||||||
1584 | \sa QTextStream::Status, status(), setStatus() | - | ||||||||||||||||||||||||
1585 | */ | - | ||||||||||||||||||||||||
1586 | void QTextStream::resetStatus() | - | ||||||||||||||||||||||||
1587 | { | - | ||||||||||||||||||||||||
1588 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1589 | d->status = Ok; | - | ||||||||||||||||||||||||
1590 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
1591 | - | |||||||||||||||||||||||||
1592 | /*! | - | ||||||||||||||||||||||||
1593 | \since 4.1 | - | ||||||||||||||||||||||||
1594 | - | |||||||||||||||||||||||||
1595 | Sets the status of the text stream to the \a status given. | - | ||||||||||||||||||||||||
1596 | - | |||||||||||||||||||||||||
1597 | Subsequent calls to setStatus() are ignored until resetStatus() | - | ||||||||||||||||||||||||
1598 | is called. | - | ||||||||||||||||||||||||
1599 | - | |||||||||||||||||||||||||
1600 | \sa Status, status(), resetStatus() | - | ||||||||||||||||||||||||
1601 | */ | - | ||||||||||||||||||||||||
1602 | void QTextStream::setStatus(Status status) | - | ||||||||||||||||||||||||
1603 | { | - | ||||||||||||||||||||||||
1604 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1605 | if (d->status == Ok)
| 0-79 | ||||||||||||||||||||||||
1606 | d->status = status; executed 79 times by 1 test: d->status = status; Executed by:
| 79 | ||||||||||||||||||||||||
1607 | } executed 79 times by 1 test: end of block Executed by:
| 79 | ||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||
1609 | /*! | - | ||||||||||||||||||||||||
1610 | Returns \c true if there is no more data to be read from the | - | ||||||||||||||||||||||||
1611 | QTextStream; otherwise returns \c false. This is similar to, but not | - | ||||||||||||||||||||||||
1612 | the same as calling QIODevice::atEnd(), as QTextStream also takes | - | ||||||||||||||||||||||||
1613 | into account its internal Unicode buffer. | - | ||||||||||||||||||||||||
1614 | */ | - | ||||||||||||||||||||||||
1615 | bool QTextStream::atEnd() const | - | ||||||||||||||||||||||||
1616 | { | - | ||||||||||||||||||||||||
1617 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
1618 | CHECK_VALID_STREAM(true); executed 1 time by 1 test: return true; Executed by:
| 1-113676 | ||||||||||||||||||||||||
1619 | - | |||||||||||||||||||||||||
1620 | if (d->string)
| 48149-113675 | ||||||||||||||||||||||||
1621 | return d->string->size() == d->stringOffset; executed 48149 times by 3 tests: return d->string->size() == d->stringOffset; Executed by:
| 48149 | ||||||||||||||||||||||||
1622 | return d->readBuffer.isEmpty() && d->device->atEnd(); executed 113675 times by 11 tests: return d->readBuffer.isEmpty() && d->device->atEnd(); Executed by:
| 407-113675 | ||||||||||||||||||||||||
1623 | } | - | ||||||||||||||||||||||||
1624 | - | |||||||||||||||||||||||||
1625 | /*! | - | ||||||||||||||||||||||||
1626 | Reads the entire content of the stream, and returns it as a | - | ||||||||||||||||||||||||
1627 | QString. Avoid this function when working on large files, as it | - | ||||||||||||||||||||||||
1628 | will consume a significant amount of memory. | - | ||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||
1630 | Calling \l {QTextStream::readLine()}{readLine()} is better if you do not know how much data is | - | ||||||||||||||||||||||||
1631 | available. | - | ||||||||||||||||||||||||
1632 | - | |||||||||||||||||||||||||
1633 | \sa readLine() | - | ||||||||||||||||||||||||
1634 | */ | - | ||||||||||||||||||||||||
1635 | QString QTextStream::readAll() | - | ||||||||||||||||||||||||
1636 | { | - | ||||||||||||||||||||||||
1637 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1638 | CHECK_VALID_STREAM(QString()); executed 1 time by 1 test: return QString(); Executed by:
| 1-1865 | ||||||||||||||||||||||||
1639 | - | |||||||||||||||||||||||||
1640 | return d->read(INT_MAX); executed 1869 times by 2 tests: return d->read(2147483647); Executed by:
| 1869 | ||||||||||||||||||||||||
1641 | } | - | ||||||||||||||||||||||||
1642 | - | |||||||||||||||||||||||||
1643 | /*! | - | ||||||||||||||||||||||||
1644 | Reads one line of text from the stream, and returns it as a | - | ||||||||||||||||||||||||
1645 | QString. The maximum allowed line length is set to \a maxlen. If | - | ||||||||||||||||||||||||
1646 | the stream contains lines longer than this, then the lines will be | - | ||||||||||||||||||||||||
1647 | split after \a maxlen characters and returned in parts. | - | ||||||||||||||||||||||||
1648 | - | |||||||||||||||||||||||||
1649 | If \a maxlen is 0, the lines can be of any length. | - | ||||||||||||||||||||||||
1650 | - | |||||||||||||||||||||||||
1651 | The returned line has no trailing end-of-line characters ("\\n" | - | ||||||||||||||||||||||||
1652 | or "\\r\\n"), so calling QString::trimmed() can be unnecessary. | - | ||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||
1654 | If the stream has read to the end of the file, \l {QTextStream::readLine()}{readLine()} | - | ||||||||||||||||||||||||
1655 | will return a null QString. For strings, or for devices that support it, | - | ||||||||||||||||||||||||
1656 | you can explicitly test for the end of the stream using atEnd(). | - | ||||||||||||||||||||||||
1657 | - | |||||||||||||||||||||||||
1658 | \sa readAll(), QIODevice::readLine() | - | ||||||||||||||||||||||||
1659 | */ | - | ||||||||||||||||||||||||
1660 | QString QTextStream::readLine(qint64 maxlen) | - | ||||||||||||||||||||||||
1661 | { | - | ||||||||||||||||||||||||
1662 | QString line; | - | ||||||||||||||||||||||||
1663 | - | |||||||||||||||||||||||||
1664 | readLineInto(&line, maxlen); | - | ||||||||||||||||||||||||
1665 | return line; executed 154266 times by 14 tests: return line; Executed by:
| 154266 | ||||||||||||||||||||||||
1666 | } | - | ||||||||||||||||||||||||
1667 | - | |||||||||||||||||||||||||
1668 | /*! | - | ||||||||||||||||||||||||
1669 | \since 5.5 | - | ||||||||||||||||||||||||
1670 | - | |||||||||||||||||||||||||
1671 | Reads one line of text from the stream into \a line. | - | ||||||||||||||||||||||||
1672 | If \a line is 0, the read line is not stored. | - | ||||||||||||||||||||||||
1673 | - | |||||||||||||||||||||||||
1674 | The maximum allowed line length is set to \a maxlen. If | - | ||||||||||||||||||||||||
1675 | the stream contains lines longer than this, then the lines will be | - | ||||||||||||||||||||||||
1676 | split after \a maxlen characters and returned in parts. | - | ||||||||||||||||||||||||
1677 | - | |||||||||||||||||||||||||
1678 | If \a maxlen is 0, the lines can be of any length. | - | ||||||||||||||||||||||||
1679 | - | |||||||||||||||||||||||||
1680 | The resulting line has no trailing end-of-line characters ("\\n" | - | ||||||||||||||||||||||||
1681 | or "\\r\\n"), so calling QString::trimmed() can be unnecessary. | - | ||||||||||||||||||||||||
1682 | - | |||||||||||||||||||||||||
1683 | If \a line has sufficient capacity for the data that is about to be | - | ||||||||||||||||||||||||
1684 | read, this function may not need to allocate new memory. Because of | - | ||||||||||||||||||||||||
1685 | this, it can be faster than readLine(). | - | ||||||||||||||||||||||||
1686 | - | |||||||||||||||||||||||||
1687 | Returns \c false if the stream has read to the end of the file or | - | ||||||||||||||||||||||||
1688 | an error has occurred; otherwise returns \c true. The contents in | - | ||||||||||||||||||||||||
1689 | \a line before the call are discarded in any case. | - | ||||||||||||||||||||||||
1690 | - | |||||||||||||||||||||||||
1691 | \sa readAll(), QIODevice::readLine() | - | ||||||||||||||||||||||||
1692 | */ | - | ||||||||||||||||||||||||
1693 | bool QTextStream::readLineInto(QString *line, qint64 maxlen) | - | ||||||||||||||||||||||||
1694 | { | - | ||||||||||||||||||||||||
1695 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1696 | // keep in sync with CHECK_VALID_STREAM | - | ||||||||||||||||||||||||
1697 | if (!d->string && !d->device) {
| 0-160288 | ||||||||||||||||||||||||
1698 | qWarning("QTextStream: No device"); | - | ||||||||||||||||||||||||
1699 | if (line && !line->isNull())
| 0 | ||||||||||||||||||||||||
1700 | line->resize(0); never executed: line->resize(0); | 0 | ||||||||||||||||||||||||
1701 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1702 | } | - | ||||||||||||||||||||||||
1703 | - | |||||||||||||||||||||||||
1704 | const QChar *readPtr; | - | ||||||||||||||||||||||||
1705 | int length; | - | ||||||||||||||||||||||||
1706 | if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine)) {
| 14-184393 | ||||||||||||||||||||||||
1707 | if (line && !line->isNull())
| 0-14 | ||||||||||||||||||||||||
1708 | line->resize(0); executed 4 times by 1 test: line->resize(0); Executed by:
| 4 | ||||||||||||||||||||||||
1709 | return false; executed 14 times by 1 test: return false; Executed by:
| 14 | ||||||||||||||||||||||||
1710 | } | - | ||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||
1712 | if (Q_LIKELY(line))
| 1-184392 | ||||||||||||||||||||||||
1713 | line->setUnicode(readPtr, length); executed 184392 times by 14 tests: line->setUnicode(readPtr, length); Executed by:
| 184392 | ||||||||||||||||||||||||
1714 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
1715 | return true; executed 184393 times by 14 tests: return true; Executed by:
| 184393 | ||||||||||||||||||||||||
1716 | } | - | ||||||||||||||||||||||||
1717 | - | |||||||||||||||||||||||||
1718 | /*! | - | ||||||||||||||||||||||||
1719 | \since 4.1 | - | ||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||
1721 | Reads at most \a maxlen characters from the stream, and returns the data | - | ||||||||||||||||||||||||
1722 | read as a QString. | - | ||||||||||||||||||||||||
1723 | - | |||||||||||||||||||||||||
1724 | \sa readAll(), readLine(), QIODevice::read() | - | ||||||||||||||||||||||||
1725 | */ | - | ||||||||||||||||||||||||
1726 | QString QTextStream::read(qint64 maxlen) | - | ||||||||||||||||||||||||
1727 | { | - | ||||||||||||||||||||||||
1728 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
1729 | CHECK_VALID_STREAM(QString()); never executed: return QString();
| 0-8 | ||||||||||||||||||||||||
1730 | - | |||||||||||||||||||||||||
1731 | if (maxlen <= 0)
| 1-7 | ||||||||||||||||||||||||
1732 | return QString::fromLatin1(""); // empty, not null executed 1 time by 1 test: return QString::fromLatin1(""); Executed by:
| 1 | ||||||||||||||||||||||||
1733 | - | |||||||||||||||||||||||||
1734 | return d->read(int(maxlen)); executed 7 times by 1 test: return d->read(int(maxlen)); Executed by:
| 7 | ||||||||||||||||||||||||
1735 | } | - | ||||||||||||||||||||||||
1736 | - | |||||||||||||||||||||||||
1737 | /*! | - | ||||||||||||||||||||||||
1738 | \internal | - | ||||||||||||||||||||||||
1739 | */ | - | ||||||||||||||||||||||||
1740 | QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong *ret) | - | ||||||||||||||||||||||||
1741 | { | - | ||||||||||||||||||||||||
1742 | scan(0, 0, 0, NotSpace); | - | ||||||||||||||||||||||||
1743 | consumeLastToken(); | - | ||||||||||||||||||||||||
1744 | - | |||||||||||||||||||||||||
1745 | // detect int encoding | - | ||||||||||||||||||||||||
1746 | int base = params.integerBase; | - | ||||||||||||||||||||||||
1747 | if (base == 0) {
| 4875-16440 | ||||||||||||||||||||||||
1748 | QChar ch; | - | ||||||||||||||||||||||||
1749 | if (!getChar(&ch))
| 26-16414 | ||||||||||||||||||||||||
1750 | return npsInvalidPrefix; executed 26 times by 1 test: return npsInvalidPrefix; Executed by:
| 26 | ||||||||||||||||||||||||
1751 | if (ch == QLatin1Char('0')) {
| 1733-14681 | ||||||||||||||||||||||||
1752 | QChar ch2; | - | ||||||||||||||||||||||||
1753 | if (!getChar(&ch2)) {
| 6-1727 | ||||||||||||||||||||||||
1754 | // Result is the number 0 | - | ||||||||||||||||||||||||
1755 | *ret = 0; | - | ||||||||||||||||||||||||
1756 | return npsOk; executed 6 times by 1 test: return npsOk; Executed by:
| 6 | ||||||||||||||||||||||||
1757 | } | - | ||||||||||||||||||||||||
1758 | ch2 = ch2.toLower(); | - | ||||||||||||||||||||||||
1759 | - | |||||||||||||||||||||||||
1760 | if (ch2 == QLatin1Char('x')) {
| 60-1667 | ||||||||||||||||||||||||
1761 | base = 16; | - | ||||||||||||||||||||||||
1762 | } else if (ch2 == QLatin1Char('b')) { executed 60 times by 1 test: end of block Executed by:
| 42-1625 | ||||||||||||||||||||||||
1763 | base = 2; | - | ||||||||||||||||||||||||
1764 | } else if (ch2.isDigit() && ch2.digitValue() >= 0 && ch2.digitValue() <= 7) { executed 42 times by 1 test: end of block Executed by:
| 0-1601 | ||||||||||||||||||||||||
1765 | base = 8; | - | ||||||||||||||||||||||||
1766 | } else { executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||
1767 | base = 10; | - | ||||||||||||||||||||||||
1768 | } executed 1601 times by 1 test: end of block Executed by:
| 1601 | ||||||||||||||||||||||||
1769 | ungetChar(ch2); | - | ||||||||||||||||||||||||
1770 | } else if (ch == locale.negativeSign() || ch == locale.positiveSign() || ch.isDigit()) { executed 1727 times by 1 test: end of block Executed by:
| 2-14577 | ||||||||||||||||||||||||
1771 | base = 10; | - | ||||||||||||||||||||||||
1772 | } else { executed 14673 times by 2 tests: end of block Executed by:
| 14673 | ||||||||||||||||||||||||
1773 | ungetChar(ch); | - | ||||||||||||||||||||||||
1774 | return npsInvalidPrefix; executed 8 times by 1 test: return npsInvalidPrefix; Executed by:
| 8 | ||||||||||||||||||||||||
1775 | } | - | ||||||||||||||||||||||||
1776 | ungetChar(ch); | - | ||||||||||||||||||||||||
1777 | // State of the stream is now the same as on entry | - | ||||||||||||||||||||||||
1778 | // (cursor is at prefix), | - | ||||||||||||||||||||||||
1779 | // and local variable 'base' has been set appropriately. | - | ||||||||||||||||||||||||
1780 | } executed 16400 times by 2 tests: end of block Executed by:
| 16400 | ||||||||||||||||||||||||
1781 | - | |||||||||||||||||||||||||
1782 | qulonglong val=0; | - | ||||||||||||||||||||||||
1783 | switch (base) { | - | ||||||||||||||||||||||||
1784 | case 2: { executed 42 times by 1 test: case 2: Executed by:
| 42 | ||||||||||||||||||||||||
1785 | QChar pf1, pf2, dig; | - | ||||||||||||||||||||||||
1786 | // Parse prefix '0b' | - | ||||||||||||||||||||||||
1787 | if (!getChar(&pf1) || pf1 != QLatin1Char('0'))
| 0-42 | ||||||||||||||||||||||||
1788 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1789 | if (!getChar(&pf2) || pf2.toLower() != QLatin1Char('b'))
| 0-42 | ||||||||||||||||||||||||
1790 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1791 | // Parse digits | - | ||||||||||||||||||||||||
1792 | int ndigits = 0; | - | ||||||||||||||||||||||||
1793 | while (getChar(&dig)) {
| 30-156 | ||||||||||||||||||||||||
1794 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
1795 | if (n == '0' || n == '1') {
| 12-84 | ||||||||||||||||||||||||
1796 | val <<= 1; | - | ||||||||||||||||||||||||
1797 | val += n - '0'; | - | ||||||||||||||||||||||||
1798 | } else { executed 144 times by 1 test: end of block Executed by:
| 144 | ||||||||||||||||||||||||
1799 | ungetChar(dig); | - | ||||||||||||||||||||||||
1800 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||||||||
1801 | } | - | ||||||||||||||||||||||||
1802 | ndigits++; | - | ||||||||||||||||||||||||
1803 | } executed 144 times by 1 test: end of block Executed by:
| 144 | ||||||||||||||||||||||||
1804 | if (ndigits == 0) {
| 0-42 | ||||||||||||||||||||||||
1805 | // Unwind the prefix and abort | - | ||||||||||||||||||||||||
1806 | ungetChar(pf2); | - | ||||||||||||||||||||||||
1807 | ungetChar(pf1); | - | ||||||||||||||||||||||||
1808 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
1809 | } | - | ||||||||||||||||||||||||
1810 | break; executed 42 times by 1 test: break; Executed by:
| 42 | ||||||||||||||||||||||||
1811 | } | - | ||||||||||||||||||||||||
1812 | case 8: { executed 24 times by 1 test: case 8: Executed by:
| 24 | ||||||||||||||||||||||||
1813 | QChar pf, dig; | - | ||||||||||||||||||||||||
1814 | // Parse prefix '0' | - | ||||||||||||||||||||||||
1815 | if (!getChar(&pf) || pf != QLatin1Char('0'))
| 0-24 | ||||||||||||||||||||||||
1816 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1817 | // Parse digits | - | ||||||||||||||||||||||||
1818 | int ndigits = 0; | - | ||||||||||||||||||||||||
1819 | while (getChar(&dig)) {
| 12-72 | ||||||||||||||||||||||||
1820 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
1821 | if (n >= '0' && n <= '7') {
| 0-72 | ||||||||||||||||||||||||
1822 | val *= 8; | - | ||||||||||||||||||||||||
1823 | val += n - '0'; | - | ||||||||||||||||||||||||
1824 | } else { executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||||||||
1825 | ungetChar(dig); | - | ||||||||||||||||||||||||
1826 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||||||||
1827 | } | - | ||||||||||||||||||||||||
1828 | ndigits++; | - | ||||||||||||||||||||||||
1829 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||||||||
1830 | if (ndigits == 0) {
| 0-24 | ||||||||||||||||||||||||
1831 | // Unwind the prefix and abort | - | ||||||||||||||||||||||||
1832 | ungetChar(pf); | - | ||||||||||||||||||||||||
1833 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
1834 | } | - | ||||||||||||||||||||||||
1835 | break; executed 24 times by 1 test: break; Executed by:
| 24 | ||||||||||||||||||||||||
1836 | } | - | ||||||||||||||||||||||||
1837 | case 10: { executed 21149 times by 3 tests: case 10: Executed by:
| 21149 | ||||||||||||||||||||||||
1838 | // Parse sign (or first digit) | - | ||||||||||||||||||||||||
1839 | QChar sign; | - | ||||||||||||||||||||||||
1840 | int ndigits = 0; | - | ||||||||||||||||||||||||
1841 | if (!getChar(&sign))
| 0-21149 | ||||||||||||||||||||||||
1842 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
1843 | if (sign != locale.negativeSign() && sign != locale.positiveSign()) {
| 2-21045 | ||||||||||||||||||||||||
1844 | if (!sign.isDigit()) {
| 0-21043 | ||||||||||||||||||||||||
1845 | ungetChar(sign); | - | ||||||||||||||||||||||||
1846 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
1847 | } | - | ||||||||||||||||||||||||
1848 | val += sign.digitValue(); | - | ||||||||||||||||||||||||
1849 | ndigits++; | - | ||||||||||||||||||||||||
1850 | } executed 21043 times by 3 tests: end of block Executed by:
| 21043 | ||||||||||||||||||||||||
1851 | // Parse digits | - | ||||||||||||||||||||||||
1852 | QChar ch; | - | ||||||||||||||||||||||||
1853 | while (getChar(&ch)) {
| 260-28447 | ||||||||||||||||||||||||
1854 | if (ch.isDigit()) {
| 7557-20890 | ||||||||||||||||||||||||
1855 | val *= 10; | - | ||||||||||||||||||||||||
1856 | val += ch.digitValue(); | - | ||||||||||||||||||||||||
1857 | } else if (locale != QLocale::c() && ch == locale.groupSeparator()) { executed 7557 times by 3 tests: end of block Executed by:
| 0-20889 | ||||||||||||||||||||||||
1858 | continue; executed 1 time by 1 test: continue; Executed by:
| 1 | ||||||||||||||||||||||||
1859 | } else { | - | ||||||||||||||||||||||||
1860 | ungetChar(ch); | - | ||||||||||||||||||||||||
1861 | break; executed 20889 times by 3 tests: break; Executed by:
| 20889 | ||||||||||||||||||||||||
1862 | } | - | ||||||||||||||||||||||||
1863 | ndigits++; | - | ||||||||||||||||||||||||
1864 | } executed 7557 times by 3 tests: end of block Executed by:
| 7557 | ||||||||||||||||||||||||
1865 | if (ndigits == 0)
| 0-21149 | ||||||||||||||||||||||||
1866 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
1867 | if (sign == locale.negativeSign()) {
| 104-21045 | ||||||||||||||||||||||||
1868 | qlonglong ival = qlonglong(val); | - | ||||||||||||||||||||||||
1869 | if (ival > 0)
| 6-98 | ||||||||||||||||||||||||
1870 | ival = -ival; executed 98 times by 1 test: ival = -ival; Executed by:
| 98 | ||||||||||||||||||||||||
1871 | val = qulonglong(ival); | - | ||||||||||||||||||||||||
1872 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||||||||
1873 | break; executed 21149 times by 3 tests: break; Executed by:
| 21149 | ||||||||||||||||||||||||
1874 | } | - | ||||||||||||||||||||||||
1875 | case 16: { executed 60 times by 1 test: case 16: Executed by:
| 60 | ||||||||||||||||||||||||
1876 | QChar pf1, pf2, dig; | - | ||||||||||||||||||||||||
1877 | // Parse prefix ' 0x' | - | ||||||||||||||||||||||||
1878 | if (!getChar(&pf1) || pf1 != QLatin1Char('0'))
| 0-60 | ||||||||||||||||||||||||
1879 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1880 | if (!getChar(&pf2) || pf2.toLower() != QLatin1Char('x'))
| 0-60 | ||||||||||||||||||||||||
1881 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1882 | // Parse digits | - | ||||||||||||||||||||||||
1883 | int ndigits = 0; | - | ||||||||||||||||||||||||
1884 | while (getChar(&dig)) {
| 48-318 | ||||||||||||||||||||||||
1885 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
1886 | if (n >= '0' && n <= '9') {
| 0-318 | ||||||||||||||||||||||||
1887 | val <<= 4; | - | ||||||||||||||||||||||||
1888 | val += n - '0'; | - | ||||||||||||||||||||||||
1889 | } else if (n >= 'a' && n <= 'f') { executed 12 times by 1 test: end of block Executed by:
| 0-306 | ||||||||||||||||||||||||
1890 | val <<= 4; | - | ||||||||||||||||||||||||
1891 | val += 10 + (n - 'a'); | - | ||||||||||||||||||||||||
1892 | } else { executed 294 times by 1 test: end of block Executed by:
| 294 | ||||||||||||||||||||||||
1893 | ungetChar(dig); | - | ||||||||||||||||||||||||
1894 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||||||||
1895 | } | - | ||||||||||||||||||||||||
1896 | ndigits++; | - | ||||||||||||||||||||||||
1897 | } executed 306 times by 1 test: end of block Executed by:
| 306 | ||||||||||||||||||||||||
1898 | if (ndigits == 0) {
| 6-54 | ||||||||||||||||||||||||
1899 | return npsMissingDigit; executed 6 times by 1 test: return npsMissingDigit; Executed by:
| 6 | ||||||||||||||||||||||||
1900 | } | - | ||||||||||||||||||||||||
1901 | break; executed 54 times by 1 test: break; Executed by:
| 54 | ||||||||||||||||||||||||
1902 | } | - | ||||||||||||||||||||||||
1903 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1904 | // Unsupported integerBase | - | ||||||||||||||||||||||||
1905 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
1906 | } | - | ||||||||||||||||||||||||
1907 | - | |||||||||||||||||||||||||
1908 | if (ret)
| 0-21269 | ||||||||||||||||||||||||
1909 | *ret = val; executed 21269 times by 3 tests: *ret = val; Executed by:
| 21269 | ||||||||||||||||||||||||
1910 | return npsOk; executed 21269 times by 3 tests: return npsOk; Executed by:
| 21269 | ||||||||||||||||||||||||
1911 | } | - | ||||||||||||||||||||||||
1912 | - | |||||||||||||||||||||||||
1913 | /*! | - | ||||||||||||||||||||||||
1914 | \internal | - | ||||||||||||||||||||||||
1915 | (hihi) | - | ||||||||||||||||||||||||
1916 | */ | - | ||||||||||||||||||||||||
1917 | bool QTextStreamPrivate::getReal(double *f) | - | ||||||||||||||||||||||||
1918 | { | - | ||||||||||||||||||||||||
1919 | // We use a table-driven FSM to parse floating point numbers | - | ||||||||||||||||||||||||
1920 | // strtod() cannot be used directly since we may be reading from a | - | ||||||||||||||||||||||||
1921 | // QIODevice. | - | ||||||||||||||||||||||||
1922 | enum ParserState { | - | ||||||||||||||||||||||||
1923 | Init = 0, | - | ||||||||||||||||||||||||
1924 | Sign = 1, | - | ||||||||||||||||||||||||
1925 | Mantissa = 2, | - | ||||||||||||||||||||||||
1926 | Dot = 3, | - | ||||||||||||||||||||||||
1927 | Abscissa = 4, | - | ||||||||||||||||||||||||
1928 | ExpMark = 5, | - | ||||||||||||||||||||||||
1929 | ExpSign = 6, | - | ||||||||||||||||||||||||
1930 | Exponent = 7, | - | ||||||||||||||||||||||||
1931 | Nan1 = 8, | - | ||||||||||||||||||||||||
1932 | Nan2 = 9, | - | ||||||||||||||||||||||||
1933 | Inf1 = 10, | - | ||||||||||||||||||||||||
1934 | Inf2 = 11, | - | ||||||||||||||||||||||||
1935 | NanInf = 12, | - | ||||||||||||||||||||||||
1936 | Done = 13 | - | ||||||||||||||||||||||||
1937 | }; | - | ||||||||||||||||||||||||
1938 | enum InputToken { | - | ||||||||||||||||||||||||
1939 | None = 0, | - | ||||||||||||||||||||||||
1940 | InputSign = 1, | - | ||||||||||||||||||||||||
1941 | InputDigit = 2, | - | ||||||||||||||||||||||||
1942 | InputDot = 3, | - | ||||||||||||||||||||||||
1943 | InputExp = 4, | - | ||||||||||||||||||||||||
1944 | InputI = 5, | - | ||||||||||||||||||||||||
1945 | InputN = 6, | - | ||||||||||||||||||||||||
1946 | InputF = 7, | - | ||||||||||||||||||||||||
1947 | InputA = 8, | - | ||||||||||||||||||||||||
1948 | InputT = 9 | - | ||||||||||||||||||||||||
1949 | }; | - | ||||||||||||||||||||||||
1950 | - | |||||||||||||||||||||||||
1951 | static const uchar table[13][10] = { | - | ||||||||||||||||||||||||
1952 | // None InputSign InputDigit InputDot InputExp InputI InputN InputF InputA InputT | - | ||||||||||||||||||||||||
1953 | { 0, Sign, Mantissa, Dot, 0, Inf1, Nan1, 0, 0, 0 }, // 0 Init | - | ||||||||||||||||||||||||
1954 | { 0, 0, Mantissa, Dot, 0, Inf1, Nan1, 0, 0, 0 }, // 1 Sign | - | ||||||||||||||||||||||||
1955 | { Done, Done, Mantissa, Dot, ExpMark, 0, 0, 0, 0, 0 }, // 2 Mantissa | - | ||||||||||||||||||||||||
1956 | { 0, 0, Abscissa, 0, 0, 0, 0, 0, 0, 0 }, // 3 Dot | - | ||||||||||||||||||||||||
1957 | { Done, Done, Abscissa, Done, ExpMark, 0, 0, 0, 0, 0 }, // 4 Abscissa | - | ||||||||||||||||||||||||
1958 | { 0, ExpSign, Exponent, 0, 0, 0, 0, 0, 0, 0 }, // 5 ExpMark | - | ||||||||||||||||||||||||
1959 | { 0, 0, Exponent, 0, 0, 0, 0, 0, 0, 0 }, // 6 ExpSign | - | ||||||||||||||||||||||||
1960 | { Done, Done, Exponent, Done, Done, 0, 0, 0, 0, 0 }, // 7 Exponent | - | ||||||||||||||||||||||||
1961 | { 0, 0, 0, 0, 0, 0, 0, 0, Nan2, 0 }, // 8 Nan1 | - | ||||||||||||||||||||||||
1962 | { 0, 0, 0, 0, 0, 0, NanInf, 0, 0, 0 }, // 9 Nan2 | - | ||||||||||||||||||||||||
1963 | { 0, 0, 0, 0, 0, 0, Inf2, 0, 0, 0 }, // 10 Inf1 | - | ||||||||||||||||||||||||
1964 | { 0, 0, 0, 0, 0, 0, 0, NanInf, 0, 0 }, // 11 Inf2 | - | ||||||||||||||||||||||||
1965 | { Done, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 11 NanInf | - | ||||||||||||||||||||||||
1966 | }; | - | ||||||||||||||||||||||||
1967 | - | |||||||||||||||||||||||||
1968 | ParserState state = Init; | - | ||||||||||||||||||||||||
1969 | InputToken input = None; | - | ||||||||||||||||||||||||
1970 | - | |||||||||||||||||||||||||
1971 | scan(0, 0, 0, NotSpace); | - | ||||||||||||||||||||||||
1972 | consumeLastToken(); | - | ||||||||||||||||||||||||
1973 | - | |||||||||||||||||||||||||
1974 | const int BufferSize = 128; | - | ||||||||||||||||||||||||
1975 | char buf[BufferSize]; | - | ||||||||||||||||||||||||
1976 | int i = 0; | - | ||||||||||||||||||||||||
1977 | - | |||||||||||||||||||||||||
1978 | QChar c; | - | ||||||||||||||||||||||||
1979 | while (getChar(&c)) {
| 29-282 | ||||||||||||||||||||||||
1980 | switch (c.unicode()) { | - | ||||||||||||||||||||||||
1981 | case '0': case '1': case '2': case '3': case '4': executed 10 times by 1 test: case '0': Executed by:
executed 23 times by 1 test: case '1': Executed by:
executed 11 times by 1 test: case '2': Executed by:
executed 15 times by 1 test: case '3': Executed by:
executed 16 times by 1 test: case '4': Executed by:
| 10-23 | ||||||||||||||||||||||||
1982 | case '5': case '6': case '7': case '8': case '9': executed 2 times by 1 test: case '5': Executed by:
never executed: case '6': never executed: case '7': never executed: case '8': never executed: case '9': | 0-2 | ||||||||||||||||||||||||
1983 | input = InputDigit; | - | ||||||||||||||||||||||||
1984 | break; executed 77 times by 1 test: break; Executed by:
| 77 | ||||||||||||||||||||||||
1985 | case 'i': case 'I': executed 12 times by 1 test: case 'i': Executed by:
executed 6 times by 1 test: case 'I': Executed by:
| 6-12 | ||||||||||||||||||||||||
1986 | input = InputI; | - | ||||||||||||||||||||||||
1987 | break; executed 18 times by 1 test: break; Executed by:
| 18 | ||||||||||||||||||||||||
1988 | case 'n': case 'N': executed 30 times by 1 test: case 'n': Executed by:
executed 24 times by 1 test: case 'N': Executed by:
| 24-30 | ||||||||||||||||||||||||
1989 | input = InputN; | - | ||||||||||||||||||||||||
1990 | break; executed 54 times by 1 test: break; Executed by:
| 54 | ||||||||||||||||||||||||
1991 | case 'f': case 'F': executed 12 times by 1 test: case 'f': Executed by:
executed 6 times by 1 test: case 'F': Executed by:
| 6-12 | ||||||||||||||||||||||||
1992 | input = InputF; | - | ||||||||||||||||||||||||
1993 | break; executed 18 times by 1 test: break; Executed by:
| 18 | ||||||||||||||||||||||||
1994 | case 'a': case 'A': executed 9 times by 1 test: case 'a': Executed by:
executed 12 times by 1 test: case 'A': Executed by:
| 9-12 | ||||||||||||||||||||||||
1995 | input = InputA; | - | ||||||||||||||||||||||||
1996 | break; executed 21 times by 1 test: break; Executed by:
| 21 | ||||||||||||||||||||||||
1997 | case 't': case 'T': never executed: case 't': never executed: case 'T': | 0 | ||||||||||||||||||||||||
1998 | input = InputT; | - | ||||||||||||||||||||||||
1999 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2000 | default: { executed 94 times by 1 test: default: Executed by:
| 94 | ||||||||||||||||||||||||
2001 | QChar lc = c.toLower(); | - | ||||||||||||||||||||||||
2002 | if (lc == locale.decimalPoint().toLower())
| 13-81 | ||||||||||||||||||||||||
2003 | input = InputDot; executed 13 times by 1 test: input = InputDot; Executed by:
| 13 | ||||||||||||||||||||||||
2004 | else if (lc == locale.exponential().toLower())
| 8-73 | ||||||||||||||||||||||||
2005 | input = InputExp; executed 8 times by 1 test: input = InputExp; Executed by:
| 8 | ||||||||||||||||||||||||
2006 | else if (lc == locale.negativeSign().toLower()
| 20-53 | ||||||||||||||||||||||||
2007 | || lc == locale.positiveSign().toLower())
| 16-37 | ||||||||||||||||||||||||
2008 | input = InputSign; executed 36 times by 1 test: input = InputSign; Executed by:
| 36 | ||||||||||||||||||||||||
2009 | else if (locale != QLocale::c() // backward-compatibility
| 0-37 | ||||||||||||||||||||||||
2010 | && lc == locale.groupSeparator().toLower())
| 0 | ||||||||||||||||||||||||
2011 | input = InputDigit; // well, it isn't a digit, but no one cares. never executed: input = InputDigit; | 0 | ||||||||||||||||||||||||
2012 | else | - | ||||||||||||||||||||||||
2013 | input = None; executed 37 times by 1 test: input = None; Executed by:
| 37 | ||||||||||||||||||||||||
2014 | } | - | ||||||||||||||||||||||||
2015 | break; executed 94 times by 1 test: break; Executed by:
| 94 | ||||||||||||||||||||||||
2016 | } | - | ||||||||||||||||||||||||
2017 | - | |||||||||||||||||||||||||
2018 | state = ParserState(table[state][input]); | - | ||||||||||||||||||||||||
2019 | - | |||||||||||||||||||||||||
2020 | if (state == Init || state == Done || i > (BufferSize - 5)) {
| 0-279 | ||||||||||||||||||||||||
2021 | ungetChar(c); | - | ||||||||||||||||||||||||
2022 | if (i > (BufferSize - 5)) { // ignore rest of digits
| 0-40 | ||||||||||||||||||||||||
2023 | while (getChar(&c)) {
| 0 | ||||||||||||||||||||||||
2024 | if (!c.isDigit()) {
| 0 | ||||||||||||||||||||||||
2025 | ungetChar(c); | - | ||||||||||||||||||||||||
2026 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2027 | } | - | ||||||||||||||||||||||||
2028 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2029 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2030 | break; executed 40 times by 1 test: break; Executed by:
| 40 | ||||||||||||||||||||||||
2031 | } | - | ||||||||||||||||||||||||
2032 | - | |||||||||||||||||||||||||
2033 | buf[i++] = c.toLatin1(); | - | ||||||||||||||||||||||||
2034 | } executed 242 times by 1 test: end of block Executed by:
| 242 | ||||||||||||||||||||||||
2035 | - | |||||||||||||||||||||||||
2036 | if (i == 0)
| 10-59 | ||||||||||||||||||||||||
2037 | return false; executed 10 times by 1 test: return false; Executed by:
| 10 | ||||||||||||||||||||||||
2038 | if (!f)
| 0-59 | ||||||||||||||||||||||||
2039 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
2040 | buf[i] = '\0'; | - | ||||||||||||||||||||||||
2041 | - | |||||||||||||||||||||||||
2042 | // backward-compatibility. Old implementation supported +nan/-nan | - | ||||||||||||||||||||||||
2043 | // for some reason. QLocale only checks for lower-case | - | ||||||||||||||||||||||||
2044 | // nan/+inf/-inf, so here we also check for uppercase and mixed | - | ||||||||||||||||||||||||
2045 | // case versions. | - | ||||||||||||||||||||||||
2046 | if (!qstricmp(buf, "nan") || !qstricmp(buf, "+nan") || !qstricmp(buf, "-nan")) {
| 6-53 | ||||||||||||||||||||||||
2047 | *f = qSNaN(); | - | ||||||||||||||||||||||||
2048 | return true; executed 18 times by 1 test: return true; Executed by:
| 18 | ||||||||||||||||||||||||
2049 | } else if (!qstricmp(buf, "+inf") || !qstricmp(buf, "inf")) {
| 6-35 | ||||||||||||||||||||||||
2050 | *f = qInf(); | - | ||||||||||||||||||||||||
2051 | return true; executed 12 times by 1 test: return true; Executed by:
| 12 | ||||||||||||||||||||||||
2052 | } else if (!qstricmp(buf, "-inf")) {
| 6-23 | ||||||||||||||||||||||||
2053 | *f = -qInf(); | - | ||||||||||||||||||||||||
2054 | return true; executed 6 times by 1 test: return true; Executed by:
| 6 | ||||||||||||||||||||||||
2055 | } | - | ||||||||||||||||||||||||
2056 | bool ok; | - | ||||||||||||||||||||||||
2057 | *f = locale.toDouble(QString::fromLatin1(buf), &ok); | - | ||||||||||||||||||||||||
2058 | return ok; executed 23 times by 1 test: return ok; Executed by:
| 23 | ||||||||||||||||||||||||
2059 | } | - | ||||||||||||||||||||||||
2060 | - | |||||||||||||||||||||||||
2061 | /*! | - | ||||||||||||||||||||||||
2062 | Reads a character from the stream and stores it in \a c. Returns a | - | ||||||||||||||||||||||||
2063 | reference to the QTextStream, so several operators can be | - | ||||||||||||||||||||||||
2064 | nested. Example: | - | ||||||||||||||||||||||||
2065 | - | |||||||||||||||||||||||||
2066 | \snippet code/src_corelib_io_qtextstream.cpp 7 | - | ||||||||||||||||||||||||
2067 | - | |||||||||||||||||||||||||
2068 | Whitespace is \e not skipped. | - | ||||||||||||||||||||||||
2069 | */ | - | ||||||||||||||||||||||||
2070 | - | |||||||||||||||||||||||||
2071 | QTextStream &QTextStream::operator>>(QChar &c) | - | ||||||||||||||||||||||||
2072 | { | - | ||||||||||||||||||||||||
2073 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2074 | CHECK_VALID_STREAM(*this); executed 1 time by 1 test: return *this; Executed by:
| 1-830 | ||||||||||||||||||||||||
2075 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
2076 | if (!d->getChar(&c))
| 16-823 | ||||||||||||||||||||||||
2077 | setStatus(ReadPastEnd); executed 16 times by 1 test: setStatus(ReadPastEnd); Executed by:
| 16 | ||||||||||||||||||||||||
2078 | return *this; executed 839 times by 1 test: return *this; Executed by:
| 839 | ||||||||||||||||||||||||
2079 | } | - | ||||||||||||||||||||||||
2080 | - | |||||||||||||||||||||||||
2081 | /*! | - | ||||||||||||||||||||||||
2082 | \overload | - | ||||||||||||||||||||||||
2083 | - | |||||||||||||||||||||||||
2084 | Reads a character from the stream and stores it in \a c. The | - | ||||||||||||||||||||||||
2085 | character from the stream is converted to ISO-5589-1 before it is | - | ||||||||||||||||||||||||
2086 | stored. | - | ||||||||||||||||||||||||
2087 | - | |||||||||||||||||||||||||
2088 | \sa QChar::toLatin1() | - | ||||||||||||||||||||||||
2089 | */ | - | ||||||||||||||||||||||||
2090 | QTextStream &QTextStream::operator>>(char &c) | - | ||||||||||||||||||||||||
2091 | { | - | ||||||||||||||||||||||||
2092 | QChar ch; | - | ||||||||||||||||||||||||
2093 | *this >> ch; | - | ||||||||||||||||||||||||
2094 | c = ch.toLatin1(); | - | ||||||||||||||||||||||||
2095 | return *this; executed 19 times by 1 test: return *this; Executed by:
| 19 | ||||||||||||||||||||||||
2096 | } | - | ||||||||||||||||||||||||
2097 | - | |||||||||||||||||||||||||
2098 | /*! | - | ||||||||||||||||||||||||
2099 | Reads an integer from the stream and stores it in \a i, then | - | ||||||||||||||||||||||||
2100 | returns a reference to the QTextStream. The number is cast to | - | ||||||||||||||||||||||||
2101 | the correct type before it is stored. If no number was detected on | - | ||||||||||||||||||||||||
2102 | the stream, \a i is set to 0. | - | ||||||||||||||||||||||||
2103 | - | |||||||||||||||||||||||||
2104 | By default, QTextStream will attempt to detect the base of the | - | ||||||||||||||||||||||||
2105 | number using the following rules: | - | ||||||||||||||||||||||||
2106 | - | |||||||||||||||||||||||||
2107 | \table | - | ||||||||||||||||||||||||
2108 | \header \li Prefix \li Base | - | ||||||||||||||||||||||||
2109 | \row \li "0b" or "0B" \li 2 (binary) | - | ||||||||||||||||||||||||
2110 | \row \li "0" followed by "0-7" \li 8 (octal) | - | ||||||||||||||||||||||||
2111 | \row \li "0" otherwise \li 10 (decimal) | - | ||||||||||||||||||||||||
2112 | \row \li "0x" or "0X" \li 16 (hexadecimal) | - | ||||||||||||||||||||||||
2113 | \row \li "1" to "9" \li 10 (decimal) | - | ||||||||||||||||||||||||
2114 | \endtable | - | ||||||||||||||||||||||||
2115 | - | |||||||||||||||||||||||||
2116 | By calling setIntegerBase(), you can specify the integer base | - | ||||||||||||||||||||||||
2117 | explicitly. This will disable the auto-detection, and speed up | - | ||||||||||||||||||||||||
2118 | QTextStream slightly. | - | ||||||||||||||||||||||||
2119 | - | |||||||||||||||||||||||||
2120 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
2121 | */ | - | ||||||||||||||||||||||||
2122 | QTextStream &QTextStream::operator>>(signed short &i) | - | ||||||||||||||||||||||||
2123 | { | - | ||||||||||||||||||||||||
2124 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed short); never executed: return *this; executed 63 times by 1 test: break; Executed by:
executed 6 times by 1 test: break; Executed by:
executed 69 times by 1 test: return *this; Executed by:
executed 63 times by 1 test: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 5 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-69 | ||||||||||||||||||||||||
2125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2126 | - | |||||||||||||||||||||||||
2127 | /*! | - | ||||||||||||||||||||||||
2128 | \overload | - | ||||||||||||||||||||||||
2129 | - | |||||||||||||||||||||||||
2130 | Stores the integer in the unsigned short \a i. | - | ||||||||||||||||||||||||
2131 | */ | - | ||||||||||||||||||||||||
2132 | QTextStream &QTextStream::operator>>(unsigned short &i) | - | ||||||||||||||||||||||||
2133 | { | - | ||||||||||||||||||||||||
2134 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned short); never executed: return *this; executed 63 times by 1 test: break; Executed by:
executed 6 times by 1 test: break; Executed by:
executed 69 times by 1 test: return *this; Executed by:
executed 63 times by 1 test: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 5 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-69 | ||||||||||||||||||||||||
2135 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2136 | - | |||||||||||||||||||||||||
2137 | /*! | - | ||||||||||||||||||||||||
2138 | \overload | - | ||||||||||||||||||||||||
2139 | - | |||||||||||||||||||||||||
2140 | Stores the integer in the signed int \a i. | - | ||||||||||||||||||||||||
2141 | */ | - | ||||||||||||||||||||||||
2142 | QTextStream &QTextStream::operator>>(signed int &i) | - | ||||||||||||||||||||||||
2143 | { | - | ||||||||||||||||||||||||
2144 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed int); never executed: return *this; executed 20960 times by 3 tests: break; Executed by:
executed 10 times by 1 test: break; Executed by:
executed 20970 times by 3 tests: return *this; Executed by:
executed 20960 times by 3 tests: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 9 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-20970 | ||||||||||||||||||||||||
2145 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2146 | - | |||||||||||||||||||||||||
2147 | /*! | - | ||||||||||||||||||||||||
2148 | \overload | - | ||||||||||||||||||||||||
2149 | - | |||||||||||||||||||||||||
2150 | Stores the integer in the unsigned int \a i. | - | ||||||||||||||||||||||||
2151 | */ | - | ||||||||||||||||||||||||
2152 | QTextStream &QTextStream::operator>>(unsigned int &i) | - | ||||||||||||||||||||||||
2153 | { | - | ||||||||||||||||||||||||
2154 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned int); never executed: return *this; executed 63 times by 1 test: break; Executed by:
executed 6 times by 1 test: break; Executed by:
executed 69 times by 1 test: return *this; Executed by:
executed 63 times by 1 test: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 5 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-69 | ||||||||||||||||||||||||
2155 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2156 | - | |||||||||||||||||||||||||
2157 | /*! | - | ||||||||||||||||||||||||
2158 | \overload | - | ||||||||||||||||||||||||
2159 | - | |||||||||||||||||||||||||
2160 | Stores the integer in the signed long \a i. | - | ||||||||||||||||||||||||
2161 | */ | - | ||||||||||||||||||||||||
2162 | QTextStream &QTextStream::operator>>(signed long &i) | - | ||||||||||||||||||||||||
2163 | { | - | ||||||||||||||||||||||||
2164 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed long); never executed: return *this; never executed: break; never executed: break; never executed: return *this; never executed: case QTextStreamPrivate::npsOk: never executed: case QTextStreamPrivate::npsMissingDigit: never executed: case QTextStreamPrivate::npsInvalidPrefix:
| 0 | ||||||||||||||||||||||||
2165 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2166 | - | |||||||||||||||||||||||||
2167 | /*! | - | ||||||||||||||||||||||||
2168 | \overload | - | ||||||||||||||||||||||||
2169 | - | |||||||||||||||||||||||||
2170 | Stores the integer in the unsigned long \a i. | - | ||||||||||||||||||||||||
2171 | */ | - | ||||||||||||||||||||||||
2172 | QTextStream &QTextStream::operator>>(unsigned long &i) | - | ||||||||||||||||||||||||
2173 | { | - | ||||||||||||||||||||||||
2174 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned long); never executed: return *this; never executed: break; never executed: break; never executed: return *this; never executed: case QTextStreamPrivate::npsOk: never executed: case QTextStreamPrivate::npsMissingDigit: never executed: case QTextStreamPrivate::npsInvalidPrefix:
| 0 | ||||||||||||||||||||||||
2175 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2176 | - | |||||||||||||||||||||||||
2177 | /*! | - | ||||||||||||||||||||||||
2178 | \overload | - | ||||||||||||||||||||||||
2179 | - | |||||||||||||||||||||||||
2180 | Stores the integer in the qlonglong \a i. | - | ||||||||||||||||||||||||
2181 | */ | - | ||||||||||||||||||||||||
2182 | QTextStream &QTextStream::operator>>(qlonglong &i) | - | ||||||||||||||||||||||||
2183 | { | - | ||||||||||||||||||||||||
2184 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(qlonglong); never executed: return *this; executed 63 times by 1 test: break; Executed by:
executed 6 times by 1 test: break; Executed by:
executed 69 times by 1 test: return *this; Executed by:
executed 63 times by 1 test: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 5 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-69 | ||||||||||||||||||||||||
2185 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2186 | - | |||||||||||||||||||||||||
2187 | /*! | - | ||||||||||||||||||||||||
2188 | \overload | - | ||||||||||||||||||||||||
2189 | - | |||||||||||||||||||||||||
2190 | Stores the integer in the qulonglong \a i. | - | ||||||||||||||||||||||||
2191 | */ | - | ||||||||||||||||||||||||
2192 | QTextStream &QTextStream::operator>>(qulonglong &i) | - | ||||||||||||||||||||||||
2193 | { | - | ||||||||||||||||||||||||
2194 | IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(qulonglong); never executed: return *this; executed 63 times by 1 test: break; Executed by:
executed 6 times by 1 test: break; Executed by:
executed 69 times by 1 test: return *this; Executed by:
executed 63 times by 1 test: case QTextStreamPrivate::npsOk: Executed by:
executed 1 time by 1 test: case QTextStreamPrivate::npsMissingDigit: Executed by:
executed 5 times by 1 test: case QTextStreamPrivate::npsInvalidPrefix: Executed by:
| 0-69 | ||||||||||||||||||||||||
2195 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2196 | - | |||||||||||||||||||||||||
2197 | /*! | - | ||||||||||||||||||||||||
2198 | Reads a real number from the stream and stores it in \a f, then | - | ||||||||||||||||||||||||
2199 | returns a reference to the QTextStream. The number is cast to | - | ||||||||||||||||||||||||
2200 | the correct type. If no real number is detect on the stream, \a f | - | ||||||||||||||||||||||||
2201 | is set to 0.0. | - | ||||||||||||||||||||||||
2202 | - | |||||||||||||||||||||||||
2203 | As a special exception, QTextStream allows the strings "nan" and "inf" to | - | ||||||||||||||||||||||||
2204 | represent NAN and INF floats or doubles. | - | ||||||||||||||||||||||||
2205 | - | |||||||||||||||||||||||||
2206 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
2207 | */ | - | ||||||||||||||||||||||||
2208 | QTextStream &QTextStream::operator>>(float &f) | - | ||||||||||||||||||||||||
2209 | { | - | ||||||||||||||||||||||||
2210 | IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(float); never executed: return *this; executed 28 times by 1 test: end of block Executed by:
executed 4 times by 1 test: end of block Executed by:
executed 32 times by 1 test: return *this; Executed by:
| 0-32 | ||||||||||||||||||||||||
2211 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2212 | - | |||||||||||||||||||||||||
2213 | /*! | - | ||||||||||||||||||||||||
2214 | \overload | - | ||||||||||||||||||||||||
2215 | - | |||||||||||||||||||||||||
2216 | Stores the real number in the double \a f. | - | ||||||||||||||||||||||||
2217 | */ | - | ||||||||||||||||||||||||
2218 | QTextStream &QTextStream::operator>>(double &f) | - | ||||||||||||||||||||||||
2219 | { | - | ||||||||||||||||||||||||
2220 | IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(double); never executed: return *this; executed 31 times by 1 test: end of block Executed by:
executed 6 times by 1 test: end of block Executed by:
executed 37 times by 1 test: return *this; Executed by:
| 0-37 | ||||||||||||||||||||||||
2221 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2222 | - | |||||||||||||||||||||||||
2223 | /*! | - | ||||||||||||||||||||||||
2224 | Reads a word from the stream and stores it in \a str, then returns | - | ||||||||||||||||||||||||
2225 | a reference to the stream. Words are separated by whitespace | - | ||||||||||||||||||||||||
2226 | (i.e., all characters for which QChar::isSpace() returns \c true). | - | ||||||||||||||||||||||||
2227 | - | |||||||||||||||||||||||||
2228 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
2229 | */ | - | ||||||||||||||||||||||||
2230 | QTextStream &QTextStream::operator>>(QString &str) | - | ||||||||||||||||||||||||
2231 | { | - | ||||||||||||||||||||||||
2232 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2233 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-425 | ||||||||||||||||||||||||
2234 | - | |||||||||||||||||||||||||
2235 | str.clear(); | - | ||||||||||||||||||||||||
2236 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
2237 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2238 | - | |||||||||||||||||||||||||
2239 | const QChar *ptr; | - | ||||||||||||||||||||||||
2240 | int length; | - | ||||||||||||||||||||||||
2241 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 4-433 | ||||||||||||||||||||||||
2242 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
2243 | return *this; executed 4 times by 1 test: return *this; Executed by:
| 4 | ||||||||||||||||||||||||
2244 | } | - | ||||||||||||||||||||||||
2245 | - | |||||||||||||||||||||||||
2246 | str = QString(ptr, length); | - | ||||||||||||||||||||||||
2247 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2248 | return *this; executed 433 times by 4 tests: return *this; Executed by:
| 433 | ||||||||||||||||||||||||
2249 | } | - | ||||||||||||||||||||||||
2250 | - | |||||||||||||||||||||||||
2251 | /*! | - | ||||||||||||||||||||||||
2252 | \overload | - | ||||||||||||||||||||||||
2253 | - | |||||||||||||||||||||||||
2254 | Converts the word to ISO-8859-1, then stores it in \a array. | - | ||||||||||||||||||||||||
2255 | - | |||||||||||||||||||||||||
2256 | \sa QString::toLatin1() | - | ||||||||||||||||||||||||
2257 | */ | - | ||||||||||||||||||||||||
2258 | QTextStream &QTextStream::operator>>(QByteArray &array) | - | ||||||||||||||||||||||||
2259 | { | - | ||||||||||||||||||||||||
2260 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2261 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-14 | ||||||||||||||||||||||||
2262 | - | |||||||||||||||||||||||||
2263 | array.clear(); | - | ||||||||||||||||||||||||
2264 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
2265 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2266 | - | |||||||||||||||||||||||||
2267 | const QChar *ptr; | - | ||||||||||||||||||||||||
2268 | int length; | - | ||||||||||||||||||||||||
2269 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 3-11 | ||||||||||||||||||||||||
2270 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
2271 | return *this; executed 3 times by 1 test: return *this; Executed by:
| 3 | ||||||||||||||||||||||||
2272 | } | - | ||||||||||||||||||||||||
2273 | - | |||||||||||||||||||||||||
2274 | for (int i = 0; i < length; ++i)
| 11-20 | ||||||||||||||||||||||||
2275 | array += ptr[i].toLatin1(); executed 20 times by 1 test: array += ptr[i].toLatin1(); Executed by:
| 20 | ||||||||||||||||||||||||
2276 | - | |||||||||||||||||||||||||
2277 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2278 | return *this; executed 11 times by 1 test: return *this; Executed by:
| 11 | ||||||||||||||||||||||||
2279 | } | - | ||||||||||||||||||||||||
2280 | - | |||||||||||||||||||||||||
2281 | /*! | - | ||||||||||||||||||||||||
2282 | \overload | - | ||||||||||||||||||||||||
2283 | - | |||||||||||||||||||||||||
2284 | Stores the word in \a c, terminated by a '\\0' character. If no word is | - | ||||||||||||||||||||||||
2285 | available, only the '\\0' character is stored. | - | ||||||||||||||||||||||||
2286 | - | |||||||||||||||||||||||||
2287 | Warning: Although convenient, this operator is dangerous and must | - | ||||||||||||||||||||||||
2288 | be used with care. QTextStream assumes that \a c points to a | - | ||||||||||||||||||||||||
2289 | buffer with enough space to hold the word. If the buffer is too | - | ||||||||||||||||||||||||
2290 | small, your application may crash. | - | ||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||
2292 | If possible, use the QByteArray operator instead. | - | ||||||||||||||||||||||||
2293 | */ | - | ||||||||||||||||||||||||
2294 | QTextStream &QTextStream::operator>>(char *c) | - | ||||||||||||||||||||||||
2295 | { | - | ||||||||||||||||||||||||
2296 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2297 | *c = 0; | - | ||||||||||||||||||||||||
2298 | CHECK_VALID_STREAM(*this); executed 1 time by 1 test: return *this; Executed by:
| 0-13 | ||||||||||||||||||||||||
2299 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
2300 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2301 | - | |||||||||||||||||||||||||
2302 | const QChar *ptr; | - | ||||||||||||||||||||||||
2303 | int length; | - | ||||||||||||||||||||||||
2304 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 3-9 | ||||||||||||||||||||||||
2305 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
2306 | return *this; executed 3 times by 1 test: return *this; Executed by:
| 3 | ||||||||||||||||||||||||
2307 | } | - | ||||||||||||||||||||||||
2308 | - | |||||||||||||||||||||||||
2309 | for (int i = 0; i < length; ++i)
| 9-14 | ||||||||||||||||||||||||
2310 | *c++ = ptr[i].toLatin1(); executed 14 times by 1 test: *c++ = ptr[i].toLatin1(); Executed by:
| 14 | ||||||||||||||||||||||||
2311 | *c = '\0'; | - | ||||||||||||||||||||||||
2312 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
2313 | return *this; executed 9 times by 1 test: return *this; Executed by:
| 9 | ||||||||||||||||||||||||
2314 | } | - | ||||||||||||||||||||||||
2315 | - | |||||||||||||||||||||||||
2316 | /*! | - | ||||||||||||||||||||||||
2317 | \internal | - | ||||||||||||||||||||||||
2318 | */ | - | ||||||||||||||||||||||||
2319 | void QTextStreamPrivate::putNumber(qulonglong number, bool negative) | - | ||||||||||||||||||||||||
2320 | { | - | ||||||||||||||||||||||||
2321 | QString result; | - | ||||||||||||||||||||||||
2322 | - | |||||||||||||||||||||||||
2323 | unsigned flags = 0; | - | ||||||||||||||||||||||||
2324 | const QTextStream::NumberFlags numberFlags = params.numberFlags; | - | ||||||||||||||||||||||||
2325 | if (numberFlags & QTextStream::ShowBase)
| 134-24925 | ||||||||||||||||||||||||
2326 | flags |= QLocaleData::ShowBase; executed 134 times by 11 tests: flags |= QLocaleData::ShowBase; Executed by:
| 134 | ||||||||||||||||||||||||
2327 | if (numberFlags & QTextStream::ForceSign)
| 3-25056 | ||||||||||||||||||||||||
2328 | flags |= QLocaleData::AlwaysShowSign; executed 3 times by 1 test: flags |= QLocaleData::AlwaysShowSign; Executed by:
| 3 | ||||||||||||||||||||||||
2329 | if (numberFlags & QTextStream::UppercaseBase)
| 7-25052 | ||||||||||||||||||||||||
2330 | flags |= QLocaleData::UppercaseBase; executed 7 times by 1 test: flags |= QLocaleData::UppercaseBase; Executed by:
| 7 | ||||||||||||||||||||||||
2331 | if (numberFlags & QTextStream::UppercaseDigits)
| 9-25050 | ||||||||||||||||||||||||
2332 | flags |= QLocaleData::CapitalEorX; executed 9 times by 1 test: flags |= QLocaleData::CapitalEorX; Executed by:
| 9 | ||||||||||||||||||||||||
2333 | - | |||||||||||||||||||||||||
2334 | // add thousands group separators. For backward compatibility we | - | ||||||||||||||||||||||||
2335 | // don't add a group separator for C locale. | - | ||||||||||||||||||||||||
2336 | if (locale != QLocale::c() && !locale.numberOptions().testFlag(QLocale::OmitGroupSeparator))
| 86-24798 | ||||||||||||||||||||||||
2337 | flags |= QLocaleData::ThousandsGroup; executed 175 times by 1 test: flags |= QLocaleData::ThousandsGroup; Executed by:
| 175 | ||||||||||||||||||||||||
2338 | - | |||||||||||||||||||||||||
2339 | const QLocaleData *dd = locale.d->m_data; | - | ||||||||||||||||||||||||
2340 | int base = params.integerBase ? params.integerBase : 10;
| 235-24824 | ||||||||||||||||||||||||
2341 | if (negative && base == 10) {
| 4-23661 | ||||||||||||||||||||||||
2342 | result = dd->longLongToString(-static_cast<qlonglong>(number), -1, | - | ||||||||||||||||||||||||
2343 | base, -1, flags); | - | ||||||||||||||||||||||||
2344 | } else if (negative) { executed 1394 times by 8 tests: end of block Executed by:
| 4-23661 | ||||||||||||||||||||||||
2345 | // Workaround for backward compatibility for writing negative | - | ||||||||||||||||||||||||
2346 | // numbers in octal and hex: | - | ||||||||||||||||||||||||
2347 | // QTextStream(result) << showbase << hex << -1 << oct << -1 | - | ||||||||||||||||||||||||
2348 | // should output: -0x1 -0b1 | - | ||||||||||||||||||||||||
2349 | result = dd->unsLongLongToString(number, -1, base, -1, flags); | - | ||||||||||||||||||||||||
2350 | result.prepend(locale.negativeSign()); | - | ||||||||||||||||||||||||
2351 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
2352 | result = dd->unsLongLongToString(number, -1, base, -1, flags); | - | ||||||||||||||||||||||||
2353 | // workaround for backward compatibility - in octal form with | - | ||||||||||||||||||||||||
2354 | // ShowBase flag set zero should be written as '00' | - | ||||||||||||||||||||||||
2355 | if (number == 0 && base == 8 && params.numberFlags & QTextStream::ShowBase
| 1-20911 | ||||||||||||||||||||||||
2356 | && result == QLatin1String("0")) {
| 0-1 | ||||||||||||||||||||||||
2357 | result.prepend(QLatin1Char('0')); | - | ||||||||||||||||||||||||
2358 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
2359 | } executed 23661 times by 47 tests: end of block Executed by:
| 23661 | ||||||||||||||||||||||||
2360 | putString(result, true); | - | ||||||||||||||||||||||||
2361 | } executed 25059 times by 47 tests: end of block Executed by:
| 25059 | ||||||||||||||||||||||||
2362 | - | |||||||||||||||||||||||||
2363 | /*! | - | ||||||||||||||||||||||||
2364 | Writes the character \a c to the stream, then returns a reference | - | ||||||||||||||||||||||||
2365 | to the QTextStream. | - | ||||||||||||||||||||||||
2366 | - | |||||||||||||||||||||||||
2367 | \sa setFieldWidth() | - | ||||||||||||||||||||||||
2368 | */ | - | ||||||||||||||||||||||||
2369 | QTextStream &QTextStream::operator<<(QChar c) | - | ||||||||||||||||||||||||
2370 | { | - | ||||||||||||||||||||||||
2371 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2372 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-26222 | ||||||||||||||||||||||||
2373 | d->putChar(c); | - | ||||||||||||||||||||||||
2374 | return *this; executed 50798 times by 15 tests: return *this; Executed by:
| 50798 | ||||||||||||||||||||||||
2375 | } | - | ||||||||||||||||||||||||
2376 | - | |||||||||||||||||||||||||
2377 | /*! | - | ||||||||||||||||||||||||
2378 | \overload | - | ||||||||||||||||||||||||
2379 | - | |||||||||||||||||||||||||
2380 | Converts \a c from ASCII to a QChar, then writes it to the stream. | - | ||||||||||||||||||||||||
2381 | */ | - | ||||||||||||||||||||||||
2382 | QTextStream &QTextStream::operator<<(char c) | - | ||||||||||||||||||||||||
2383 | { | - | ||||||||||||||||||||||||
2384 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2385 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-68682 | ||||||||||||||||||||||||
2386 | d->putChar(QChar::fromLatin1(c)); | - | ||||||||||||||||||||||||
2387 | return *this; executed 107556 times by 82 tests: return *this; Executed by:
| 107556 | ||||||||||||||||||||||||
2388 | } | - | ||||||||||||||||||||||||
2389 | - | |||||||||||||||||||||||||
2390 | /*! | - | ||||||||||||||||||||||||
2391 | Writes the integer number \a i to the stream, then returns a | - | ||||||||||||||||||||||||
2392 | reference to the QTextStream. By default, the number is stored in | - | ||||||||||||||||||||||||
2393 | decimal form, but you can also set the base by calling | - | ||||||||||||||||||||||||
2394 | setIntegerBase(). | - | ||||||||||||||||||||||||
2395 | - | |||||||||||||||||||||||||
2396 | \sa setFieldWidth(), setNumberFlags() | - | ||||||||||||||||||||||||
2397 | */ | - | ||||||||||||||||||||||||
2398 | QTextStream &QTextStream::operator<<(signed short i) | - | ||||||||||||||||||||||||
2399 | { | - | ||||||||||||||||||||||||
2400 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2401 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-36 | ||||||||||||||||||||||||
2402 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
2403 | return *this; executed 38 times by 3 tests: return *this; Executed by:
| 38 | ||||||||||||||||||||||||
2404 | } | - | ||||||||||||||||||||||||
2405 | - | |||||||||||||||||||||||||
2406 | /*! | - | ||||||||||||||||||||||||
2407 | \overload | - | ||||||||||||||||||||||||
2408 | - | |||||||||||||||||||||||||
2409 | Writes the unsigned short \a i to the stream. | - | ||||||||||||||||||||||||
2410 | */ | - | ||||||||||||||||||||||||
2411 | QTextStream &QTextStream::operator<<(unsigned short i) | - | ||||||||||||||||||||||||
2412 | { | - | ||||||||||||||||||||||||
2413 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2414 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-117 | ||||||||||||||||||||||||
2415 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
2416 | return *this; executed 198 times by 6 tests: return *this; Executed by:
| 198 | ||||||||||||||||||||||||
2417 | } | - | ||||||||||||||||||||||||
2418 | - | |||||||||||||||||||||||||
2419 | /*! | - | ||||||||||||||||||||||||
2420 | \overload | - | ||||||||||||||||||||||||
2421 | - | |||||||||||||||||||||||||
2422 | Writes the signed int \a i to the stream. | - | ||||||||||||||||||||||||
2423 | */ | - | ||||||||||||||||||||||||
2424 | QTextStream &QTextStream::operator<<(signed int i) | - | ||||||||||||||||||||||||
2425 | { | - | ||||||||||||||||||||||||
2426 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2427 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-15069 | ||||||||||||||||||||||||
2428 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
2429 | return *this; executed 18479 times by 39 tests: return *this; Executed by:
| 18479 | ||||||||||||||||||||||||
2430 | } | - | ||||||||||||||||||||||||
2431 | - | |||||||||||||||||||||||||
2432 | /*! | - | ||||||||||||||||||||||||
2433 | \overload | - | ||||||||||||||||||||||||
2434 | - | |||||||||||||||||||||||||
2435 | Writes the unsigned int \a i to the stream. | - | ||||||||||||||||||||||||
2436 | */ | - | ||||||||||||||||||||||||
2437 | QTextStream &QTextStream::operator<<(unsigned int i) | - | ||||||||||||||||||||||||
2438 | { | - | ||||||||||||||||||||||||
2439 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2440 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-60 | ||||||||||||||||||||||||
2441 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
2442 | return *this; executed 66 times by 4 tests: return *this; Executed by:
| 66 | ||||||||||||||||||||||||
2443 | } | - | ||||||||||||||||||||||||
2444 | - | |||||||||||||||||||||||||
2445 | /*! | - | ||||||||||||||||||||||||
2446 | \overload | - | ||||||||||||||||||||||||
2447 | - | |||||||||||||||||||||||||
2448 | Writes the signed long \a i to the stream. | - | ||||||||||||||||||||||||
2449 | */ | - | ||||||||||||||||||||||||
2450 | QTextStream &QTextStream::operator<<(signed long i) | - | ||||||||||||||||||||||||
2451 | { | - | ||||||||||||||||||||||||
2452 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2453 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-2 | ||||||||||||||||||||||||
2454 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
2455 | return *this; executed 2 times by 2 tests: return *this; Executed by:
| 2 | ||||||||||||||||||||||||
2456 | } | - | ||||||||||||||||||||||||
2457 | - | |||||||||||||||||||||||||
2458 | /*! | - | ||||||||||||||||||||||||
2459 | \overload | - | ||||||||||||||||||||||||
2460 | - | |||||||||||||||||||||||||
2461 | Writes the unsigned long \a i to the stream. | - | ||||||||||||||||||||||||
2462 | */ | - | ||||||||||||||||||||||||
2463 | QTextStream &QTextStream::operator<<(unsigned long i) | - | ||||||||||||||||||||||||
2464 | { | - | ||||||||||||||||||||||||
2465 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2466 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-1 | ||||||||||||||||||||||||
2467 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
2468 | return *this; executed 1 time by 1 test: return *this; Executed by:
| 1 | ||||||||||||||||||||||||
2469 | } | - | ||||||||||||||||||||||||
2470 | - | |||||||||||||||||||||||||
2471 | /*! | - | ||||||||||||||||||||||||
2472 | \overload | - | ||||||||||||||||||||||||
2473 | - | |||||||||||||||||||||||||
2474 | Writes the qlonglong \a i to the stream. | - | ||||||||||||||||||||||||
2475 | */ | - | ||||||||||||||||||||||||
2476 | QTextStream &QTextStream::operator<<(qlonglong i) | - | ||||||||||||||||||||||||
2477 | { | - | ||||||||||||||||||||||||
2478 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2479 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-6038 | ||||||||||||||||||||||||
2480 | d->putNumber((qulonglong)qAbs(i), i < 0); | - | ||||||||||||||||||||||||
2481 | return *this; executed 6135 times by 11 tests: return *this; Executed by:
| 6135 | ||||||||||||||||||||||||
2482 | } | - | ||||||||||||||||||||||||
2483 | - | |||||||||||||||||||||||||
2484 | /*! | - | ||||||||||||||||||||||||
2485 | \overload | - | ||||||||||||||||||||||||
2486 | - | |||||||||||||||||||||||||
2487 | Writes the qulonglong \a i to the stream. | - | ||||||||||||||||||||||||
2488 | */ | - | ||||||||||||||||||||||||
2489 | QTextStream &QTextStream::operator<<(qulonglong i) | - | ||||||||||||||||||||||||
2490 | { | - | ||||||||||||||||||||||||
2491 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2492 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-76 | ||||||||||||||||||||||||
2493 | d->putNumber(i, false); | - | ||||||||||||||||||||||||
2494 | return *this; executed 90 times by 5 tests: return *this; Executed by:
| 90 | ||||||||||||||||||||||||
2495 | } | - | ||||||||||||||||||||||||
2496 | - | |||||||||||||||||||||||||
2497 | /*! | - | ||||||||||||||||||||||||
2498 | Writes the real number \a f to the stream, then returns a | - | ||||||||||||||||||||||||
2499 | reference to the QTextStream. By default, QTextStream stores it | - | ||||||||||||||||||||||||
2500 | using SmartNotation, with up to 6 digits of precision. You can | - | ||||||||||||||||||||||||
2501 | change the textual representation QTextStream will use for real | - | ||||||||||||||||||||||||
2502 | numbers by calling setRealNumberNotation(), | - | ||||||||||||||||||||||||
2503 | setRealNumberPrecision() and setNumberFlags(). | - | ||||||||||||||||||||||||
2504 | - | |||||||||||||||||||||||||
2505 | \sa setFieldWidth(), setRealNumberNotation(), | - | ||||||||||||||||||||||||
2506 | setRealNumberPrecision(), setNumberFlags() | - | ||||||||||||||||||||||||
2507 | */ | - | ||||||||||||||||||||||||
2508 | QTextStream &QTextStream::operator<<(float f) | - | ||||||||||||||||||||||||
2509 | { | - | ||||||||||||||||||||||||
2510 | return *this << double(f); executed 54 times by 3 tests: return *this << double(f); Executed by:
| 54 | ||||||||||||||||||||||||
2511 | } | - | ||||||||||||||||||||||||
2512 | - | |||||||||||||||||||||||||
2513 | /*! | - | ||||||||||||||||||||||||
2514 | \overload | - | ||||||||||||||||||||||||
2515 | - | |||||||||||||||||||||||||
2516 | Writes the double \a f to the stream. | - | ||||||||||||||||||||||||
2517 | */ | - | ||||||||||||||||||||||||
2518 | QTextStream &QTextStream::operator<<(double f) | - | ||||||||||||||||||||||||
2519 | { | - | ||||||||||||||||||||||||
2520 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2521 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-278 | ||||||||||||||||||||||||
2522 | - | |||||||||||||||||||||||||
2523 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
2524 | switch (realNumberNotation()) { | - | ||||||||||||||||||||||||
2525 | case FixedNotation: executed 2 times by 1 test: case FixedNotation: Executed by:
| 2 | ||||||||||||||||||||||||
2526 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
2527 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2528 | case ScientificNotation: executed 5 times by 1 test: case ScientificNotation: Executed by:
| 5 | ||||||||||||||||||||||||
2529 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||||||||
2530 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||||||||
2531 | case SmartNotation: executed 299 times by 9 tests: case SmartNotation: Executed by:
| 299 | ||||||||||||||||||||||||
2532 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||||||||
2533 | break; executed 299 times by 9 tests: break; Executed by:
| 299 | ||||||||||||||||||||||||
2534 | } | - | ||||||||||||||||||||||||
2535 | - | |||||||||||||||||||||||||
2536 | uint flags = 0; | - | ||||||||||||||||||||||||
2537 | if (numberFlags() & ShowBase)
| 0-306 | ||||||||||||||||||||||||
2538 | flags |= QLocaleData::ShowBase; never executed: flags |= QLocaleData::ShowBase; | 0 | ||||||||||||||||||||||||
2539 | if (numberFlags() & ForceSign)
| 4-302 | ||||||||||||||||||||||||
2540 | flags |= QLocaleData::AlwaysShowSign; executed 4 times by 1 test: flags |= QLocaleData::AlwaysShowSign; Executed by:
| 4 | ||||||||||||||||||||||||
2541 | if (numberFlags() & UppercaseBase)
| 1-305 | ||||||||||||||||||||||||
2542 | flags |= QLocaleData::UppercaseBase; executed 1 time by 1 test: flags |= QLocaleData::UppercaseBase; Executed by:
| 1 | ||||||||||||||||||||||||
2543 | if (numberFlags() & UppercaseDigits)
| 7-299 | ||||||||||||||||||||||||
2544 | flags |= QLocaleData::CapitalEorX; executed 7 times by 1 test: flags |= QLocaleData::CapitalEorX; Executed by:
| 7 | ||||||||||||||||||||||||
2545 | if (numberFlags() & ForcePoint)
| 6-300 | ||||||||||||||||||||||||
2546 | flags |= QLocaleData::Alternate; executed 6 times by 1 test: flags |= QLocaleData::Alternate; Executed by:
| 6 | ||||||||||||||||||||||||
2547 | if (locale() != QLocale::c() && !(locale().numberOptions() & QLocale::OmitGroupSeparator))
| 0-294 | ||||||||||||||||||||||||
2548 | flags |= QLocaleData::ThousandsGroup; executed 12 times by 1 test: flags |= QLocaleData::ThousandsGroup; Executed by:
| 12 | ||||||||||||||||||||||||
2549 | - | |||||||||||||||||||||||||
2550 | const QLocaleData *dd = d->locale.d->m_data; | - | ||||||||||||||||||||||||
2551 | QString num = dd->doubleToString(f, d->params.realNumberPrecision, form, -1, flags); | - | ||||||||||||||||||||||||
2552 | d->putString(num, true); | - | ||||||||||||||||||||||||
2553 | return *this; executed 306 times by 9 tests: return *this; Executed by:
| 306 | ||||||||||||||||||||||||
2554 | } | - | ||||||||||||||||||||||||
2555 | - | |||||||||||||||||||||||||
2556 | /*! | - | ||||||||||||||||||||||||
2557 | Writes the string \a string to the stream, and returns a reference | - | ||||||||||||||||||||||||
2558 | to the QTextStream. The string is first encoded using the assigned | - | ||||||||||||||||||||||||
2559 | codec (the default codec is QTextCodec::codecForLocale()) before | - | ||||||||||||||||||||||||
2560 | it is written to the stream. | - | ||||||||||||||||||||||||
2561 | - | |||||||||||||||||||||||||
2562 | \sa setFieldWidth(), setCodec() | - | ||||||||||||||||||||||||
2563 | */ | - | ||||||||||||||||||||||||
2564 | QTextStream &QTextStream::operator<<(const QString &string) | - | ||||||||||||||||||||||||
2565 | { | - | ||||||||||||||||||||||||
2566 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2567 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-93635 | ||||||||||||||||||||||||
2568 | d->putString(string); | - | ||||||||||||||||||||||||
2569 | return *this; executed 120646 times by 80 tests: return *this; Executed by:
| 120646 | ||||||||||||||||||||||||
2570 | } | - | ||||||||||||||||||||||||
2571 | - | |||||||||||||||||||||||||
2572 | /*! | - | ||||||||||||||||||||||||
2573 | \overload | - | ||||||||||||||||||||||||
2574 | - | |||||||||||||||||||||||||
2575 | Writes \a string to the stream, and returns a reference to the | - | ||||||||||||||||||||||||
2576 | QTextStream. | - | ||||||||||||||||||||||||
2577 | */ | - | ||||||||||||||||||||||||
2578 | QTextStream &QTextStream::operator<<(QLatin1String string) | - | ||||||||||||||||||||||||
2579 | { | - | ||||||||||||||||||||||||
2580 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2581 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-3 | ||||||||||||||||||||||||
2582 | d->putString(string); | - | ||||||||||||||||||||||||
2583 | return *this; executed 3 times by 1 test: return *this; Executed by:
| 3 | ||||||||||||||||||||||||
2584 | } | - | ||||||||||||||||||||||||
2585 | - | |||||||||||||||||||||||||
2586 | /*! | - | ||||||||||||||||||||||||
2587 | \since 5.6 | - | ||||||||||||||||||||||||
2588 | \overload | - | ||||||||||||||||||||||||
2589 | - | |||||||||||||||||||||||||
2590 | Writes \a string to the stream, and returns a reference to the | - | ||||||||||||||||||||||||
2591 | QTextStream. | - | ||||||||||||||||||||||||
2592 | */ | - | ||||||||||||||||||||||||
2593 | QTextStream &QTextStream::operator<<(const QStringRef &string) | - | ||||||||||||||||||||||||
2594 | { | - | ||||||||||||||||||||||||
2595 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2596 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-2 | ||||||||||||||||||||||||
2597 | d->putString(string.data(), string.size()); | - | ||||||||||||||||||||||||
2598 | return *this; executed 2 times by 1 test: return *this; Executed by:
| 2 | ||||||||||||||||||||||||
2599 | } | - | ||||||||||||||||||||||||
2600 | - | |||||||||||||||||||||||||
2601 | /*! | - | ||||||||||||||||||||||||
2602 | \overload | - | ||||||||||||||||||||||||
2603 | - | |||||||||||||||||||||||||
2604 | Writes \a array to the stream. The contents of \a array are | - | ||||||||||||||||||||||||
2605 | converted with QString::fromUtf8(). | - | ||||||||||||||||||||||||
2606 | */ | - | ||||||||||||||||||||||||
2607 | QTextStream &QTextStream::operator<<(const QByteArray &array) | - | ||||||||||||||||||||||||
2608 | { | - | ||||||||||||||||||||||||
2609 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2610 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-247 | ||||||||||||||||||||||||
2611 | d->putString(QString::fromUtf8(array.constData(), array.length())); | - | ||||||||||||||||||||||||
2612 | return *this; executed 441 times by 3 tests: return *this; Executed by:
| 441 | ||||||||||||||||||||||||
2613 | } | - | ||||||||||||||||||||||||
2614 | - | |||||||||||||||||||||||||
2615 | /*! | - | ||||||||||||||||||||||||
2616 | \overload | - | ||||||||||||||||||||||||
2617 | - | |||||||||||||||||||||||||
2618 | Writes the constant string pointed to by \a string to the stream. \a | - | ||||||||||||||||||||||||
2619 | string is assumed to be in ISO-8859-1 encoding. This operator | - | ||||||||||||||||||||||||
2620 | is convenient when working with constant string data. Example: | - | ||||||||||||||||||||||||
2621 | - | |||||||||||||||||||||||||
2622 | \snippet code/src_corelib_io_qtextstream.cpp 8 | - | ||||||||||||||||||||||||
2623 | - | |||||||||||||||||||||||||
2624 | Warning: QTextStream assumes that \a string points to a string of | - | ||||||||||||||||||||||||
2625 | text, terminated by a '\\0' character. If there is no terminating | - | ||||||||||||||||||||||||
2626 | '\\0' character, your application may crash. | - | ||||||||||||||||||||||||
2627 | */ | - | ||||||||||||||||||||||||
2628 | QTextStream &QTextStream::operator<<(const char *string) | - | ||||||||||||||||||||||||
2629 | { | - | ||||||||||||||||||||||||
2630 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2631 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-41270 | ||||||||||||||||||||||||
2632 | d->putString(QLatin1String(string)); | - | ||||||||||||||||||||||||
2633 | return *this; executed 67508 times by 30 tests: return *this; Executed by:
| 67508 | ||||||||||||||||||||||||
2634 | } | - | ||||||||||||||||||||||||
2635 | - | |||||||||||||||||||||||||
2636 | /*! | - | ||||||||||||||||||||||||
2637 | \overload | - | ||||||||||||||||||||||||
2638 | - | |||||||||||||||||||||||||
2639 | Writes \a ptr to the stream as a hexadecimal number with a base. | - | ||||||||||||||||||||||||
2640 | */ | - | ||||||||||||||||||||||||
2641 | - | |||||||||||||||||||||||||
2642 | QTextStream &QTextStream::operator<<(const void *ptr) | - | ||||||||||||||||||||||||
2643 | { | - | ||||||||||||||||||||||||
2644 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
2645 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-50 | ||||||||||||||||||||||||
2646 | const int oldBase = d->params.integerBase; | - | ||||||||||||||||||||||||
2647 | const NumberFlags oldFlags = d->params.numberFlags; | - | ||||||||||||||||||||||||
2648 | d->params.integerBase = 16; | - | ||||||||||||||||||||||||
2649 | d->params.numberFlags |= ShowBase; | - | ||||||||||||||||||||||||
2650 | d->putNumber(reinterpret_cast<quintptr>(ptr), false); | - | ||||||||||||||||||||||||
2651 | d->params.integerBase = oldBase; | - | ||||||||||||||||||||||||
2652 | d->params.numberFlags = oldFlags; | - | ||||||||||||||||||||||||
2653 | return *this; executed 50 times by 7 tests: return *this; Executed by:
| 50 | ||||||||||||||||||||||||
2654 | } | - | ||||||||||||||||||||||||
2655 | - | |||||||||||||||||||||||||
2656 | /*! | - | ||||||||||||||||||||||||
2657 | \relates QTextStream | - | ||||||||||||||||||||||||
2658 | - | |||||||||||||||||||||||||
2659 | Calls QTextStream::setIntegerBase(2) on \a stream and returns \a | - | ||||||||||||||||||||||||
2660 | stream. | - | ||||||||||||||||||||||||
2661 | - | |||||||||||||||||||||||||
2662 | \sa oct(), dec(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2663 | */ | - | ||||||||||||||||||||||||
2664 | QTextStream &bin(QTextStream &stream) | - | ||||||||||||||||||||||||
2665 | { | - | ||||||||||||||||||||||||
2666 | stream.setIntegerBase(2); | - | ||||||||||||||||||||||||
2667 | return stream; executed 15 times by 1 test: return stream; Executed by:
| 15 | ||||||||||||||||||||||||
2668 | } | - | ||||||||||||||||||||||||
2669 | - | |||||||||||||||||||||||||
2670 | /*! | - | ||||||||||||||||||||||||
2671 | \relates QTextStream | - | ||||||||||||||||||||||||
2672 | - | |||||||||||||||||||||||||
2673 | Calls QTextStream::setIntegerBase(8) on \a stream and returns \a | - | ||||||||||||||||||||||||
2674 | stream. | - | ||||||||||||||||||||||||
2675 | - | |||||||||||||||||||||||||
2676 | \sa bin(), dec(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2677 | */ | - | ||||||||||||||||||||||||
2678 | QTextStream &oct(QTextStream &stream) | - | ||||||||||||||||||||||||
2679 | { | - | ||||||||||||||||||||||||
2680 | stream.setIntegerBase(8); | - | ||||||||||||||||||||||||
2681 | return stream; executed 3 times by 1 test: return stream; Executed by:
| 3 | ||||||||||||||||||||||||
2682 | } | - | ||||||||||||||||||||||||
2683 | - | |||||||||||||||||||||||||
2684 | /*! | - | ||||||||||||||||||||||||
2685 | \relates QTextStream | - | ||||||||||||||||||||||||
2686 | - | |||||||||||||||||||||||||
2687 | Calls QTextStream::setIntegerBase(10) on \a stream and returns \a | - | ||||||||||||||||||||||||
2688 | stream. | - | ||||||||||||||||||||||||
2689 | - | |||||||||||||||||||||||||
2690 | \sa bin(), oct(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2691 | */ | - | ||||||||||||||||||||||||
2692 | QTextStream &dec(QTextStream &stream) | - | ||||||||||||||||||||||||
2693 | { | - | ||||||||||||||||||||||||
2694 | stream.setIntegerBase(10); | - | ||||||||||||||||||||||||
2695 | return stream; executed 82 times by 2 tests: return stream; Executed by:
| 82 | ||||||||||||||||||||||||
2696 | } | - | ||||||||||||||||||||||||
2697 | - | |||||||||||||||||||||||||
2698 | /*! | - | ||||||||||||||||||||||||
2699 | \relates QTextStream | - | ||||||||||||||||||||||||
2700 | - | |||||||||||||||||||||||||
2701 | Calls QTextStream::setIntegerBase(16) on \a stream and returns \a | - | ||||||||||||||||||||||||
2702 | stream. | - | ||||||||||||||||||||||||
2703 | - | |||||||||||||||||||||||||
2704 | \note The hex modifier can only be used for writing to streams. | - | ||||||||||||||||||||||||
2705 | \sa bin(), oct(), dec(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2706 | */ | - | ||||||||||||||||||||||||
2707 | QTextStream &hex(QTextStream &stream) | - | ||||||||||||||||||||||||
2708 | { | - | ||||||||||||||||||||||||
2709 | stream.setIntegerBase(16); | - | ||||||||||||||||||||||||
2710 | return stream; executed 136 times by 6 tests: return stream; Executed by:
| 136 | ||||||||||||||||||||||||
2711 | } | - | ||||||||||||||||||||||||
2712 | - | |||||||||||||||||||||||||
2713 | /*! | - | ||||||||||||||||||||||||
2714 | \relates QTextStream | - | ||||||||||||||||||||||||
2715 | - | |||||||||||||||||||||||||
2716 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
2717 | QTextStream::ShowBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2718 | - | |||||||||||||||||||||||||
2719 | \sa noshowbase(), forcesign(), forcepoint(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2720 | */ | - | ||||||||||||||||||||||||
2721 | QTextStream &showbase(QTextStream &stream) | - | ||||||||||||||||||||||||
2722 | { | - | ||||||||||||||||||||||||
2723 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ShowBase); | - | ||||||||||||||||||||||||
2724 | return stream; executed 59 times by 4 tests: return stream; Executed by:
| 59 | ||||||||||||||||||||||||
2725 | } | - | ||||||||||||||||||||||||
2726 | - | |||||||||||||||||||||||||
2727 | /*! | - | ||||||||||||||||||||||||
2728 | \relates QTextStream | - | ||||||||||||||||||||||||
2729 | - | |||||||||||||||||||||||||
2730 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
2731 | QTextStream::ForceSign) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2732 | - | |||||||||||||||||||||||||
2733 | \sa noforcesign(), forcepoint(), showbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2734 | */ | - | ||||||||||||||||||||||||
2735 | QTextStream &forcesign(QTextStream &stream) | - | ||||||||||||||||||||||||
2736 | { | - | ||||||||||||||||||||||||
2737 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ForceSign); | - | ||||||||||||||||||||||||
2738 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
2739 | } | - | ||||||||||||||||||||||||
2740 | - | |||||||||||||||||||||||||
2741 | /*! | - | ||||||||||||||||||||||||
2742 | \relates QTextStream | - | ||||||||||||||||||||||||
2743 | - | |||||||||||||||||||||||||
2744 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
2745 | QTextStream::ForcePoint) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2746 | - | |||||||||||||||||||||||||
2747 | \sa noforcepoint(), forcesign(), showbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2748 | */ | - | ||||||||||||||||||||||||
2749 | QTextStream &forcepoint(QTextStream &stream) | - | ||||||||||||||||||||||||
2750 | { | - | ||||||||||||||||||||||||
2751 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ForcePoint); | - | ||||||||||||||||||||||||
2752 | return stream; executed 3 times by 1 test: return stream; Executed by:
| 3 | ||||||||||||||||||||||||
2753 | } | - | ||||||||||||||||||||||||
2754 | - | |||||||||||||||||||||||||
2755 | /*! | - | ||||||||||||||||||||||||
2756 | \relates QTextStream | - | ||||||||||||||||||||||||
2757 | - | |||||||||||||||||||||||||
2758 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
2759 | ~QTextStream::ShowBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2760 | - | |||||||||||||||||||||||||
2761 | \sa showbase(), noforcesign(), noforcepoint(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2762 | */ | - | ||||||||||||||||||||||||
2763 | QTextStream &noshowbase(QTextStream &stream) | - | ||||||||||||||||||||||||
2764 | { | - | ||||||||||||||||||||||||
2765 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ShowBase); | - | ||||||||||||||||||||||||
2766 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
2767 | } | - | ||||||||||||||||||||||||
2768 | - | |||||||||||||||||||||||||
2769 | /*! | - | ||||||||||||||||||||||||
2770 | \relates QTextStream | - | ||||||||||||||||||||||||
2771 | - | |||||||||||||||||||||||||
2772 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
2773 | ~QTextStream::ForceSign) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2774 | - | |||||||||||||||||||||||||
2775 | \sa forcesign(), noforcepoint(), noshowbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2776 | */ | - | ||||||||||||||||||||||||
2777 | QTextStream &noforcesign(QTextStream &stream) | - | ||||||||||||||||||||||||
2778 | { | - | ||||||||||||||||||||||||
2779 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ForceSign); | - | ||||||||||||||||||||||||
2780 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
2781 | } | - | ||||||||||||||||||||||||
2782 | - | |||||||||||||||||||||||||
2783 | /*! | - | ||||||||||||||||||||||||
2784 | \relates QTextStream | - | ||||||||||||||||||||||||
2785 | - | |||||||||||||||||||||||||
2786 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
2787 | ~QTextStream::ForcePoint) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2788 | - | |||||||||||||||||||||||||
2789 | \sa forcepoint(), noforcesign(), noshowbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2790 | */ | - | ||||||||||||||||||||||||
2791 | QTextStream &noforcepoint(QTextStream &stream) | - | ||||||||||||||||||||||||
2792 | { | - | ||||||||||||||||||||||||
2793 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ForcePoint); | - | ||||||||||||||||||||||||
2794 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
2795 | } | - | ||||||||||||||||||||||||
2796 | - | |||||||||||||||||||||||||
2797 | /*! | - | ||||||||||||||||||||||||
2798 | \relates QTextStream | - | ||||||||||||||||||||||||
2799 | - | |||||||||||||||||||||||||
2800 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
2801 | QTextStream::UppercaseBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2802 | - | |||||||||||||||||||||||||
2803 | \sa lowercasebase(), uppercasedigits(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2804 | */ | - | ||||||||||||||||||||||||
2805 | QTextStream &uppercasebase(QTextStream &stream) | - | ||||||||||||||||||||||||
2806 | { | - | ||||||||||||||||||||||||
2807 | stream.setNumberFlags(stream.numberFlags() | QTextStream::UppercaseBase); | - | ||||||||||||||||||||||||
2808 | return stream; executed 7 times by 1 test: return stream; Executed by:
| 7 | ||||||||||||||||||||||||
2809 | } | - | ||||||||||||||||||||||||
2810 | - | |||||||||||||||||||||||||
2811 | /*! | - | ||||||||||||||||||||||||
2812 | \relates QTextStream | - | ||||||||||||||||||||||||
2813 | - | |||||||||||||||||||||||||
2814 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
2815 | QTextStream::UppercaseDigits) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2816 | - | |||||||||||||||||||||||||
2817 | \sa lowercasedigits(), uppercasebase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2818 | */ | - | ||||||||||||||||||||||||
2819 | QTextStream &uppercasedigits(QTextStream &stream) | - | ||||||||||||||||||||||||
2820 | { | - | ||||||||||||||||||||||||
2821 | stream.setNumberFlags(stream.numberFlags() | QTextStream::UppercaseDigits); | - | ||||||||||||||||||||||||
2822 | return stream; executed 10 times by 1 test: return stream; Executed by:
| 10 | ||||||||||||||||||||||||
2823 | } | - | ||||||||||||||||||||||||
2824 | - | |||||||||||||||||||||||||
2825 | /*! | - | ||||||||||||||||||||||||
2826 | \relates QTextStream | - | ||||||||||||||||||||||||
2827 | - | |||||||||||||||||||||||||
2828 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
2829 | ~QTextStream::UppercaseBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2830 | - | |||||||||||||||||||||||||
2831 | \sa uppercasebase(), lowercasedigits(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2832 | */ | - | ||||||||||||||||||||||||
2833 | QTextStream &lowercasebase(QTextStream &stream) | - | ||||||||||||||||||||||||
2834 | { | - | ||||||||||||||||||||||||
2835 | stream.setNumberFlags(stream.numberFlags() & ~QTextStream::UppercaseBase); | - | ||||||||||||||||||||||||
2836 | return stream; executed 5 times by 1 test: return stream; Executed by:
| 5 | ||||||||||||||||||||||||
2837 | } | - | ||||||||||||||||||||||||
2838 | - | |||||||||||||||||||||||||
2839 | /*! | - | ||||||||||||||||||||||||
2840 | \relates QTextStream | - | ||||||||||||||||||||||||
2841 | - | |||||||||||||||||||||||||
2842 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
2843 | ~QTextStream::UppercaseDigits) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2844 | - | |||||||||||||||||||||||||
2845 | \sa uppercasedigits(), lowercasebase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2846 | */ | - | ||||||||||||||||||||||||
2847 | QTextStream &lowercasedigits(QTextStream &stream) | - | ||||||||||||||||||||||||
2848 | { | - | ||||||||||||||||||||||||
2849 | stream.setNumberFlags(stream.numberFlags() & ~QTextStream::UppercaseDigits); | - | ||||||||||||||||||||||||
2850 | return stream; executed 3 times by 1 test: return stream; Executed by:
| 3 | ||||||||||||||||||||||||
2851 | } | - | ||||||||||||||||||||||||
2852 | - | |||||||||||||||||||||||||
2853 | /*! | - | ||||||||||||||||||||||||
2854 | \relates QTextStream | - | ||||||||||||||||||||||||
2855 | - | |||||||||||||||||||||||||
2856 | Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) | - | ||||||||||||||||||||||||
2857 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2858 | - | |||||||||||||||||||||||||
2859 | \sa scientific(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2860 | */ | - | ||||||||||||||||||||||||
2861 | QTextStream &fixed(QTextStream &stream) | - | ||||||||||||||||||||||||
2862 | { | - | ||||||||||||||||||||||||
2863 | stream.setRealNumberNotation(QTextStream::FixedNotation); | - | ||||||||||||||||||||||||
2864 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
2865 | } | - | ||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||
2867 | /*! | - | ||||||||||||||||||||||||
2868 | \relates QTextStream | - | ||||||||||||||||||||||||
2869 | - | |||||||||||||||||||||||||
2870 | Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) | - | ||||||||||||||||||||||||
2871 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2872 | - | |||||||||||||||||||||||||
2873 | \sa fixed(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2874 | */ | - | ||||||||||||||||||||||||
2875 | QTextStream &scientific(QTextStream &stream) | - | ||||||||||||||||||||||||
2876 | { | - | ||||||||||||||||||||||||
2877 | stream.setRealNumberNotation(QTextStream::ScientificNotation); | - | ||||||||||||||||||||||||
2878 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
2879 | } | - | ||||||||||||||||||||||||
2880 | - | |||||||||||||||||||||||||
2881 | /*! | - | ||||||||||||||||||||||||
2882 | \relates QTextStream | - | ||||||||||||||||||||||||
2883 | - | |||||||||||||||||||||||||
2884 | Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) | - | ||||||||||||||||||||||||
2885 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2886 | - | |||||||||||||||||||||||||
2887 | \sa {QTextStream::}{right()}, {QTextStream::}{center()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
2888 | */ | - | ||||||||||||||||||||||||
2889 | QTextStream &left(QTextStream &stream) | - | ||||||||||||||||||||||||
2890 | { | - | ||||||||||||||||||||||||
2891 | stream.setFieldAlignment(QTextStream::AlignLeft); | - | ||||||||||||||||||||||||
2892 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
2893 | } | - | ||||||||||||||||||||||||
2894 | - | |||||||||||||||||||||||||
2895 | /*! | - | ||||||||||||||||||||||||
2896 | \relates QTextStream | - | ||||||||||||||||||||||||
2897 | - | |||||||||||||||||||||||||
2898 | Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) | - | ||||||||||||||||||||||||
2899 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2900 | - | |||||||||||||||||||||||||
2901 | \sa {QTextStream::}{left()}, {QTextStream::}{center()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
2902 | */ | - | ||||||||||||||||||||||||
2903 | QTextStream &right(QTextStream &stream) | - | ||||||||||||||||||||||||
2904 | { | - | ||||||||||||||||||||||||
2905 | stream.setFieldAlignment(QTextStream::AlignRight); | - | ||||||||||||||||||||||||
2906 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
2907 | } | - | ||||||||||||||||||||||||
2908 | - | |||||||||||||||||||||||||
2909 | /*! | - | ||||||||||||||||||||||||
2910 | \relates QTextStream | - | ||||||||||||||||||||||||
2911 | - | |||||||||||||||||||||||||
2912 | Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) | - | ||||||||||||||||||||||||
2913 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2914 | - | |||||||||||||||||||||||||
2915 | \sa {QTextStream::}{left()}, {QTextStream::}{right()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
2916 | */ | - | ||||||||||||||||||||||||
2917 | QTextStream ¢er(QTextStream &stream) | - | ||||||||||||||||||||||||
2918 | { | - | ||||||||||||||||||||||||
2919 | stream.setFieldAlignment(QTextStream::AlignCenter); | - | ||||||||||||||||||||||||
2920 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
2921 | } | - | ||||||||||||||||||||||||
2922 | - | |||||||||||||||||||||||||
2923 | /*! | - | ||||||||||||||||||||||||
2924 | \relates QTextStream | - | ||||||||||||||||||||||||
2925 | - | |||||||||||||||||||||||||
2926 | Writes '\\n' to the \a stream and flushes the stream. | - | ||||||||||||||||||||||||
2927 | - | |||||||||||||||||||||||||
2928 | Equivalent to | - | ||||||||||||||||||||||||
2929 | - | |||||||||||||||||||||||||
2930 | \snippet code/src_corelib_io_qtextstream.cpp 9 | - | ||||||||||||||||||||||||
2931 | - | |||||||||||||||||||||||||
2932 | Note: On Windows, all '\\n' characters are written as '\\r\\n' if | - | ||||||||||||||||||||||||
2933 | QTextStream's device or string is opened using the QIODevice::Text flag. | - | ||||||||||||||||||||||||
2934 | - | |||||||||||||||||||||||||
2935 | \sa flush(), reset(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2936 | */ | - | ||||||||||||||||||||||||
2937 | QTextStream &endl(QTextStream &stream) | - | ||||||||||||||||||||||||
2938 | { | - | ||||||||||||||||||||||||
2939 | return stream << QLatin1Char('\n') << flush; executed 50771 times by 14 tests: return stream << QLatin1Char('\n') << flush; Executed by:
| 50771 | ||||||||||||||||||||||||
2940 | } | - | ||||||||||||||||||||||||
2941 | - | |||||||||||||||||||||||||
2942 | /*! | - | ||||||||||||||||||||||||
2943 | \relates QTextStream | - | ||||||||||||||||||||||||
2944 | - | |||||||||||||||||||||||||
2945 | Calls QTextStream::flush() on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2946 | - | |||||||||||||||||||||||||
2947 | \sa endl(), reset(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2948 | */ | - | ||||||||||||||||||||||||
2949 | QTextStream &flush(QTextStream &stream) | - | ||||||||||||||||||||||||
2950 | { | - | ||||||||||||||||||||||||
2951 | stream.flush(); | - | ||||||||||||||||||||||||
2952 | return stream; executed 50774 times by 15 tests: return stream; Executed by:
| 50774 | ||||||||||||||||||||||||
2953 | } | - | ||||||||||||||||||||||||
2954 | - | |||||||||||||||||||||||||
2955 | /*! | - | ||||||||||||||||||||||||
2956 | \relates QTextStream | - | ||||||||||||||||||||||||
2957 | - | |||||||||||||||||||||||||
2958 | Calls QTextStream::reset() on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2959 | - | |||||||||||||||||||||||||
2960 | \sa flush(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
2961 | */ | - | ||||||||||||||||||||||||
2962 | QTextStream &reset(QTextStream &stream) | - | ||||||||||||||||||||||||
2963 | { | - | ||||||||||||||||||||||||
2964 | stream.reset(); | - | ||||||||||||||||||||||||
2965 | return stream; executed 3 times by 2 tests: return stream; Executed by:
| 3 | ||||||||||||||||||||||||
2966 | } | - | ||||||||||||||||||||||||
2967 | - | |||||||||||||||||||||||||
2968 | /*! | - | ||||||||||||||||||||||||
2969 | \relates QTextStream | - | ||||||||||||||||||||||||
2970 | - | |||||||||||||||||||||||||
2971 | Calls \l {QTextStream::}{skipWhiteSpace()} on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
2972 | - | |||||||||||||||||||||||||
2973 | \sa {QTextStream manipulators} | - | ||||||||||||||||||||||||
2974 | */ | - | ||||||||||||||||||||||||
2975 | QTextStream &ws(QTextStream &stream) | - | ||||||||||||||||||||||||
2976 | { | - | ||||||||||||||||||||||||
2977 | stream.skipWhiteSpace(); | - | ||||||||||||||||||||||||
2978 | return stream; executed 3 times by 1 test: return stream; Executed by:
| 3 | ||||||||||||||||||||||||
2979 | } | - | ||||||||||||||||||||||||
2980 | - | |||||||||||||||||||||||||
2981 | /*! | - | ||||||||||||||||||||||||
2982 | \fn QTextStreamManipulator qSetFieldWidth(int width) | - | ||||||||||||||||||||||||
2983 | \relates QTextStream | - | ||||||||||||||||||||||||
2984 | - | |||||||||||||||||||||||||
2985 | Equivalent to QTextStream::setFieldWidth(\a width). | - | ||||||||||||||||||||||||
2986 | */ | - | ||||||||||||||||||||||||
2987 | - | |||||||||||||||||||||||||
2988 | /*! | - | ||||||||||||||||||||||||
2989 | \fn QTextStreamManipulator qSetPadChar(QChar ch) | - | ||||||||||||||||||||||||
2990 | \relates QTextStream | - | ||||||||||||||||||||||||
2991 | - | |||||||||||||||||||||||||
2992 | Equivalent to QTextStream::setPadChar(\a ch). | - | ||||||||||||||||||||||||
2993 | */ | - | ||||||||||||||||||||||||
2994 | - | |||||||||||||||||||||||||
2995 | /*! | - | ||||||||||||||||||||||||
2996 | \fn QTextStreamManipulator qSetRealNumberPrecision(int precision) | - | ||||||||||||||||||||||||
2997 | \relates QTextStream | - | ||||||||||||||||||||||||
2998 | - | |||||||||||||||||||||||||
2999 | Equivalent to QTextStream::setRealNumberPrecision(\a precision). | - | ||||||||||||||||||||||||
3000 | */ | - | ||||||||||||||||||||||||
3001 | - | |||||||||||||||||||||||||
3002 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
3003 | /*! | - | ||||||||||||||||||||||||
3004 | \relates QTextStream | - | ||||||||||||||||||||||||
3005 | - | |||||||||||||||||||||||||
3006 | Toggles insertion of the Byte Order Mark on \a stream when QTextStream is | - | ||||||||||||||||||||||||
3007 | used with a UTF codec. | - | ||||||||||||||||||||||||
3008 | - | |||||||||||||||||||||||||
3009 | \sa QTextStream::setGenerateByteOrderMark(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
3010 | */ | - | ||||||||||||||||||||||||
3011 | QTextStream &bom(QTextStream &stream) | - | ||||||||||||||||||||||||
3012 | { | - | ||||||||||||||||||||||||
3013 | stream.setGenerateByteOrderMark(true); | - | ||||||||||||||||||||||||
3014 | return stream; executed 1 time by 1 test: return stream; Executed by:
| 1 | ||||||||||||||||||||||||
3015 | } | - | ||||||||||||||||||||||||
3016 | - | |||||||||||||||||||||||||
3017 | /*! | - | ||||||||||||||||||||||||
3018 | Sets the codec for this stream to \a codec. The codec is used for | - | ||||||||||||||||||||||||
3019 | decoding any data that is read from the assigned device, and for | - | ||||||||||||||||||||||||
3020 | encoding any data that is written. By default, | - | ||||||||||||||||||||||||
3021 | QTextCodec::codecForLocale() is used, and automatic unicode | - | ||||||||||||||||||||||||
3022 | detection is enabled. | - | ||||||||||||||||||||||||
3023 | - | |||||||||||||||||||||||||
3024 | If QTextStream operates on a string, this function does nothing. | - | ||||||||||||||||||||||||
3025 | - | |||||||||||||||||||||||||
3026 | \warning If you call this function while the text stream is reading | - | ||||||||||||||||||||||||
3027 | from an open sequential socket, the internal buffer may still contain | - | ||||||||||||||||||||||||
3028 | text decoded using the old codec. | - | ||||||||||||||||||||||||
3029 | - | |||||||||||||||||||||||||
3030 | \sa codec(), setAutoDetectUnicode(), setLocale() | - | ||||||||||||||||||||||||
3031 | */ | - | ||||||||||||||||||||||||
3032 | void QTextStream::setCodec(QTextCodec *codec) | - | ||||||||||||||||||||||||
3033 | { | - | ||||||||||||||||||||||||
3034 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
3035 | qint64 seekPos = -1; | - | ||||||||||||||||||||||||
3036 | if (!d->readBuffer.isEmpty()) {
| 1-2129 | ||||||||||||||||||||||||
3037 | if (!d->device->isSequential()) {
| 0-1 | ||||||||||||||||||||||||
3038 | seekPos = pos(); | - | ||||||||||||||||||||||||
3039 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
3040 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
3041 | d->codec = codec; | - | ||||||||||||||||||||||||
3042 | if (seekPos >=0 && !d->readBuffer.isEmpty())
| 0-2129 | ||||||||||||||||||||||||
3043 | seek(seekPos); executed 1 time by 1 test: seek(seekPos); Executed by:
| 1 | ||||||||||||||||||||||||
3044 | } executed 2130 times by 6 tests: end of block Executed by:
| 2130 | ||||||||||||||||||||||||
3045 | - | |||||||||||||||||||||||||
3046 | /*! | - | ||||||||||||||||||||||||
3047 | Sets the codec for this stream to the QTextCodec for the encoding | - | ||||||||||||||||||||||||
3048 | specified by \a codecName. Common values for \c codecName include | - | ||||||||||||||||||||||||
3049 | "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't | - | ||||||||||||||||||||||||
3050 | recognized, nothing happens. | - | ||||||||||||||||||||||||
3051 | - | |||||||||||||||||||||||||
3052 | Example: | - | ||||||||||||||||||||||||
3053 | - | |||||||||||||||||||||||||
3054 | \snippet code/src_corelib_io_qtextstream.cpp 10 | - | ||||||||||||||||||||||||
3055 | - | |||||||||||||||||||||||||
3056 | \sa QTextCodec::codecForName(), setLocale() | - | ||||||||||||||||||||||||
3057 | */ | - | ||||||||||||||||||||||||
3058 | void QTextStream::setCodec(const char *codecName) | - | ||||||||||||||||||||||||
3059 | { | - | ||||||||||||||||||||||||
3060 | QTextCodec *codec = QTextCodec::codecForName(codecName); | - | ||||||||||||||||||||||||
3061 | if (codec)
| 0-1941 | ||||||||||||||||||||||||
3062 | setCodec(codec); executed 1941 times by 4 tests: setCodec(codec); Executed by:
| 1941 | ||||||||||||||||||||||||
3063 | } executed 1941 times by 4 tests: end of block Executed by:
| 1941 | ||||||||||||||||||||||||
3064 | - | |||||||||||||||||||||||||
3065 | /*! | - | ||||||||||||||||||||||||
3066 | Returns the codec that is current assigned to the stream. | - | ||||||||||||||||||||||||
3067 | - | |||||||||||||||||||||||||
3068 | \sa setCodec(), setAutoDetectUnicode(), locale() | - | ||||||||||||||||||||||||
3069 | */ | - | ||||||||||||||||||||||||
3070 | QTextCodec *QTextStream::codec() const | - | ||||||||||||||||||||||||
3071 | { | - | ||||||||||||||||||||||||
3072 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
3073 | return d->codec; executed 401 times by 3 tests: return d->codec; Executed by:
| 401 | ||||||||||||||||||||||||
3074 | } | - | ||||||||||||||||||||||||
3075 | - | |||||||||||||||||||||||||
3076 | /*! | - | ||||||||||||||||||||||||
3077 | If \a enabled is true, QTextStream will attempt to detect Unicode | - | ||||||||||||||||||||||||
3078 | encoding by peeking into the stream data to see if it can find the | - | ||||||||||||||||||||||||
3079 | UTF-16 or UTF-32 BOM (Byte Order Mark). If this mark is found, QTextStream | - | ||||||||||||||||||||||||
3080 | will replace the current codec with the UTF codec. | - | ||||||||||||||||||||||||
3081 | - | |||||||||||||||||||||||||
3082 | This function can be used together with setCodec(). It is common | - | ||||||||||||||||||||||||
3083 | to set the codec to UTF-8, and then enable UTF-16 detection. | - | ||||||||||||||||||||||||
3084 | - | |||||||||||||||||||||||||
3085 | \sa autoDetectUnicode(), setCodec() | - | ||||||||||||||||||||||||
3086 | */ | - | ||||||||||||||||||||||||
3087 | void QTextStream::setAutoDetectUnicode(bool enabled) | - | ||||||||||||||||||||||||
3088 | { | - | ||||||||||||||||||||||||
3089 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
3090 | d->autoDetectUnicode = enabled; | - | ||||||||||||||||||||||||
3091 | } executed 55 times by 1 test: end of block Executed by:
| 55 | ||||||||||||||||||||||||
3092 | - | |||||||||||||||||||||||||
3093 | /*! | - | ||||||||||||||||||||||||
3094 | Returns \c true if automatic Unicode detection is enabled, otherwise | - | ||||||||||||||||||||||||
3095 | returns \c false. Automatic Unicode detection is enabled by default. | - | ||||||||||||||||||||||||
3096 | - | |||||||||||||||||||||||||
3097 | \sa setAutoDetectUnicode(), setCodec() | - | ||||||||||||||||||||||||
3098 | */ | - | ||||||||||||||||||||||||
3099 | bool QTextStream::autoDetectUnicode() const | - | ||||||||||||||||||||||||
3100 | { | - | ||||||||||||||||||||||||
3101 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
3102 | return d->autoDetectUnicode; executed 2 times by 1 test: return d->autoDetectUnicode; Executed by:
| 2 | ||||||||||||||||||||||||
3103 | } | - | ||||||||||||||||||||||||
3104 | - | |||||||||||||||||||||||||
3105 | /*! | - | ||||||||||||||||||||||||
3106 | If \a generate is true and a UTF codec is used, QTextStream will insert | - | ||||||||||||||||||||||||
3107 | the BOM (Byte Order Mark) before any data has been written to the | - | ||||||||||||||||||||||||
3108 | device. If \a generate is false, no BOM will be inserted. This function | - | ||||||||||||||||||||||||
3109 | must be called before any data is written. Otherwise, it does nothing. | - | ||||||||||||||||||||||||
3110 | - | |||||||||||||||||||||||||
3111 | \sa generateByteOrderMark(), bom() | - | ||||||||||||||||||||||||
3112 | */ | - | ||||||||||||||||||||||||
3113 | void QTextStream::setGenerateByteOrderMark(bool generate) | - | ||||||||||||||||||||||||
3114 | { | - | ||||||||||||||||||||||||
3115 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
3116 | if (d->writeBuffer.isEmpty()) {
| 0-3 | ||||||||||||||||||||||||
3117 | if (generate)
| 1-2 | ||||||||||||||||||||||||
3118 | d->writeConverterState.flags &= ~QTextCodec::IgnoreHeader; executed 2 times by 1 test: d->writeConverterState.flags &= ~QTextCodec::IgnoreHeader; Executed by:
| 2 | ||||||||||||||||||||||||
3119 | else | - | ||||||||||||||||||||||||
3120 | d->writeConverterState.flags |= QTextCodec::IgnoreHeader; executed 1 time by 1 test: d->writeConverterState.flags |= QTextCodec::IgnoreHeader; Executed by:
| 1 | ||||||||||||||||||||||||
3121 | } | - | ||||||||||||||||||||||||
3122 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
3123 | - | |||||||||||||||||||||||||
3124 | /*! | - | ||||||||||||||||||||||||
3125 | Returns \c true if QTextStream is set to generate the UTF BOM (Byte Order | - | ||||||||||||||||||||||||
3126 | Mark) when using a UTF codec; otherwise returns \c false. UTF BOM generation is | - | ||||||||||||||||||||||||
3127 | set to false by default. | - | ||||||||||||||||||||||||
3128 | - | |||||||||||||||||||||||||
3129 | \sa setGenerateByteOrderMark() | - | ||||||||||||||||||||||||
3130 | */ | - | ||||||||||||||||||||||||
3131 | bool QTextStream::generateByteOrderMark() const | - | ||||||||||||||||||||||||
3132 | { | - | ||||||||||||||||||||||||
3133 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
3134 | return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0; executed 2 times by 1 test: return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0; Executed by:
| 2 | ||||||||||||||||||||||||
3135 | } | - | ||||||||||||||||||||||||
3136 | - | |||||||||||||||||||||||||
3137 | #endif | - | ||||||||||||||||||||||||
3138 | - | |||||||||||||||||||||||||
3139 | /*! | - | ||||||||||||||||||||||||
3140 | \since 4.5 | - | ||||||||||||||||||||||||
3141 | - | |||||||||||||||||||||||||
3142 | Sets the locale for this stream to \a locale. The specified locale is | - | ||||||||||||||||||||||||
3143 | used for conversions between numbers and their string representations. | - | ||||||||||||||||||||||||
3144 | - | |||||||||||||||||||||||||
3145 | The default locale is C and it is a special case - the thousands | - | ||||||||||||||||||||||||
3146 | group separator is not used for backward compatibility reasons. | - | ||||||||||||||||||||||||
3147 | - | |||||||||||||||||||||||||
3148 | \sa locale() | - | ||||||||||||||||||||||||
3149 | */ | - | ||||||||||||||||||||||||
3150 | void QTextStream::setLocale(const QLocale &locale) | - | ||||||||||||||||||||||||
3151 | { | - | ||||||||||||||||||||||||
3152 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
3153 | d->locale = locale; | - | ||||||||||||||||||||||||
3154 | } executed 384 times by 1 test: end of block Executed by:
| 384 | ||||||||||||||||||||||||
3155 | - | |||||||||||||||||||||||||
3156 | /*! | - | ||||||||||||||||||||||||
3157 | \since 4.5 | - | ||||||||||||||||||||||||
3158 | - | |||||||||||||||||||||||||
3159 | Returns the locale for this stream. The default locale is C. | - | ||||||||||||||||||||||||
3160 | - | |||||||||||||||||||||||||
3161 | \sa setLocale() | - | ||||||||||||||||||||||||
3162 | */ | - | ||||||||||||||||||||||||
3163 | QLocale QTextStream::locale() const | - | ||||||||||||||||||||||||
3164 | { | - | ||||||||||||||||||||||||
3165 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
3166 | return d->locale; executed 318 times by 9 tests: return d->locale; Executed by:
| 318 | ||||||||||||||||||||||||
3167 | } | - | ||||||||||||||||||||||||
3168 | - | |||||||||||||||||||||||||
3169 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
3170 | - | |||||||||||||||||||||||||
Source code | Switch to Preprocessed file |