| 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) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | //#define QTEXTSTREAM_DEBUG | - | ||||||||||||||||||||||||
| 42 | static const int QTEXTSTREAM_BUFFERSIZE = 16384; | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | /*! | - | ||||||||||||||||||||||||
| 45 | \class QTextStream | - | ||||||||||||||||||||||||
| 46 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | \brief The QTextStream class provides a convenient interface for | - | ||||||||||||||||||||||||
| 49 | reading and writing text. | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | \ingroup io | - | ||||||||||||||||||||||||
| 52 | \ingroup string-processing | - | ||||||||||||||||||||||||
| 53 | \reentrant | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | QTextStream can operate on a QIODevice, a QByteArray or a | - | ||||||||||||||||||||||||
| 56 | QString. Using QTextStream's streaming operators, you can | - | ||||||||||||||||||||||||
| 57 | conveniently read and write words, lines and numbers. For | - | ||||||||||||||||||||||||
| 58 | generating text, QTextStream supports formatting options for field | - | ||||||||||||||||||||||||
| 59 | padding and alignment, and formatting of numbers. Example: | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | \snippet code/src_corelib_io_qtextstream.cpp 0 | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | It's also common to use QTextStream to read console input and write | - | ||||||||||||||||||||||||
| 64 | console output. QTextStream is locale aware, and will automatically decode | - | ||||||||||||||||||||||||
| 65 | standard input using the correct codec. Example: | - | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | \snippet code/src_corelib_io_qtextstream.cpp 1 | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | Besides using QTextStream's constructors, you can also set the | - | ||||||||||||||||||||||||
| 70 | device or string QTextStream operates on by calling setDevice() or | - | ||||||||||||||||||||||||
| 71 | setString(). You can seek to a position by calling seek(), and | - | ||||||||||||||||||||||||
| 72 | atEnd() will return true when there is no data left to be read. If | - | ||||||||||||||||||||||||
| 73 | you call flush(), QTextStream will empty all data from its write | - | ||||||||||||||||||||||||
| 74 | buffer into the device and call flush() on the device. | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | Internally, QTextStream uses a Unicode based buffer, and | - | ||||||||||||||||||||||||
| 77 | QTextCodec is used by QTextStream to automatically support | - | ||||||||||||||||||||||||
| 78 | different character sets. By default, QTextCodec::codecForLocale() | - | ||||||||||||||||||||||||
| 79 | is used for reading and writing, but you can also set the codec by | - | ||||||||||||||||||||||||
| 80 | calling setCodec(). Automatic Unicode detection is also | - | ||||||||||||||||||||||||
| 81 | supported. When this feature is enabled (the default behavior), | - | ||||||||||||||||||||||||
| 82 | QTextStream will detect the UTF-16 or the UTF-32 BOM (Byte Order Mark) and | - | ||||||||||||||||||||||||
| 83 | switch to the appropriate UTF codec when reading. QTextStream | - | ||||||||||||||||||||||||
| 84 | does not write a BOM by default, but you can enable this by calling | - | ||||||||||||||||||||||||
| 85 | setGenerateByteOrderMark(true). When QTextStream operates on a QString | - | ||||||||||||||||||||||||
| 86 | directly, the codec is disabled. | - | ||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | There are three general ways to use QTextStream when reading text | - | ||||||||||||||||||||||||
| 89 | files: | - | ||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||
| 91 | \list | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | \li Chunk by chunk, by calling readLine() or readAll(). | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | \li Word by word. QTextStream supports streaming into \l {QString}s, | - | ||||||||||||||||||||||||
| 96 | \l {QByteArray}s and char* buffers. Words are delimited by space, and | - | ||||||||||||||||||||||||
| 97 | leading white space is automatically skipped. | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | \li Character by character, by streaming into QChar or char types. | - | ||||||||||||||||||||||||
| 100 | This method is often used for convenient input handling when | - | ||||||||||||||||||||||||
| 101 | parsing files, independent of character encoding and end-of-line | - | ||||||||||||||||||||||||
| 102 | semantics. To skip white space, call skipWhiteSpace(). | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | \endlist | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | Since the text stream uses a buffer, you should not read from | - | ||||||||||||||||||||||||
| 107 | the stream using the implementation of a superclass. For instance, | - | ||||||||||||||||||||||||
| 108 | if you have a QFile and read from it directly using | - | ||||||||||||||||||||||||
| 109 | QFile::readLine() instead of using the stream, the text stream's | - | ||||||||||||||||||||||||
| 110 | internal position will be out of sync with the file's position. | - | ||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | By default, when reading numbers from a stream of text, | - | ||||||||||||||||||||||||
| 113 | QTextStream will automatically detect the number's base | - | ||||||||||||||||||||||||
| 114 | representation. For example, if the number starts with "0x", it is | - | ||||||||||||||||||||||||
| 115 | assumed to be in hexadecimal form. If it starts with the digits | - | ||||||||||||||||||||||||
| 116 | 1-9, it is assumed to be in decimal form, and so on. You can set | - | ||||||||||||||||||||||||
| 117 | the integer base, thereby disabling the automatic detection, by | - | ||||||||||||||||||||||||
| 118 | calling setIntegerBase(). Example: | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | \snippet code/src_corelib_io_qtextstream.cpp 2 | - | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | QTextStream supports many formatting options for generating text. | - | ||||||||||||||||||||||||
| 123 | You can set the field width and pad character by calling | - | ||||||||||||||||||||||||
| 124 | setFieldWidth() and setPadChar(). Use setFieldAlignment() to set | - | ||||||||||||||||||||||||
| 125 | the alignment within each field. For real numbers, call | - | ||||||||||||||||||||||||
| 126 | setRealNumberNotation() and setRealNumberPrecision() to set the | - | ||||||||||||||||||||||||
| 127 | notation (SmartNotation, ScientificNotation, FixedNotation) and precision in | - | ||||||||||||||||||||||||
| 128 | digits of the generated number. Some extra number formatting | - | ||||||||||||||||||||||||
| 129 | options are also available through setNumberFlags(). | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | \target QTextStream manipulators | - | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | Like \c <iostream> in the standard C++ library, QTextStream also | - | ||||||||||||||||||||||||
| 134 | defines several global manipulator functions: | - | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | \table | - | ||||||||||||||||||||||||
| 137 | \header \li Manipulator \li Description | - | ||||||||||||||||||||||||
| 138 | \row \li \c bin \li Same as setIntegerBase(2). | - | ||||||||||||||||||||||||
| 139 | \row \li \c oct \li Same as setIntegerBase(8). | - | ||||||||||||||||||||||||
| 140 | \row \li \c dec \li Same as setIntegerBase(10). | - | ||||||||||||||||||||||||
| 141 | \row \li \c hex \li Same as setIntegerBase(16). | - | ||||||||||||||||||||||||
| 142 | \row \li \c showbase \li Same as setNumberFlags(numberFlags() | ShowBase). | - | ||||||||||||||||||||||||
| 143 | \row \li \c forcesign \li Same as setNumberFlags(numberFlags() | ForceSign). | - | ||||||||||||||||||||||||
| 144 | \row \li \c forcepoint \li Same as setNumberFlags(numberFlags() | ForcePoint). | - | ||||||||||||||||||||||||
| 145 | \row \li \c noshowbase \li Same as setNumberFlags(numberFlags() & ~ShowBase). | - | ||||||||||||||||||||||||
| 146 | \row \li \c noforcesign \li Same as setNumberFlags(numberFlags() & ~ForceSign). | - | ||||||||||||||||||||||||
| 147 | \row \li \c noforcepoint \li Same as setNumberFlags(numberFlags() & ~ForcePoint). | - | ||||||||||||||||||||||||
| 148 | \row \li \c uppercasebase \li Same as setNumberFlags(numberFlags() | UppercaseBase). | - | ||||||||||||||||||||||||
| 149 | \row \li \c uppercasedigits \li Same as setNumberFlags(numberFlags() | UppercaseDigits). | - | ||||||||||||||||||||||||
| 150 | \row \li \c lowercasebase \li Same as setNumberFlags(numberFlags() & ~UppercaseBase). | - | ||||||||||||||||||||||||
| 151 | \row \li \c lowercasedigits \li Same as setNumberFlags(numberFlags() & ~UppercaseDigits). | - | ||||||||||||||||||||||||
| 152 | \row \li \c fixed \li Same as setRealNumberNotation(FixedNotation). | - | ||||||||||||||||||||||||
| 153 | \row \li \c scientific \li Same as setRealNumberNotation(ScientificNotation). | - | ||||||||||||||||||||||||
| 154 | \row \li \c left \li Same as setFieldAlignment(AlignLeft). | - | ||||||||||||||||||||||||
| 155 | \row \li \c right \li Same as setFieldAlignment(AlignRight). | - | ||||||||||||||||||||||||
| 156 | \row \li \c center \li Same as setFieldAlignment(AlignCenter). | - | ||||||||||||||||||||||||
| 157 | \row \li \c endl \li Same as operator<<('\\n') and flush(). | - | ||||||||||||||||||||||||
| 158 | \row \li \c flush \li Same as flush(). | - | ||||||||||||||||||||||||
| 159 | \row \li \c reset \li Same as reset(). | - | ||||||||||||||||||||||||
| 160 | \row \li \c ws \li Same as skipWhiteSpace(). | - | ||||||||||||||||||||||||
| 161 | \row \li \c bom \li Same as setGenerateByteOrderMark(true). | - | ||||||||||||||||||||||||
| 162 | \endtable | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | In addition, Qt provides three global manipulators that take a | - | ||||||||||||||||||||||||
| 165 | parameter: qSetFieldWidth(), qSetPadChar(), and | - | ||||||||||||||||||||||||
| 166 | qSetRealNumberPrecision(). | - | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | \sa QDataStream, QIODevice, QFile, QBuffer, QTcpSocket, {Text Codecs Example} | - | ||||||||||||||||||||||||
| 169 | */ | - | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | /*! \enum QTextStream::RealNumberNotation | - | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | This enum specifies which notations to use for expressing \c | - | ||||||||||||||||||||||||
| 174 | float and \c double as strings. | - | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | \value ScientificNotation Scientific notation (\c{printf()}'s \c %e flag). | - | ||||||||||||||||||||||||
| 177 | \value FixedNotation Fixed-point notation (\c{printf()}'s \c %f flag). | - | ||||||||||||||||||||||||
| 178 | \value SmartNotation Scientific or fixed-point notation, depending on which makes most sense (\c{printf()}'s \c %g flag). | - | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | \sa setRealNumberNotation() | - | ||||||||||||||||||||||||
| 181 | */ | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | /*! \enum QTextStream::FieldAlignment | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | This enum specifies how to align text in fields when the field is | - | ||||||||||||||||||||||||
| 186 | wider than the text that occupies it. | - | ||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||
| 188 | \value AlignLeft Pad on the right side of fields. | - | ||||||||||||||||||||||||
| 189 | \value AlignRight Pad on the left side of fields. | - | ||||||||||||||||||||||||
| 190 | \value AlignCenter Pad on both sides of field. | - | ||||||||||||||||||||||||
| 191 | \value AlignAccountingStyle Same as AlignRight, except that the | - | ||||||||||||||||||||||||
| 192 | sign of a number is flush left. | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | \sa setFieldAlignment() | - | ||||||||||||||||||||||||
| 195 | */ | - | ||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | /*! \enum QTextStream::NumberFlag | - | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | This enum specifies various flags that can be set to affect the | - | ||||||||||||||||||||||||
| 200 | output of integers, \c{float}s, and \c{double}s. | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | \value ShowBase Show the base as a prefix if the base | - | ||||||||||||||||||||||||
| 203 | is 16 ("0x"), 8 ("0"), or 2 ("0b"). | - | ||||||||||||||||||||||||
| 204 | \value ForcePoint Always put the decimal separator in numbers, even if | - | ||||||||||||||||||||||||
| 205 | there are no decimals. | - | ||||||||||||||||||||||||
| 206 | \value ForceSign Always put the sign in numbers, even for positive numbers. | - | ||||||||||||||||||||||||
| 207 | \value UppercaseBase Use uppercase versions of base prefixes ("0X", "0B"). | - | ||||||||||||||||||||||||
| 208 | \value UppercaseDigits Use uppercase letters for expressing | - | ||||||||||||||||||||||||
| 209 | digits 10 to 35 instead of lowercase. | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | \sa setNumberFlags() | - | ||||||||||||||||||||||||
| 212 | */ | - | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | /*! \enum QTextStream::Status | - | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | This enum describes the current status of the text stream. | - | ||||||||||||||||||||||||
| 217 | - | |||||||||||||||||||||||||
| 218 | \value Ok The text stream is operating normally. | - | ||||||||||||||||||||||||
| 219 | \value ReadPastEnd The text stream has read past the end of the | - | ||||||||||||||||||||||||
| 220 | data in the underlying device. | - | ||||||||||||||||||||||||
| 221 | \value ReadCorruptData The text stream has read corrupt data. | - | ||||||||||||||||||||||||
| 222 | \value WriteFailed The text stream cannot write to the underlying device. | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | \sa status() | - | ||||||||||||||||||||||||
| 225 | */ | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | #include "qtextstream.h" | - | ||||||||||||||||||||||||
| 228 | #include "private/qtextstream_p.h" | - | ||||||||||||||||||||||||
| 229 | #include "qbuffer.h" | - | ||||||||||||||||||||||||
| 230 | #include "qfile.h" | - | ||||||||||||||||||||||||
| 231 | #include "qnumeric.h" | - | ||||||||||||||||||||||||
| 232 | #include "qvarlengtharray.h" | - | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | #ifndef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 235 | #include <locale.h> | - | ||||||||||||||||||||||||
| 236 | #endif | - | ||||||||||||||||||||||||
| 237 | #include "private/qlocale_p.h" | - | ||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | #include <stdlib.h> | - | ||||||||||||||||||||||||
| 240 | #include <limits.h> | - | ||||||||||||||||||||||||
| 241 | #include <new> | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | #if defined QTEXTSTREAM_DEBUG | - | ||||||||||||||||||||||||
| 244 | #include <ctype.h> | - | ||||||||||||||||||||||||
| 245 | #include "private/qtools_p.h" | - | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||
| 249 | // Returns a human readable representation of the first \a len | - | ||||||||||||||||||||||||
| 250 | // characters in \a data. | - | ||||||||||||||||||||||||
| 251 | static QByteArray qt_prettyDebug(const char *data, int len, int maxSize) | - | ||||||||||||||||||||||||
| 252 | { | - | ||||||||||||||||||||||||
| 253 | if (!data) return "(null)"; | - | ||||||||||||||||||||||||
| 254 | QByteArray out; | - | ||||||||||||||||||||||||
| 255 | for (int i = 0; i < len; ++i) { | - | ||||||||||||||||||||||||
| 256 | char c = data[i]; | - | ||||||||||||||||||||||||
| 257 | if (isprint(int(uchar(c)))) { | - | ||||||||||||||||||||||||
| 258 | out += c; | - | ||||||||||||||||||||||||
| 259 | } else switch (c) { | - | ||||||||||||||||||||||||
| 260 | case '\n': out += "\\n"; break; | - | ||||||||||||||||||||||||
| 261 | case '\r': out += "\\r"; break; | - | ||||||||||||||||||||||||
| 262 | case '\t': out += "\\t"; break; | - | ||||||||||||||||||||||||
| 263 | default: { | - | ||||||||||||||||||||||||
| 264 | const char buf[] = { | - | ||||||||||||||||||||||||
| 265 | '\\', | - | ||||||||||||||||||||||||
| 266 | 'x', | - | ||||||||||||||||||||||||
| 267 | QtMiscUtils::toHexLower(uchar(c) / 16), | - | ||||||||||||||||||||||||
| 268 | QtMiscUtils::toHexLower(uchar(c) % 16), | - | ||||||||||||||||||||||||
| 269 | 0 | - | ||||||||||||||||||||||||
| 270 | }; | - | ||||||||||||||||||||||||
| 271 | out += buf; | - | ||||||||||||||||||||||||
| 272 | } | - | ||||||||||||||||||||||||
| 273 | } | - | ||||||||||||||||||||||||
| 274 | } | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | if (len < maxSize) | - | ||||||||||||||||||||||||
| 277 | out += "..."; | - | ||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||
| 279 | return out; | - | ||||||||||||||||||||||||
| 280 | } | - | ||||||||||||||||||||||||
| 281 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | #endif | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | // A precondition macro | - | ||||||||||||||||||||||||
| 286 | #define Q_VOID | - | ||||||||||||||||||||||||
| 287 | #define CHECK_VALID_STREAM(x) do { \ | - | ||||||||||||||||||||||||
| 288 | if (!d->string && !d->device) { \ | - | ||||||||||||||||||||||||
| 289 | qWarning("QTextStream: No device"); \ | - | ||||||||||||||||||||||||
| 290 | return x; \ | - | ||||||||||||||||||||||||
| 291 | } } while (0) | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | // Base implementations of operator>> for ints and reals | - | ||||||||||||||||||||||||
| 294 | #define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type) do { \ | - | ||||||||||||||||||||||||
| 295 | Q_D(QTextStream); \ | - | ||||||||||||||||||||||||
| 296 | CHECK_VALID_STREAM(*this); \ | - | ||||||||||||||||||||||||
| 297 | qulonglong tmp; \ | - | ||||||||||||||||||||||||
| 298 | switch (d->getNumber(&tmp)) { \ | - | ||||||||||||||||||||||||
| 299 | case QTextStreamPrivate::npsOk: \ | - | ||||||||||||||||||||||||
| 300 | i = (type)tmp; \ | - | ||||||||||||||||||||||||
| 301 | break; \ | - | ||||||||||||||||||||||||
| 302 | case QTextStreamPrivate::npsMissingDigit: \ | - | ||||||||||||||||||||||||
| 303 | case QTextStreamPrivate::npsInvalidPrefix: \ | - | ||||||||||||||||||||||||
| 304 | i = (type)0; \ | - | ||||||||||||||||||||||||
| 305 | setStatus(atEnd() ? QTextStream::ReadPastEnd : QTextStream::ReadCorruptData); \ | - | ||||||||||||||||||||||||
| 306 | break; \ | - | ||||||||||||||||||||||||
| 307 | } \ | - | ||||||||||||||||||||||||
| 308 | return *this; } while (0) | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | #define IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(type) do { \ | - | ||||||||||||||||||||||||
| 311 | Q_D(QTextStream); \ | - | ||||||||||||||||||||||||
| 312 | CHECK_VALID_STREAM(*this); \ | - | ||||||||||||||||||||||||
| 313 | double tmp; \ | - | ||||||||||||||||||||||||
| 314 | if (d->getReal(&tmp)) { \ | - | ||||||||||||||||||||||||
| 315 | f = (type)tmp; \ | - | ||||||||||||||||||||||||
| 316 | } else { \ | - | ||||||||||||||||||||||||
| 317 | f = (type)0; \ | - | ||||||||||||||||||||||||
| 318 | setStatus(atEnd() ? QTextStream::ReadPastEnd : QTextStream::ReadCorruptData); \ | - | ||||||||||||||||||||||||
| 319 | } \ | - | ||||||||||||||||||||||||
| 320 | return *this; } while (0) | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | //------------------------------------------------------------------- | - | ||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||
| 326 | /*! | - | ||||||||||||||||||||||||
| 327 | \internal | - | ||||||||||||||||||||||||
| 328 | */ | - | ||||||||||||||||||||||||
| 329 | QTextStreamPrivate::QTextStreamPrivate(QTextStream *q_ptr) | - | ||||||||||||||||||||||||
| 330 | : | - | ||||||||||||||||||||||||
| 331 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 332 | readConverterSavedState(0), | - | ||||||||||||||||||||||||
| 333 | #endif | - | ||||||||||||||||||||||||
| 334 | readConverterSavedStateOffset(0), | - | ||||||||||||||||||||||||
| 335 | locale(QLocale::c()) | - | ||||||||||||||||||||||||
| 336 | { | - | ||||||||||||||||||||||||
| 337 | this->q_ptr = q_ptr; | - | ||||||||||||||||||||||||
| 338 | reset(); | - | ||||||||||||||||||||||||
| 339 | } executed 79221 times by 96 tests: end of blockExecuted by:
| 79221 | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | /*! | - | ||||||||||||||||||||||||
| 342 | \internal | - | ||||||||||||||||||||||||
| 343 | */ | - | ||||||||||||||||||||||||
| 344 | QTextStreamPrivate::~QTextStreamPrivate() | - | ||||||||||||||||||||||||
| 345 | { | - | ||||||||||||||||||||||||
| 346 | if (deleteDevice) {
| 845-78376 | ||||||||||||||||||||||||
| 347 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 348 | device->blockSignals(true); | - | ||||||||||||||||||||||||
| 349 | #endif | - | ||||||||||||||||||||||||
| 350 | delete device; | - | ||||||||||||||||||||||||
| 351 | } executed 845 times by 8 tests: end of blockExecuted by:
| 845 | ||||||||||||||||||||||||
| 352 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 353 | delete readConverterSavedState; | - | ||||||||||||||||||||||||
| 354 | #endif | - | ||||||||||||||||||||||||
| 355 | } executed 79221 times by 96 tests: end of blockExecuted by:
| 79221 | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 358 | static void resetCodecConverterStateHelper(QTextCodec::ConverterState *state) | - | ||||||||||||||||||||||||
| 359 | { | - | ||||||||||||||||||||||||
| 360 | state->~ConverterState(); | - | ||||||||||||||||||||||||
| 361 | new (state) QTextCodec::ConverterState; | - | ||||||||||||||||||||||||
| 362 | } executed 589195 times by 96 tests: end of blockExecuted by:
| 589195 | ||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||
| 364 | static void copyConverterStateHelper(QTextCodec::ConverterState *dest, | - | ||||||||||||||||||||||||
| 365 | const QTextCodec::ConverterState *src) | - | ||||||||||||||||||||||||
| 366 | { | - | ||||||||||||||||||||||||
| 367 | // ### QTextCodec::ConverterState's copy constructors and assignments are | - | ||||||||||||||||||||||||
| 368 | // private. This function copies the structure manually. | - | ||||||||||||||||||||||||
| 369 | Q_ASSERT(!src->d); | - | ||||||||||||||||||||||||
| 370 | dest->flags = src->flags; | - | ||||||||||||||||||||||||
| 371 | dest->invalidChars = src->invalidChars; | - | ||||||||||||||||||||||||
| 372 | dest->state_data[0] = src->state_data[0]; | - | ||||||||||||||||||||||||
| 373 | dest->state_data[1] = src->state_data[1]; | - | ||||||||||||||||||||||||
| 374 | dest->state_data[2] = src->state_data[2]; | - | ||||||||||||||||||||||||
| 375 | } executed 2698 times by 16 tests: end of blockExecuted by:
| 2698 | ||||||||||||||||||||||||
| 376 | #endif | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | void QTextStreamPrivate::Params::reset() | - | ||||||||||||||||||||||||
| 379 | { | - | ||||||||||||||||||||||||
| 380 | realNumberPrecision = 6; | - | ||||||||||||||||||||||||
| 381 | integerBase = 0; | - | ||||||||||||||||||||||||
| 382 | fieldWidth = 0; | - | ||||||||||||||||||||||||
| 383 | padChar = QLatin1Char(' '); | - | ||||||||||||||||||||||||
| 384 | fieldAlignment = QTextStream::AlignRight; | - | ||||||||||||||||||||||||
| 385 | realNumberNotation = QTextStream::SmartNotation; | - | ||||||||||||||||||||||||
| 386 | numberFlags = 0; | - | ||||||||||||||||||||||||
| 387 | } executed 93328 times by 96 tests: end of blockExecuted by:
| 93328 | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | /*! | - | ||||||||||||||||||||||||
| 390 | \internal | - | ||||||||||||||||||||||||
| 391 | */ | - | ||||||||||||||||||||||||
| 392 | void QTextStreamPrivate::reset() | - | ||||||||||||||||||||||||
| 393 | { | - | ||||||||||||||||||||||||
| 394 | params.reset(); | - | ||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | device = 0; | - | ||||||||||||||||||||||||
| 397 | deleteDevice = false; | - | ||||||||||||||||||||||||
| 398 | string = 0; | - | ||||||||||||||||||||||||
| 399 | stringOffset = 0; | - | ||||||||||||||||||||||||
| 400 | stringOpenMode = QIODevice::NotOpen; | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
| 403 | readBufferStartDevicePos = 0; | - | ||||||||||||||||||||||||
| 404 | lastTokenSize = 0; | - | ||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 407 | codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||||||||
| 408 | resetCodecConverterStateHelper(&readConverterState); | - | ||||||||||||||||||||||||
| 409 | resetCodecConverterStateHelper(&writeConverterState); | - | ||||||||||||||||||||||||
| 410 | delete readConverterSavedState; | - | ||||||||||||||||||||||||
| 411 | readConverterSavedState = 0; | - | ||||||||||||||||||||||||
| 412 | writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
| 413 | autoDetectUnicode = true; | - | ||||||||||||||||||||||||
| 414 | #endif | - | ||||||||||||||||||||||||
| 415 | } executed 79239 times by 96 tests: end of blockExecuted by:
| 79239 | ||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||
| 417 | /*! | - | ||||||||||||||||||||||||
| 418 | \internal | - | ||||||||||||||||||||||||
| 419 | */ | - | ||||||||||||||||||||||||
| 420 | bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) | - | ||||||||||||||||||||||||
| 421 | { | - | ||||||||||||||||||||||||
| 422 | // no buffer next to the QString itself; this function should only | - | ||||||||||||||||||||||||
| 423 | // be called internally, for devices. | - | ||||||||||||||||||||||||
| 424 | Q_ASSERT(!string); | - | ||||||||||||||||||||||||
| 425 | Q_ASSERT(device); | - | ||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||
| 427 | // handle text translation and bypass the Text flag in the device. | - | ||||||||||||||||||||||||
| 428 | bool textModeEnabled = device->isTextModeEnabled(); | - | ||||||||||||||||||||||||
| 429 | if (textModeEnabled)
| 2563-41040053 | ||||||||||||||||||||||||
| 430 | device->setTextModeEnabled(false); executed 41040053 times by 6 tests: device->setTextModeEnabled(false);Executed by:
| 41040053 | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | // read raw data into a temporary buffer | - | ||||||||||||||||||||||||
| 433 | char buf[QTEXTSTREAM_BUFFERSIZE]; | - | ||||||||||||||||||||||||
| 434 | qint64 bytesRead = 0; | - | ||||||||||||||||||||||||
| 435 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 436 | // On Windows, there is no non-blocking stdin - so we fall back to reading | - | ||||||||||||||||||||||||
| 437 | // lines instead. If there is no QOBJECT, we read lines for all sequential | - | ||||||||||||||||||||||||
| 438 | // devices; otherwise, we read lines only for stdin. | - | ||||||||||||||||||||||||
| 439 | QFile *file = 0; | - | ||||||||||||||||||||||||
| 440 | Q_UNUSED(file); | - | ||||||||||||||||||||||||
| 441 | if (device->isSequential() | - | ||||||||||||||||||||||||
| 442 | #if !defined(QT_NO_QOBJECT) | - | ||||||||||||||||||||||||
| 443 | && (file = qobject_cast<QFile *>(device)) && file->handle() == 0 | - | ||||||||||||||||||||||||
| 444 | #endif | - | ||||||||||||||||||||||||
| 445 | ) { | - | ||||||||||||||||||||||||
| 446 | if (maxBytes != -1) | - | ||||||||||||||||||||||||
| 447 | bytesRead = device->readLine(buf, qMin<qint64>(sizeof(buf), maxBytes)); | - | ||||||||||||||||||||||||
| 448 | else | - | ||||||||||||||||||||||||
| 449 | bytesRead = device->readLine(buf, sizeof(buf)); | - | ||||||||||||||||||||||||
| 450 | } else | - | ||||||||||||||||||||||||
| 451 | #endif | - | ||||||||||||||||||||||||
| 452 | { | - | ||||||||||||||||||||||||
| 453 | if (maxBytes != -1)
| 7322-41035294 | ||||||||||||||||||||||||
| 454 | 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 | ||||||||||||||||||||||||
| 455 | else | - | ||||||||||||||||||||||||
| 456 | bytesRead = device->read(buf, sizeof(buf)); executed 7322 times by 17 tests: bytesRead = device->read(buf, sizeof(buf));Executed by:
| 7322 | ||||||||||||||||||||||||
| 457 | } | - | ||||||||||||||||||||||||
| 458 | - | |||||||||||||||||||||||||
| 459 | // reset the Text flag. | - | ||||||||||||||||||||||||
| 460 | if (textModeEnabled)
| 2563-41040053 | ||||||||||||||||||||||||
| 461 | device->setTextModeEnabled(true); executed 41040053 times by 6 tests: device->setTextModeEnabled(true);Executed by:
| 41040053 | ||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| 463 | if (bytesRead <= 0)
| 2523-41040093 | ||||||||||||||||||||||||
| 464 | return false; executed 2523 times by 7 tests: return false;Executed by:
| 2523 | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 467 | // codec auto detection, explicitly defaults to locale encoding if the | - | ||||||||||||||||||||||||
| 468 | // codec has been set to 0. | - | ||||||||||||||||||||||||
| 469 | if (!codec || autoDetectUnicode) {
| 0-41040093 | ||||||||||||||||||||||||
| 470 | autoDetectUnicode = false; | - | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | codec = QTextCodec::codecForUtfText(QByteArray::fromRawData(buf, bytesRead), codec); | - | ||||||||||||||||||||||||
| 473 | if (!codec) {
| 0-4547 | ||||||||||||||||||||||||
| 474 | codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||||||||
| 475 | writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
| 476 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 477 | } executed 4547 times by 17 tests: end of blockExecuted by:
| 4547 | ||||||||||||||||||||||||
| 478 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 479 | qDebug("QTextStreamPrivate::fillReadBuffer(), using %s codec", | - | ||||||||||||||||||||||||
| 480 | codec ? codec->name().constData() : "no"); | - | ||||||||||||||||||||||||
| 481 | #endif | - | ||||||||||||||||||||||||
| 482 | #endif | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 485 | qDebug("QTextStreamPrivate::fillReadBuffer(), device->read(\"%s\", %d) == %d", | - | ||||||||||||||||||||||||
| 486 | qt_prettyDebug(buf, qMin(32,int(bytesRead)) , int(bytesRead)).constData(), int(sizeof(buf)), int(bytesRead)); | - | ||||||||||||||||||||||||
| 487 | #endif | - | ||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||
| 489 | int oldReadBufferSize = readBuffer.size(); | - | ||||||||||||||||||||||||
| 490 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 491 | // convert to unicode | - | ||||||||||||||||||||||||
| 492 | readBuffer += Q_LIKELY(codec) ? codec->toUnicode(buf, bytesRead, &readConverterState)
| 0-41040093 | ||||||||||||||||||||||||
| 493 | : QString::fromLatin1(buf, bytesRead); | - | ||||||||||||||||||||||||
| 494 | #else | - | ||||||||||||||||||||||||
| 495 | readBuffer += QString::fromLatin1(buf, bytesRead); | - | ||||||||||||||||||||||||
| 496 | #endif | - | ||||||||||||||||||||||||
| 497 | - | |||||||||||||||||||||||||
| 498 | // remove all '\r\n' in the string. | - | ||||||||||||||||||||||||
| 499 | if (readBuffer.size() > oldReadBufferSize && textModeEnabled) {
| 682-41039411 | ||||||||||||||||||||||||
| 500 | QChar CR = QLatin1Char('\r'); | - | ||||||||||||||||||||||||
| 501 | QChar *writePtr = readBuffer.data() + oldReadBufferSize; | - | ||||||||||||||||||||||||
| 502 | QChar *readPtr = readBuffer.data() + oldReadBufferSize; | - | ||||||||||||||||||||||||
| 503 | QChar *endPtr = readBuffer.data() + readBuffer.size(); | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | int n = oldReadBufferSize; | - | ||||||||||||||||||||||||
| 506 | if (readPtr < endPtr) {
| 0-41037818 | ||||||||||||||||||||||||
| 507 | // Cut-off to avoid unnecessary self-copying. | - | ||||||||||||||||||||||||
| 508 | while (*readPtr++ != CR) {
| 110-63893758 | ||||||||||||||||||||||||
| 509 | ++n; | - | ||||||||||||||||||||||||
| 510 | if (++writePtr == endPtr)
| 22856050-41037708 | ||||||||||||||||||||||||
| 511 | break; executed 41037708 times by 6 tests: break;Executed by:
| 41037708 | ||||||||||||||||||||||||
| 512 | } executed 22856050 times by 6 tests: end of blockExecuted by:
| 22856050 | ||||||||||||||||||||||||
| 513 | } executed 41037818 times by 6 tests: end of blockExecuted by:
| 41037818 | ||||||||||||||||||||||||
| 514 | while (readPtr < endPtr) {
| 146620-41037818 | ||||||||||||||||||||||||
| 515 | QChar ch = *readPtr++; | - | ||||||||||||||||||||||||
| 516 | if (ch != CR) {
| 22205-124415 | ||||||||||||||||||||||||
| 517 | *writePtr++ = ch; | - | ||||||||||||||||||||||||
| 518 | } else { executed 124415 times by 1 test: end of blockExecuted by:
| 124415 | ||||||||||||||||||||||||
| 519 | if (n < readBufferOffset)
| 0-22205 | ||||||||||||||||||||||||
| 520 | --readBufferOffset; never executed: --readBufferOffset; | 0 | ||||||||||||||||||||||||
| 521 | --bytesRead; | - | ||||||||||||||||||||||||
| 522 | } executed 22205 times by 1 test: end of blockExecuted by:
| 22205 | ||||||||||||||||||||||||
| 523 | ++n; | - | ||||||||||||||||||||||||
| 524 | } executed 146620 times by 1 test: end of blockExecuted by:
| 146620 | ||||||||||||||||||||||||
| 525 | readBuffer.resize(writePtr - readBuffer.data()); | - | ||||||||||||||||||||||||
| 526 | } executed 41037818 times by 6 tests: end of blockExecuted by:
| 41037818 | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 529 | qDebug("QTextStreamPrivate::fillReadBuffer() read %d bytes from device. readBuffer = [%s]", int(bytesRead), | - | ||||||||||||||||||||||||
| 530 | qt_prettyDebug(readBuffer.toLatin1(), readBuffer.size(), readBuffer.size()).data()); | - | ||||||||||||||||||||||||
| 531 | #endif | - | ||||||||||||||||||||||||
| 532 | return true; executed 41040093 times by 17 tests: return true;Executed by:
| 41040093 | ||||||||||||||||||||||||
| 533 | } | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | /*! | - | ||||||||||||||||||||||||
| 536 | \internal | - | ||||||||||||||||||||||||
| 537 | */ | - | ||||||||||||||||||||||||
| 538 | void QTextStreamPrivate::resetReadBuffer() | - | ||||||||||||||||||||||||
| 539 | { | - | ||||||||||||||||||||||||
| 540 | readBuffer.clear(); | - | ||||||||||||||||||||||||
| 541 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
| 542 | readBufferStartDevicePos = (device ? device->pos() : 0);
| 1-214481 | ||||||||||||||||||||||||
| 543 | } executed 214482 times by 1 test: end of blockExecuted by:
| 214482 | ||||||||||||||||||||||||
| 544 | - | |||||||||||||||||||||||||
| 545 | /*! | - | ||||||||||||||||||||||||
| 546 | \internal | - | ||||||||||||||||||||||||
| 547 | */ | - | ||||||||||||||||||||||||
| 548 | void QTextStreamPrivate::flushWriteBuffer() | - | ||||||||||||||||||||||||
| 549 | { | - | ||||||||||||||||||||||||
| 550 | // no buffer next to the QString itself; this function should only | - | ||||||||||||||||||||||||
| 551 | // be called internally, for devices. | - | ||||||||||||||||||||||||
| 552 | if (string || !device)
| 13-241565 | ||||||||||||||||||||||||
| 553 | return; executed 48610 times by 7 tests: return;Executed by:
| 48610 | ||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | // Stream went bye-bye already. Appending further data may succeed again, | - | ||||||||||||||||||||||||
| 556 | // but would create a corrupted stream anyway. | - | ||||||||||||||||||||||||
| 557 | if (status != QTextStream::Ok)
| 3-241549 | ||||||||||||||||||||||||
| 558 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | if (writeBuffer.isEmpty())
| 26664-214885 | ||||||||||||||||||||||||
| 561 | return; executed 214885 times by 6 tests: return;Executed by:
| 214885 | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | #if defined (Q_OS_WIN) | - | ||||||||||||||||||||||||
| 564 | // handle text translation and bypass the Text flag in the device. | - | ||||||||||||||||||||||||
| 565 | bool textModeEnabled = device->isTextModeEnabled(); | - | ||||||||||||||||||||||||
| 566 | if (textModeEnabled) { | - | ||||||||||||||||||||||||
| 567 | device->setTextModeEnabled(false); | - | ||||||||||||||||||||||||
| 568 | writeBuffer.replace(QLatin1Char('\n'), QLatin1String("\r\n")); | - | ||||||||||||||||||||||||
| 569 | } | - | ||||||||||||||||||||||||
| 570 | #endif | - | ||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||
| 572 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 573 | if (!codec)
| 1-26663 | ||||||||||||||||||||||||
| 574 | codec = QTextCodec::codecForLocale(); executed 1 time by 1 test: codec = QTextCodec::codecForLocale();Executed by:
| 1 | ||||||||||||||||||||||||
| 575 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 576 | qDebug("QTextStreamPrivate::flushWriteBuffer(), using %s codec (%s generating BOM)", | - | ||||||||||||||||||||||||
| 577 | codec ? codec->name().constData() : "no", | - | ||||||||||||||||||||||||
| 578 | !codec || (writeConverterState.flags & QTextCodec::IgnoreHeader) ? "not" : ""); | - | ||||||||||||||||||||||||
| 579 | #endif | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | // convert from unicode to raw data | - | ||||||||||||||||||||||||
| 582 | // codec might be null if we're already inside global destructors (QTestCodec::codecForLocale returned null) | - | ||||||||||||||||||||||||
| 583 | QByteArray data = Q_LIKELY(codec) ? codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState)
| 1-26663 | ||||||||||||||||||||||||
| 584 | : writeBuffer.toLatin1(); | - | ||||||||||||||||||||||||
| 585 | #else | - | ||||||||||||||||||||||||
| 586 | QByteArray data = writeBuffer.toLatin1(); | - | ||||||||||||||||||||||||
| 587 | #endif | - | ||||||||||||||||||||||||
| 588 | writeBuffer.clear(); | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | // write raw data to the device | - | ||||||||||||||||||||||||
| 591 | qint64 bytesWritten = device->write(data); | - | ||||||||||||||||||||||||
| 592 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 593 | qDebug("QTextStreamPrivate::flushWriteBuffer(), device->write(\"%s\") == %d", | - | ||||||||||||||||||||||||
| 594 | qt_prettyDebug(data.constData(), qMin(data.size(),32), data.size()).constData(), int(bytesWritten)); | - | ||||||||||||||||||||||||
| 595 | #endif | - | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | #if defined (Q_OS_WIN) | - | ||||||||||||||||||||||||
| 598 | // reset the text flag | - | ||||||||||||||||||||||||
| 599 | if (textModeEnabled) | - | ||||||||||||||||||||||||
| 600 | device->setTextModeEnabled(true); | - | ||||||||||||||||||||||||
| 601 | #endif | - | ||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 | if (bytesWritten <= 0) {
| 2-26662 | ||||||||||||||||||||||||
| 604 | status = QTextStream::WriteFailed; | - | ||||||||||||||||||||||||
| 605 | return; executed 2 times by 2 tests: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 606 | } | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | // flush the file | - | ||||||||||||||||||||||||
| 609 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 610 | QFileDevice *file = qobject_cast<QFileDevice *>(device); | - | ||||||||||||||||||||||||
| 611 | bool flushed = !file || file->flush();
| 0-15832 | ||||||||||||||||||||||||
| 612 | #else | - | ||||||||||||||||||||||||
| 613 | bool flushed = true; | - | ||||||||||||||||||||||||
| 614 | #endif | - | ||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||
| 616 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 617 | qDebug("QTextStreamPrivate::flushWriteBuffer() wrote %d bytes", | - | ||||||||||||||||||||||||
| 618 | int(bytesWritten)); | - | ||||||||||||||||||||||||
| 619 | #endif | - | ||||||||||||||||||||||||
| 620 | if (!flushed || bytesWritten != qint64(data.size()))
| 0-26662 | ||||||||||||||||||||||||
| 621 | status = QTextStream::WriteFailed; never executed: status = QTextStream::WriteFailed; | 0 | ||||||||||||||||||||||||
| 622 | } executed 26662 times by 17 tests: end of blockExecuted by:
| 26662 | ||||||||||||||||||||||||
| 623 | - | |||||||||||||||||||||||||
| 624 | QString QTextStreamPrivate::read(int maxlen) | - | ||||||||||||||||||||||||
| 625 | { | - | ||||||||||||||||||||||||
| 626 | QString ret; | - | ||||||||||||||||||||||||
| 627 | if (string) {
| 5-1871 | ||||||||||||||||||||||||
| 628 | lastTokenSize = qMin(maxlen, string->size() - stringOffset); | - | ||||||||||||||||||||||||
| 629 | ret = string->mid(stringOffset, lastTokenSize); | - | ||||||||||||||||||||||||
| 630 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 631 | while (readBuffer.size() - readBufferOffset < maxlen && fillReadBuffer()) ; executed 1867 times by 2 tests: ;Executed by:
| 7-3731 | ||||||||||||||||||||||||
| 632 | lastTokenSize = qMin(maxlen, readBuffer.size() - readBufferOffset); | - | ||||||||||||||||||||||||
| 633 | ret = readBuffer.mid(readBufferOffset, lastTokenSize); | - | ||||||||||||||||||||||||
| 634 | } executed 1871 times by 2 tests: end of blockExecuted by:
| 1871 | ||||||||||||||||||||||||
| 635 | consumeLastToken(); | - | ||||||||||||||||||||||||
| 636 | - | |||||||||||||||||||||||||
| 637 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 638 | qDebug("QTextStreamPrivate::read() maxlen = %d, token length = %d", maxlen, ret.length()); | - | ||||||||||||||||||||||||
| 639 | #endif | - | ||||||||||||||||||||||||
| 640 | return ret; executed 1876 times by 2 tests: return ret;Executed by:
| 1876 | ||||||||||||||||||||||||
| 641 | } | - | ||||||||||||||||||||||||
| 642 | - | |||||||||||||||||||||||||
| 643 | /*! | - | ||||||||||||||||||||||||
| 644 | \internal | - | ||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||
| 646 | Scans no more than \a maxlen QChars in the current buffer for the | - | ||||||||||||||||||||||||
| 647 | first \a delimiter. Stores a pointer to the start offset of the | - | ||||||||||||||||||||||||
| 648 | token in \a ptr, and the length in QChars in \a length. | - | ||||||||||||||||||||||||
| 649 | */ | - | ||||||||||||||||||||||||
| 650 | bool QTextStreamPrivate::scan(const QChar **ptr, int *length, int maxlen, TokenDelimiter delimiter) | - | ||||||||||||||||||||||||
| 651 | { | - | ||||||||||||||||||||||||
| 652 | int totalSize = 0; | - | ||||||||||||||||||||||||
| 653 | int delimSize = 0; | - | ||||||||||||||||||||||||
| 654 | bool consumeDelimiter = false; | - | ||||||||||||||||||||||||
| 655 | bool foundToken = false; | - | ||||||||||||||||||||||||
| 656 | int startOffset = device ? readBufferOffset : stringOffset;
| 24207-183752 | ||||||||||||||||||||||||
| 657 | QChar lastChar; | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | bool canStillReadFromDevice = true; | - | ||||||||||||||||||||||||
| 660 | do { | - | ||||||||||||||||||||||||
| 661 | int endOffset; | - | ||||||||||||||||||||||||
| 662 | const QChar *chPtr; | - | ||||||||||||||||||||||||
| 663 | if (device) {
| 24207-186683 | ||||||||||||||||||||||||
| 664 | chPtr = readBuffer.constData(); | - | ||||||||||||||||||||||||
| 665 | endOffset = readBuffer.size(); | - | ||||||||||||||||||||||||
| 666 | } else { executed 186683 times by 16 tests: end of blockExecuted by:
| 186683 | ||||||||||||||||||||||||
| 667 | chPtr = string->constData(); | - | ||||||||||||||||||||||||
| 668 | endOffset = string->size(); | - | ||||||||||||||||||||||||
| 669 | } executed 24207 times by 4 tests: end of blockExecuted by:
| 24207 | ||||||||||||||||||||||||
| 670 | chPtr += startOffset; | - | ||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | for (; !foundToken && startOffset < endOffset && (!maxlen || totalSize < maxlen); ++startOffset) {
| 10-4218720 | ||||||||||||||||||||||||
| 673 | const QChar ch = *chPtr++; | - | ||||||||||||||||||||||||
| 674 | ++totalSize; | - | ||||||||||||||||||||||||
| 675 | - | |||||||||||||||||||||||||
| 676 | switch (delimiter) { | - | ||||||||||||||||||||||||
| 677 | case Space: executed 5982 times by 4 tests: case Space:Executed by:
| 5982 | ||||||||||||||||||||||||
| 678 | if (ch.isSpace()) {
| 424-5558 | ||||||||||||||||||||||||
| 679 | foundToken = true; | - | ||||||||||||||||||||||||
| 680 | delimSize = 1; | - | ||||||||||||||||||||||||
| 681 | } executed 424 times by 3 tests: end of blockExecuted by:
| 424 | ||||||||||||||||||||||||
| 682 | break; executed 5982 times by 4 tests: break;Executed by:
| 5982 | ||||||||||||||||||||||||
| 683 | case NotSpace: executed 63851 times by 4 tests: case NotSpace:Executed by:
| 63851 | ||||||||||||||||||||||||
| 684 | if (!ch.isSpace()) {
| 22940-40911 | ||||||||||||||||||||||||
| 685 | foundToken = true; | - | ||||||||||||||||||||||||
| 686 | delimSize = 1; | - | ||||||||||||||||||||||||
| 687 | } executed 22940 times by 4 tests: end of blockExecuted by:
| 22940 | ||||||||||||||||||||||||
| 688 | break; executed 63851 times by 4 tests: break;Executed by:
| 63851 | ||||||||||||||||||||||||
| 689 | case EndOfLine: executed 4145673 times by 14 tests: case EndOfLine:Executed by:
| 4145673 | ||||||||||||||||||||||||
| 690 | if (ch == QLatin1Char('\n')) {
| 184312-3961361 | ||||||||||||||||||||||||
| 691 | foundToken = true; | - | ||||||||||||||||||||||||
| 692 | delimSize = (lastChar == QLatin1Char('\r')) ? 2 : 1;
| 75386-108926 | ||||||||||||||||||||||||
| 693 | consumeDelimiter = true; | - | ||||||||||||||||||||||||
| 694 | } executed 184312 times by 13 tests: end of blockExecuted by:
| 184312 | ||||||||||||||||||||||||
| 695 | lastChar = ch; | - | ||||||||||||||||||||||||
| 696 | break; executed 4145673 times by 14 tests: break;Executed by:
| 4145673 | ||||||||||||||||||||||||
| 697 | } | - | ||||||||||||||||||||||||
| 698 | } executed 4214578 times by 17 tests: end of blockExecuted by:
| 4214578 | ||||||||||||||||||||||||
| 699 | } while (!foundToken executed 210890 times by 17 tests: end of blockExecuted by:
| 3214-210890 | ||||||||||||||||||||||||
| 700 | && (!maxlen || totalSize < maxlen)
| 12-3186 | ||||||||||||||||||||||||
| 701 | && (device && (canStillReadFromDevice = fillReadBuffer())));
| 28-3174 | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | if (totalSize == 0) {
| 79-207880 | ||||||||||||||||||||||||
| 704 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 705 | qDebug("QTextStreamPrivate::scan() reached the end of input."); | - | ||||||||||||||||||||||||
| 706 | #endif | - | ||||||||||||||||||||||||
| 707 | return false; executed 79 times by 1 test: return false;Executed by:
| 79 | ||||||||||||||||||||||||
| 708 | } | - | ||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||
| 710 | // if we find a '\r' at the end of the data when reading lines, | - | ||||||||||||||||||||||||
| 711 | // don't make it part of the line. | - | ||||||||||||||||||||||||
| 712 | if (delimiter == EndOfLine && totalSize > 0 && !foundToken) {
| 0-184388 | ||||||||||||||||||||||||
| 713 | if (((string && stringOffset + totalSize == string->size()) || (device && device->atEnd()))
| 2-55 | ||||||||||||||||||||||||
| 714 | && lastChar == QLatin1Char('\r')) {
| 11-58 | ||||||||||||||||||||||||
| 715 | consumeDelimiter = true; | - | ||||||||||||||||||||||||
| 716 | ++delimSize; | - | ||||||||||||||||||||||||
| 717 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||||||||
| 718 | } executed 76 times by 4 tests: end of blockExecuted by:
| 76 | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | // set the read offset and length of the token | - | ||||||||||||||||||||||||
| 721 | if (length)
| 23039-184841 | ||||||||||||||||||||||||
| 722 | *length = totalSize - delimSize; executed 184841 times by 17 tests: *length = totalSize - delimSize;Executed by:
| 184841 | ||||||||||||||||||||||||
| 723 | if (ptr)
| 23039-184841 | ||||||||||||||||||||||||
| 724 | *ptr = readPtr(); executed 184841 times by 17 tests: *ptr = readPtr();Executed by:
| 184841 | ||||||||||||||||||||||||
| 725 | - | |||||||||||||||||||||||||
| 726 | // update last token size. the callee will call consumeLastToken() when | - | ||||||||||||||||||||||||
| 727 | // done. | - | ||||||||||||||||||||||||
| 728 | lastTokenSize = totalSize; | - | ||||||||||||||||||||||||
| 729 | if (!consumeDelimiter)
| 23557-184323 | ||||||||||||||||||||||||
| 730 | lastTokenSize -= delimSize; executed 23557 times by 7 tests: lastTokenSize -= delimSize;Executed by:
| 23557 | ||||||||||||||||||||||||
| 731 | - | |||||||||||||||||||||||||
| 732 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 733 | qDebug("QTextStreamPrivate::scan(%p, %p, %d, %x) token length = %d, delimiter = %d", | - | ||||||||||||||||||||||||
| 734 | ptr, length, maxlen, (int)delimiter, totalSize - delimSize, delimSize); | - | ||||||||||||||||||||||||
| 735 | #endif | - | ||||||||||||||||||||||||
| 736 | return true; executed 207880 times by 17 tests: return true;Executed by:
| 207880 | ||||||||||||||||||||||||
| 737 | } | - | ||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||
| 739 | /*! | - | ||||||||||||||||||||||||
| 740 | \internal | - | ||||||||||||||||||||||||
| 741 | */ | - | ||||||||||||||||||||||||
| 742 | inline const QChar *QTextStreamPrivate::readPtr() const | - | ||||||||||||||||||||||||
| 743 | { | - | ||||||||||||||||||||||||
| 744 | Q_ASSERT(readBufferOffset <= readBuffer.size()); | - | ||||||||||||||||||||||||
| 745 | if (string)
| 24368-230089 | ||||||||||||||||||||||||
| 746 | return string->constData() + stringOffset; executed 24368 times by 4 tests: return string->constData() + stringOffset;Executed by:
| 24368 | ||||||||||||||||||||||||
| 747 | return readBuffer.constData() + readBufferOffset; executed 230089 times by 16 tests: return readBuffer.constData() + readBufferOffset;Executed by:
| 230089 | ||||||||||||||||||||||||
| 748 | } | - | ||||||||||||||||||||||||
| 749 | - | |||||||||||||||||||||||||
| 750 | /*! | - | ||||||||||||||||||||||||
| 751 | \internal | - | ||||||||||||||||||||||||
| 752 | */ | - | ||||||||||||||||||||||||
| 753 | inline void QTextStreamPrivate::consumeLastToken() | - | ||||||||||||||||||||||||
| 754 | { | - | ||||||||||||||||||||||||
| 755 | if (lastTokenSize)
| 867-208105 | ||||||||||||||||||||||||
| 756 | consume(lastTokenSize); executed 208105 times by 18 tests: consume(lastTokenSize);Executed by:
| 208105 | ||||||||||||||||||||||||
| 757 | lastTokenSize = 0; | - | ||||||||||||||||||||||||
| 758 | } executed 208972 times by 18 tests: end of blockExecuted by:
| 208972 | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | /*! | - | ||||||||||||||||||||||||
| 761 | \internal | - | ||||||||||||||||||||||||
| 762 | */ | - | ||||||||||||||||||||||||
| 763 | inline void QTextStreamPrivate::consume(int size) | - | ||||||||||||||||||||||||
| 764 | { | - | ||||||||||||||||||||||||
| 765 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 766 | qDebug("QTextStreamPrivate::consume(%d)", size); | - | ||||||||||||||||||||||||
| 767 | #endif | - | ||||||||||||||||||||||||
| 768 | if (string) {
| 24412-253309 | ||||||||||||||||||||||||
| 769 | stringOffset += size; | - | ||||||||||||||||||||||||
| 770 | if (stringOffset > string->size())
| 0-24412 | ||||||||||||||||||||||||
| 771 | stringOffset = string->size(); never executed: stringOffset = string->size(); | 0 | ||||||||||||||||||||||||
| 772 | } else { executed 24412 times by 4 tests: end of blockExecuted by:
| 24412 | ||||||||||||||||||||||||
| 773 | readBufferOffset += size; | - | ||||||||||||||||||||||||
| 774 | if (readBufferOffset >= readBuffer.size()) {
| 2698-250611 | ||||||||||||||||||||||||
| 775 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
| 776 | readBuffer.clear(); | - | ||||||||||||||||||||||||
| 777 | saveConverterState(device->pos()); | - | ||||||||||||||||||||||||
| 778 | } else if (readBufferOffset > QTEXTSTREAM_BUFFERSIZE) { executed 2698 times by 16 tests: end of blockExecuted by:
| 1300-249311 | ||||||||||||||||||||||||
| 779 | readBuffer = readBuffer.remove(0,readBufferOffset); | - | ||||||||||||||||||||||||
| 780 | readConverterSavedStateOffset += readBufferOffset; | - | ||||||||||||||||||||||||
| 781 | readBufferOffset = 0; | - | ||||||||||||||||||||||||
| 782 | } executed 1300 times by 3 tests: end of blockExecuted by:
| 1300 | ||||||||||||||||||||||||
| 783 | } executed 253309 times by 17 tests: end of blockExecuted by:
| 253309 | ||||||||||||||||||||||||
| 784 | } | - | ||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | /*! | - | ||||||||||||||||||||||||
| 787 | \internal | - | ||||||||||||||||||||||||
| 788 | */ | - | ||||||||||||||||||||||||
| 789 | inline void QTextStreamPrivate::saveConverterState(qint64 newPos) | - | ||||||||||||||||||||||||
| 790 | { | - | ||||||||||||||||||||||||
| 791 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 792 | if (readConverterState.d) {
| 0-2698 | ||||||||||||||||||||||||
| 793 | // converter cannot be copied, so don't save anything | - | ||||||||||||||||||||||||
| 794 | // don't update readBufferStartDevicePos either | - | ||||||||||||||||||||||||
| 795 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 796 | } | - | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | if (!readConverterSavedState)
| 32-2666 | ||||||||||||||||||||||||
| 799 | readConverterSavedState = new QTextCodec::ConverterState; executed 2666 times by 16 tests: readConverterSavedState = new QTextCodec::ConverterState;Executed by:
| 2666 | ||||||||||||||||||||||||
| 800 | copyConverterStateHelper(readConverterSavedState, &readConverterState); | - | ||||||||||||||||||||||||
| 801 | #endif | - | ||||||||||||||||||||||||
| 802 | - | |||||||||||||||||||||||||
| 803 | readBufferStartDevicePos = newPos; | - | ||||||||||||||||||||||||
| 804 | readConverterSavedStateOffset = 0; | - | ||||||||||||||||||||||||
| 805 | } executed 2698 times by 16 tests: end of blockExecuted by:
| 2698 | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | /*! | - | ||||||||||||||||||||||||
| 808 | \internal | - | ||||||||||||||||||||||||
| 809 | */ | - | ||||||||||||||||||||||||
| 810 | inline void QTextStreamPrivate::restoreToSavedConverterState() | - | ||||||||||||||||||||||||
| 811 | { | - | ||||||||||||||||||||||||
| 812 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 813 | if (readConverterSavedState) {
| 0-1775 | ||||||||||||||||||||||||
| 814 | // we have a saved state | - | ||||||||||||||||||||||||
| 815 | // that means the converter can be copied | - | ||||||||||||||||||||||||
| 816 | copyConverterStateHelper(&readConverterState, readConverterSavedState); | - | ||||||||||||||||||||||||
| 817 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 818 | // the only state we could save was the initial | - | ||||||||||||||||||||||||
| 819 | // so reset to that | - | ||||||||||||||||||||||||
| 820 | resetCodecConverterStateHelper(&readConverterState); | - | ||||||||||||||||||||||||
| 821 | } executed 1775 times by 1 test: end of blockExecuted by:
| 1775 | ||||||||||||||||||||||||
| 822 | #endif | - | ||||||||||||||||||||||||
| 823 | } | - | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | /*! | - | ||||||||||||||||||||||||
| 826 | \internal | - | ||||||||||||||||||||||||
| 827 | */ | - | ||||||||||||||||||||||||
| 828 | void QTextStreamPrivate::write(const QChar *data, int len) | - | ||||||||||||||||||||||||
| 829 | { | - | ||||||||||||||||||||||||
| 830 | if (string) {
| 33084-162509 | ||||||||||||||||||||||||
| 831 | // ### What about seek()?? | - | ||||||||||||||||||||||||
| 832 | string->append(data, len); | - | ||||||||||||||||||||||||
| 833 | } else { executed 162509 times by 79 tests: end of blockExecuted by:
| 162509 | ||||||||||||||||||||||||
| 834 | writeBuffer.append(data, len); | - | ||||||||||||||||||||||||
| 835 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 4-33080 | ||||||||||||||||||||||||
| 836 | flushWriteBuffer(); executed 4 times by 2 tests: flushWriteBuffer();Executed by:
| 4 | ||||||||||||||||||||||||
| 837 | } executed 33084 times by 13 tests: end of blockExecuted by:
| 33084 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | /*! | - | ||||||||||||||||||||||||
| 841 | \internal | - | ||||||||||||||||||||||||
| 842 | */ | - | ||||||||||||||||||||||||
| 843 | inline void QTextStreamPrivate::write(QChar ch) | - | ||||||||||||||||||||||||
| 844 | { | - | ||||||||||||||||||||||||
| 845 | if (string) {
| 70541-94016 | ||||||||||||||||||||||||
| 846 | // ### What about seek()?? | - | ||||||||||||||||||||||||
| 847 | string->append(ch); | - | ||||||||||||||||||||||||
| 848 | } else { executed 94016 times by 75 tests: end of blockExecuted by:
| 94016 | ||||||||||||||||||||||||
| 849 | writeBuffer += ch; | - | ||||||||||||||||||||||||
| 850 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 0-70541 | ||||||||||||||||||||||||
| 851 | flushWriteBuffer(); never executed: flushWriteBuffer(); | 0 | ||||||||||||||||||||||||
| 852 | } executed 70541 times by 11 tests: end of blockExecuted by:
| 70541 | ||||||||||||||||||||||||
| 853 | } | - | ||||||||||||||||||||||||
| 854 | - | |||||||||||||||||||||||||
| 855 | /*! | - | ||||||||||||||||||||||||
| 856 | \internal | - | ||||||||||||||||||||||||
| 857 | */ | - | ||||||||||||||||||||||||
| 858 | void QTextStreamPrivate::write(QLatin1String data) | - | ||||||||||||||||||||||||
| 859 | { | - | ||||||||||||||||||||||||
| 860 | if (string) {
| 18796-41996 | ||||||||||||||||||||||||
| 861 | // ### What about seek()?? | - | ||||||||||||||||||||||||
| 862 | string->append(data); | - | ||||||||||||||||||||||||
| 863 | } else { executed 41996 times by 19 tests: end of blockExecuted by:
| 41996 | ||||||||||||||||||||||||
| 864 | writeBuffer += data; | - | ||||||||||||||||||||||||
| 865 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 0-18796 | ||||||||||||||||||||||||
| 866 | flushWriteBuffer(); never executed: flushWriteBuffer(); | 0 | ||||||||||||||||||||||||
| 867 | } executed 18796 times by 14 tests: end of blockExecuted by:
| 18796 | ||||||||||||||||||||||||
| 868 | } | - | ||||||||||||||||||||||||
| 869 | - | |||||||||||||||||||||||||
| 870 | /*! | - | ||||||||||||||||||||||||
| 871 | \internal | - | ||||||||||||||||||||||||
| 872 | */ | - | ||||||||||||||||||||||||
| 873 | void QTextStreamPrivate::writePadding(int len) | - | ||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||
| 875 | if (string) {
| 72-4406 | ||||||||||||||||||||||||
| 876 | // ### What about seek()?? | - | ||||||||||||||||||||||||
| 877 | string->resize(string->size() + len, params.padChar); | - | ||||||||||||||||||||||||
| 878 | } else { executed 72 times by 4 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||||||||
| 879 | writeBuffer.resize(writeBuffer.size() + len, params.padChar); | - | ||||||||||||||||||||||||
| 880 | if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
| 0-4406 | ||||||||||||||||||||||||
| 881 | flushWriteBuffer(); never executed: flushWriteBuffer(); | 0 | ||||||||||||||||||||||||
| 882 | } executed 4406 times by 1 test: end of blockExecuted by:
| 4406 | ||||||||||||||||||||||||
| 883 | } | - | ||||||||||||||||||||||||
| 884 | - | |||||||||||||||||||||||||
| 885 | /*! | - | ||||||||||||||||||||||||
| 886 | \internal | - | ||||||||||||||||||||||||
| 887 | */ | - | ||||||||||||||||||||||||
| 888 | inline bool QTextStreamPrivate::getChar(QChar *ch) | - | ||||||||||||||||||||||||
| 889 | { | - | ||||||||||||||||||||||||
| 890 | if ((string && stringOffset == string->size())
| 11-69793 | ||||||||||||||||||||||||
| 891 | || (device && readBuffer.isEmpty() && !fillReadBuffer())) {
| 1-69793 | ||||||||||||||||||||||||
| 892 | if (ch)
| 0-427 | ||||||||||||||||||||||||
| 893 | *ch = 0; executed 427 times by 2 tests: *ch = 0;Executed by:
| 427 | ||||||||||||||||||||||||
| 894 | return false; executed 427 times by 2 tests: return false;Executed by:
| 427 | ||||||||||||||||||||||||
| 895 | } | - | ||||||||||||||||||||||||
| 896 | if (ch)
| 0-69616 | ||||||||||||||||||||||||
| 897 | *ch = *readPtr(); executed 69616 times by 3 tests: *ch = *readPtr();Executed by:
| 69616 | ||||||||||||||||||||||||
| 898 | consume(1); | - | ||||||||||||||||||||||||
| 899 | return true; executed 69616 times by 3 tests: return true;Executed by:
| 69616 | ||||||||||||||||||||||||
| 900 | } | - | ||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | /*! | - | ||||||||||||||||||||||||
| 903 | \internal | - | ||||||||||||||||||||||||
| 904 | */ | - | ||||||||||||||||||||||||
| 905 | inline void QTextStreamPrivate::ungetChar(QChar ch) | - | ||||||||||||||||||||||||
| 906 | { | - | ||||||||||||||||||||||||
| 907 | if (string) {
| 51-39049 | ||||||||||||||||||||||||
| 908 | if (stringOffset == 0)
| 0-51 | ||||||||||||||||||||||||
| 909 | string->prepend(ch); never executed: string->prepend(ch); | 0 | ||||||||||||||||||||||||
| 910 | else | - | ||||||||||||||||||||||||
| 911 | (*string)[--stringOffset] = ch; executed 51 times by 2 tests: (*string)[--stringOffset] = ch;Executed by:
| 51 | ||||||||||||||||||||||||
| 912 | return; executed 51 times by 2 tests: return;Executed by:
| 51 | ||||||||||||||||||||||||
| 913 | } | - | ||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | if (readBufferOffset == 0) {
| 45-39004 | ||||||||||||||||||||||||
| 916 | readBuffer.prepend(ch); | - | ||||||||||||||||||||||||
| 917 | return; executed 45 times by 2 tests: return;Executed by:
| 45 | ||||||||||||||||||||||||
| 918 | } | - | ||||||||||||||||||||||||
| 919 | - | |||||||||||||||||||||||||
| 920 | readBuffer[--readBufferOffset] = ch; | - | ||||||||||||||||||||||||
| 921 | } executed 39004 times by 2 tests: end of blockExecuted by:
| 39004 | ||||||||||||||||||||||||
| 922 | - | |||||||||||||||||||||||||
| 923 | /*! | - | ||||||||||||||||||||||||
| 924 | \internal | - | ||||||||||||||||||||||||
| 925 | */ | - | ||||||||||||||||||||||||
| 926 | inline void QTextStreamPrivate::putChar(QChar ch) | - | ||||||||||||||||||||||||
| 927 | { | - | ||||||||||||||||||||||||
| 928 | if (params.fieldWidth > 0)
| 2004-164557 | ||||||||||||||||||||||||
| 929 | putString(&ch, 1); executed 2004 times by 2 tests: putString(&ch, 1);Executed by:
| 2004 | ||||||||||||||||||||||||
| 930 | else | - | ||||||||||||||||||||||||
| 931 | write(ch); executed 164428 times by 82 tests: write(ch);Executed by:
| 164428 | ||||||||||||||||||||||||
| 932 | } | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||
| 935 | /*! | - | ||||||||||||||||||||||||
| 936 | \internal | - | ||||||||||||||||||||||||
| 937 | */ | - | ||||||||||||||||||||||||
| 938 | QTextStreamPrivate::PaddingResult QTextStreamPrivate::padding(int len) const | - | ||||||||||||||||||||||||
| 939 | { | - | ||||||||||||||||||||||||
| 940 | Q_ASSERT(params.fieldWidth > len); // calling padding() when no padding is needed is an error | - | ||||||||||||||||||||||||
| 941 | - | |||||||||||||||||||||||||
| 942 | int left = 0, right = 0; | - | ||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | const int padSize = params.fieldWidth - len; | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | switch (params.fieldAlignment) { | - | ||||||||||||||||||||||||
| 947 | case QTextStream::AlignLeft: never executed: case QTextStream::AlignLeft: | 0 | ||||||||||||||||||||||||
| 948 | right = padSize; | - | ||||||||||||||||||||||||
| 949 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 950 | case QTextStream::AlignRight: executed 2235 times by 4 tests: case QTextStream::AlignRight:Executed by:
| 2235 | ||||||||||||||||||||||||
| 951 | case QTextStream::AlignAccountingStyle: executed 4 times by 1 test: case QTextStream::AlignAccountingStyle:Executed by:
| 4 | ||||||||||||||||||||||||
| 952 | left = padSize; | - | ||||||||||||||||||||||||
| 953 | break; executed 2239 times by 4 tests: break;Executed by:
| 2239 | ||||||||||||||||||||||||
| 954 | case QTextStream::AlignCenter: never executed: case QTextStream::AlignCenter: | 0 | ||||||||||||||||||||||||
| 955 | left = padSize/2; | - | ||||||||||||||||||||||||
| 956 | right = padSize - padSize/2; | - | ||||||||||||||||||||||||
| 957 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 958 | } | - | ||||||||||||||||||||||||
| 959 | const PaddingResult result = { left, right }; | - | ||||||||||||||||||||||||
| 960 | return result; executed 2239 times by 4 tests: return result;Executed by:
| 2239 | ||||||||||||||||||||||||
| 961 | } | - | ||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||
| 963 | /*! | - | ||||||||||||||||||||||||
| 964 | \internal | - | ||||||||||||||||||||||||
| 965 | */ | - | ||||||||||||||||||||||||
| 966 | void QTextStreamPrivate::putString(const QChar *data, int len, bool number) | - | ||||||||||||||||||||||||
| 967 | { | - | ||||||||||||||||||||||||
| 968 | if (Q_UNLIKELY(params.fieldWidth > len)) {
| 2237-149522 | ||||||||||||||||||||||||
| 969 | - | |||||||||||||||||||||||||
| 970 | // handle padding: | - | ||||||||||||||||||||||||
| 971 | - | |||||||||||||||||||||||||
| 972 | const PaddingResult pad = padding(len); | - | ||||||||||||||||||||||||
| 973 | - | |||||||||||||||||||||||||
| 974 | if (params.fieldAlignment == QTextStream::AlignAccountingStyle && number) {
| 0-2235 | ||||||||||||||||||||||||
| 975 | const QChar sign = len > 0 ? data[0] : QChar();
| 0-2 | ||||||||||||||||||||||||
| 976 | if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
| 0-2 | ||||||||||||||||||||||||
| 977 | // write the sign before the padding, then skip it later | - | ||||||||||||||||||||||||
| 978 | write(&sign, 1); | - | ||||||||||||||||||||||||
| 979 | ++data; | - | ||||||||||||||||||||||||
| 980 | --len; | - | ||||||||||||||||||||||||
| 981 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 982 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 983 | - | |||||||||||||||||||||||||
| 984 | writePadding(pad.left); | - | ||||||||||||||||||||||||
| 985 | write(data, len); | - | ||||||||||||||||||||||||
| 986 | writePadding(pad.right); | - | ||||||||||||||||||||||||
| 987 | } else { executed 2237 times by 4 tests: end of blockExecuted by:
| 2237 | ||||||||||||||||||||||||
| 988 | write(data, len); | - | ||||||||||||||||||||||||
| 989 | } executed 149522 times by 86 tests: end of blockExecuted by:
| 149522 | ||||||||||||||||||||||||
| 990 | } | - | ||||||||||||||||||||||||
| 991 | - | |||||||||||||||||||||||||
| 992 | /*! | - | ||||||||||||||||||||||||
| 993 | \internal | - | ||||||||||||||||||||||||
| 994 | */ | - | ||||||||||||||||||||||||
| 995 | void QTextStreamPrivate::putString(QLatin1String data, bool number) | - | ||||||||||||||||||||||||
| 996 | { | - | ||||||||||||||||||||||||
| 997 | if (Q_UNLIKELY(params.fieldWidth > data.size())) {
| 2-60790 | ||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||
| 999 | // handle padding | - | ||||||||||||||||||||||||
| 1000 | - | |||||||||||||||||||||||||
| 1001 | const PaddingResult pad = padding(data.size()); | - | ||||||||||||||||||||||||
| 1002 | - | |||||||||||||||||||||||||
| 1003 | if (params.fieldAlignment == QTextStream::AlignAccountingStyle && number) {
| 0-2 | ||||||||||||||||||||||||
| 1004 | const QChar sign = data.size() > 0 ? QLatin1Char(*data.data()) : QChar();
| 0 | ||||||||||||||||||||||||
| 1005 | if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
| 0 | ||||||||||||||||||||||||
| 1006 | // write the sign before the padding, then skip it later | - | ||||||||||||||||||||||||
| 1007 | write(&sign, 1); | - | ||||||||||||||||||||||||
| 1008 | data = QLatin1String(data.data() + 1, data.size() - 1); | - | ||||||||||||||||||||||||
| 1009 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1010 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | writePadding(pad.left); | - | ||||||||||||||||||||||||
| 1013 | write(data); | - | ||||||||||||||||||||||||
| 1014 | writePadding(pad.right); | - | ||||||||||||||||||||||||
| 1015 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1016 | write(data); | - | ||||||||||||||||||||||||
| 1017 | } executed 60790 times by 30 tests: end of blockExecuted by:
| 60790 | ||||||||||||||||||||||||
| 1018 | } | - | ||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||
| 1020 | /*! | - | ||||||||||||||||||||||||
| 1021 | Constructs a QTextStream. Before you can use it for reading or | - | ||||||||||||||||||||||||
| 1022 | writing, you must assign a device or a string. | - | ||||||||||||||||||||||||
| 1023 | - | |||||||||||||||||||||||||
| 1024 | \sa setDevice(), setString() | - | ||||||||||||||||||||||||
| 1025 | */ | - | ||||||||||||||||||||||||
| 1026 | QTextStream::QTextStream() | - | ||||||||||||||||||||||||
| 1027 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1028 | { | - | ||||||||||||||||||||||||
| 1029 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1030 | qDebug("QTextStream::QTextStream()"); | - | ||||||||||||||||||||||||
| 1031 | #endif | - | ||||||||||||||||||||||||
| 1032 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1033 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1034 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||
| 1036 | /*! | - | ||||||||||||||||||||||||
| 1037 | Constructs a QTextStream that operates on \a device. | - | ||||||||||||||||||||||||
| 1038 | */ | - | ||||||||||||||||||||||||
| 1039 | QTextStream::QTextStream(QIODevice *device) | - | ||||||||||||||||||||||||
| 1040 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1041 | { | - | ||||||||||||||||||||||||
| 1042 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1043 | qDebug("QTextStream::QTextStream(QIODevice *device == *%p)", | - | ||||||||||||||||||||||||
| 1044 | device); | - | ||||||||||||||||||||||||
| 1045 | #endif | - | ||||||||||||||||||||||||
| 1046 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1047 | d->device = device; | - | ||||||||||||||||||||||||
| 1048 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1049 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
| 1050 | #endif | - | ||||||||||||||||||||||||
| 1051 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1052 | } executed 2874 times by 22 tests: end of blockExecuted by:
| 2874 | ||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||
| 1054 | /*! | - | ||||||||||||||||||||||||
| 1055 | Constructs a QTextStream that operates on \a string, using \a | - | ||||||||||||||||||||||||
| 1056 | openMode to define the open mode. | - | ||||||||||||||||||||||||
| 1057 | */ | - | ||||||||||||||||||||||||
| 1058 | QTextStream::QTextStream(QString *string, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
| 1059 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1060 | { | - | ||||||||||||||||||||||||
| 1061 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1062 | qDebug("QTextStream::QTextStream(QString *string == *%p, openMode = %d)", | - | ||||||||||||||||||||||||
| 1063 | string, int(openMode)); | - | ||||||||||||||||||||||||
| 1064 | #endif | - | ||||||||||||||||||||||||
| 1065 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1066 | d->string = string; | - | ||||||||||||||||||||||||
| 1067 | d->stringOpenMode = openMode; | - | ||||||||||||||||||||||||
| 1068 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1069 | } executed 75486 times by 80 tests: end of blockExecuted by:
| 75486 | ||||||||||||||||||||||||
| 1070 | - | |||||||||||||||||||||||||
| 1071 | /*! | - | ||||||||||||||||||||||||
| 1072 | Constructs a QTextStream that operates on \a array, using \a | - | ||||||||||||||||||||||||
| 1073 | openMode to define the open mode. Internally, the array is wrapped | - | ||||||||||||||||||||||||
| 1074 | by a QBuffer. | - | ||||||||||||||||||||||||
| 1075 | */ | - | ||||||||||||||||||||||||
| 1076 | QTextStream::QTextStream(QByteArray *array, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
| 1077 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1078 | { | - | ||||||||||||||||||||||||
| 1079 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1080 | qDebug("QTextStream::QTextStream(QByteArray *array == *%p, openMode = %d)", | - | ||||||||||||||||||||||||
| 1081 | array, int(openMode)); | - | ||||||||||||||||||||||||
| 1082 | #endif | - | ||||||||||||||||||||||||
| 1083 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1084 | d->device = new QBuffer(array); | - | ||||||||||||||||||||||||
| 1085 | d->device->open(openMode); | - | ||||||||||||||||||||||||
| 1086 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
| 1087 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1088 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
| 1089 | #endif | - | ||||||||||||||||||||||||
| 1090 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1091 | } executed 830 times by 6 tests: end of blockExecuted by:
| 830 | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | /*! | - | ||||||||||||||||||||||||
| 1094 | Constructs a QTextStream that operates on \a array, using \a | - | ||||||||||||||||||||||||
| 1095 | openMode to define the open mode. The array is accessed as | - | ||||||||||||||||||||||||
| 1096 | read-only, regardless of the values in \a openMode. | - | ||||||||||||||||||||||||
| 1097 | - | |||||||||||||||||||||||||
| 1098 | This constructor is convenient for working on constant | - | ||||||||||||||||||||||||
| 1099 | strings. Example: | - | ||||||||||||||||||||||||
| 1100 | - | |||||||||||||||||||||||||
| 1101 | \snippet code/src_corelib_io_qtextstream.cpp 3 | - | ||||||||||||||||||||||||
| 1102 | */ | - | ||||||||||||||||||||||||
| 1103 | QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
| 1104 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1105 | { | - | ||||||||||||||||||||||||
| 1106 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1107 | qDebug("QTextStream::QTextStream(const QByteArray &array == *(%p), openMode = %d)", | - | ||||||||||||||||||||||||
| 1108 | &array, int(openMode)); | - | ||||||||||||||||||||||||
| 1109 | #endif | - | ||||||||||||||||||||||||
| 1110 | QBuffer *buffer = new QBuffer; | - | ||||||||||||||||||||||||
| 1111 | buffer->setData(array); | - | ||||||||||||||||||||||||
| 1112 | buffer->open(openMode); | - | ||||||||||||||||||||||||
| 1113 | - | |||||||||||||||||||||||||
| 1114 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1115 | d->device = buffer; | - | ||||||||||||||||||||||||
| 1116 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
| 1117 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1118 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
| 1119 | #endif | - | ||||||||||||||||||||||||
| 1120 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1121 | } executed 16 times by 3 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | /*! | - | ||||||||||||||||||||||||
| 1124 | Constructs a QTextStream that operates on \a fileHandle, using \a | - | ||||||||||||||||||||||||
| 1125 | openMode to define the open mode. Internally, a QFile is created | - | ||||||||||||||||||||||||
| 1126 | to handle the FILE pointer. | - | ||||||||||||||||||||||||
| 1127 | - | |||||||||||||||||||||||||
| 1128 | This constructor is useful for working directly with the common | - | ||||||||||||||||||||||||
| 1129 | FILE based input and output streams: stdin, stdout and stderr. Example: | - | ||||||||||||||||||||||||
| 1130 | - | |||||||||||||||||||||||||
| 1131 | \snippet code/src_corelib_io_qtextstream.cpp 4 | - | ||||||||||||||||||||||||
| 1132 | */ | - | ||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||
| 1134 | QTextStream::QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
| 1135 | : d_ptr(new QTextStreamPrivate(this)) | - | ||||||||||||||||||||||||
| 1136 | { | - | ||||||||||||||||||||||||
| 1137 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1138 | qDebug("QTextStream::QTextStream(FILE *fileHandle = %p, openMode = %d)", | - | ||||||||||||||||||||||||
| 1139 | fileHandle, int(openMode)); | - | ||||||||||||||||||||||||
| 1140 | #endif | - | ||||||||||||||||||||||||
| 1141 | QFile *file = new QFile; | - | ||||||||||||||||||||||||
| 1142 | file->open(fileHandle, openMode); | - | ||||||||||||||||||||||||
| 1143 | - | |||||||||||||||||||||||||
| 1144 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1145 | d->device = file; | - | ||||||||||||||||||||||||
| 1146 | d->deleteDevice = true; | - | ||||||||||||||||||||||||
| 1147 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1148 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
| 1149 | #endif | - | ||||||||||||||||||||||||
| 1150 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1151 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1152 | - | |||||||||||||||||||||||||
| 1153 | /*! | - | ||||||||||||||||||||||||
| 1154 | Destroys the QTextStream. | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | If the stream operates on a device, flush() will be called | - | ||||||||||||||||||||||||
| 1157 | implicitly. Otherwise, the device is unaffected. | - | ||||||||||||||||||||||||
| 1158 | */ | - | ||||||||||||||||||||||||
| 1159 | QTextStream::~QTextStream() | - | ||||||||||||||||||||||||
| 1160 | { | - | ||||||||||||||||||||||||
| 1161 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1162 | #if defined (QTEXTSTREAM_DEBUG) | - | ||||||||||||||||||||||||
| 1163 | qDebug("QTextStream::~QTextStream()"); | - | ||||||||||||||||||||||||
| 1164 | #endif | - | ||||||||||||||||||||||||
| 1165 | if (!d->writeBuffer.isEmpty())
| 21-79200 | ||||||||||||||||||||||||
| 1166 | d->flushWriteBuffer(); executed 21 times by 4 tests: d->flushWriteBuffer();Executed by:
| 21 | ||||||||||||||||||||||||
| 1167 | } executed 79221 times by 96 tests: end of blockExecuted by:
| 79221 | ||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | /*! | - | ||||||||||||||||||||||||
| 1170 | Resets QTextStream's formatting options, bringing it back to its | - | ||||||||||||||||||||||||
| 1171 | original constructed state. The device, string and any buffered | - | ||||||||||||||||||||||||
| 1172 | data is left untouched. | - | ||||||||||||||||||||||||
| 1173 | */ | - | ||||||||||||||||||||||||
| 1174 | void QTextStream::reset() | - | ||||||||||||||||||||||||
| 1175 | { | - | ||||||||||||||||||||||||
| 1176 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1177 | - | |||||||||||||||||||||||||
| 1178 | d->params.reset(); | - | ||||||||||||||||||||||||
| 1179 | } executed 924 times by 13 tests: end of blockExecuted by:
| 924 | ||||||||||||||||||||||||
| 1180 | - | |||||||||||||||||||||||||
| 1181 | /*! | - | ||||||||||||||||||||||||
| 1182 | Flushes any buffered data waiting to be written to the device. | - | ||||||||||||||||||||||||
| 1183 | - | |||||||||||||||||||||||||
| 1184 | If QTextStream operates on a string, this function does nothing. | - | ||||||||||||||||||||||||
| 1185 | */ | - | ||||||||||||||||||||||||
| 1186 | void QTextStream::flush() | - | ||||||||||||||||||||||||
| 1187 | { | - | ||||||||||||||||||||||||
| 1188 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1189 | d->flushWriteBuffer(); | - | ||||||||||||||||||||||||
| 1190 | } executed 75666 times by 21 tests: end of blockExecuted by:
| 75666 | ||||||||||||||||||||||||
| 1191 | - | |||||||||||||||||||||||||
| 1192 | /*! | - | ||||||||||||||||||||||||
| 1193 | Seeks to the position \a pos in the device. Returns \c true on | - | ||||||||||||||||||||||||
| 1194 | success; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1195 | */ | - | ||||||||||||||||||||||||
| 1196 | bool QTextStream::seek(qint64 pos) | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1199 | d->lastTokenSize = 0; | - | ||||||||||||||||||||||||
| 1200 | - | |||||||||||||||||||||||||
| 1201 | if (d->device) {
| 47-214471 | ||||||||||||||||||||||||
| 1202 | // Empty the write buffer | - | ||||||||||||||||||||||||
| 1203 | d->flushWriteBuffer(); | - | ||||||||||||||||||||||||
| 1204 | if (!d->device->seek(pos))
| 0-214471 | ||||||||||||||||||||||||
| 1205 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1206 | d->resetReadBuffer(); | - | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 1209 | // Reset the codec converter states. | - | ||||||||||||||||||||||||
| 1210 | resetCodecConverterStateHelper(&d->readConverterState); | - | ||||||||||||||||||||||||
| 1211 | resetCodecConverterStateHelper(&d->writeConverterState); | - | ||||||||||||||||||||||||
| 1212 | delete d->readConverterSavedState; | - | ||||||||||||||||||||||||
| 1213 | d->readConverterSavedState = 0; | - | ||||||||||||||||||||||||
| 1214 | d->writeConverterState.flags |= QTextCodec::IgnoreHeader; | - | ||||||||||||||||||||||||
| 1215 | #endif | - | ||||||||||||||||||||||||
| 1216 | return true; executed 214471 times by 1 test: return true;Executed by:
| 214471 | ||||||||||||||||||||||||
| 1217 | } | - | ||||||||||||||||||||||||
| 1218 | - | |||||||||||||||||||||||||
| 1219 | // string | - | ||||||||||||||||||||||||
| 1220 | if (d->string && pos <= d->string->size()) {
| 0-47 | ||||||||||||||||||||||||
| 1221 | d->stringOffset = int(pos); | - | ||||||||||||||||||||||||
| 1222 | return true; executed 47 times by 1 test: return true;Executed by:
| 47 | ||||||||||||||||||||||||
| 1223 | } | - | ||||||||||||||||||||||||
| 1224 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1225 | } | - | ||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | /*! | - | ||||||||||||||||||||||||
| 1228 | \since 4.2 | - | ||||||||||||||||||||||||
| 1229 | - | |||||||||||||||||||||||||
| 1230 | Returns the device position corresponding to the current position of the | - | ||||||||||||||||||||||||
| 1231 | stream, or -1 if an error occurs (e.g., if there is no device or string, | - | ||||||||||||||||||||||||
| 1232 | or if there's a device error). | - | ||||||||||||||||||||||||
| 1233 | - | |||||||||||||||||||||||||
| 1234 | Because QTextStream is buffered, this function may have to | - | ||||||||||||||||||||||||
| 1235 | seek the device to reconstruct a valid device position. This | - | ||||||||||||||||||||||||
| 1236 | operation can be expensive, so you may want to avoid calling this | - | ||||||||||||||||||||||||
| 1237 | function in a tight loop. | - | ||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||
| 1239 | \sa seek() | - | ||||||||||||||||||||||||
| 1240 | */ | - | ||||||||||||||||||||||||
| 1241 | qint64 QTextStream::pos() const | - | ||||||||||||||||||||||||
| 1242 | { | - | ||||||||||||||||||||||||
| 1243 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1244 | if (d->device) {
| 36-216444 | ||||||||||||||||||||||||
| 1245 | // Cutoff | - | ||||||||||||||||||||||||
| 1246 | if (d->readBuffer.isEmpty())
| 1775-214669 | ||||||||||||||||||||||||
| 1247 | return d->device->pos(); executed 214669 times by 1 test: return d->device->pos();Executed by:
| 214669 | ||||||||||||||||||||||||
| 1248 | if (d->device->isSequential())
| 0-1775 | ||||||||||||||||||||||||
| 1249 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1250 | - | |||||||||||||||||||||||||
| 1251 | // Seek the device | - | ||||||||||||||||||||||||
| 1252 | if (!d->device->seek(d->readBufferStartDevicePos))
| 0-1775 | ||||||||||||||||||||||||
| 1253 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | // Reset the read buffer | - | ||||||||||||||||||||||||
| 1256 | QTextStreamPrivate *thatd = const_cast<QTextStreamPrivate *>(d); | - | ||||||||||||||||||||||||
| 1257 | thatd->readBuffer.clear(); | - | ||||||||||||||||||||||||
| 1258 | - | |||||||||||||||||||||||||
| 1259 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 1260 | thatd->restoreToSavedConverterState(); | - | ||||||||||||||||||||||||
| 1261 | if (d->readBufferStartDevicePos == 0)
| 15-1760 | ||||||||||||||||||||||||
| 1262 | thatd->autoDetectUnicode = true; executed 1760 times by 1 test: thatd->autoDetectUnicode = true;Executed by:
| 1760 | ||||||||||||||||||||||||
| 1263 | #endif | - | ||||||||||||||||||||||||
| 1264 | - | |||||||||||||||||||||||||
| 1265 | // Rewind the device to get to the current position Ensure that | - | ||||||||||||||||||||||||
| 1266 | // readBufferOffset is unaffected by fillReadBuffer() | - | ||||||||||||||||||||||||
| 1267 | int oldReadBufferOffset = d->readBufferOffset + d->readConverterSavedStateOffset; | - | ||||||||||||||||||||||||
| 1268 | while (d->readBuffer.size() < oldReadBufferOffset) {
| 1775-41035294 | ||||||||||||||||||||||||
| 1269 | if (!thatd->fillReadBuffer(1))
| 0-41035294 | ||||||||||||||||||||||||
| 1270 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
| 1271 | } executed 41035294 times by 1 test: end of blockExecuted by:
| 41035294 | ||||||||||||||||||||||||
| 1272 | thatd->readBufferOffset = oldReadBufferOffset; | - | ||||||||||||||||||||||||
| 1273 | thatd->readConverterSavedStateOffset = 0; | - | ||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | // Return the device position. | - | ||||||||||||||||||||||||
| 1276 | return d->device->pos(); executed 1775 times by 1 test: return d->device->pos();Executed by:
| 1775 | ||||||||||||||||||||||||
| 1277 | } | - | ||||||||||||||||||||||||
| 1278 | - | |||||||||||||||||||||||||
| 1279 | if (d->string)
| 0-36 | ||||||||||||||||||||||||
| 1280 | return d->stringOffset; executed 36 times by 1 test: return d->stringOffset;Executed by:
| 36 | ||||||||||||||||||||||||
| 1281 | - | |||||||||||||||||||||||||
| 1282 | qWarning("QTextStream::pos: no device"); | - | ||||||||||||||||||||||||
| 1283 | return qint64(-1); never executed: return qint64(-1); | 0 | ||||||||||||||||||||||||
| 1284 | } | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | /*! | - | ||||||||||||||||||||||||
| 1287 | Reads and discards whitespace from the stream until either a | - | ||||||||||||||||||||||||
| 1288 | non-space character is detected, or until atEnd() returns | - | ||||||||||||||||||||||||
| 1289 | true. This function is useful when reading a stream character by | - | ||||||||||||||||||||||||
| 1290 | character. | - | ||||||||||||||||||||||||
| 1291 | - | |||||||||||||||||||||||||
| 1292 | Whitespace characters are all characters for which | - | ||||||||||||||||||||||||
| 1293 | QChar::isSpace() returns \c true. | - | ||||||||||||||||||||||||
| 1294 | - | |||||||||||||||||||||||||
| 1295 | \sa operator>>() | - | ||||||||||||||||||||||||
| 1296 | */ | - | ||||||||||||||||||||||||
| 1297 | void QTextStream::skipWhiteSpace() | - | ||||||||||||||||||||||||
| 1298 | { | - | ||||||||||||||||||||||||
| 1299 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1300 | CHECK_VALID_STREAM(Q_VOID); never executed: return ;
| 0-405 | ||||||||||||||||||||||||
| 1301 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
| 1302 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 1303 | } executed 408 times by 2 tests: end of blockExecuted by:
| 408 | ||||||||||||||||||||||||
| 1304 | - | |||||||||||||||||||||||||
| 1305 | /*! | - | ||||||||||||||||||||||||
| 1306 | Sets the current device to \a device. If a device has already been | - | ||||||||||||||||||||||||
| 1307 | assigned, QTextStream will call flush() before the old device is | - | ||||||||||||||||||||||||
| 1308 | replaced. | - | ||||||||||||||||||||||||
| 1309 | - | |||||||||||||||||||||||||
| 1310 | \note This function resets locale to the default locale ('C') | - | ||||||||||||||||||||||||
| 1311 | and codec to the default codec, QTextCodec::codecForLocale(). | - | ||||||||||||||||||||||||
| 1312 | - | |||||||||||||||||||||||||
| 1313 | \sa device(), setString() | - | ||||||||||||||||||||||||
| 1314 | */ | - | ||||||||||||||||||||||||
| 1315 | void QTextStream::setDevice(QIODevice *device) | - | ||||||||||||||||||||||||
| 1316 | { | - | ||||||||||||||||||||||||
| 1317 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1318 | flush(); | - | ||||||||||||||||||||||||
| 1319 | if (d->deleteDevice) {
| 1-10 | ||||||||||||||||||||||||
| 1320 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1321 | d->deviceClosedNotifier.disconnect(); | - | ||||||||||||||||||||||||
| 1322 | #endif | - | ||||||||||||||||||||||||
| 1323 | delete d->device; | - | ||||||||||||||||||||||||
| 1324 | d->deleteDevice = false; | - | ||||||||||||||||||||||||
| 1325 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | d->reset(); | - | ||||||||||||||||||||||||
| 1328 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1329 | d->device = device; | - | ||||||||||||||||||||||||
| 1330 | d->resetReadBuffer(); | - | ||||||||||||||||||||||||
| 1331 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1332 | d->deviceClosedNotifier.setupDevice(this, d->device); | - | ||||||||||||||||||||||||
| 1333 | #endif | - | ||||||||||||||||||||||||
| 1334 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | /*! | - | ||||||||||||||||||||||||
| 1337 | Returns the current device associated with the QTextStream, | - | ||||||||||||||||||||||||
| 1338 | or 0 if no device has been assigned. | - | ||||||||||||||||||||||||
| 1339 | - | |||||||||||||||||||||||||
| 1340 | \sa setDevice(), string() | - | ||||||||||||||||||||||||
| 1341 | */ | - | ||||||||||||||||||||||||
| 1342 | QIODevice *QTextStream::device() const | - | ||||||||||||||||||||||||
| 1343 | { | - | ||||||||||||||||||||||||
| 1344 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1345 | return d->device; executed 3 times by 1 test: return d->device;Executed by:
| 3 | ||||||||||||||||||||||||
| 1346 | } | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | /*! | - | ||||||||||||||||||||||||
| 1349 | Sets the current string to \a string, using the given \a | - | ||||||||||||||||||||||||
| 1350 | openMode. If a device has already been assigned, QTextStream will | - | ||||||||||||||||||||||||
| 1351 | call flush() before replacing it. | - | ||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||
| 1353 | \sa string(), setDevice() | - | ||||||||||||||||||||||||
| 1354 | */ | - | ||||||||||||||||||||||||
| 1355 | void QTextStream::setString(QString *string, QIODevice::OpenMode openMode) | - | ||||||||||||||||||||||||
| 1356 | { | - | ||||||||||||||||||||||||
| 1357 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1358 | flush(); | - | ||||||||||||||||||||||||
| 1359 | if (d->deleteDevice) {
| 0-7 | ||||||||||||||||||||||||
| 1360 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1361 | d->deviceClosedNotifier.disconnect(); | - | ||||||||||||||||||||||||
| 1362 | d->device->blockSignals(true); | - | ||||||||||||||||||||||||
| 1363 | #endif | - | ||||||||||||||||||||||||
| 1364 | delete d->device; | - | ||||||||||||||||||||||||
| 1365 | d->deleteDevice = false; | - | ||||||||||||||||||||||||
| 1366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1367 | - | |||||||||||||||||||||||||
| 1368 | d->reset(); | - | ||||||||||||||||||||||||
| 1369 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1370 | d->string = string; | - | ||||||||||||||||||||||||
| 1371 | d->stringOpenMode = openMode; | - | ||||||||||||||||||||||||
| 1372 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||
| 1373 | - | |||||||||||||||||||||||||
| 1374 | /*! | - | ||||||||||||||||||||||||
| 1375 | Returns the current string assigned to the QTextStream, or 0 if no | - | ||||||||||||||||||||||||
| 1376 | string has been assigned. | - | ||||||||||||||||||||||||
| 1377 | - | |||||||||||||||||||||||||
| 1378 | \sa setString(), device() | - | ||||||||||||||||||||||||
| 1379 | */ | - | ||||||||||||||||||||||||
| 1380 | QString *QTextStream::string() const | - | ||||||||||||||||||||||||
| 1381 | { | - | ||||||||||||||||||||||||
| 1382 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1383 | return d->string; executed 1 time by 1 test: return d->string;Executed by:
| 1 | ||||||||||||||||||||||||
| 1384 | } | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | /*! | - | ||||||||||||||||||||||||
| 1387 | Sets the field alignment to \a mode. When used together with | - | ||||||||||||||||||||||||
| 1388 | setFieldWidth(), this function allows you to generate formatted | - | ||||||||||||||||||||||||
| 1389 | output with text aligned to the left, to the right or center | - | ||||||||||||||||||||||||
| 1390 | aligned. | - | ||||||||||||||||||||||||
| 1391 | - | |||||||||||||||||||||||||
| 1392 | \sa fieldAlignment(), setFieldWidth() | - | ||||||||||||||||||||||||
| 1393 | */ | - | ||||||||||||||||||||||||
| 1394 | void QTextStream::setFieldAlignment(FieldAlignment mode) | - | ||||||||||||||||||||||||
| 1395 | { | - | ||||||||||||||||||||||||
| 1396 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1397 | d->params.fieldAlignment = mode; | - | ||||||||||||||||||||||||
| 1398 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 1399 | - | |||||||||||||||||||||||||
| 1400 | /*! | - | ||||||||||||||||||||||||
| 1401 | Returns the current field alignment. | - | ||||||||||||||||||||||||
| 1402 | - | |||||||||||||||||||||||||
| 1403 | \sa setFieldAlignment(), fieldWidth() | - | ||||||||||||||||||||||||
| 1404 | */ | - | ||||||||||||||||||||||||
| 1405 | QTextStream::FieldAlignment QTextStream::fieldAlignment() const | - | ||||||||||||||||||||||||
| 1406 | { | - | ||||||||||||||||||||||||
| 1407 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1408 | return d->params.fieldAlignment; executed 4 times by 1 test: return d->params.fieldAlignment;Executed by:
| 4 | ||||||||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||||||||
| 1410 | - | |||||||||||||||||||||||||
| 1411 | /*! | - | ||||||||||||||||||||||||
| 1412 | Sets the pad character to \a ch. The default value is the ASCII | - | ||||||||||||||||||||||||
| 1413 | space character (' '), or QChar(0x20). This character is used to | - | ||||||||||||||||||||||||
| 1414 | fill in the space in fields when generating text. | - | ||||||||||||||||||||||||
| 1415 | - | |||||||||||||||||||||||||
| 1416 | Example: | - | ||||||||||||||||||||||||
| 1417 | - | |||||||||||||||||||||||||
| 1418 | \snippet code/src_corelib_io_qtextstream.cpp 5 | - | ||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | The string \c s contains: | - | ||||||||||||||||||||||||
| 1421 | - | |||||||||||||||||||||||||
| 1422 | \snippet code/src_corelib_io_qtextstream.cpp 6 | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | \sa padChar(), setFieldWidth() | - | ||||||||||||||||||||||||
| 1425 | */ | - | ||||||||||||||||||||||||
| 1426 | void QTextStream::setPadChar(QChar ch) | - | ||||||||||||||||||||||||
| 1427 | { | - | ||||||||||||||||||||||||
| 1428 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1429 | d->params.padChar = ch; | - | ||||||||||||||||||||||||
| 1430 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 1431 | - | |||||||||||||||||||||||||
| 1432 | /*! | - | ||||||||||||||||||||||||
| 1433 | Returns the current pad character. | - | ||||||||||||||||||||||||
| 1434 | - | |||||||||||||||||||||||||
| 1435 | \sa setPadChar(), setFieldWidth() | - | ||||||||||||||||||||||||
| 1436 | */ | - | ||||||||||||||||||||||||
| 1437 | QChar QTextStream::padChar() const | - | ||||||||||||||||||||||||
| 1438 | { | - | ||||||||||||||||||||||||
| 1439 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1440 | return d->params.padChar; executed 2 times by 1 test: return d->params.padChar;Executed by:
| 2 | ||||||||||||||||||||||||
| 1441 | } | - | ||||||||||||||||||||||||
| 1442 | - | |||||||||||||||||||||||||
| 1443 | /*! | - | ||||||||||||||||||||||||
| 1444 | Sets the current field width to \a width. If \a width is 0 (the | - | ||||||||||||||||||||||||
| 1445 | default), the field width is equal to the length of the generated | - | ||||||||||||||||||||||||
| 1446 | text. | - | ||||||||||||||||||||||||
| 1447 | - | |||||||||||||||||||||||||
| 1448 | \note The field width applies to every element appended to this | - | ||||||||||||||||||||||||
| 1449 | stream after this function has been called (e.g., it also pads | - | ||||||||||||||||||||||||
| 1450 | endl). This behavior is different from similar classes in the STL, | - | ||||||||||||||||||||||||
| 1451 | where the field width only applies to the next element. | - | ||||||||||||||||||||||||
| 1452 | - | |||||||||||||||||||||||||
| 1453 | \sa fieldWidth(), setPadChar() | - | ||||||||||||||||||||||||
| 1454 | */ | - | ||||||||||||||||||||||||
| 1455 | void QTextStream::setFieldWidth(int width) | - | ||||||||||||||||||||||||
| 1456 | { | - | ||||||||||||||||||||||||
| 1457 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1458 | d->params.fieldWidth = width; | - | ||||||||||||||||||||||||
| 1459 | } executed 31 times by 4 tests: end of blockExecuted by:
| 31 | ||||||||||||||||||||||||
| 1460 | - | |||||||||||||||||||||||||
| 1461 | /*! | - | ||||||||||||||||||||||||
| 1462 | Returns the current field width. | - | ||||||||||||||||||||||||
| 1463 | - | |||||||||||||||||||||||||
| 1464 | \sa setFieldWidth() | - | ||||||||||||||||||||||||
| 1465 | */ | - | ||||||||||||||||||||||||
| 1466 | int QTextStream::fieldWidth() const | - | ||||||||||||||||||||||||
| 1467 | { | - | ||||||||||||||||||||||||
| 1468 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1469 | return d->params.fieldWidth; executed 3 times by 1 test: return d->params.fieldWidth;Executed by:
| 3 | ||||||||||||||||||||||||
| 1470 | } | - | ||||||||||||||||||||||||
| 1471 | - | |||||||||||||||||||||||||
| 1472 | /*! | - | ||||||||||||||||||||||||
| 1473 | Sets the current number flags to \a flags. \a flags is a set of | - | ||||||||||||||||||||||||
| 1474 | flags from the NumberFlag enum, and describes options for | - | ||||||||||||||||||||||||
| 1475 | formatting generated code (e.g., whether or not to always write | - | ||||||||||||||||||||||||
| 1476 | the base or sign of a number). | - | ||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | \sa numberFlags(), setIntegerBase(), setRealNumberNotation() | - | ||||||||||||||||||||||||
| 1479 | */ | - | ||||||||||||||||||||||||
| 1480 | void QTextStream::setNumberFlags(NumberFlags flags) | - | ||||||||||||||||||||||||
| 1481 | { | - | ||||||||||||||||||||||||
| 1482 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1483 | d->params.numberFlags = flags; | - | ||||||||||||||||||||||||
| 1484 | } executed 103 times by 4 tests: end of blockExecuted by:
| 103 | ||||||||||||||||||||||||
| 1485 | - | |||||||||||||||||||||||||
| 1486 | /*! | - | ||||||||||||||||||||||||
| 1487 | Returns the current number flags. | - | ||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||
| 1489 | \sa setNumberFlags(), integerBase(), realNumberNotation() | - | ||||||||||||||||||||||||
| 1490 | */ | - | ||||||||||||||||||||||||
| 1491 | QTextStream::NumberFlags QTextStream::numberFlags() const | - | ||||||||||||||||||||||||
| 1492 | { | - | ||||||||||||||||||||||||
| 1493 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1494 | return d->params.numberFlags; executed 1624 times by 10 tests: return d->params.numberFlags;Executed by:
| 1624 | ||||||||||||||||||||||||
| 1495 | } | - | ||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||
| 1497 | /*! | - | ||||||||||||||||||||||||
| 1498 | Sets the base of integers to \a base, both for reading and for | - | ||||||||||||||||||||||||
| 1499 | generating numbers. \a base can be either 2 (binary), 8 (octal), | - | ||||||||||||||||||||||||
| 1500 | 10 (decimal) or 16 (hexadecimal). If \a base is 0, QTextStream | - | ||||||||||||||||||||||||
| 1501 | will attempt to detect the base by inspecting the data on the | - | ||||||||||||||||||||||||
| 1502 | stream. When generating numbers, QTextStream assumes base is 10 | - | ||||||||||||||||||||||||
| 1503 | unless the base has been set explicitly. | - | ||||||||||||||||||||||||
| 1504 | - | |||||||||||||||||||||||||
| 1505 | \sa integerBase(), QString::number(), setNumberFlags() | - | ||||||||||||||||||||||||
| 1506 | */ | - | ||||||||||||||||||||||||
| 1507 | void QTextStream::setIntegerBase(int base) | - | ||||||||||||||||||||||||
| 1508 | { | - | ||||||||||||||||||||||||
| 1509 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1510 | d->params.integerBase = base; | - | ||||||||||||||||||||||||
| 1511 | } executed 240 times by 7 tests: end of blockExecuted by:
| 240 | ||||||||||||||||||||||||
| 1512 | - | |||||||||||||||||||||||||
| 1513 | /*! | - | ||||||||||||||||||||||||
| 1514 | Returns the current base of integers. 0 means that the base is | - | ||||||||||||||||||||||||
| 1515 | detected when reading, or 10 (decimal) when generating numbers. | - | ||||||||||||||||||||||||
| 1516 | - | |||||||||||||||||||||||||
| 1517 | \sa setIntegerBase(), QString::number(), numberFlags() | - | ||||||||||||||||||||||||
| 1518 | */ | - | ||||||||||||||||||||||||
| 1519 | int QTextStream::integerBase() const | - | ||||||||||||||||||||||||
| 1520 | { | - | ||||||||||||||||||||||||
| 1521 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1522 | return d->params.integerBase; executed 3 times by 1 test: return d->params.integerBase;Executed by:
| 3 | ||||||||||||||||||||||||
| 1523 | } | - | ||||||||||||||||||||||||
| 1524 | - | |||||||||||||||||||||||||
| 1525 | /*! | - | ||||||||||||||||||||||||
| 1526 | Sets the real number notation to \a notation (SmartNotation, | - | ||||||||||||||||||||||||
| 1527 | FixedNotation, ScientificNotation). When reading and generating | - | ||||||||||||||||||||||||
| 1528 | numbers, QTextStream uses this value to detect the formatting of | - | ||||||||||||||||||||||||
| 1529 | real numbers. | - | ||||||||||||||||||||||||
| 1530 | - | |||||||||||||||||||||||||
| 1531 | \sa realNumberNotation(), setRealNumberPrecision(), setNumberFlags(), setIntegerBase() | - | ||||||||||||||||||||||||
| 1532 | */ | - | ||||||||||||||||||||||||
| 1533 | void QTextStream::setRealNumberNotation(RealNumberNotation notation) | - | ||||||||||||||||||||||||
| 1534 | { | - | ||||||||||||||||||||||||
| 1535 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1536 | d->params.realNumberNotation = notation; | - | ||||||||||||||||||||||||
| 1537 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 1538 | - | |||||||||||||||||||||||||
| 1539 | /*! | - | ||||||||||||||||||||||||
| 1540 | Returns the current real number notation. | - | ||||||||||||||||||||||||
| 1541 | - | |||||||||||||||||||||||||
| 1542 | \sa setRealNumberNotation(), realNumberPrecision(), numberFlags(), integerBase() | - | ||||||||||||||||||||||||
| 1543 | */ | - | ||||||||||||||||||||||||
| 1544 | QTextStream::RealNumberNotation QTextStream::realNumberNotation() const | - | ||||||||||||||||||||||||
| 1545 | { | - | ||||||||||||||||||||||||
| 1546 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1547 | return d->params.realNumberNotation; executed 309 times by 9 tests: return d->params.realNumberNotation;Executed by:
| 309 | ||||||||||||||||||||||||
| 1548 | } | - | ||||||||||||||||||||||||
| 1549 | - | |||||||||||||||||||||||||
| 1550 | /*! | - | ||||||||||||||||||||||||
| 1551 | Sets the precision of real numbers to \a precision. This value | - | ||||||||||||||||||||||||
| 1552 | describes the number of fraction digits QTextStream should | - | ||||||||||||||||||||||||
| 1553 | write when generating real numbers. | - | ||||||||||||||||||||||||
| 1554 | - | |||||||||||||||||||||||||
| 1555 | The precision cannot be a negative value. The default value is 6. | - | ||||||||||||||||||||||||
| 1556 | - | |||||||||||||||||||||||||
| 1557 | \sa realNumberPrecision(), setRealNumberNotation() | - | ||||||||||||||||||||||||
| 1558 | */ | - | ||||||||||||||||||||||||
| 1559 | void QTextStream::setRealNumberPrecision(int precision) | - | ||||||||||||||||||||||||
| 1560 | { | - | ||||||||||||||||||||||||
| 1561 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1562 | if (precision < 0) {
| 2-10 | ||||||||||||||||||||||||
| 1563 | qWarning("QTextStream::setRealNumberPrecision: Invalid precision (%d)", precision); | - | ||||||||||||||||||||||||
| 1564 | d->params.realNumberPrecision = 6; | - | ||||||||||||||||||||||||
| 1565 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 1566 | } | - | ||||||||||||||||||||||||
| 1567 | d->params.realNumberPrecision = precision; | - | ||||||||||||||||||||||||
| 1568 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 1569 | - | |||||||||||||||||||||||||
| 1570 | /*! | - | ||||||||||||||||||||||||
| 1571 | Returns the current real number precision, or the number of fraction | - | ||||||||||||||||||||||||
| 1572 | digits QTextStream will write when generating real numbers. | - | ||||||||||||||||||||||||
| 1573 | - | |||||||||||||||||||||||||
| 1574 | \sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase() | - | ||||||||||||||||||||||||
| 1575 | */ | - | ||||||||||||||||||||||||
| 1576 | int QTextStream::realNumberPrecision() const | - | ||||||||||||||||||||||||
| 1577 | { | - | ||||||||||||||||||||||||
| 1578 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1579 | return d->params.realNumberPrecision; executed 3 times by 1 test: return d->params.realNumberPrecision;Executed by:
| 3 | ||||||||||||||||||||||||
| 1580 | } | - | ||||||||||||||||||||||||
| 1581 | - | |||||||||||||||||||||||||
| 1582 | /*! | - | ||||||||||||||||||||||||
| 1583 | Returns the status of the text stream. | - | ||||||||||||||||||||||||
| 1584 | - | |||||||||||||||||||||||||
| 1585 | \sa QTextStream::Status, setStatus(), resetStatus() | - | ||||||||||||||||||||||||
| 1586 | */ | - | ||||||||||||||||||||||||
| 1587 | - | |||||||||||||||||||||||||
| 1588 | QTextStream::Status QTextStream::status() const | - | ||||||||||||||||||||||||
| 1589 | { | - | ||||||||||||||||||||||||
| 1590 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1591 | return d->status; executed 17141 times by 4 tests: return d->status;Executed by:
| 17141 | ||||||||||||||||||||||||
| 1592 | } | - | ||||||||||||||||||||||||
| 1593 | - | |||||||||||||||||||||||||
| 1594 | /*! | - | ||||||||||||||||||||||||
| 1595 | \since 4.1 | - | ||||||||||||||||||||||||
| 1596 | - | |||||||||||||||||||||||||
| 1597 | Resets the status of the text stream. | - | ||||||||||||||||||||||||
| 1598 | - | |||||||||||||||||||||||||
| 1599 | \sa QTextStream::Status, status(), setStatus() | - | ||||||||||||||||||||||||
| 1600 | */ | - | ||||||||||||||||||||||||
| 1601 | void QTextStream::resetStatus() | - | ||||||||||||||||||||||||
| 1602 | { | - | ||||||||||||||||||||||||
| 1603 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1604 | d->status = Ok; | - | ||||||||||||||||||||||||
| 1605 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 1606 | - | |||||||||||||||||||||||||
| 1607 | /*! | - | ||||||||||||||||||||||||
| 1608 | \since 4.1 | - | ||||||||||||||||||||||||
| 1609 | - | |||||||||||||||||||||||||
| 1610 | Sets the status of the text stream to the \a status given. | - | ||||||||||||||||||||||||
| 1611 | - | |||||||||||||||||||||||||
| 1612 | Subsequent calls to setStatus() are ignored until resetStatus() | - | ||||||||||||||||||||||||
| 1613 | is called. | - | ||||||||||||||||||||||||
| 1614 | - | |||||||||||||||||||||||||
| 1615 | \sa Status, status(), resetStatus() | - | ||||||||||||||||||||||||
| 1616 | */ | - | ||||||||||||||||||||||||
| 1617 | void QTextStream::setStatus(Status status) | - | ||||||||||||||||||||||||
| 1618 | { | - | ||||||||||||||||||||||||
| 1619 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1620 | if (d->status == Ok)
| 0-79 | ||||||||||||||||||||||||
| 1621 | d->status = status; executed 79 times by 1 test: d->status = status;Executed by:
| 79 | ||||||||||||||||||||||||
| 1622 | } executed 79 times by 1 test: end of blockExecuted by:
| 79 | ||||||||||||||||||||||||
| 1623 | - | |||||||||||||||||||||||||
| 1624 | /*! | - | ||||||||||||||||||||||||
| 1625 | Returns \c true if there is no more data to be read from the | - | ||||||||||||||||||||||||
| 1626 | QTextStream; otherwise returns \c false. This is similar to, but not | - | ||||||||||||||||||||||||
| 1627 | the same as calling QIODevice::atEnd(), as QTextStream also takes | - | ||||||||||||||||||||||||
| 1628 | into account its internal Unicode buffer. | - | ||||||||||||||||||||||||
| 1629 | */ | - | ||||||||||||||||||||||||
| 1630 | bool QTextStream::atEnd() const | - | ||||||||||||||||||||||||
| 1631 | { | - | ||||||||||||||||||||||||
| 1632 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 1633 | CHECK_VALID_STREAM(true); executed 1 time by 1 test: return true;Executed by:
| 1-113676 | ||||||||||||||||||||||||
| 1634 | - | |||||||||||||||||||||||||
| 1635 | if (d->string)
| 48149-113675 | ||||||||||||||||||||||||
| 1636 | return d->string->size() == d->stringOffset; executed 48149 times by 3 tests: return d->string->size() == d->stringOffset;Executed by:
| 48149 | ||||||||||||||||||||||||
| 1637 | return d->readBuffer.isEmpty() && d->device->atEnd(); executed 113675 times by 11 tests: return d->readBuffer.isEmpty() && d->device->atEnd();Executed by:
| 113675 | ||||||||||||||||||||||||
| 1638 | } | - | ||||||||||||||||||||||||
| 1639 | - | |||||||||||||||||||||||||
| 1640 | /*! | - | ||||||||||||||||||||||||
| 1641 | Reads the entire content of the stream, and returns it as a | - | ||||||||||||||||||||||||
| 1642 | QString. Avoid this function when working on large files, as it | - | ||||||||||||||||||||||||
| 1643 | will consume a significant amount of memory. | - | ||||||||||||||||||||||||
| 1644 | - | |||||||||||||||||||||||||
| 1645 | Calling \l {QTextStream::readLine()}{readLine()} is better if you do not know how much data is | - | ||||||||||||||||||||||||
| 1646 | available. | - | ||||||||||||||||||||||||
| 1647 | - | |||||||||||||||||||||||||
| 1648 | \sa readLine() | - | ||||||||||||||||||||||||
| 1649 | */ | - | ||||||||||||||||||||||||
| 1650 | QString QTextStream::readAll() | - | ||||||||||||||||||||||||
| 1651 | { | - | ||||||||||||||||||||||||
| 1652 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1653 | CHECK_VALID_STREAM(QString()); executed 1 time by 1 test: return QString();Executed by:
| 1-1865 | ||||||||||||||||||||||||
| 1654 | - | |||||||||||||||||||||||||
| 1655 | return d->read(INT_MAX); executed 1869 times by 2 tests: return d->read(2147483647);Executed by:
| 1869 | ||||||||||||||||||||||||
| 1656 | } | - | ||||||||||||||||||||||||
| 1657 | - | |||||||||||||||||||||||||
| 1658 | /*! | - | ||||||||||||||||||||||||
| 1659 | Reads one line of text from the stream, and returns it as a | - | ||||||||||||||||||||||||
| 1660 | QString. The maximum allowed line length is set to \a maxlen. If | - | ||||||||||||||||||||||||
| 1661 | the stream contains lines longer than this, then the lines will be | - | ||||||||||||||||||||||||
| 1662 | split after \a maxlen characters and returned in parts. | - | ||||||||||||||||||||||||
| 1663 | - | |||||||||||||||||||||||||
| 1664 | If \a maxlen is 0, the lines can be of any length. | - | ||||||||||||||||||||||||
| 1665 | - | |||||||||||||||||||||||||
| 1666 | The returned line has no trailing end-of-line characters ("\\n" | - | ||||||||||||||||||||||||
| 1667 | or "\\r\\n"), so calling QString::trimmed() can be unnecessary. | - | ||||||||||||||||||||||||
| 1668 | - | |||||||||||||||||||||||||
| 1669 | If the stream has read to the end of the file, \l {QTextStream::readLine()}{readLine()} | - | ||||||||||||||||||||||||
| 1670 | will return a null QString. For strings, or for devices that support it, | - | ||||||||||||||||||||||||
| 1671 | you can explicitly test for the end of the stream using atEnd(). | - | ||||||||||||||||||||||||
| 1672 | - | |||||||||||||||||||||||||
| 1673 | \sa readAll(), QIODevice::readLine() | - | ||||||||||||||||||||||||
| 1674 | */ | - | ||||||||||||||||||||||||
| 1675 | QString QTextStream::readLine(qint64 maxlen) | - | ||||||||||||||||||||||||
| 1676 | { | - | ||||||||||||||||||||||||
| 1677 | QString line; | - | ||||||||||||||||||||||||
| 1678 | - | |||||||||||||||||||||||||
| 1679 | readLineInto(&line, maxlen); | - | ||||||||||||||||||||||||
| 1680 | return line; executed 154261 times by 14 tests: return line;Executed by:
| 154261 | ||||||||||||||||||||||||
| 1681 | } | - | ||||||||||||||||||||||||
| 1682 | - | |||||||||||||||||||||||||
| 1683 | /*! | - | ||||||||||||||||||||||||
| 1684 | \since 5.5 | - | ||||||||||||||||||||||||
| 1685 | - | |||||||||||||||||||||||||
| 1686 | Reads one line of text from the stream into \a line. | - | ||||||||||||||||||||||||
| 1687 | If \a line is 0, the read line is not stored. | - | ||||||||||||||||||||||||
| 1688 | - | |||||||||||||||||||||||||
| 1689 | The maximum allowed line length is set to \a maxlen. If | - | ||||||||||||||||||||||||
| 1690 | the stream contains lines longer than this, then the lines will be | - | ||||||||||||||||||||||||
| 1691 | split after \a maxlen characters and returned in parts. | - | ||||||||||||||||||||||||
| 1692 | - | |||||||||||||||||||||||||
| 1693 | If \a maxlen is 0, the lines can be of any length. | - | ||||||||||||||||||||||||
| 1694 | - | |||||||||||||||||||||||||
| 1695 | The resulting line has no trailing end-of-line characters ("\\n" | - | ||||||||||||||||||||||||
| 1696 | or "\\r\\n"), so calling QString::trimmed() can be unnecessary. | - | ||||||||||||||||||||||||
| 1697 | - | |||||||||||||||||||||||||
| 1698 | If \a line has sufficient capacity for the data that is about to be | - | ||||||||||||||||||||||||
| 1699 | read, this function may not need to allocate new memory. Because of | - | ||||||||||||||||||||||||
| 1700 | this, it can be faster than readLine(). | - | ||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||
| 1702 | Returns \c false if the stream has read to the end of the file or | - | ||||||||||||||||||||||||
| 1703 | an error has occurred; otherwise returns \c true. The contents in | - | ||||||||||||||||||||||||
| 1704 | \a line before the call are discarded in any case. | - | ||||||||||||||||||||||||
| 1705 | - | |||||||||||||||||||||||||
| 1706 | \sa readAll(), QIODevice::readLine() | - | ||||||||||||||||||||||||
| 1707 | */ | - | ||||||||||||||||||||||||
| 1708 | bool QTextStream::readLineInto(QString *line, qint64 maxlen) | - | ||||||||||||||||||||||||
| 1709 | { | - | ||||||||||||||||||||||||
| 1710 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1711 | // keep in sync with CHECK_VALID_STREAM | - | ||||||||||||||||||||||||
| 1712 | if (!d->string && !d->device) {
| 0-160283 | ||||||||||||||||||||||||
| 1713 | qWarning("QTextStream: No device"); | - | ||||||||||||||||||||||||
| 1714 | if (line && !line->isNull())
| 0 | ||||||||||||||||||||||||
| 1715 | line->resize(0); never executed: line->resize(0); | 0 | ||||||||||||||||||||||||
| 1716 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1717 | } | - | ||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||
| 1719 | const QChar *readPtr; | - | ||||||||||||||||||||||||
| 1720 | int length; | - | ||||||||||||||||||||||||
| 1721 | if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine)) {
| 14-184388 | ||||||||||||||||||||||||
| 1722 | if (line && !line->isNull())
| 0-14 | ||||||||||||||||||||||||
| 1723 | line->resize(0); executed 4 times by 1 test: line->resize(0);Executed by:
| 4 | ||||||||||||||||||||||||
| 1724 | return false; executed 14 times by 1 test: return false;Executed by:
| 14 | ||||||||||||||||||||||||
| 1725 | } | - | ||||||||||||||||||||||||
| 1726 | - | |||||||||||||||||||||||||
| 1727 | if (Q_LIKELY(line))
| 1-184387 | ||||||||||||||||||||||||
| 1728 | line->setUnicode(readPtr, length); executed 184387 times by 14 tests: line->setUnicode(readPtr, length);Executed by:
| 184387 | ||||||||||||||||||||||||
| 1729 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 1730 | return true; executed 184388 times by 14 tests: return true;Executed by:
| 184388 | ||||||||||||||||||||||||
| 1731 | } | - | ||||||||||||||||||||||||
| 1732 | - | |||||||||||||||||||||||||
| 1733 | /*! | - | ||||||||||||||||||||||||
| 1734 | \since 4.1 | - | ||||||||||||||||||||||||
| 1735 | - | |||||||||||||||||||||||||
| 1736 | Reads at most \a maxlen characters from the stream, and returns the data | - | ||||||||||||||||||||||||
| 1737 | read as a QString. | - | ||||||||||||||||||||||||
| 1738 | - | |||||||||||||||||||||||||
| 1739 | \sa readAll(), readLine(), QIODevice::read() | - | ||||||||||||||||||||||||
| 1740 | */ | - | ||||||||||||||||||||||||
| 1741 | QString QTextStream::read(qint64 maxlen) | - | ||||||||||||||||||||||||
| 1742 | { | - | ||||||||||||||||||||||||
| 1743 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 1744 | CHECK_VALID_STREAM(QString()); never executed: return QString();
| 0-8 | ||||||||||||||||||||||||
| 1745 | - | |||||||||||||||||||||||||
| 1746 | if (maxlen <= 0)
| 1-7 | ||||||||||||||||||||||||
| 1747 | return QString::fromLatin1(""); // empty, not null executed 1 time by 1 test: return QString::fromLatin1("");Executed by:
| 1 | ||||||||||||||||||||||||
| 1748 | - | |||||||||||||||||||||||||
| 1749 | return d->read(int(maxlen)); executed 7 times by 1 test: return d->read(int(maxlen));Executed by:
| 7 | ||||||||||||||||||||||||
| 1750 | } | - | ||||||||||||||||||||||||
| 1751 | - | |||||||||||||||||||||||||
| 1752 | /*! | - | ||||||||||||||||||||||||
| 1753 | \internal | - | ||||||||||||||||||||||||
| 1754 | */ | - | ||||||||||||||||||||||||
| 1755 | QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong *ret) | - | ||||||||||||||||||||||||
| 1756 | { | - | ||||||||||||||||||||||||
| 1757 | scan(0, 0, 0, NotSpace); | - | ||||||||||||||||||||||||
| 1758 | consumeLastToken(); | - | ||||||||||||||||||||||||
| 1759 | - | |||||||||||||||||||||||||
| 1760 | // detect int encoding | - | ||||||||||||||||||||||||
| 1761 | int base = params.integerBase; | - | ||||||||||||||||||||||||
| 1762 | if (base == 0) {
| 4875-16440 | ||||||||||||||||||||||||
| 1763 | QChar ch; | - | ||||||||||||||||||||||||
| 1764 | if (!getChar(&ch))
| 26-16414 | ||||||||||||||||||||||||
| 1765 | return npsInvalidPrefix; executed 26 times by 1 test: return npsInvalidPrefix;Executed by:
| 26 | ||||||||||||||||||||||||
| 1766 | if (ch == QLatin1Char('0')) {
| 1733-14681 | ||||||||||||||||||||||||
| 1767 | QChar ch2; | - | ||||||||||||||||||||||||
| 1768 | if (!getChar(&ch2)) {
| 6-1727 | ||||||||||||||||||||||||
| 1769 | // Result is the number 0 | - | ||||||||||||||||||||||||
| 1770 | *ret = 0; | - | ||||||||||||||||||||||||
| 1771 | return npsOk; executed 6 times by 1 test: return npsOk;Executed by:
| 6 | ||||||||||||||||||||||||
| 1772 | } | - | ||||||||||||||||||||||||
| 1773 | ch2 = ch2.toLower(); | - | ||||||||||||||||||||||||
| 1774 | - | |||||||||||||||||||||||||
| 1775 | if (ch2 == QLatin1Char('x')) {
| 60-1667 | ||||||||||||||||||||||||
| 1776 | base = 16; | - | ||||||||||||||||||||||||
| 1777 | } else if (ch2 == QLatin1Char('b')) { executed 60 times by 1 test: end of blockExecuted by:
| 42-1625 | ||||||||||||||||||||||||
| 1778 | base = 2; | - | ||||||||||||||||||||||||
| 1779 | } else if (ch2.isDigit() && ch2.digitValue() >= 0 && ch2.digitValue() <= 7) { executed 42 times by 1 test: end of blockExecuted by:
| 0-1601 | ||||||||||||||||||||||||
| 1780 | base = 8; | - | ||||||||||||||||||||||||
| 1781 | } else { executed 24 times by 1 test: end of blockExecuted by:
| 24 | ||||||||||||||||||||||||
| 1782 | base = 10; | - | ||||||||||||||||||||||||
| 1783 | } executed 1601 times by 1 test: end of blockExecuted by:
| 1601 | ||||||||||||||||||||||||
| 1784 | ungetChar(ch2); | - | ||||||||||||||||||||||||
| 1785 | } else if (ch == locale.negativeSign() || ch == locale.positiveSign() || ch.isDigit()) { executed 1727 times by 1 test: end of blockExecuted by:
| 2-14577 | ||||||||||||||||||||||||
| 1786 | base = 10; | - | ||||||||||||||||||||||||
| 1787 | } else { executed 14673 times by 2 tests: end of blockExecuted by:
| 14673 | ||||||||||||||||||||||||
| 1788 | ungetChar(ch); | - | ||||||||||||||||||||||||
| 1789 | return npsInvalidPrefix; executed 8 times by 1 test: return npsInvalidPrefix;Executed by:
| 8 | ||||||||||||||||||||||||
| 1790 | } | - | ||||||||||||||||||||||||
| 1791 | ungetChar(ch); | - | ||||||||||||||||||||||||
| 1792 | // State of the stream is now the same as on entry | - | ||||||||||||||||||||||||
| 1793 | // (cursor is at prefix), | - | ||||||||||||||||||||||||
| 1794 | // and local variable 'base' has been set appropriately. | - | ||||||||||||||||||||||||
| 1795 | } executed 16400 times by 2 tests: end of blockExecuted by:
| 16400 | ||||||||||||||||||||||||
| 1796 | - | |||||||||||||||||||||||||
| 1797 | qulonglong val=0; | - | ||||||||||||||||||||||||
| 1798 | switch (base) { | - | ||||||||||||||||||||||||
| 1799 | case 2: { executed 42 times by 1 test: case 2:Executed by:
| 42 | ||||||||||||||||||||||||
| 1800 | QChar pf1, pf2, dig; | - | ||||||||||||||||||||||||
| 1801 | // Parse prefix '0b' | - | ||||||||||||||||||||||||
| 1802 | if (!getChar(&pf1) || pf1 != QLatin1Char('0'))
| 0-42 | ||||||||||||||||||||||||
| 1803 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1804 | if (!getChar(&pf2) || pf2.toLower() != QLatin1Char('b'))
| 0-42 | ||||||||||||||||||||||||
| 1805 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1806 | // Parse digits | - | ||||||||||||||||||||||||
| 1807 | int ndigits = 0; | - | ||||||||||||||||||||||||
| 1808 | while (getChar(&dig)) {
| 30-156 | ||||||||||||||||||||||||
| 1809 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
| 1810 | if (n == '0' || n == '1') {
| 12-84 | ||||||||||||||||||||||||
| 1811 | val <<= 1; | - | ||||||||||||||||||||||||
| 1812 | val += n - '0'; | - | ||||||||||||||||||||||||
| 1813 | } else { executed 144 times by 1 test: end of blockExecuted by:
| 144 | ||||||||||||||||||||||||
| 1814 | ungetChar(dig); | - | ||||||||||||||||||||||||
| 1815 | break; executed 12 times by 1 test: break;Executed by:
| 12 | ||||||||||||||||||||||||
| 1816 | } | - | ||||||||||||||||||||||||
| 1817 | ndigits++; | - | ||||||||||||||||||||||||
| 1818 | } executed 144 times by 1 test: end of blockExecuted by:
| 144 | ||||||||||||||||||||||||
| 1819 | if (ndigits == 0) {
| 0-42 | ||||||||||||||||||||||||
| 1820 | // Unwind the prefix and abort | - | ||||||||||||||||||||||||
| 1821 | ungetChar(pf2); | - | ||||||||||||||||||||||||
| 1822 | ungetChar(pf1); | - | ||||||||||||||||||||||||
| 1823 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
| 1824 | } | - | ||||||||||||||||||||||||
| 1825 | break; executed 42 times by 1 test: break;Executed by:
| 42 | ||||||||||||||||||||||||
| 1826 | } | - | ||||||||||||||||||||||||
| 1827 | case 8: { executed 24 times by 1 test: case 8:Executed by:
| 24 | ||||||||||||||||||||||||
| 1828 | QChar pf, dig; | - | ||||||||||||||||||||||||
| 1829 | // Parse prefix '0' | - | ||||||||||||||||||||||||
| 1830 | if (!getChar(&pf) || pf != QLatin1Char('0'))
| 0-24 | ||||||||||||||||||||||||
| 1831 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1832 | // Parse digits | - | ||||||||||||||||||||||||
| 1833 | int ndigits = 0; | - | ||||||||||||||||||||||||
| 1834 | while (getChar(&dig)) {
| 12-72 | ||||||||||||||||||||||||
| 1835 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
| 1836 | if (n >= '0' && n <= '7') {
| 0-72 | ||||||||||||||||||||||||
| 1837 | val *= 8; | - | ||||||||||||||||||||||||
| 1838 | val += n - '0'; | - | ||||||||||||||||||||||||
| 1839 | } else { executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||||||||
| 1840 | ungetChar(dig); | - | ||||||||||||||||||||||||
| 1841 | break; executed 12 times by 1 test: break;Executed by:
| 12 | ||||||||||||||||||||||||
| 1842 | } | - | ||||||||||||||||||||||||
| 1843 | ndigits++; | - | ||||||||||||||||||||||||
| 1844 | } executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||||||||
| 1845 | if (ndigits == 0) {
| 0-24 | ||||||||||||||||||||||||
| 1846 | // Unwind the prefix and abort | - | ||||||||||||||||||||||||
| 1847 | ungetChar(pf); | - | ||||||||||||||||||||||||
| 1848 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
| 1849 | } | - | ||||||||||||||||||||||||
| 1850 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||||||||
| 1851 | } | - | ||||||||||||||||||||||||
| 1852 | case 10: { executed 21149 times by 3 tests: case 10:Executed by:
| 21149 | ||||||||||||||||||||||||
| 1853 | // Parse sign (or first digit) | - | ||||||||||||||||||||||||
| 1854 | QChar sign; | - | ||||||||||||||||||||||||
| 1855 | int ndigits = 0; | - | ||||||||||||||||||||||||
| 1856 | if (!getChar(&sign))
| 0-21149 | ||||||||||||||||||||||||
| 1857 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
| 1858 | if (sign != locale.negativeSign() && sign != locale.positiveSign()) {
| 2-21045 | ||||||||||||||||||||||||
| 1859 | if (!sign.isDigit()) {
| 0-21043 | ||||||||||||||||||||||||
| 1860 | ungetChar(sign); | - | ||||||||||||||||||||||||
| 1861 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
| 1862 | } | - | ||||||||||||||||||||||||
| 1863 | val += sign.digitValue(); | - | ||||||||||||||||||||||||
| 1864 | ndigits++; | - | ||||||||||||||||||||||||
| 1865 | } executed 21043 times by 3 tests: end of blockExecuted by:
| 21043 | ||||||||||||||||||||||||
| 1866 | // Parse digits | - | ||||||||||||||||||||||||
| 1867 | QChar ch; | - | ||||||||||||||||||||||||
| 1868 | while (getChar(&ch)) {
| 260-28447 | ||||||||||||||||||||||||
| 1869 | if (ch.isDigit()) {
| 7557-20890 | ||||||||||||||||||||||||
| 1870 | val *= 10; | - | ||||||||||||||||||||||||
| 1871 | val += ch.digitValue(); | - | ||||||||||||||||||||||||
| 1872 | } else if (locale != QLocale::c() && ch == locale.groupSeparator()) { executed 7557 times by 3 tests: end of blockExecuted by:
| 0-20889 | ||||||||||||||||||||||||
| 1873 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||||||||
| 1874 | } else { | - | ||||||||||||||||||||||||
| 1875 | ungetChar(ch); | - | ||||||||||||||||||||||||
| 1876 | break; executed 20889 times by 3 tests: break;Executed by:
| 20889 | ||||||||||||||||||||||||
| 1877 | } | - | ||||||||||||||||||||||||
| 1878 | ndigits++; | - | ||||||||||||||||||||||||
| 1879 | } executed 7557 times by 3 tests: end of blockExecuted by:
| 7557 | ||||||||||||||||||||||||
| 1880 | if (ndigits == 0)
| 0-21149 | ||||||||||||||||||||||||
| 1881 | return npsMissingDigit; never executed: return npsMissingDigit; | 0 | ||||||||||||||||||||||||
| 1882 | if (sign == locale.negativeSign()) {
| 104-21045 | ||||||||||||||||||||||||
| 1883 | qlonglong ival = qlonglong(val); | - | ||||||||||||||||||||||||
| 1884 | if (ival > 0)
| 6-98 | ||||||||||||||||||||||||
| 1885 | ival = -ival; executed 98 times by 1 test: ival = -ival;Executed by:
| 98 | ||||||||||||||||||||||||
| 1886 | val = qulonglong(ival); | - | ||||||||||||||||||||||||
| 1887 | } executed 104 times by 1 test: end of blockExecuted by:
| 104 | ||||||||||||||||||||||||
| 1888 | break; executed 21149 times by 3 tests: break;Executed by:
| 21149 | ||||||||||||||||||||||||
| 1889 | } | - | ||||||||||||||||||||||||
| 1890 | case 16: { executed 60 times by 1 test: case 16:Executed by:
| 60 | ||||||||||||||||||||||||
| 1891 | QChar pf1, pf2, dig; | - | ||||||||||||||||||||||||
| 1892 | // Parse prefix ' 0x' | - | ||||||||||||||||||||||||
| 1893 | if (!getChar(&pf1) || pf1 != QLatin1Char('0'))
| 0-60 | ||||||||||||||||||||||||
| 1894 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1895 | if (!getChar(&pf2) || pf2.toLower() != QLatin1Char('x'))
| 0-60 | ||||||||||||||||||||||||
| 1896 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1897 | // Parse digits | - | ||||||||||||||||||||||||
| 1898 | int ndigits = 0; | - | ||||||||||||||||||||||||
| 1899 | while (getChar(&dig)) {
| 48-318 | ||||||||||||||||||||||||
| 1900 | int n = dig.toLower().unicode(); | - | ||||||||||||||||||||||||
| 1901 | if (n >= '0' && n <= '9') {
| 0-318 | ||||||||||||||||||||||||
| 1902 | val <<= 4; | - | ||||||||||||||||||||||||
| 1903 | val += n - '0'; | - | ||||||||||||||||||||||||
| 1904 | } else if (n >= 'a' && n <= 'f') { executed 12 times by 1 test: end of blockExecuted by:
| 0-306 | ||||||||||||||||||||||||
| 1905 | val <<= 4; | - | ||||||||||||||||||||||||
| 1906 | val += 10 + (n - 'a'); | - | ||||||||||||||||||||||||
| 1907 | } else { executed 294 times by 1 test: end of blockExecuted by:
| 294 | ||||||||||||||||||||||||
| 1908 | ungetChar(dig); | - | ||||||||||||||||||||||||
| 1909 | break; executed 12 times by 1 test: break;Executed by:
| 12 | ||||||||||||||||||||||||
| 1910 | } | - | ||||||||||||||||||||||||
| 1911 | ndigits++; | - | ||||||||||||||||||||||||
| 1912 | } executed 306 times by 1 test: end of blockExecuted by:
| 306 | ||||||||||||||||||||||||
| 1913 | if (ndigits == 0) {
| 6-54 | ||||||||||||||||||||||||
| 1914 | return npsMissingDigit; executed 6 times by 1 test: return npsMissingDigit;Executed by:
| 6 | ||||||||||||||||||||||||
| 1915 | } | - | ||||||||||||||||||||||||
| 1916 | break; executed 54 times by 1 test: break;Executed by:
| 54 | ||||||||||||||||||||||||
| 1917 | } | - | ||||||||||||||||||||||||
| 1918 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1919 | // Unsupported integerBase | - | ||||||||||||||||||||||||
| 1920 | return npsInvalidPrefix; never executed: return npsInvalidPrefix; | 0 | ||||||||||||||||||||||||
| 1921 | } | - | ||||||||||||||||||||||||
| 1922 | - | |||||||||||||||||||||||||
| 1923 | if (ret)
| 0-21269 | ||||||||||||||||||||||||
| 1924 | *ret = val; executed 21269 times by 3 tests: *ret = val;Executed by:
| 21269 | ||||||||||||||||||||||||
| 1925 | return npsOk; executed 21269 times by 3 tests: return npsOk;Executed by:
| 21269 | ||||||||||||||||||||||||
| 1926 | } | - | ||||||||||||||||||||||||
| 1927 | - | |||||||||||||||||||||||||
| 1928 | /*! | - | ||||||||||||||||||||||||
| 1929 | \internal | - | ||||||||||||||||||||||||
| 1930 | (hihi) | - | ||||||||||||||||||||||||
| 1931 | */ | - | ||||||||||||||||||||||||
| 1932 | bool QTextStreamPrivate::getReal(double *f) | - | ||||||||||||||||||||||||
| 1933 | { | - | ||||||||||||||||||||||||
| 1934 | // We use a table-driven FSM to parse floating point numbers | - | ||||||||||||||||||||||||
| 1935 | // strtod() cannot be used directly since we may be reading from a | - | ||||||||||||||||||||||||
| 1936 | // QIODevice. | - | ||||||||||||||||||||||||
| 1937 | enum ParserState { | - | ||||||||||||||||||||||||
| 1938 | Init = 0, | - | ||||||||||||||||||||||||
| 1939 | Sign = 1, | - | ||||||||||||||||||||||||
| 1940 | Mantissa = 2, | - | ||||||||||||||||||||||||
| 1941 | Dot = 3, | - | ||||||||||||||||||||||||
| 1942 | Abscissa = 4, | - | ||||||||||||||||||||||||
| 1943 | ExpMark = 5, | - | ||||||||||||||||||||||||
| 1944 | ExpSign = 6, | - | ||||||||||||||||||||||||
| 1945 | Exponent = 7, | - | ||||||||||||||||||||||||
| 1946 | Nan1 = 8, | - | ||||||||||||||||||||||||
| 1947 | Nan2 = 9, | - | ||||||||||||||||||||||||
| 1948 | Inf1 = 10, | - | ||||||||||||||||||||||||
| 1949 | Inf2 = 11, | - | ||||||||||||||||||||||||
| 1950 | NanInf = 12, | - | ||||||||||||||||||||||||
| 1951 | Done = 13 | - | ||||||||||||||||||||||||
| 1952 | }; | - | ||||||||||||||||||||||||
| 1953 | enum InputToken { | - | ||||||||||||||||||||||||
| 1954 | None = 0, | - | ||||||||||||||||||||||||
| 1955 | InputSign = 1, | - | ||||||||||||||||||||||||
| 1956 | InputDigit = 2, | - | ||||||||||||||||||||||||
| 1957 | InputDot = 3, | - | ||||||||||||||||||||||||
| 1958 | InputExp = 4, | - | ||||||||||||||||||||||||
| 1959 | InputI = 5, | - | ||||||||||||||||||||||||
| 1960 | InputN = 6, | - | ||||||||||||||||||||||||
| 1961 | InputF = 7, | - | ||||||||||||||||||||||||
| 1962 | InputA = 8, | - | ||||||||||||||||||||||||
| 1963 | InputT = 9 | - | ||||||||||||||||||||||||
| 1964 | }; | - | ||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||
| 1966 | static const uchar table[13][10] = { | - | ||||||||||||||||||||||||
| 1967 | // None InputSign InputDigit InputDot InputExp InputI InputN InputF InputA InputT | - | ||||||||||||||||||||||||
| 1968 | { 0, Sign, Mantissa, Dot, 0, Inf1, Nan1, 0, 0, 0 }, // 0 Init | - | ||||||||||||||||||||||||
| 1969 | { 0, 0, Mantissa, Dot, 0, Inf1, Nan1, 0, 0, 0 }, // 1 Sign | - | ||||||||||||||||||||||||
| 1970 | { Done, Done, Mantissa, Dot, ExpMark, 0, 0, 0, 0, 0 }, // 2 Mantissa | - | ||||||||||||||||||||||||
| 1971 | { 0, 0, Abscissa, 0, 0, 0, 0, 0, 0, 0 }, // 3 Dot | - | ||||||||||||||||||||||||
| 1972 | { Done, Done, Abscissa, Done, ExpMark, 0, 0, 0, 0, 0 }, // 4 Abscissa | - | ||||||||||||||||||||||||
| 1973 | { 0, ExpSign, Exponent, 0, 0, 0, 0, 0, 0, 0 }, // 5 ExpMark | - | ||||||||||||||||||||||||
| 1974 | { 0, 0, Exponent, 0, 0, 0, 0, 0, 0, 0 }, // 6 ExpSign | - | ||||||||||||||||||||||||
| 1975 | { Done, Done, Exponent, Done, Done, 0, 0, 0, 0, 0 }, // 7 Exponent | - | ||||||||||||||||||||||||
| 1976 | { 0, 0, 0, 0, 0, 0, 0, 0, Nan2, 0 }, // 8 Nan1 | - | ||||||||||||||||||||||||
| 1977 | { 0, 0, 0, 0, 0, 0, NanInf, 0, 0, 0 }, // 9 Nan2 | - | ||||||||||||||||||||||||
| 1978 | { 0, 0, 0, 0, 0, 0, Inf2, 0, 0, 0 }, // 10 Inf1 | - | ||||||||||||||||||||||||
| 1979 | { 0, 0, 0, 0, 0, 0, 0, NanInf, 0, 0 }, // 11 Inf2 | - | ||||||||||||||||||||||||
| 1980 | { Done, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 11 NanInf | - | ||||||||||||||||||||||||
| 1981 | }; | - | ||||||||||||||||||||||||
| 1982 | - | |||||||||||||||||||||||||
| 1983 | ParserState state = Init; | - | ||||||||||||||||||||||||
| 1984 | InputToken input = None; | - | ||||||||||||||||||||||||
| 1985 | - | |||||||||||||||||||||||||
| 1986 | scan(0, 0, 0, NotSpace); | - | ||||||||||||||||||||||||
| 1987 | consumeLastToken(); | - | ||||||||||||||||||||||||
| 1988 | - | |||||||||||||||||||||||||
| 1989 | const int BufferSize = 128; | - | ||||||||||||||||||||||||
| 1990 | char buf[BufferSize]; | - | ||||||||||||||||||||||||
| 1991 | int i = 0; | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | QChar c; | - | ||||||||||||||||||||||||
| 1994 | while (getChar(&c)) {
| 29-282 | ||||||||||||||||||||||||
| 1995 | switch (c.unicode()) { | - | ||||||||||||||||||||||||
| 1996 | 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 | ||||||||||||||||||||||||
| 1997 | 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 | ||||||||||||||||||||||||
| 1998 | input = InputDigit; | - | ||||||||||||||||||||||||
| 1999 | break; executed 77 times by 1 test: break;Executed by:
| 77 | ||||||||||||||||||||||||
| 2000 | 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 | ||||||||||||||||||||||||
| 2001 | input = InputI; | - | ||||||||||||||||||||||||
| 2002 | break; executed 18 times by 1 test: break;Executed by:
| 18 | ||||||||||||||||||||||||
| 2003 | 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 | ||||||||||||||||||||||||
| 2004 | input = InputN; | - | ||||||||||||||||||||||||
| 2005 | break; executed 54 times by 1 test: break;Executed by:
| 54 | ||||||||||||||||||||||||
| 2006 | 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 | ||||||||||||||||||||||||
| 2007 | input = InputF; | - | ||||||||||||||||||||||||
| 2008 | break; executed 18 times by 1 test: break;Executed by:
| 18 | ||||||||||||||||||||||||
| 2009 | 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 | ||||||||||||||||||||||||
| 2010 | input = InputA; | - | ||||||||||||||||||||||||
| 2011 | break; executed 21 times by 1 test: break;Executed by:
| 21 | ||||||||||||||||||||||||
| 2012 | case 't': case 'T': never executed: case 't':never executed: case 'T': | 0 | ||||||||||||||||||||||||
| 2013 | input = InputT; | - | ||||||||||||||||||||||||
| 2014 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2015 | default: { executed 94 times by 1 test: default:Executed by:
| 94 | ||||||||||||||||||||||||
| 2016 | QChar lc = c.toLower(); | - | ||||||||||||||||||||||||
| 2017 | if (lc == locale.decimalPoint().toLower())
| 13-81 | ||||||||||||||||||||||||
| 2018 | input = InputDot; executed 13 times by 1 test: input = InputDot;Executed by:
| 13 | ||||||||||||||||||||||||
| 2019 | else if (lc == locale.exponential().toLower())
| 8-73 | ||||||||||||||||||||||||
| 2020 | input = InputExp; executed 8 times by 1 test: input = InputExp;Executed by:
| 8 | ||||||||||||||||||||||||
| 2021 | else if (lc == locale.negativeSign().toLower()
| 20-53 | ||||||||||||||||||||||||
| 2022 | || lc == locale.positiveSign().toLower())
| 16-37 | ||||||||||||||||||||||||
| 2023 | input = InputSign; executed 36 times by 1 test: input = InputSign;Executed by:
| 36 | ||||||||||||||||||||||||
| 2024 | else if (locale != QLocale::c() // backward-compatibility
| 0-37 | ||||||||||||||||||||||||
| 2025 | && lc == locale.groupSeparator().toLower())
| 0 | ||||||||||||||||||||||||
| 2026 | input = InputDigit; // well, it isn't a digit, but no one cares. never executed: input = InputDigit; | 0 | ||||||||||||||||||||||||
| 2027 | else | - | ||||||||||||||||||||||||
| 2028 | input = None; executed 37 times by 1 test: input = None;Executed by:
| 37 | ||||||||||||||||||||||||
| 2029 | } | - | ||||||||||||||||||||||||
| 2030 | break; executed 94 times by 1 test: break;Executed by:
| 94 | ||||||||||||||||||||||||
| 2031 | } | - | ||||||||||||||||||||||||
| 2032 | - | |||||||||||||||||||||||||
| 2033 | state = ParserState(table[state][input]); | - | ||||||||||||||||||||||||
| 2034 | - | |||||||||||||||||||||||||
| 2035 | if (state == Init || state == Done || i > (BufferSize - 5)) {
| 0-279 | ||||||||||||||||||||||||
| 2036 | ungetChar(c); | - | ||||||||||||||||||||||||
| 2037 | if (i > (BufferSize - 5)) { // ignore rest of digits
| 0-40 | ||||||||||||||||||||||||
| 2038 | while (getChar(&c)) {
| 0 | ||||||||||||||||||||||||
| 2039 | if (!c.isDigit()) {
| 0 | ||||||||||||||||||||||||
| 2040 | ungetChar(c); | - | ||||||||||||||||||||||||
| 2041 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2042 | } | - | ||||||||||||||||||||||||
| 2043 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2044 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2045 | break; executed 40 times by 1 test: break;Executed by:
| 40 | ||||||||||||||||||||||||
| 2046 | } | - | ||||||||||||||||||||||||
| 2047 | - | |||||||||||||||||||||||||
| 2048 | buf[i++] = c.toLatin1(); | - | ||||||||||||||||||||||||
| 2049 | } executed 242 times by 1 test: end of blockExecuted by:
| 242 | ||||||||||||||||||||||||
| 2050 | - | |||||||||||||||||||||||||
| 2051 | if (i == 0)
| 10-59 | ||||||||||||||||||||||||
| 2052 | return false; executed 10 times by 1 test: return false;Executed by:
| 10 | ||||||||||||||||||||||||
| 2053 | if (!f)
| 0-59 | ||||||||||||||||||||||||
| 2054 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2055 | buf[i] = '\0'; | - | ||||||||||||||||||||||||
| 2056 | - | |||||||||||||||||||||||||
| 2057 | // backward-compatibility. Old implementation supported +nan/-nan | - | ||||||||||||||||||||||||
| 2058 | // for some reason. QLocale only checks for lower-case | - | ||||||||||||||||||||||||
| 2059 | // nan/+inf/-inf, so here we also check for uppercase and mixed | - | ||||||||||||||||||||||||
| 2060 | // case versions. | - | ||||||||||||||||||||||||
| 2061 | if (!qstricmp(buf, "nan") || !qstricmp(buf, "+nan") || !qstricmp(buf, "-nan")) {
| 6-53 | ||||||||||||||||||||||||
| 2062 | *f = qSNaN(); | - | ||||||||||||||||||||||||
| 2063 | return true; executed 18 times by 1 test: return true;Executed by:
| 18 | ||||||||||||||||||||||||
| 2064 | } else if (!qstricmp(buf, "+inf") || !qstricmp(buf, "inf")) {
| 6-35 | ||||||||||||||||||||||||
| 2065 | *f = qInf(); | - | ||||||||||||||||||||||||
| 2066 | return true; executed 12 times by 1 test: return true;Executed by:
| 12 | ||||||||||||||||||||||||
| 2067 | } else if (!qstricmp(buf, "-inf")) {
| 6-23 | ||||||||||||||||||||||||
| 2068 | *f = -qInf(); | - | ||||||||||||||||||||||||
| 2069 | return true; executed 6 times by 1 test: return true;Executed by:
| 6 | ||||||||||||||||||||||||
| 2070 | } | - | ||||||||||||||||||||||||
| 2071 | bool ok; | - | ||||||||||||||||||||||||
| 2072 | *f = locale.toDouble(QString::fromLatin1(buf), &ok); | - | ||||||||||||||||||||||||
| 2073 | return ok; executed 23 times by 1 test: return ok;Executed by:
| 23 | ||||||||||||||||||||||||
| 2074 | } | - | ||||||||||||||||||||||||
| 2075 | - | |||||||||||||||||||||||||
| 2076 | /*! | - | ||||||||||||||||||||||||
| 2077 | Reads a character from the stream and stores it in \a c. Returns a | - | ||||||||||||||||||||||||
| 2078 | reference to the QTextStream, so several operators can be | - | ||||||||||||||||||||||||
| 2079 | nested. Example: | - | ||||||||||||||||||||||||
| 2080 | - | |||||||||||||||||||||||||
| 2081 | \snippet code/src_corelib_io_qtextstream.cpp 7 | - | ||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | Whitespace is \e not skipped. | - | ||||||||||||||||||||||||
| 2084 | */ | - | ||||||||||||||||||||||||
| 2085 | - | |||||||||||||||||||||||||
| 2086 | QTextStream &QTextStream::operator>>(QChar &c) | - | ||||||||||||||||||||||||
| 2087 | { | - | ||||||||||||||||||||||||
| 2088 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2089 | CHECK_VALID_STREAM(*this); executed 1 time by 1 test: return *this;Executed by:
| 1-830 | ||||||||||||||||||||||||
| 2090 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
| 2091 | if (!d->getChar(&c))
| 16-823 | ||||||||||||||||||||||||
| 2092 | setStatus(ReadPastEnd); executed 16 times by 1 test: setStatus(ReadPastEnd);Executed by:
| 16 | ||||||||||||||||||||||||
| 2093 | return *this; executed 839 times by 1 test: return *this;Executed by:
| 839 | ||||||||||||||||||||||||
| 2094 | } | - | ||||||||||||||||||||||||
| 2095 | - | |||||||||||||||||||||||||
| 2096 | /*! | - | ||||||||||||||||||||||||
| 2097 | \overload | - | ||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||
| 2099 | Reads a character from the stream and stores it in \a c. The | - | ||||||||||||||||||||||||
| 2100 | character from the stream is converted to ISO-5589-1 before it is | - | ||||||||||||||||||||||||
| 2101 | stored. | - | ||||||||||||||||||||||||
| 2102 | - | |||||||||||||||||||||||||
| 2103 | \sa QChar::toLatin1() | - | ||||||||||||||||||||||||
| 2104 | */ | - | ||||||||||||||||||||||||
| 2105 | QTextStream &QTextStream::operator>>(char &c) | - | ||||||||||||||||||||||||
| 2106 | { | - | ||||||||||||||||||||||||
| 2107 | QChar ch; | - | ||||||||||||||||||||||||
| 2108 | *this >> ch; | - | ||||||||||||||||||||||||
| 2109 | c = ch.toLatin1(); | - | ||||||||||||||||||||||||
| 2110 | return *this; executed 19 times by 1 test: return *this;Executed by:
| 19 | ||||||||||||||||||||||||
| 2111 | } | - | ||||||||||||||||||||||||
| 2112 | - | |||||||||||||||||||||||||
| 2113 | /*! | - | ||||||||||||||||||||||||
| 2114 | Reads an integer from the stream and stores it in \a i, then | - | ||||||||||||||||||||||||
| 2115 | returns a reference to the QTextStream. The number is cast to | - | ||||||||||||||||||||||||
| 2116 | the correct type before it is stored. If no number was detected on | - | ||||||||||||||||||||||||
| 2117 | the stream, \a i is set to 0. | - | ||||||||||||||||||||||||
| 2118 | - | |||||||||||||||||||||||||
| 2119 | By default, QTextStream will attempt to detect the base of the | - | ||||||||||||||||||||||||
| 2120 | number using the following rules: | - | ||||||||||||||||||||||||
| 2121 | - | |||||||||||||||||||||||||
| 2122 | \table | - | ||||||||||||||||||||||||
| 2123 | \header \li Prefix \li Base | - | ||||||||||||||||||||||||
| 2124 | \row \li "0b" or "0B" \li 2 (binary) | - | ||||||||||||||||||||||||
| 2125 | \row \li "0" followed by "0-7" \li 8 (octal) | - | ||||||||||||||||||||||||
| 2126 | \row \li "0" otherwise \li 10 (decimal) | - | ||||||||||||||||||||||||
| 2127 | \row \li "0x" or "0X" \li 16 (hexadecimal) | - | ||||||||||||||||||||||||
| 2128 | \row \li "1" to "9" \li 10 (decimal) | - | ||||||||||||||||||||||||
| 2129 | \endtable | - | ||||||||||||||||||||||||
| 2130 | - | |||||||||||||||||||||||||
| 2131 | By calling setIntegerBase(), you can specify the integer base | - | ||||||||||||||||||||||||
| 2132 | explicitly. This will disable the auto-detection, and speed up | - | ||||||||||||||||||||||||
| 2133 | QTextStream slightly. | - | ||||||||||||||||||||||||
| 2134 | - | |||||||||||||||||||||||||
| 2135 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
| 2136 | */ | - | ||||||||||||||||||||||||
| 2137 | QTextStream &QTextStream::operator>>(signed short &i) | - | ||||||||||||||||||||||||
| 2138 | { | - | ||||||||||||||||||||||||
| 2139 | 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 | ||||||||||||||||||||||||
| 2140 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2141 | - | |||||||||||||||||||||||||
| 2142 | /*! | - | ||||||||||||||||||||||||
| 2143 | \overload | - | ||||||||||||||||||||||||
| 2144 | - | |||||||||||||||||||||||||
| 2145 | Stores the integer in the unsigned short \a i. | - | ||||||||||||||||||||||||
| 2146 | */ | - | ||||||||||||||||||||||||
| 2147 | QTextStream &QTextStream::operator>>(unsigned short &i) | - | ||||||||||||||||||||||||
| 2148 | { | - | ||||||||||||||||||||||||
| 2149 | 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 | ||||||||||||||||||||||||
| 2150 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2151 | - | |||||||||||||||||||||||||
| 2152 | /*! | - | ||||||||||||||||||||||||
| 2153 | \overload | - | ||||||||||||||||||||||||
| 2154 | - | |||||||||||||||||||||||||
| 2155 | Stores the integer in the signed int \a i. | - | ||||||||||||||||||||||||
| 2156 | */ | - | ||||||||||||||||||||||||
| 2157 | QTextStream &QTextStream::operator>>(signed int &i) | - | ||||||||||||||||||||||||
| 2158 | { | - | ||||||||||||||||||||||||
| 2159 | 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 | ||||||||||||||||||||||||
| 2160 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2161 | - | |||||||||||||||||||||||||
| 2162 | /*! | - | ||||||||||||||||||||||||
| 2163 | \overload | - | ||||||||||||||||||||||||
| 2164 | - | |||||||||||||||||||||||||
| 2165 | Stores the integer in the unsigned int \a i. | - | ||||||||||||||||||||||||
| 2166 | */ | - | ||||||||||||||||||||||||
| 2167 | QTextStream &QTextStream::operator>>(unsigned int &i) | - | ||||||||||||||||||||||||
| 2168 | { | - | ||||||||||||||||||||||||
| 2169 | 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 | ||||||||||||||||||||||||
| 2170 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2171 | - | |||||||||||||||||||||||||
| 2172 | /*! | - | ||||||||||||||||||||||||
| 2173 | \overload | - | ||||||||||||||||||||||||
| 2174 | - | |||||||||||||||||||||||||
| 2175 | Stores the integer in the signed long \a i. | - | ||||||||||||||||||||||||
| 2176 | */ | - | ||||||||||||||||||||||||
| 2177 | QTextStream &QTextStream::operator>>(signed long &i) | - | ||||||||||||||||||||||||
| 2178 | { | - | ||||||||||||||||||||||||
| 2179 | 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 | ||||||||||||||||||||||||
| 2180 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2181 | - | |||||||||||||||||||||||||
| 2182 | /*! | - | ||||||||||||||||||||||||
| 2183 | \overload | - | ||||||||||||||||||||||||
| 2184 | - | |||||||||||||||||||||||||
| 2185 | Stores the integer in the unsigned long \a i. | - | ||||||||||||||||||||||||
| 2186 | */ | - | ||||||||||||||||||||||||
| 2187 | QTextStream &QTextStream::operator>>(unsigned long &i) | - | ||||||||||||||||||||||||
| 2188 | { | - | ||||||||||||||||||||||||
| 2189 | 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 | ||||||||||||||||||||||||
| 2190 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2191 | - | |||||||||||||||||||||||||
| 2192 | /*! | - | ||||||||||||||||||||||||
| 2193 | \overload | - | ||||||||||||||||||||||||
| 2194 | - | |||||||||||||||||||||||||
| 2195 | Stores the integer in the qlonglong \a i. | - | ||||||||||||||||||||||||
| 2196 | */ | - | ||||||||||||||||||||||||
| 2197 | QTextStream &QTextStream::operator>>(qlonglong &i) | - | ||||||||||||||||||||||||
| 2198 | { | - | ||||||||||||||||||||||||
| 2199 | 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 | ||||||||||||||||||||||||
| 2200 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2201 | - | |||||||||||||||||||||||||
| 2202 | /*! | - | ||||||||||||||||||||||||
| 2203 | \overload | - | ||||||||||||||||||||||||
| 2204 | - | |||||||||||||||||||||||||
| 2205 | Stores the integer in the qulonglong \a i. | - | ||||||||||||||||||||||||
| 2206 | */ | - | ||||||||||||||||||||||||
| 2207 | QTextStream &QTextStream::operator>>(qulonglong &i) | - | ||||||||||||||||||||||||
| 2208 | { | - | ||||||||||||||||||||||||
| 2209 | 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 | ||||||||||||||||||||||||
| 2210 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2211 | - | |||||||||||||||||||||||||
| 2212 | /*! | - | ||||||||||||||||||||||||
| 2213 | Reads a real number from the stream and stores it in \a f, then | - | ||||||||||||||||||||||||
| 2214 | returns a reference to the QTextStream. The number is cast to | - | ||||||||||||||||||||||||
| 2215 | the correct type. If no real number is detect on the stream, \a f | - | ||||||||||||||||||||||||
| 2216 | is set to 0.0. | - | ||||||||||||||||||||||||
| 2217 | - | |||||||||||||||||||||||||
| 2218 | As a special exception, QTextStream allows the strings "nan" and "inf" to | - | ||||||||||||||||||||||||
| 2219 | represent NAN and INF floats or doubles. | - | ||||||||||||||||||||||||
| 2220 | - | |||||||||||||||||||||||||
| 2221 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
| 2222 | */ | - | ||||||||||||||||||||||||
| 2223 | QTextStream &QTextStream::operator>>(float &f) | - | ||||||||||||||||||||||||
| 2224 | { | - | ||||||||||||||||||||||||
| 2225 | IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(float); never executed: return *this;executed 28 times by 1 test: end of blockExecuted by:
executed 4 times by 1 test: end of blockExecuted by:
executed 32 times by 1 test: return *this;Executed by:
| 0-32 | ||||||||||||||||||||||||
| 2226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2227 | - | |||||||||||||||||||||||||
| 2228 | /*! | - | ||||||||||||||||||||||||
| 2229 | \overload | - | ||||||||||||||||||||||||
| 2230 | - | |||||||||||||||||||||||||
| 2231 | Stores the real number in the double \a f. | - | ||||||||||||||||||||||||
| 2232 | */ | - | ||||||||||||||||||||||||
| 2233 | QTextStream &QTextStream::operator>>(double &f) | - | ||||||||||||||||||||||||
| 2234 | { | - | ||||||||||||||||||||||||
| 2235 | IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(double); never executed: return *this;executed 31 times by 1 test: end of blockExecuted by:
executed 6 times by 1 test: end of blockExecuted by:
executed 37 times by 1 test: return *this;Executed by:
| 0-37 | ||||||||||||||||||||||||
| 2236 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2237 | - | |||||||||||||||||||||||||
| 2238 | /*! | - | ||||||||||||||||||||||||
| 2239 | Reads a word from the stream and stores it in \a str, then returns | - | ||||||||||||||||||||||||
| 2240 | a reference to the stream. Words are separated by whitespace | - | ||||||||||||||||||||||||
| 2241 | (i.e., all characters for which QChar::isSpace() returns \c true). | - | ||||||||||||||||||||||||
| 2242 | - | |||||||||||||||||||||||||
| 2243 | Leading whitespace is skipped. | - | ||||||||||||||||||||||||
| 2244 | */ | - | ||||||||||||||||||||||||
| 2245 | QTextStream &QTextStream::operator>>(QString &str) | - | ||||||||||||||||||||||||
| 2246 | { | - | ||||||||||||||||||||||||
| 2247 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2248 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-425 | ||||||||||||||||||||||||
| 2249 | - | |||||||||||||||||||||||||
| 2250 | str.clear(); | - | ||||||||||||||||||||||||
| 2251 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
| 2252 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2253 | - | |||||||||||||||||||||||||
| 2254 | const QChar *ptr; | - | ||||||||||||||||||||||||
| 2255 | int length; | - | ||||||||||||||||||||||||
| 2256 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 4-433 | ||||||||||||||||||||||||
| 2257 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
| 2258 | return *this; executed 4 times by 1 test: return *this;Executed by:
| 4 | ||||||||||||||||||||||||
| 2259 | } | - | ||||||||||||||||||||||||
| 2260 | - | |||||||||||||||||||||||||
| 2261 | str = QString(ptr, length); | - | ||||||||||||||||||||||||
| 2262 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2263 | return *this; executed 433 times by 4 tests: return *this;Executed by:
| 433 | ||||||||||||||||||||||||
| 2264 | } | - | ||||||||||||||||||||||||
| 2265 | - | |||||||||||||||||||||||||
| 2266 | /*! | - | ||||||||||||||||||||||||
| 2267 | \overload | - | ||||||||||||||||||||||||
| 2268 | - | |||||||||||||||||||||||||
| 2269 | Converts the word to ISO-8859-1, then stores it in \a array. | - | ||||||||||||||||||||||||
| 2270 | - | |||||||||||||||||||||||||
| 2271 | \sa QString::toLatin1() | - | ||||||||||||||||||||||||
| 2272 | */ | - | ||||||||||||||||||||||||
| 2273 | QTextStream &QTextStream::operator>>(QByteArray &array) | - | ||||||||||||||||||||||||
| 2274 | { | - | ||||||||||||||||||||||||
| 2275 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2276 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-14 | ||||||||||||||||||||||||
| 2277 | - | |||||||||||||||||||||||||
| 2278 | array.clear(); | - | ||||||||||||||||||||||||
| 2279 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
| 2280 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2281 | - | |||||||||||||||||||||||||
| 2282 | const QChar *ptr; | - | ||||||||||||||||||||||||
| 2283 | int length; | - | ||||||||||||||||||||||||
| 2284 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 3-11 | ||||||||||||||||||||||||
| 2285 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
| 2286 | return *this; executed 3 times by 1 test: return *this;Executed by:
| 3 | ||||||||||||||||||||||||
| 2287 | } | - | ||||||||||||||||||||||||
| 2288 | - | |||||||||||||||||||||||||
| 2289 | for (int i = 0; i < length; ++i)
| 11-20 | ||||||||||||||||||||||||
| 2290 | array += ptr[i].toLatin1(); executed 20 times by 1 test: array += ptr[i].toLatin1();Executed by:
| 20 | ||||||||||||||||||||||||
| 2291 | - | |||||||||||||||||||||||||
| 2292 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2293 | return *this; executed 11 times by 1 test: return *this;Executed by:
| 11 | ||||||||||||||||||||||||
| 2294 | } | - | ||||||||||||||||||||||||
| 2295 | - | |||||||||||||||||||||||||
| 2296 | /*! | - | ||||||||||||||||||||||||
| 2297 | \overload | - | ||||||||||||||||||||||||
| 2298 | - | |||||||||||||||||||||||||
| 2299 | Stores the word in \a c, terminated by a '\\0' character. If no word is | - | ||||||||||||||||||||||||
| 2300 | available, only the '\\0' character is stored. | - | ||||||||||||||||||||||||
| 2301 | - | |||||||||||||||||||||||||
| 2302 | Warning: Although convenient, this operator is dangerous and must | - | ||||||||||||||||||||||||
| 2303 | be used with care. QTextStream assumes that \a c points to a | - | ||||||||||||||||||||||||
| 2304 | buffer with enough space to hold the word. If the buffer is too | - | ||||||||||||||||||||||||
| 2305 | small, your application may crash. | - | ||||||||||||||||||||||||
| 2306 | - | |||||||||||||||||||||||||
| 2307 | If possible, use the QByteArray operator instead. | - | ||||||||||||||||||||||||
| 2308 | */ | - | ||||||||||||||||||||||||
| 2309 | QTextStream &QTextStream::operator>>(char *c) | - | ||||||||||||||||||||||||
| 2310 | { | - | ||||||||||||||||||||||||
| 2311 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2312 | *c = 0; | - | ||||||||||||||||||||||||
| 2313 | CHECK_VALID_STREAM(*this); executed 1 time by 1 test: return *this;Executed by:
| 0-13 | ||||||||||||||||||||||||
| 2314 | d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); | - | ||||||||||||||||||||||||
| 2315 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2316 | - | |||||||||||||||||||||||||
| 2317 | const QChar *ptr; | - | ||||||||||||||||||||||||
| 2318 | int length; | - | ||||||||||||||||||||||||
| 2319 | if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
| 3-9 | ||||||||||||||||||||||||
| 2320 | setStatus(ReadPastEnd); | - | ||||||||||||||||||||||||
| 2321 | return *this; executed 3 times by 1 test: return *this;Executed by:
| 3 | ||||||||||||||||||||||||
| 2322 | } | - | ||||||||||||||||||||||||
| 2323 | - | |||||||||||||||||||||||||
| 2324 | for (int i = 0; i < length; ++i)
| 9-14 | ||||||||||||||||||||||||
| 2325 | *c++ = ptr[i].toLatin1(); executed 14 times by 1 test: *c++ = ptr[i].toLatin1();Executed by:
| 14 | ||||||||||||||||||||||||
| 2326 | *c = '\0'; | - | ||||||||||||||||||||||||
| 2327 | d->consumeLastToken(); | - | ||||||||||||||||||||||||
| 2328 | return *this; executed 9 times by 1 test: return *this;Executed by:
| 9 | ||||||||||||||||||||||||
| 2329 | } | - | ||||||||||||||||||||||||
| 2330 | - | |||||||||||||||||||||||||
| 2331 | /*! | - | ||||||||||||||||||||||||
| 2332 | \internal | - | ||||||||||||||||||||||||
| 2333 | */ | - | ||||||||||||||||||||||||
| 2334 | void QTextStreamPrivate::putNumber(qulonglong number, bool negative) | - | ||||||||||||||||||||||||
| 2335 | { | - | ||||||||||||||||||||||||
| 2336 | QString result; | - | ||||||||||||||||||||||||
| 2337 | - | |||||||||||||||||||||||||
| 2338 | unsigned flags = 0; | - | ||||||||||||||||||||||||
| 2339 | const QTextStream::NumberFlags numberFlags = params.numberFlags; | - | ||||||||||||||||||||||||
| 2340 | if (numberFlags & QTextStream::ShowBase)
| 134-24545 | ||||||||||||||||||||||||
| 2341 | flags |= QLocaleData::ShowBase; executed 134 times by 11 tests: flags |= QLocaleData::ShowBase;Executed by:
| 134 | ||||||||||||||||||||||||
| 2342 | if (numberFlags & QTextStream::ForceSign)
| 3-24676 | ||||||||||||||||||||||||
| 2343 | flags |= QLocaleData::AlwaysShowSign; executed 3 times by 1 test: flags |= QLocaleData::AlwaysShowSign;Executed by:
| 3 | ||||||||||||||||||||||||
| 2344 | if (numberFlags & QTextStream::UppercaseBase)
| 7-24672 | ||||||||||||||||||||||||
| 2345 | flags |= QLocaleData::UppercaseBase; executed 7 times by 1 test: flags |= QLocaleData::UppercaseBase;Executed by:
| 7 | ||||||||||||||||||||||||
| 2346 | if (numberFlags & QTextStream::UppercaseDigits)
| 9-24670 | ||||||||||||||||||||||||
| 2347 | flags |= QLocaleData::CapitalEorX; executed 9 times by 1 test: flags |= QLocaleData::CapitalEorX;Executed by:
| 9 | ||||||||||||||||||||||||
| 2348 | - | |||||||||||||||||||||||||
| 2349 | // add thousands group separators. For backward compatibility we | - | ||||||||||||||||||||||||
| 2350 | // don't add a group separator for C locale. | - | ||||||||||||||||||||||||
| 2351 | if (locale != QLocale::c() && !locale.numberOptions().testFlag(QLocale::OmitGroupSeparator))
| 86-24418 | ||||||||||||||||||||||||
| 2352 | flags |= QLocaleData::ThousandsGroup; executed 175 times by 1 test: flags |= QLocaleData::ThousandsGroup;Executed by:
| 175 | ||||||||||||||||||||||||
| 2353 | - | |||||||||||||||||||||||||
| 2354 | const QLocaleData *dd = locale.d->m_data; | - | ||||||||||||||||||||||||
| 2355 | int base = params.integerBase ? params.integerBase : 10;
| 235-24444 | ||||||||||||||||||||||||
| 2356 | if (negative && base == 10) {
| 4-23338 | ||||||||||||||||||||||||
| 2357 | result = dd->longLongToString(-static_cast<qlonglong>(number), -1, | - | ||||||||||||||||||||||||
| 2358 | base, -1, flags); | - | ||||||||||||||||||||||||
| 2359 | } else if (negative) { executed 1337 times by 8 tests: end of blockExecuted by:
| 4-23338 | ||||||||||||||||||||||||
| 2360 | // Workaround for backward compatibility for writing negative | - | ||||||||||||||||||||||||
| 2361 | // numbers in octal and hex: | - | ||||||||||||||||||||||||
| 2362 | // QTextStream(result) << showbase << hex << -1 << oct << -1 | - | ||||||||||||||||||||||||
| 2363 | // should output: -0x1 -0b1 | - | ||||||||||||||||||||||||
| 2364 | result = dd->unsLongLongToString(number, -1, base, -1, flags); | - | ||||||||||||||||||||||||
| 2365 | result.prepend(locale.negativeSign()); | - | ||||||||||||||||||||||||
| 2366 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 2367 | result = dd->unsLongLongToString(number, -1, base, -1, flags); | - | ||||||||||||||||||||||||
| 2368 | // workaround for backward compatibility - in octal form with | - | ||||||||||||||||||||||||
| 2369 | // ShowBase flag set zero should be written as '00' | - | ||||||||||||||||||||||||
| 2370 | if (number == 0 && base == 8 && params.numberFlags & QTextStream::ShowBase
| 1-20588 | ||||||||||||||||||||||||
| 2371 | && result == QLatin1String("0")) {
| 0-1 | ||||||||||||||||||||||||
| 2372 | result.prepend(QLatin1Char('0')); | - | ||||||||||||||||||||||||
| 2373 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 2374 | } executed 23338 times by 47 tests: end of blockExecuted by:
| 23338 | ||||||||||||||||||||||||
| 2375 | putString(result, true); | - | ||||||||||||||||||||||||
| 2376 | } executed 24679 times by 47 tests: end of blockExecuted by:
| 24679 | ||||||||||||||||||||||||
| 2377 | - | |||||||||||||||||||||||||
| 2378 | /*! | - | ||||||||||||||||||||||||
| 2379 | Writes the character \a c to the stream, then returns a reference | - | ||||||||||||||||||||||||
| 2380 | to the QTextStream. | - | ||||||||||||||||||||||||
| 2381 | - | |||||||||||||||||||||||||
| 2382 | \sa setFieldWidth() | - | ||||||||||||||||||||||||
| 2383 | */ | - | ||||||||||||||||||||||||
| 2384 | QTextStream &QTextStream::operator<<(QChar c) | - | ||||||||||||||||||||||||
| 2385 | { | - | ||||||||||||||||||||||||
| 2386 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2387 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-26222 | ||||||||||||||||||||||||
| 2388 | d->putChar(c); | - | ||||||||||||||||||||||||
| 2389 | return *this; executed 50798 times by 15 tests: return *this;Executed by:
| 50798 | ||||||||||||||||||||||||
| 2390 | } | - | ||||||||||||||||||||||||
| 2391 | - | |||||||||||||||||||||||||
| 2392 | /*! | - | ||||||||||||||||||||||||
| 2393 | \overload | - | ||||||||||||||||||||||||
| 2394 | - | |||||||||||||||||||||||||
| 2395 | Converts \a c from ASCII to a QChar, then writes it to the stream. | - | ||||||||||||||||||||||||
| 2396 | */ | - | ||||||||||||||||||||||||
| 2397 | QTextStream &QTextStream::operator<<(char c) | - | ||||||||||||||||||||||||
| 2398 | { | - | ||||||||||||||||||||||||
| 2399 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2400 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-69444 | ||||||||||||||||||||||||
| 2401 | d->putChar(QChar::fromLatin1(c)); | - | ||||||||||||||||||||||||
| 2402 | return *this; executed 115763 times by 80 tests: return *this;Executed by:
| 115763 | ||||||||||||||||||||||||
| 2403 | } | - | ||||||||||||||||||||||||
| 2404 | - | |||||||||||||||||||||||||
| 2405 | /*! | - | ||||||||||||||||||||||||
| 2406 | Writes the integer number \a i to the stream, then returns a | - | ||||||||||||||||||||||||
| 2407 | reference to the QTextStream. By default, the number is stored in | - | ||||||||||||||||||||||||
| 2408 | decimal form, but you can also set the base by calling | - | ||||||||||||||||||||||||
| 2409 | setIntegerBase(). | - | ||||||||||||||||||||||||
| 2410 | - | |||||||||||||||||||||||||
| 2411 | \sa setFieldWidth(), setNumberFlags() | - | ||||||||||||||||||||||||
| 2412 | */ | - | ||||||||||||||||||||||||
| 2413 | QTextStream &QTextStream::operator<<(signed short i) | - | ||||||||||||||||||||||||
| 2414 | { | - | ||||||||||||||||||||||||
| 2415 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2416 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-36 | ||||||||||||||||||||||||
| 2417 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
| 2418 | return *this; executed 38 times by 3 tests: return *this;Executed by:
| 38 | ||||||||||||||||||||||||
| 2419 | } | - | ||||||||||||||||||||||||
| 2420 | - | |||||||||||||||||||||||||
| 2421 | /*! | - | ||||||||||||||||||||||||
| 2422 | \overload | - | ||||||||||||||||||||||||
| 2423 | - | |||||||||||||||||||||||||
| 2424 | Writes the unsigned short \a i to the stream. | - | ||||||||||||||||||||||||
| 2425 | */ | - | ||||||||||||||||||||||||
| 2426 | QTextStream &QTextStream::operator<<(unsigned short i) | - | ||||||||||||||||||||||||
| 2427 | { | - | ||||||||||||||||||||||||
| 2428 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2429 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-117 | ||||||||||||||||||||||||
| 2430 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
| 2431 | return *this; executed 198 times by 6 tests: return *this;Executed by:
| 198 | ||||||||||||||||||||||||
| 2432 | } | - | ||||||||||||||||||||||||
| 2433 | - | |||||||||||||||||||||||||
| 2434 | /*! | - | ||||||||||||||||||||||||
| 2435 | \overload | - | ||||||||||||||||||||||||
| 2436 | - | |||||||||||||||||||||||||
| 2437 | Writes the signed int \a i to the stream. | - | ||||||||||||||||||||||||
| 2438 | */ | - | ||||||||||||||||||||||||
| 2439 | QTextStream &QTextStream::operator<<(signed int i) | - | ||||||||||||||||||||||||
| 2440 | { | - | ||||||||||||||||||||||||
| 2441 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2442 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-14993 | ||||||||||||||||||||||||
| 2443 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
| 2444 | return *this; executed 18403 times by 39 tests: return *this;Executed by:
| 18403 | ||||||||||||||||||||||||
| 2445 | } | - | ||||||||||||||||||||||||
| 2446 | - | |||||||||||||||||||||||||
| 2447 | /*! | - | ||||||||||||||||||||||||
| 2448 | \overload | - | ||||||||||||||||||||||||
| 2449 | - | |||||||||||||||||||||||||
| 2450 | Writes the unsigned int \a i to the stream. | - | ||||||||||||||||||||||||
| 2451 | */ | - | ||||||||||||||||||||||||
| 2452 | QTextStream &QTextStream::operator<<(unsigned int i) | - | ||||||||||||||||||||||||
| 2453 | { | - | ||||||||||||||||||||||||
| 2454 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2455 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-60 | ||||||||||||||||||||||||
| 2456 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
| 2457 | return *this; executed 66 times by 4 tests: return *this;Executed by:
| 66 | ||||||||||||||||||||||||
| 2458 | } | - | ||||||||||||||||||||||||
| 2459 | - | |||||||||||||||||||||||||
| 2460 | /*! | - | ||||||||||||||||||||||||
| 2461 | \overload | - | ||||||||||||||||||||||||
| 2462 | - | |||||||||||||||||||||||||
| 2463 | Writes the signed long \a i to the stream. | - | ||||||||||||||||||||||||
| 2464 | */ | - | ||||||||||||||||||||||||
| 2465 | QTextStream &QTextStream::operator<<(signed long i) | - | ||||||||||||||||||||||||
| 2466 | { | - | ||||||||||||||||||||||||
| 2467 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2468 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-2 | ||||||||||||||||||||||||
| 2469 | d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); | - | ||||||||||||||||||||||||
| 2470 | return *this; executed 2 times by 2 tests: return *this;Executed by:
| 2 | ||||||||||||||||||||||||
| 2471 | } | - | ||||||||||||||||||||||||
| 2472 | - | |||||||||||||||||||||||||
| 2473 | /*! | - | ||||||||||||||||||||||||
| 2474 | \overload | - | ||||||||||||||||||||||||
| 2475 | - | |||||||||||||||||||||||||
| 2476 | Writes the unsigned long \a i to the stream. | - | ||||||||||||||||||||||||
| 2477 | */ | - | ||||||||||||||||||||||||
| 2478 | QTextStream &QTextStream::operator<<(unsigned long i) | - | ||||||||||||||||||||||||
| 2479 | { | - | ||||||||||||||||||||||||
| 2480 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2481 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-1 | ||||||||||||||||||||||||
| 2482 | d->putNumber((qulonglong)i, false); | - | ||||||||||||||||||||||||
| 2483 | return *this; executed 1 time by 1 test: return *this;Executed by:
| 1 | ||||||||||||||||||||||||
| 2484 | } | - | ||||||||||||||||||||||||
| 2485 | - | |||||||||||||||||||||||||
| 2486 | /*! | - | ||||||||||||||||||||||||
| 2487 | \overload | - | ||||||||||||||||||||||||
| 2488 | - | |||||||||||||||||||||||||
| 2489 | Writes the qlonglong \a i to the stream. | - | ||||||||||||||||||||||||
| 2490 | */ | - | ||||||||||||||||||||||||
| 2491 | QTextStream &QTextStream::operator<<(qlonglong i) | - | ||||||||||||||||||||||||
| 2492 | { | - | ||||||||||||||||||||||||
| 2493 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2494 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-5734 | ||||||||||||||||||||||||
| 2495 | d->putNumber((qulonglong)qAbs(i), i < 0); | - | ||||||||||||||||||||||||
| 2496 | return *this; executed 5831 times by 11 tests: return *this;Executed by:
| 5831 | ||||||||||||||||||||||||
| 2497 | } | - | ||||||||||||||||||||||||
| 2498 | - | |||||||||||||||||||||||||
| 2499 | /*! | - | ||||||||||||||||||||||||
| 2500 | \overload | - | ||||||||||||||||||||||||
| 2501 | - | |||||||||||||||||||||||||
| 2502 | Writes the qulonglong \a i to the stream. | - | ||||||||||||||||||||||||
| 2503 | */ | - | ||||||||||||||||||||||||
| 2504 | QTextStream &QTextStream::operator<<(qulonglong i) | - | ||||||||||||||||||||||||
| 2505 | { | - | ||||||||||||||||||||||||
| 2506 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2507 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-76 | ||||||||||||||||||||||||
| 2508 | d->putNumber(i, false); | - | ||||||||||||||||||||||||
| 2509 | return *this; executed 90 times by 5 tests: return *this;Executed by:
| 90 | ||||||||||||||||||||||||
| 2510 | } | - | ||||||||||||||||||||||||
| 2511 | - | |||||||||||||||||||||||||
| 2512 | /*! | - | ||||||||||||||||||||||||
| 2513 | Writes the real number \a f to the stream, then returns a | - | ||||||||||||||||||||||||
| 2514 | reference to the QTextStream. By default, QTextStream stores it | - | ||||||||||||||||||||||||
| 2515 | using SmartNotation, with up to 6 digits of precision. You can | - | ||||||||||||||||||||||||
| 2516 | change the textual representation QTextStream will use for real | - | ||||||||||||||||||||||||
| 2517 | numbers by calling setRealNumberNotation(), | - | ||||||||||||||||||||||||
| 2518 | setRealNumberPrecision() and setNumberFlags(). | - | ||||||||||||||||||||||||
| 2519 | - | |||||||||||||||||||||||||
| 2520 | \sa setFieldWidth(), setRealNumberNotation(), | - | ||||||||||||||||||||||||
| 2521 | setRealNumberPrecision(), setNumberFlags() | - | ||||||||||||||||||||||||
| 2522 | */ | - | ||||||||||||||||||||||||
| 2523 | QTextStream &QTextStream::operator<<(float f) | - | ||||||||||||||||||||||||
| 2524 | { | - | ||||||||||||||||||||||||
| 2525 | return *this << double(f); executed 54 times by 3 tests: return *this << double(f);Executed by:
| 54 | ||||||||||||||||||||||||
| 2526 | } | - | ||||||||||||||||||||||||
| 2527 | - | |||||||||||||||||||||||||
| 2528 | /*! | - | ||||||||||||||||||||||||
| 2529 | \overload | - | ||||||||||||||||||||||||
| 2530 | - | |||||||||||||||||||||||||
| 2531 | Writes the double \a f to the stream. | - | ||||||||||||||||||||||||
| 2532 | */ | - | ||||||||||||||||||||||||
| 2533 | QTextStream &QTextStream::operator<<(double f) | - | ||||||||||||||||||||||||
| 2534 | { | - | ||||||||||||||||||||||||
| 2535 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2536 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-278 | ||||||||||||||||||||||||
| 2537 | - | |||||||||||||||||||||||||
| 2538 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
| 2539 | switch (realNumberNotation()) { | - | ||||||||||||||||||||||||
| 2540 | case FixedNotation: executed 2 times by 1 test: case FixedNotation:Executed by:
| 2 | ||||||||||||||||||||||||
| 2541 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
| 2542 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 2543 | case ScientificNotation: executed 5 times by 1 test: case ScientificNotation:Executed by:
| 5 | ||||||||||||||||||||||||
| 2544 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||||||||
| 2545 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||||||||
| 2546 | case SmartNotation: executed 299 times by 9 tests: case SmartNotation:Executed by:
| 299 | ||||||||||||||||||||||||
| 2547 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||||||||
| 2548 | break; executed 299 times by 9 tests: break;Executed by:
| 299 | ||||||||||||||||||||||||
| 2549 | } | - | ||||||||||||||||||||||||
| 2550 | - | |||||||||||||||||||||||||
| 2551 | uint flags = 0; | - | ||||||||||||||||||||||||
| 2552 | if (numberFlags() & ShowBase)
| 0-306 | ||||||||||||||||||||||||
| 2553 | flags |= QLocaleData::ShowBase; never executed: flags |= QLocaleData::ShowBase; | 0 | ||||||||||||||||||||||||
| 2554 | if (numberFlags() & ForceSign)
| 4-302 | ||||||||||||||||||||||||
| 2555 | flags |= QLocaleData::AlwaysShowSign; executed 4 times by 1 test: flags |= QLocaleData::AlwaysShowSign;Executed by:
| 4 | ||||||||||||||||||||||||
| 2556 | if (numberFlags() & UppercaseBase)
| 1-305 | ||||||||||||||||||||||||
| 2557 | flags |= QLocaleData::UppercaseBase; executed 1 time by 1 test: flags |= QLocaleData::UppercaseBase;Executed by:
| 1 | ||||||||||||||||||||||||
| 2558 | if (numberFlags() & UppercaseDigits)
| 7-299 | ||||||||||||||||||||||||
| 2559 | flags |= QLocaleData::CapitalEorX; executed 7 times by 1 test: flags |= QLocaleData::CapitalEorX;Executed by:
| 7 | ||||||||||||||||||||||||
| 2560 | if (numberFlags() & ForcePoint)
| 6-300 | ||||||||||||||||||||||||
| 2561 | flags |= QLocaleData::Alternate; executed 6 times by 1 test: flags |= QLocaleData::Alternate;Executed by:
| 6 | ||||||||||||||||||||||||
| 2562 | if (locale() != QLocale::c() && !(locale().numberOptions() & QLocale::OmitGroupSeparator))
| 0-294 | ||||||||||||||||||||||||
| 2563 | flags |= QLocaleData::ThousandsGroup; executed 12 times by 1 test: flags |= QLocaleData::ThousandsGroup;Executed by:
| 12 | ||||||||||||||||||||||||
| 2564 | if (!(locale().numberOptions() & QLocale::OmitLeadingZeroInExponent))
| 0-306 | ||||||||||||||||||||||||
| 2565 | flags |= QLocaleData::ZeroPadExponent; executed 306 times by 9 tests: flags |= QLocaleData::ZeroPadExponent;Executed by:
| 306 | ||||||||||||||||||||||||
| 2566 | - | |||||||||||||||||||||||||
| 2567 | const QLocaleData *dd = d->locale.d->m_data; | - | ||||||||||||||||||||||||
| 2568 | QString num = dd->doubleToString(f, d->params.realNumberPrecision, form, -1, flags); | - | ||||||||||||||||||||||||
| 2569 | d->putString(num, true); | - | ||||||||||||||||||||||||
| 2570 | return *this; executed 306 times by 9 tests: return *this;Executed by:
| 306 | ||||||||||||||||||||||||
| 2571 | } | - | ||||||||||||||||||||||||
| 2572 | - | |||||||||||||||||||||||||
| 2573 | /*! | - | ||||||||||||||||||||||||
| 2574 | Writes the string \a string to the stream, and returns a reference | - | ||||||||||||||||||||||||
| 2575 | to the QTextStream. The string is first encoded using the assigned | - | ||||||||||||||||||||||||
| 2576 | codec (the default codec is QTextCodec::codecForLocale()) before | - | ||||||||||||||||||||||||
| 2577 | it is written to the stream. | - | ||||||||||||||||||||||||
| 2578 | - | |||||||||||||||||||||||||
| 2579 | \sa setFieldWidth(), setCodec() | - | ||||||||||||||||||||||||
| 2580 | */ | - | ||||||||||||||||||||||||
| 2581 | QTextStream &QTextStream::operator<<(const QString &string) | - | ||||||||||||||||||||||||
| 2582 | { | - | ||||||||||||||||||||||||
| 2583 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2584 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-95658 | ||||||||||||||||||||||||
| 2585 | d->putString(string); | - | ||||||||||||||||||||||||
| 2586 | return *this; executed 122669 times by 78 tests: return *this;Executed by:
| 122669 | ||||||||||||||||||||||||
| 2587 | } | - | ||||||||||||||||||||||||
| 2588 | - | |||||||||||||||||||||||||
| 2589 | /*! | - | ||||||||||||||||||||||||
| 2590 | \overload | - | ||||||||||||||||||||||||
| 2591 | - | |||||||||||||||||||||||||
| 2592 | Writes \a string to the stream, and returns a reference to the | - | ||||||||||||||||||||||||
| 2593 | QTextStream. | - | ||||||||||||||||||||||||
| 2594 | */ | - | ||||||||||||||||||||||||
| 2595 | QTextStream &QTextStream::operator<<(QLatin1String string) | - | ||||||||||||||||||||||||
| 2596 | { | - | ||||||||||||||||||||||||
| 2597 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2598 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-3 | ||||||||||||||||||||||||
| 2599 | d->putString(string); | - | ||||||||||||||||||||||||
| 2600 | return *this; executed 3 times by 1 test: return *this;Executed by:
| 3 | ||||||||||||||||||||||||
| 2601 | } | - | ||||||||||||||||||||||||
| 2602 | - | |||||||||||||||||||||||||
| 2603 | /*! | - | ||||||||||||||||||||||||
| 2604 | \since 5.6 | - | ||||||||||||||||||||||||
| 2605 | \overload | - | ||||||||||||||||||||||||
| 2606 | - | |||||||||||||||||||||||||
| 2607 | Writes \a string to the stream, and returns a reference to the | - | ||||||||||||||||||||||||
| 2608 | QTextStream. | - | ||||||||||||||||||||||||
| 2609 | */ | - | ||||||||||||||||||||||||
| 2610 | QTextStream &QTextStream::operator<<(const QStringRef &string) | - | ||||||||||||||||||||||||
| 2611 | { | - | ||||||||||||||||||||||||
| 2612 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2613 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-2 | ||||||||||||||||||||||||
| 2614 | d->putString(string.data(), string.size()); | - | ||||||||||||||||||||||||
| 2615 | return *this; executed 2 times by 1 test: return *this;Executed by:
| 2 | ||||||||||||||||||||||||
| 2616 | } | - | ||||||||||||||||||||||||
| 2617 | - | |||||||||||||||||||||||||
| 2618 | /*! | - | ||||||||||||||||||||||||
| 2619 | \overload | - | ||||||||||||||||||||||||
| 2620 | - | |||||||||||||||||||||||||
| 2621 | Writes \a array to the stream. The contents of \a array are | - | ||||||||||||||||||||||||
| 2622 | converted with QString::fromUtf8(). | - | ||||||||||||||||||||||||
| 2623 | */ | - | ||||||||||||||||||||||||
| 2624 | QTextStream &QTextStream::operator<<(const QByteArray &array) | - | ||||||||||||||||||||||||
| 2625 | { | - | ||||||||||||||||||||||||
| 2626 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2627 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-247 | ||||||||||||||||||||||||
| 2628 | d->putString(QString::fromUtf8(array.constData(), array.length())); | - | ||||||||||||||||||||||||
| 2629 | return *this; executed 441 times by 3 tests: return *this;Executed by:
| 441 | ||||||||||||||||||||||||
| 2630 | } | - | ||||||||||||||||||||||||
| 2631 | - | |||||||||||||||||||||||||
| 2632 | /*! | - | ||||||||||||||||||||||||
| 2633 | \overload | - | ||||||||||||||||||||||||
| 2634 | - | |||||||||||||||||||||||||
| 2635 | Writes the constant string pointed to by \a string to the stream. \a | - | ||||||||||||||||||||||||
| 2636 | string is assumed to be in ISO-8859-1 encoding. This operator | - | ||||||||||||||||||||||||
| 2637 | is convenient when working with constant string data. Example: | - | ||||||||||||||||||||||||
| 2638 | - | |||||||||||||||||||||||||
| 2639 | \snippet code/src_corelib_io_qtextstream.cpp 8 | - | ||||||||||||||||||||||||
| 2640 | - | |||||||||||||||||||||||||
| 2641 | Warning: QTextStream assumes that \a string points to a string of | - | ||||||||||||||||||||||||
| 2642 | text, terminated by a '\\0' character. If there is no terminating | - | ||||||||||||||||||||||||
| 2643 | '\\0' character, your application may crash. | - | ||||||||||||||||||||||||
| 2644 | */ | - | ||||||||||||||||||||||||
| 2645 | QTextStream &QTextStream::operator<<(const char *string) | - | ||||||||||||||||||||||||
| 2646 | { | - | ||||||||||||||||||||||||
| 2647 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2648 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-41996 | ||||||||||||||||||||||||
| 2649 | d->putString(QLatin1String(string)); | - | ||||||||||||||||||||||||
| 2650 | return *this; executed 60789 times by 30 tests: return *this;Executed by:
| 60789 | ||||||||||||||||||||||||
| 2651 | } | - | ||||||||||||||||||||||||
| 2652 | - | |||||||||||||||||||||||||
| 2653 | /*! | - | ||||||||||||||||||||||||
| 2654 | \overload | - | ||||||||||||||||||||||||
| 2655 | - | |||||||||||||||||||||||||
| 2656 | Writes \a ptr to the stream as a hexadecimal number with a base. | - | ||||||||||||||||||||||||
| 2657 | */ | - | ||||||||||||||||||||||||
| 2658 | - | |||||||||||||||||||||||||
| 2659 | QTextStream &QTextStream::operator<<(const void *ptr) | - | ||||||||||||||||||||||||
| 2660 | { | - | ||||||||||||||||||||||||
| 2661 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 2662 | CHECK_VALID_STREAM(*this); never executed: return *this;
| 0-50 | ||||||||||||||||||||||||
| 2663 | const int oldBase = d->params.integerBase; | - | ||||||||||||||||||||||||
| 2664 | const NumberFlags oldFlags = d->params.numberFlags; | - | ||||||||||||||||||||||||
| 2665 | d->params.integerBase = 16; | - | ||||||||||||||||||||||||
| 2666 | d->params.numberFlags |= ShowBase; | - | ||||||||||||||||||||||||
| 2667 | d->putNumber(reinterpret_cast<quintptr>(ptr), false); | - | ||||||||||||||||||||||||
| 2668 | d->params.integerBase = oldBase; | - | ||||||||||||||||||||||||
| 2669 | d->params.numberFlags = oldFlags; | - | ||||||||||||||||||||||||
| 2670 | return *this; executed 50 times by 7 tests: return *this;Executed by:
| 50 | ||||||||||||||||||||||||
| 2671 | } | - | ||||||||||||||||||||||||
| 2672 | - | |||||||||||||||||||||||||
| 2673 | /*! | - | ||||||||||||||||||||||||
| 2674 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2675 | - | |||||||||||||||||||||||||
| 2676 | Calls QTextStream::setIntegerBase(2) on \a stream and returns \a | - | ||||||||||||||||||||||||
| 2677 | stream. | - | ||||||||||||||||||||||||
| 2678 | - | |||||||||||||||||||||||||
| 2679 | \sa oct(), dec(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2680 | */ | - | ||||||||||||||||||||||||
| 2681 | QTextStream &bin(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2682 | { | - | ||||||||||||||||||||||||
| 2683 | stream.setIntegerBase(2); | - | ||||||||||||||||||||||||
| 2684 | return stream; executed 15 times by 1 test: return stream;Executed by:
| 15 | ||||||||||||||||||||||||
| 2685 | } | - | ||||||||||||||||||||||||
| 2686 | - | |||||||||||||||||||||||||
| 2687 | /*! | - | ||||||||||||||||||||||||
| 2688 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2689 | - | |||||||||||||||||||||||||
| 2690 | Calls QTextStream::setIntegerBase(8) on \a stream and returns \a | - | ||||||||||||||||||||||||
| 2691 | stream. | - | ||||||||||||||||||||||||
| 2692 | - | |||||||||||||||||||||||||
| 2693 | \sa bin(), dec(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2694 | */ | - | ||||||||||||||||||||||||
| 2695 | QTextStream &oct(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2696 | { | - | ||||||||||||||||||||||||
| 2697 | stream.setIntegerBase(8); | - | ||||||||||||||||||||||||
| 2698 | return stream; executed 3 times by 1 test: return stream;Executed by:
| 3 | ||||||||||||||||||||||||
| 2699 | } | - | ||||||||||||||||||||||||
| 2700 | - | |||||||||||||||||||||||||
| 2701 | /*! | - | ||||||||||||||||||||||||
| 2702 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2703 | - | |||||||||||||||||||||||||
| 2704 | Calls QTextStream::setIntegerBase(10) on \a stream and returns \a | - | ||||||||||||||||||||||||
| 2705 | stream. | - | ||||||||||||||||||||||||
| 2706 | - | |||||||||||||||||||||||||
| 2707 | \sa bin(), oct(), hex(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2708 | */ | - | ||||||||||||||||||||||||
| 2709 | QTextStream &dec(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2710 | { | - | ||||||||||||||||||||||||
| 2711 | stream.setIntegerBase(10); | - | ||||||||||||||||||||||||
| 2712 | return stream; executed 82 times by 2 tests: return stream;Executed by:
| 82 | ||||||||||||||||||||||||
| 2713 | } | - | ||||||||||||||||||||||||
| 2714 | - | |||||||||||||||||||||||||
| 2715 | /*! | - | ||||||||||||||||||||||||
| 2716 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2717 | - | |||||||||||||||||||||||||
| 2718 | Calls QTextStream::setIntegerBase(16) on \a stream and returns \a | - | ||||||||||||||||||||||||
| 2719 | stream. | - | ||||||||||||||||||||||||
| 2720 | - | |||||||||||||||||||||||||
| 2721 | \note The hex modifier can only be used for writing to streams. | - | ||||||||||||||||||||||||
| 2722 | \sa bin(), oct(), dec(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2723 | */ | - | ||||||||||||||||||||||||
| 2724 | QTextStream &hex(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2725 | { | - | ||||||||||||||||||||||||
| 2726 | stream.setIntegerBase(16); | - | ||||||||||||||||||||||||
| 2727 | return stream; executed 136 times by 6 tests: return stream;Executed by:
| 136 | ||||||||||||||||||||||||
| 2728 | } | - | ||||||||||||||||||||||||
| 2729 | - | |||||||||||||||||||||||||
| 2730 | /*! | - | ||||||||||||||||||||||||
| 2731 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2732 | - | |||||||||||||||||||||||||
| 2733 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
| 2734 | QTextStream::ShowBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2735 | - | |||||||||||||||||||||||||
| 2736 | \sa noshowbase(), forcesign(), forcepoint(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2737 | */ | - | ||||||||||||||||||||||||
| 2738 | QTextStream &showbase(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2739 | { | - | ||||||||||||||||||||||||
| 2740 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ShowBase); | - | ||||||||||||||||||||||||
| 2741 | return stream; executed 59 times by 4 tests: return stream;Executed by:
| 59 | ||||||||||||||||||||||||
| 2742 | } | - | ||||||||||||||||||||||||
| 2743 | - | |||||||||||||||||||||||||
| 2744 | /*! | - | ||||||||||||||||||||||||
| 2745 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2746 | - | |||||||||||||||||||||||||
| 2747 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
| 2748 | QTextStream::ForceSign) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2749 | - | |||||||||||||||||||||||||
| 2750 | \sa noforcesign(), forcepoint(), showbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2751 | */ | - | ||||||||||||||||||||||||
| 2752 | QTextStream &forcesign(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2753 | { | - | ||||||||||||||||||||||||
| 2754 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ForceSign); | - | ||||||||||||||||||||||||
| 2755 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 2756 | } | - | ||||||||||||||||||||||||
| 2757 | - | |||||||||||||||||||||||||
| 2758 | /*! | - | ||||||||||||||||||||||||
| 2759 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2760 | - | |||||||||||||||||||||||||
| 2761 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
| 2762 | QTextStream::ForcePoint) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2763 | - | |||||||||||||||||||||||||
| 2764 | \sa noforcepoint(), forcesign(), showbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2765 | */ | - | ||||||||||||||||||||||||
| 2766 | QTextStream &forcepoint(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2767 | { | - | ||||||||||||||||||||||||
| 2768 | stream.setNumberFlags(stream.numberFlags() | QTextStream::ForcePoint); | - | ||||||||||||||||||||||||
| 2769 | return stream; executed 3 times by 1 test: return stream;Executed by:
| 3 | ||||||||||||||||||||||||
| 2770 | } | - | ||||||||||||||||||||||||
| 2771 | - | |||||||||||||||||||||||||
| 2772 | /*! | - | ||||||||||||||||||||||||
| 2773 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2774 | - | |||||||||||||||||||||||||
| 2775 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
| 2776 | ~QTextStream::ShowBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2777 | - | |||||||||||||||||||||||||
| 2778 | \sa showbase(), noforcesign(), noforcepoint(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2779 | */ | - | ||||||||||||||||||||||||
| 2780 | QTextStream &noshowbase(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2781 | { | - | ||||||||||||||||||||||||
| 2782 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ShowBase); | - | ||||||||||||||||||||||||
| 2783 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 2784 | } | - | ||||||||||||||||||||||||
| 2785 | - | |||||||||||||||||||||||||
| 2786 | /*! | - | ||||||||||||||||||||||||
| 2787 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2788 | - | |||||||||||||||||||||||||
| 2789 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
| 2790 | ~QTextStream::ForceSign) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2791 | - | |||||||||||||||||||||||||
| 2792 | \sa forcesign(), noforcepoint(), noshowbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2793 | */ | - | ||||||||||||||||||||||||
| 2794 | QTextStream &noforcesign(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2795 | { | - | ||||||||||||||||||||||||
| 2796 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ForceSign); | - | ||||||||||||||||||||||||
| 2797 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
| 2798 | } | - | ||||||||||||||||||||||||
| 2799 | - | |||||||||||||||||||||||||
| 2800 | /*! | - | ||||||||||||||||||||||||
| 2801 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2802 | - | |||||||||||||||||||||||||
| 2803 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
| 2804 | ~QTextStream::ForcePoint) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2805 | - | |||||||||||||||||||||||||
| 2806 | \sa forcepoint(), noforcesign(), noshowbase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2807 | */ | - | ||||||||||||||||||||||||
| 2808 | QTextStream &noforcepoint(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2809 | { | - | ||||||||||||||||||||||||
| 2810 | stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ForcePoint); | - | ||||||||||||||||||||||||
| 2811 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
| 2812 | } | - | ||||||||||||||||||||||||
| 2813 | - | |||||||||||||||||||||||||
| 2814 | /*! | - | ||||||||||||||||||||||||
| 2815 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2816 | - | |||||||||||||||||||||||||
| 2817 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
| 2818 | QTextStream::UppercaseBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2819 | - | |||||||||||||||||||||||||
| 2820 | \sa lowercasebase(), uppercasedigits(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2821 | */ | - | ||||||||||||||||||||||||
| 2822 | QTextStream &uppercasebase(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2823 | { | - | ||||||||||||||||||||||||
| 2824 | stream.setNumberFlags(stream.numberFlags() | QTextStream::UppercaseBase); | - | ||||||||||||||||||||||||
| 2825 | return stream; executed 7 times by 1 test: return stream;Executed by:
| 7 | ||||||||||||||||||||||||
| 2826 | } | - | ||||||||||||||||||||||||
| 2827 | - | |||||||||||||||||||||||||
| 2828 | /*! | - | ||||||||||||||||||||||||
| 2829 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2830 | - | |||||||||||||||||||||||||
| 2831 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | | - | ||||||||||||||||||||||||
| 2832 | QTextStream::UppercaseDigits) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2833 | - | |||||||||||||||||||||||||
| 2834 | \sa lowercasedigits(), uppercasebase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2835 | */ | - | ||||||||||||||||||||||||
| 2836 | QTextStream &uppercasedigits(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2837 | { | - | ||||||||||||||||||||||||
| 2838 | stream.setNumberFlags(stream.numberFlags() | QTextStream::UppercaseDigits); | - | ||||||||||||||||||||||||
| 2839 | return stream; executed 10 times by 1 test: return stream;Executed by:
| 10 | ||||||||||||||||||||||||
| 2840 | } | - | ||||||||||||||||||||||||
| 2841 | - | |||||||||||||||||||||||||
| 2842 | /*! | - | ||||||||||||||||||||||||
| 2843 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2844 | - | |||||||||||||||||||||||||
| 2845 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
| 2846 | ~QTextStream::UppercaseBase) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2847 | - | |||||||||||||||||||||||||
| 2848 | \sa uppercasebase(), lowercasedigits(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2849 | */ | - | ||||||||||||||||||||||||
| 2850 | QTextStream &lowercasebase(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2851 | { | - | ||||||||||||||||||||||||
| 2852 | stream.setNumberFlags(stream.numberFlags() & ~QTextStream::UppercaseBase); | - | ||||||||||||||||||||||||
| 2853 | return stream; executed 5 times by 1 test: return stream;Executed by:
| 5 | ||||||||||||||||||||||||
| 2854 | } | - | ||||||||||||||||||||||||
| 2855 | - | |||||||||||||||||||||||||
| 2856 | /*! | - | ||||||||||||||||||||||||
| 2857 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2858 | - | |||||||||||||||||||||||||
| 2859 | Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & | - | ||||||||||||||||||||||||
| 2860 | ~QTextStream::UppercaseDigits) on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2861 | - | |||||||||||||||||||||||||
| 2862 | \sa uppercasedigits(), lowercasebase(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2863 | */ | - | ||||||||||||||||||||||||
| 2864 | QTextStream &lowercasedigits(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2865 | { | - | ||||||||||||||||||||||||
| 2866 | stream.setNumberFlags(stream.numberFlags() & ~QTextStream::UppercaseDigits); | - | ||||||||||||||||||||||||
| 2867 | return stream; executed 3 times by 1 test: return stream;Executed by:
| 3 | ||||||||||||||||||||||||
| 2868 | } | - | ||||||||||||||||||||||||
| 2869 | - | |||||||||||||||||||||||||
| 2870 | /*! | - | ||||||||||||||||||||||||
| 2871 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2872 | - | |||||||||||||||||||||||||
| 2873 | Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) | - | ||||||||||||||||||||||||
| 2874 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2875 | - | |||||||||||||||||||||||||
| 2876 | \sa scientific(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2877 | */ | - | ||||||||||||||||||||||||
| 2878 | QTextStream &fixed(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2879 | { | - | ||||||||||||||||||||||||
| 2880 | stream.setRealNumberNotation(QTextStream::FixedNotation); | - | ||||||||||||||||||||||||
| 2881 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 2882 | } | - | ||||||||||||||||||||||||
| 2883 | - | |||||||||||||||||||||||||
| 2884 | /*! | - | ||||||||||||||||||||||||
| 2885 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2886 | - | |||||||||||||||||||||||||
| 2887 | Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) | - | ||||||||||||||||||||||||
| 2888 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2889 | - | |||||||||||||||||||||||||
| 2890 | \sa fixed(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2891 | */ | - | ||||||||||||||||||||||||
| 2892 | QTextStream &scientific(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2893 | { | - | ||||||||||||||||||||||||
| 2894 | stream.setRealNumberNotation(QTextStream::ScientificNotation); | - | ||||||||||||||||||||||||
| 2895 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 2896 | } | - | ||||||||||||||||||||||||
| 2897 | - | |||||||||||||||||||||||||
| 2898 | /*! | - | ||||||||||||||||||||||||
| 2899 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2900 | - | |||||||||||||||||||||||||
| 2901 | Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) | - | ||||||||||||||||||||||||
| 2902 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2903 | - | |||||||||||||||||||||||||
| 2904 | \sa {QTextStream::}{right()}, {QTextStream::}{center()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2905 | */ | - | ||||||||||||||||||||||||
| 2906 | QTextStream &left(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2907 | { | - | ||||||||||||||||||||||||
| 2908 | stream.setFieldAlignment(QTextStream::AlignLeft); | - | ||||||||||||||||||||||||
| 2909 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
| 2910 | } | - | ||||||||||||||||||||||||
| 2911 | - | |||||||||||||||||||||||||
| 2912 | /*! | - | ||||||||||||||||||||||||
| 2913 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2914 | - | |||||||||||||||||||||||||
| 2915 | Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) | - | ||||||||||||||||||||||||
| 2916 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2917 | - | |||||||||||||||||||||||||
| 2918 | \sa {QTextStream::}{left()}, {QTextStream::}{center()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2919 | */ | - | ||||||||||||||||||||||||
| 2920 | QTextStream &right(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2921 | { | - | ||||||||||||||||||||||||
| 2922 | stream.setFieldAlignment(QTextStream::AlignRight); | - | ||||||||||||||||||||||||
| 2923 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 2924 | } | - | ||||||||||||||||||||||||
| 2925 | - | |||||||||||||||||||||||||
| 2926 | /*! | - | ||||||||||||||||||||||||
| 2927 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2928 | - | |||||||||||||||||||||||||
| 2929 | Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) | - | ||||||||||||||||||||||||
| 2930 | on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2931 | - | |||||||||||||||||||||||||
| 2932 | \sa {QTextStream::}{left()}, {QTextStream::}{right()}, {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2933 | */ | - | ||||||||||||||||||||||||
| 2934 | QTextStream ¢er(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2935 | { | - | ||||||||||||||||||||||||
| 2936 | stream.setFieldAlignment(QTextStream::AlignCenter); | - | ||||||||||||||||||||||||
| 2937 | return stream; never executed: return stream; | 0 | ||||||||||||||||||||||||
| 2938 | } | - | ||||||||||||||||||||||||
| 2939 | - | |||||||||||||||||||||||||
| 2940 | /*! | - | ||||||||||||||||||||||||
| 2941 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2942 | - | |||||||||||||||||||||||||
| 2943 | Writes '\\n' to the \a stream and flushes the stream. | - | ||||||||||||||||||||||||
| 2944 | - | |||||||||||||||||||||||||
| 2945 | Equivalent to | - | ||||||||||||||||||||||||
| 2946 | - | |||||||||||||||||||||||||
| 2947 | \snippet code/src_corelib_io_qtextstream.cpp 9 | - | ||||||||||||||||||||||||
| 2948 | - | |||||||||||||||||||||||||
| 2949 | Note: On Windows, all '\\n' characters are written as '\\r\\n' if | - | ||||||||||||||||||||||||
| 2950 | QTextStream's device or string is opened using the QIODevice::Text flag. | - | ||||||||||||||||||||||||
| 2951 | - | |||||||||||||||||||||||||
| 2952 | \sa flush(), reset(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2953 | */ | - | ||||||||||||||||||||||||
| 2954 | QTextStream &endl(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2955 | { | - | ||||||||||||||||||||||||
| 2956 | return stream << QLatin1Char('\n') << flush; executed 50771 times by 14 tests: return stream << QLatin1Char('\n') << flush;Executed by:
| 50771 | ||||||||||||||||||||||||
| 2957 | } | - | ||||||||||||||||||||||||
| 2958 | - | |||||||||||||||||||||||||
| 2959 | /*! | - | ||||||||||||||||||||||||
| 2960 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2961 | - | |||||||||||||||||||||||||
| 2962 | Calls QTextStream::flush() on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2963 | - | |||||||||||||||||||||||||
| 2964 | \sa endl(), reset(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2965 | */ | - | ||||||||||||||||||||||||
| 2966 | QTextStream &flush(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2967 | { | - | ||||||||||||||||||||||||
| 2968 | stream.flush(); | - | ||||||||||||||||||||||||
| 2969 | return stream; executed 50774 times by 15 tests: return stream;Executed by:
| 50774 | ||||||||||||||||||||||||
| 2970 | } | - | ||||||||||||||||||||||||
| 2971 | - | |||||||||||||||||||||||||
| 2972 | /*! | - | ||||||||||||||||||||||||
| 2973 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2974 | - | |||||||||||||||||||||||||
| 2975 | Calls QTextStream::reset() on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2976 | - | |||||||||||||||||||||||||
| 2977 | \sa flush(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2978 | */ | - | ||||||||||||||||||||||||
| 2979 | QTextStream &reset(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2980 | { | - | ||||||||||||||||||||||||
| 2981 | stream.reset(); | - | ||||||||||||||||||||||||
| 2982 | return stream; executed 3 times by 2 tests: return stream;Executed by:
| 3 | ||||||||||||||||||||||||
| 2983 | } | - | ||||||||||||||||||||||||
| 2984 | - | |||||||||||||||||||||||||
| 2985 | /*! | - | ||||||||||||||||||||||||
| 2986 | \relates QTextStream | - | ||||||||||||||||||||||||
| 2987 | - | |||||||||||||||||||||||||
| 2988 | Calls \l {QTextStream::}{skipWhiteSpace()} on \a stream and returns \a stream. | - | ||||||||||||||||||||||||
| 2989 | - | |||||||||||||||||||||||||
| 2990 | \sa {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 2991 | */ | - | ||||||||||||||||||||||||
| 2992 | QTextStream &ws(QTextStream &stream) | - | ||||||||||||||||||||||||
| 2993 | { | - | ||||||||||||||||||||||||
| 2994 | stream.skipWhiteSpace(); | - | ||||||||||||||||||||||||
| 2995 | return stream; executed 3 times by 1 test: return stream;Executed by:
| 3 | ||||||||||||||||||||||||
| 2996 | } | - | ||||||||||||||||||||||||
| 2997 | - | |||||||||||||||||||||||||
| 2998 | /*! | - | ||||||||||||||||||||||||
| 2999 | \fn QTextStreamManipulator qSetFieldWidth(int width) | - | ||||||||||||||||||||||||
| 3000 | \relates QTextStream | - | ||||||||||||||||||||||||
| 3001 | - | |||||||||||||||||||||||||
| 3002 | Equivalent to QTextStream::setFieldWidth(\a width). | - | ||||||||||||||||||||||||
| 3003 | */ | - | ||||||||||||||||||||||||
| 3004 | - | |||||||||||||||||||||||||
| 3005 | /*! | - | ||||||||||||||||||||||||
| 3006 | \fn QTextStreamManipulator qSetPadChar(QChar ch) | - | ||||||||||||||||||||||||
| 3007 | \relates QTextStream | - | ||||||||||||||||||||||||
| 3008 | - | |||||||||||||||||||||||||
| 3009 | Equivalent to QTextStream::setPadChar(\a ch). | - | ||||||||||||||||||||||||
| 3010 | */ | - | ||||||||||||||||||||||||
| 3011 | - | |||||||||||||||||||||||||
| 3012 | /*! | - | ||||||||||||||||||||||||
| 3013 | \fn QTextStreamManipulator qSetRealNumberPrecision(int precision) | - | ||||||||||||||||||||||||
| 3014 | \relates QTextStream | - | ||||||||||||||||||||||||
| 3015 | - | |||||||||||||||||||||||||
| 3016 | Equivalent to QTextStream::setRealNumberPrecision(\a precision). | - | ||||||||||||||||||||||||
| 3017 | */ | - | ||||||||||||||||||||||||
| 3018 | - | |||||||||||||||||||||||||
| 3019 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||
| 3020 | /*! | - | ||||||||||||||||||||||||
| 3021 | \relates QTextStream | - | ||||||||||||||||||||||||
| 3022 | - | |||||||||||||||||||||||||
| 3023 | Toggles insertion of the Byte Order Mark on \a stream when QTextStream is | - | ||||||||||||||||||||||||
| 3024 | used with a UTF codec. | - | ||||||||||||||||||||||||
| 3025 | - | |||||||||||||||||||||||||
| 3026 | \sa QTextStream::setGenerateByteOrderMark(), {QTextStream manipulators} | - | ||||||||||||||||||||||||
| 3027 | */ | - | ||||||||||||||||||||||||
| 3028 | QTextStream &bom(QTextStream &stream) | - | ||||||||||||||||||||||||
| 3029 | { | - | ||||||||||||||||||||||||
| 3030 | stream.setGenerateByteOrderMark(true); | - | ||||||||||||||||||||||||
| 3031 | return stream; executed 1 time by 1 test: return stream;Executed by:
| 1 | ||||||||||||||||||||||||
| 3032 | } | - | ||||||||||||||||||||||||
| 3033 | - | |||||||||||||||||||||||||
| 3034 | /*! | - | ||||||||||||||||||||||||
| 3035 | Sets the codec for this stream to \a codec. The codec is used for | - | ||||||||||||||||||||||||
| 3036 | decoding any data that is read from the assigned device, and for | - | ||||||||||||||||||||||||
| 3037 | encoding any data that is written. By default, | - | ||||||||||||||||||||||||
| 3038 | QTextCodec::codecForLocale() is used, and automatic unicode | - | ||||||||||||||||||||||||
| 3039 | detection is enabled. | - | ||||||||||||||||||||||||
| 3040 | - | |||||||||||||||||||||||||
| 3041 | If QTextStream operates on a string, this function does nothing. | - | ||||||||||||||||||||||||
| 3042 | - | |||||||||||||||||||||||||
| 3043 | \warning If you call this function while the text stream is reading | - | ||||||||||||||||||||||||
| 3044 | from an open sequential socket, the internal buffer may still contain | - | ||||||||||||||||||||||||
| 3045 | text decoded using the old codec. | - | ||||||||||||||||||||||||
| 3046 | - | |||||||||||||||||||||||||
| 3047 | \sa codec(), setAutoDetectUnicode(), setLocale() | - | ||||||||||||||||||||||||
| 3048 | */ | - | ||||||||||||||||||||||||
| 3049 | void QTextStream::setCodec(QTextCodec *codec) | - | ||||||||||||||||||||||||
| 3050 | { | - | ||||||||||||||||||||||||
| 3051 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 3052 | qint64 seekPos = -1; | - | ||||||||||||||||||||||||
| 3053 | if (!d->readBuffer.isEmpty()) {
| 1-2129 | ||||||||||||||||||||||||
| 3054 | if (!d->device->isSequential()) {
| 0-1 | ||||||||||||||||||||||||
| 3055 | seekPos = pos(); | - | ||||||||||||||||||||||||
| 3056 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 3057 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 3058 | d->codec = codec; | - | ||||||||||||||||||||||||
| 3059 | if (seekPos >=0 && !d->readBuffer.isEmpty())
| 0-2129 | ||||||||||||||||||||||||
| 3060 | seek(seekPos); executed 1 time by 1 test: seek(seekPos);Executed by:
| 1 | ||||||||||||||||||||||||
| 3061 | } executed 2130 times by 6 tests: end of blockExecuted by:
| 2130 | ||||||||||||||||||||||||
| 3062 | - | |||||||||||||||||||||||||
| 3063 | /*! | - | ||||||||||||||||||||||||
| 3064 | Sets the codec for this stream to the QTextCodec for the encoding | - | ||||||||||||||||||||||||
| 3065 | specified by \a codecName. Common values for \c codecName include | - | ||||||||||||||||||||||||
| 3066 | "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't | - | ||||||||||||||||||||||||
| 3067 | recognized, nothing happens. | - | ||||||||||||||||||||||||
| 3068 | - | |||||||||||||||||||||||||
| 3069 | Example: | - | ||||||||||||||||||||||||
| 3070 | - | |||||||||||||||||||||||||
| 3071 | \snippet code/src_corelib_io_qtextstream.cpp 10 | - | ||||||||||||||||||||||||
| 3072 | - | |||||||||||||||||||||||||
| 3073 | \sa QTextCodec::codecForName(), setLocale() | - | ||||||||||||||||||||||||
| 3074 | */ | - | ||||||||||||||||||||||||
| 3075 | void QTextStream::setCodec(const char *codecName) | - | ||||||||||||||||||||||||
| 3076 | { | - | ||||||||||||||||||||||||
| 3077 | QTextCodec *codec = QTextCodec::codecForName(codecName); | - | ||||||||||||||||||||||||
| 3078 | if (codec)
| 0-1941 | ||||||||||||||||||||||||
| 3079 | setCodec(codec); executed 1941 times by 4 tests: setCodec(codec);Executed by:
| 1941 | ||||||||||||||||||||||||
| 3080 | } executed 1941 times by 4 tests: end of blockExecuted by:
| 1941 | ||||||||||||||||||||||||
| 3081 | - | |||||||||||||||||||||||||
| 3082 | /*! | - | ||||||||||||||||||||||||
| 3083 | Returns the codec that is current assigned to the stream. | - | ||||||||||||||||||||||||
| 3084 | - | |||||||||||||||||||||||||
| 3085 | \sa setCodec(), setAutoDetectUnicode(), locale() | - | ||||||||||||||||||||||||
| 3086 | */ | - | ||||||||||||||||||||||||
| 3087 | QTextCodec *QTextStream::codec() const | - | ||||||||||||||||||||||||
| 3088 | { | - | ||||||||||||||||||||||||
| 3089 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 3090 | return d->codec; executed 401 times by 3 tests: return d->codec;Executed by:
| 401 | ||||||||||||||||||||||||
| 3091 | } | - | ||||||||||||||||||||||||
| 3092 | - | |||||||||||||||||||||||||
| 3093 | /*! | - | ||||||||||||||||||||||||
| 3094 | If \a enabled is true, QTextStream will attempt to detect Unicode | - | ||||||||||||||||||||||||
| 3095 | encoding by peeking into the stream data to see if it can find the | - | ||||||||||||||||||||||||
| 3096 | UTF-16 or UTF-32 BOM (Byte Order Mark). If this mark is found, QTextStream | - | ||||||||||||||||||||||||
| 3097 | will replace the current codec with the UTF codec. | - | ||||||||||||||||||||||||
| 3098 | - | |||||||||||||||||||||||||
| 3099 | This function can be used together with setCodec(). It is common | - | ||||||||||||||||||||||||
| 3100 | to set the codec to UTF-8, and then enable UTF-16 detection. | - | ||||||||||||||||||||||||
| 3101 | - | |||||||||||||||||||||||||
| 3102 | \sa autoDetectUnicode(), setCodec() | - | ||||||||||||||||||||||||
| 3103 | */ | - | ||||||||||||||||||||||||
| 3104 | void QTextStream::setAutoDetectUnicode(bool enabled) | - | ||||||||||||||||||||||||
| 3105 | { | - | ||||||||||||||||||||||||
| 3106 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 3107 | d->autoDetectUnicode = enabled; | - | ||||||||||||||||||||||||
| 3108 | } executed 55 times by 1 test: end of blockExecuted by:
| 55 | ||||||||||||||||||||||||
| 3109 | - | |||||||||||||||||||||||||
| 3110 | /*! | - | ||||||||||||||||||||||||
| 3111 | Returns \c true if automatic Unicode detection is enabled, otherwise | - | ||||||||||||||||||||||||
| 3112 | returns \c false. Automatic Unicode detection is enabled by default. | - | ||||||||||||||||||||||||
| 3113 | - | |||||||||||||||||||||||||
| 3114 | \sa setAutoDetectUnicode(), setCodec() | - | ||||||||||||||||||||||||
| 3115 | */ | - | ||||||||||||||||||||||||
| 3116 | bool QTextStream::autoDetectUnicode() const | - | ||||||||||||||||||||||||
| 3117 | { | - | ||||||||||||||||||||||||
| 3118 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 3119 | return d->autoDetectUnicode; executed 2 times by 1 test: return d->autoDetectUnicode;Executed by:
| 2 | ||||||||||||||||||||||||
| 3120 | } | - | ||||||||||||||||||||||||
| 3121 | - | |||||||||||||||||||||||||
| 3122 | /*! | - | ||||||||||||||||||||||||
| 3123 | If \a generate is true and a UTF codec is used, QTextStream will insert | - | ||||||||||||||||||||||||
| 3124 | the BOM (Byte Order Mark) before any data has been written to the | - | ||||||||||||||||||||||||
| 3125 | device. If \a generate is false, no BOM will be inserted. This function | - | ||||||||||||||||||||||||
| 3126 | must be called before any data is written. Otherwise, it does nothing. | - | ||||||||||||||||||||||||
| 3127 | - | |||||||||||||||||||||||||
| 3128 | \sa generateByteOrderMark(), bom() | - | ||||||||||||||||||||||||
| 3129 | */ | - | ||||||||||||||||||||||||
| 3130 | void QTextStream::setGenerateByteOrderMark(bool generate) | - | ||||||||||||||||||||||||
| 3131 | { | - | ||||||||||||||||||||||||
| 3132 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 3133 | if (d->writeBuffer.isEmpty()) {
| 0-3 | ||||||||||||||||||||||||
| 3134 | d->writeConverterState.flags.setFlag(QTextCodec::IgnoreHeader, !generate); | - | ||||||||||||||||||||||||
| 3135 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 3136 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 3137 | - | |||||||||||||||||||||||||
| 3138 | /*! | - | ||||||||||||||||||||||||
| 3139 | Returns \c true if QTextStream is set to generate the UTF BOM (Byte Order | - | ||||||||||||||||||||||||
| 3140 | Mark) when using a UTF codec; otherwise returns \c false. UTF BOM generation is | - | ||||||||||||||||||||||||
| 3141 | set to false by default. | - | ||||||||||||||||||||||||
| 3142 | - | |||||||||||||||||||||||||
| 3143 | \sa setGenerateByteOrderMark() | - | ||||||||||||||||||||||||
| 3144 | */ | - | ||||||||||||||||||||||||
| 3145 | bool QTextStream::generateByteOrderMark() const | - | ||||||||||||||||||||||||
| 3146 | { | - | ||||||||||||||||||||||||
| 3147 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 3148 | return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0; executed 2 times by 1 test: return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0;Executed by:
| 2 | ||||||||||||||||||||||||
| 3149 | } | - | ||||||||||||||||||||||||
| 3150 | - | |||||||||||||||||||||||||
| 3151 | #endif | - | ||||||||||||||||||||||||
| 3152 | - | |||||||||||||||||||||||||
| 3153 | /*! | - | ||||||||||||||||||||||||
| 3154 | \since 4.5 | - | ||||||||||||||||||||||||
| 3155 | - | |||||||||||||||||||||||||
| 3156 | Sets the locale for this stream to \a locale. The specified locale is | - | ||||||||||||||||||||||||
| 3157 | used for conversions between numbers and their string representations. | - | ||||||||||||||||||||||||
| 3158 | - | |||||||||||||||||||||||||
| 3159 | The default locale is C and it is a special case - the thousands | - | ||||||||||||||||||||||||
| 3160 | group separator is not used for backward compatibility reasons. | - | ||||||||||||||||||||||||
| 3161 | - | |||||||||||||||||||||||||
| 3162 | \sa locale() | - | ||||||||||||||||||||||||
| 3163 | */ | - | ||||||||||||||||||||||||
| 3164 | void QTextStream::setLocale(const QLocale &locale) | - | ||||||||||||||||||||||||
| 3165 | { | - | ||||||||||||||||||||||||
| 3166 | Q_D(QTextStream); | - | ||||||||||||||||||||||||
| 3167 | d->locale = locale; | - | ||||||||||||||||||||||||
| 3168 | } executed 384 times by 1 test: end of blockExecuted by:
| 384 | ||||||||||||||||||||||||
| 3169 | - | |||||||||||||||||||||||||
| 3170 | /*! | - | ||||||||||||||||||||||||
| 3171 | \since 4.5 | - | ||||||||||||||||||||||||
| 3172 | - | |||||||||||||||||||||||||
| 3173 | Returns the locale for this stream. The default locale is C. | - | ||||||||||||||||||||||||
| 3174 | - | |||||||||||||||||||||||||
| 3175 | \sa setLocale() | - | ||||||||||||||||||||||||
| 3176 | */ | - | ||||||||||||||||||||||||
| 3177 | QLocale QTextStream::locale() const | - | ||||||||||||||||||||||||
| 3178 | { | - | ||||||||||||||||||||||||
| 3179 | Q_D(const QTextStream); | - | ||||||||||||||||||||||||
| 3180 | return d->locale; executed 624 times by 9 tests: return d->locale;Executed by:
| 624 | ||||||||||||||||||||||||
| 3181 | } | - | ||||||||||||||||||||||||
| 3182 | - | |||||||||||||||||||||||||
| 3183 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 3184 | - | |||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |