diff options
Diffstat (limited to 'src/corelib/serialization/qtextstream.cpp')
-rw-r--r-- | src/corelib/serialization/qtextstream.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index 5b0ab7fb47..e9d650b3e2 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -14,6 +14,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; \ingroup io \ingroup string-processing + \ingroup qtserialization \reentrant QTextStream can operate on a QIODevice, a QByteArray or a @@ -195,6 +196,8 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; #include "qnumeric.h" #include "qvarlengtharray.h" #include <private/qdebug_p.h> +#include <private/qnumeric_p.h> +#include <private/qtools_p.h> #include <locale.h> #include "private/qlocale_p.h" @@ -244,6 +247,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; +using namespace QtMiscUtils; //------------------------------------------------------------------- @@ -356,6 +360,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) if (bytesRead <= 0) return false; +#ifndef QT_BOOTSTRAPPED if (autoDetectUnicode) { autoDetectUnicode = false; @@ -370,6 +375,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) #if defined (QTEXTSTREAM_DEBUG) qDebug("QTextStreamPrivate::fillReadBuffer(), using %s encoding", QStringConverter::nameForEncoding(encoding)); #endif +#endif #if defined (QTEXTSTREAM_DEBUG) qDebug("QTextStreamPrivate::fillReadBuffer(), device->read(\"%s\", %d) == %d", @@ -996,7 +1002,10 @@ QTextStream::QTextStream(FILE *fileHandle, OpenMode openMode) fileHandle, int(openMode)); #endif QFile *file = new QFile; - file->open(fileHandle, openMode); + // Discarding the return value of open; even if it failed + // (and the file is not open), QTextStream still reports `Ok` + // for closed QIODevices, so there's nothing really to do here. + (void)file->open(fileHandle, openMode); Q_D(QTextStream); d->device = file; @@ -1399,7 +1408,8 @@ QTextStream::RealNumberNotation QTextStream::realNumberNotation() const /*! Sets the precision of real numbers to \a precision. This value describes the number of fraction digits QTextStream should - write when generating real numbers. + write when generating real numbers (FixedNotation, ScientificNotation), or + the maximum number of significant digits (SmartNotation). The precision cannot be a negative value. The default value is 6. @@ -1418,7 +1428,9 @@ void QTextStream::setRealNumberPrecision(int precision) /*! Returns the current real number precision, or the number of fraction - digits QTextStream will write when generating real numbers. + digits QTextStream will write when generating real numbers + (FixedNotation, ScientificNotation), or the maximum number of significant + digits (SmartNotation). \sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase() */ @@ -1682,7 +1694,7 @@ QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong int ndigits = 0; while (getChar(&dig)) { int n = dig.toLower().unicode(); - if (n >= '0' && n <= '7') { + if (isOctalDigit(n)) { val *= 8; val += n - '0'; } else { @@ -1746,13 +1758,10 @@ QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong // Parse digits int ndigits = 0; while (getChar(&dig)) { - int n = dig.toLower().unicode(); - if (n >= '0' && n <= '9') { - val <<= 4; - val += n - '0'; - } else if (n >= 'a' && n <= 'f') { + const int h = fromHex(dig.unicode()); + if (h != -1) { val <<= 4; - val += 10 + (n - 'a'); + val += h; } else { ungetChar(dig); break; @@ -1908,13 +1917,13 @@ bool QTextStreamPrivate::getReal(double *f) // nan/+inf/-inf, so here we also check for uppercase and mixed // case versions. if (!qstricmp(buf, "nan") || !qstricmp(buf, "+nan") || !qstricmp(buf, "-nan")) { - *f = qQNaN(); + *f = qt_qnan(); return true; } else if (!qstricmp(buf, "+inf") || !qstricmp(buf, "inf")) { - *f = qInf(); + *f = qt_inf(); return true; } else if (!qstricmp(buf, "-inf")) { - *f = -qInf(); + *f = -qt_inf(); return true; } bool ok; @@ -1946,7 +1955,7 @@ QTextStream &QTextStream::operator>>(QChar &c) \overload Reads a character from the stream and stores it in \a c. The - character from the stream is converted to ISO-5589-1 before it is + character from the stream is converted to ISO-8859-1 before it is stored. \sa QChar::toLatin1() @@ -2497,7 +2506,7 @@ QTextStream &QTextStream::operator<<(const QByteArray &array) { Q_D(QTextStream); CHECK_VALID_STREAM(*this); - d->putString(QString::fromUtf8(array.constData(), array.length())); + d->putString(QString::fromUtf8(array.constData(), array.size())); return *this; } @@ -2941,7 +2950,7 @@ void QTextStream::setEncoding(QStringConverter::Encoding encoding) d->encoding = encoding; d->toUtf16 = QStringDecoder(d->encoding); - bool generateBOM = d->hasWrittenData && d->generateBOM; + bool generateBOM = !d->hasWrittenData && d->generateBOM; d->fromUtf16 = QStringEncoder(d->encoding, generateBOM ? QStringEncoder::Flag::WriteBom : QStringEncoder::Flag::Default); |