summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp95
1 files changed, 77 insertions, 18 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 00d15fd518..2efe3c1a86 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2014 Intel Corporation.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -39,6 +45,7 @@
#include "qlist.h"
#include "qlocale.h"
#include "qlocale_p.h"
+#include "qlocale_tools_p.h"
#include "qstringalgorithms_p.h"
#include "qscopedpointer.h"
#include "qbytearray_p.h"
@@ -1713,6 +1720,14 @@ QByteArray &QByteArray::prepend(const char *str, int len)
return *this;
}
+/*! \fn QByteArray &QByteArray::prepend(int count, char ch)
+
+ \overload
+ \since 5.7
+
+ Prepends \a count copies of character \a ch to this byte array.
+*/
+
/*!
\overload
@@ -1825,6 +1840,17 @@ QByteArray &QByteArray::append(const char *str, int len)
return *this;
}
+/*! \fn QByteArray &QByteArray::append(int count, char ch)
+
+ \overload
+ \since 5.7
+
+ Appends \a count copies of character \a ch to this byte
+ array and returns a reference to this byte array.
+
+ If \a count is negative or zero nothing is appended to the byte array.
+*/
+
/*!
\overload
@@ -1941,6 +1967,33 @@ QByteArray &QByteArray::insert(int i, char ch)
return qbytearray_insert(this, i, &ch, 1);
}
+/*! \fn QByteArray &QByteArray::insert(int i, int count, char ch)
+
+ \overload
+ \since 5.7
+
+ Inserts \a count copies of character \a ch at index position \a i in the
+ byte array.
+
+ If \a i is greater than size(), the array is first extended using resize().
+*/
+
+QByteArray &QByteArray::insert(int i, int count, char ch)
+{
+ if (i < 0 || count <= 0)
+ return *this;
+
+ int oldsize = size();
+ resize(qMax(i, oldsize) + count);
+ char *dst = d->data();
+ if (i > oldsize)
+ ::memset(dst + oldsize, 0x20, i - oldsize);
+ else if (i < oldsize)
+ ::memmove(dst + i + count, dst + i, oldsize - i);
+ ::memset(dst + i, ch, count);
+ return *this;
+}
+
/*!
Removes \a len bytes from the array, starting at index position \a
pos, and returns a reference to the array.
@@ -3648,7 +3701,13 @@ ushort QByteArray::toUShort(bool *ok, int base) const
double QByteArray::toDouble(bool *ok) const
{
- return QLocaleData::bytearrayToDouble(nulTerminated().constData(), ok);
+ QByteArray nulled = nulTerminated();
+ bool nonNullOk = false;
+ int processed = 0;
+ double d = asciiToDouble(nulled.constData(), nulled.length(), nonNullOk, processed);
+ if (ok)
+ *ok = nonNullOk;
+ return d;
}
/*!
@@ -3877,10 +3936,10 @@ QByteArray &QByteArray::setNum(qulonglong n, int base)
QByteArray &QByteArray::setNum(double n, char f, int prec)
{
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
- uint flags = 0;
+ uint flags = QLocaleData::ZeroPadExponent;
if (qIsUpper(f))
- flags = QLocaleData::CapitalEorX;
+ flags |= QLocaleData::CapitalEorX;
f = qToLower(f);
switch (f) {