Change QString::toIntegral_helper to use QStringView
This implicitly makes it use qsizetype for the length. Change-Id: Ib39a5a8dd71e48b45179079f7c7fe5e4edbdb5eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f315f42dfd
commit
f1cbc3c9d2
@ -6656,10 +6656,10 @@ QString QString::vasprintf(const char *cformat, va_list ap)
|
||||
|
||||
qint64 QString::toLongLong(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<qlonglong>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<qlonglong>(*this, ok, base);
|
||||
}
|
||||
|
||||
qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int base)
|
||||
qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
@ -6668,7 +6668,7 @@ qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int b
|
||||
}
|
||||
#endif
|
||||
|
||||
return QLocaleData::c()->stringToLongLong(QStringView(data, len), base, ok, QLocale::RejectGroupSeparator);
|
||||
return QLocaleData::c()->stringToLongLong(string, base, ok, QLocale::RejectGroupSeparator);
|
||||
}
|
||||
|
||||
|
||||
@ -6698,10 +6698,10 @@ qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int b
|
||||
|
||||
quint64 QString::toULongLong(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<qulonglong>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<qulonglong>(*this, ok, base);
|
||||
}
|
||||
|
||||
qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int base)
|
||||
qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
@ -6710,8 +6710,7 @@ qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int
|
||||
}
|
||||
#endif
|
||||
|
||||
return QLocaleData::c()->stringToUnsLongLong(QStringView(data, len), base, ok,
|
||||
QLocale::RejectGroupSeparator);
|
||||
return QLocaleData::c()->stringToUnsLongLong(string, base, ok, QLocale::RejectGroupSeparator);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -6742,7 +6741,7 @@ qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int
|
||||
|
||||
long QString::toLong(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<long>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<long>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -6773,7 +6772,7 @@ long QString::toLong(bool *ok, int base) const
|
||||
|
||||
ulong QString::toULong(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<ulong>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<ulong>(*this, ok, base);
|
||||
}
|
||||
|
||||
|
||||
@ -6803,7 +6802,7 @@ ulong QString::toULong(bool *ok, int base) const
|
||||
|
||||
int QString::toInt(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<int>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<int>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -6832,7 +6831,7 @@ int QString::toInt(bool *ok, int base) const
|
||||
|
||||
uint QString::toUInt(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<uint>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<uint>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -6861,7 +6860,7 @@ uint QString::toUInt(bool *ok, int base) const
|
||||
|
||||
short QString::toShort(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<short>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<short>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -6890,7 +6889,7 @@ short QString::toShort(bool *ok, int base) const
|
||||
|
||||
ushort QString::toUShort(bool *ok, int base) const
|
||||
{
|
||||
return toIntegral_helper<ushort>(constData(), size(), ok, base);
|
||||
return toIntegral_helper<ushort>(*this, ok, base);
|
||||
}
|
||||
|
||||
|
||||
@ -11805,7 +11804,7 @@ QStringRef QStringRef::trimmed() const
|
||||
|
||||
qint64 QStringRef::toLongLong(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<qint64>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<qint64>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11830,7 +11829,7 @@ qint64 QStringRef::toLongLong(bool *ok, int base) const
|
||||
|
||||
quint64 QStringRef::toULongLong(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<quint64>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<quint64>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11857,7 +11856,7 @@ quint64 QStringRef::toULongLong(bool *ok, int base) const
|
||||
|
||||
long QStringRef::toLong(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<long>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<long>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11884,7 +11883,7 @@ long QStringRef::toLong(bool *ok, int base) const
|
||||
|
||||
ulong QStringRef::toULong(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<ulong>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<ulong>(*this, ok, base);
|
||||
}
|
||||
|
||||
|
||||
@ -11910,7 +11909,7 @@ ulong QStringRef::toULong(bool *ok, int base) const
|
||||
|
||||
int QStringRef::toInt(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<int>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<int>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11935,7 +11934,7 @@ int QStringRef::toInt(bool *ok, int base) const
|
||||
|
||||
uint QStringRef::toUInt(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<uint>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<uint>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11960,7 +11959,7 @@ uint QStringRef::toUInt(bool *ok, int base) const
|
||||
|
||||
short QStringRef::toShort(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<short>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<short>(*this, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -11985,7 +11984,7 @@ short QStringRef::toShort(bool *ok, int base) const
|
||||
|
||||
ushort QStringRef::toUShort(bool *ok, int base) const
|
||||
{
|
||||
return QString::toIntegral_helper<ushort>(constData(), size(), ok, base);
|
||||
return QString::toIntegral_helper<ushort>(*this, ok, base);
|
||||
}
|
||||
|
||||
|
||||
|
@ -981,8 +981,8 @@ private:
|
||||
static QByteArray toUtf8_helper(const QString &);
|
||||
static QByteArray toLocal8Bit_helper(const QChar *data, int size);
|
||||
static int toUcs4_helper(const ushort *uc, int length, uint *out);
|
||||
static qlonglong toIntegral_helper(const QChar *data, int len, bool *ok, int base);
|
||||
static qulonglong toIntegral_helper(const QChar *data, uint len, bool *ok, int base);
|
||||
static qlonglong toIntegral_helper(QStringView string, bool *ok, int base);
|
||||
static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base);
|
||||
void replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen);
|
||||
friend class QStringRef;
|
||||
friend class QStringView;
|
||||
@ -991,13 +991,13 @@ private:
|
||||
friend struct QAbstractConcatenable;
|
||||
|
||||
template <typename T> static
|
||||
T toIntegral_helper(const QChar *data, int len, bool *ok, int base)
|
||||
T toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
{
|
||||
using Int64 = typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type;
|
||||
using Int32 = typename std::conditional<std::is_unsigned<T>::value, uint, int>::type;
|
||||
|
||||
// we select the right overload by casting size() to int or uint
|
||||
Int64 val = toIntegral_helper(data, Int32(len), ok, base);
|
||||
// we select the right overload by casting base to int or uint
|
||||
Int64 val = toIntegral_helper(string, ok, Int32(base));
|
||||
if (T(val) != val) {
|
||||
if (ok)
|
||||
*ok = false;
|
||||
|
Loading…
Reference in New Issue
Block a user