Add conversion to and from long and ulong
This implements conversion parity with QString, which can convert to and from long and unsigned long. The implementation simply forwards to existing long long overloads or uses the existing helpers, so just as for the conversion to/from int or short, no additional test cases were added. Change-Id: I37ef06d9ce4d80d98bd72720353996bac723e09c Fixes: QTBUG-782 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
ae9be1a63d
commit
783953f09d
@ -1332,6 +1332,48 @@ uint QLocale::toUInt(const QString &s, bool *ok) const
|
||||
return toIntegral_helper<uint>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long int represented by the localized string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toInt(), toULong(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
|
||||
long QLocale::toLong(const QString &s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<long>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the unsigned long int represented by the localized
|
||||
string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toLong(), toInt(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
ulong QLocale::toULong(const QString &s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<ulong>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long long int represented by the localized string \a s.
|
||||
|
||||
@ -1499,6 +1541,48 @@ uint QLocale::toUInt(const QStringRef &s, bool *ok) const
|
||||
return toIntegral_helper<uint>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long int represented by the localized string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toInt(), toULong(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
|
||||
long QLocale::toLong(const QStringRef &s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<long>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the unsigned long int represented by the localized
|
||||
string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toLong(), toInt(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
ulong QLocale::toULong(const QStringRef &s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<ulong>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long long int represented by the localized string \a s.
|
||||
|
||||
@ -1675,6 +1759,48 @@ uint QLocale::toUInt(QStringView s, bool *ok) const
|
||||
return toIntegral_helper<uint>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long int represented by the localized string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toInt(), toULong(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
|
||||
long QLocale::toLong(QStringView s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<long>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the unsigned long int represented by the localized
|
||||
string \a s.
|
||||
|
||||
If the conversion fails the function returns 0.
|
||||
|
||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||
to \c false, and success by setting *\a{ok} to \c true.
|
||||
|
||||
This function ignores leading and trailing whitespace.
|
||||
|
||||
\sa toLong(), toInt(), toDouble(), toString()
|
||||
|
||||
\since 5.13
|
||||
*/
|
||||
|
||||
ulong QLocale::toULong(QStringView s, bool *ok) const
|
||||
{
|
||||
return toIntegral_helper<ulong>(d, s, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the long long int represented by the localized string \a s.
|
||||
|
||||
|
@ -961,6 +961,8 @@ public:
|
||||
ushort toUShort(const QString &s, bool *ok = nullptr) const;
|
||||
int toInt(const QString &s, bool *ok = nullptr) const;
|
||||
uint toUInt(const QString &s, bool *ok = nullptr) const;
|
||||
long toLong(const QString &s, bool *ok = nullptr) const;
|
||||
ulong toULong(const QString &s, bool *ok = nullptr) const;
|
||||
qlonglong toLongLong(const QString &s, bool *ok = nullptr) const;
|
||||
qulonglong toULongLong(const QString &s, bool *ok = nullptr) const;
|
||||
float toFloat(const QString &s, bool *ok = nullptr) const;
|
||||
@ -970,6 +972,8 @@ public:
|
||||
ushort toUShort(const QStringRef &s, bool *ok = nullptr) const;
|
||||
int toInt(const QStringRef &s, bool *ok = nullptr) const;
|
||||
uint toUInt(const QStringRef &s, bool *ok = nullptr) const;
|
||||
long toLong(const QStringRef &s, bool *ok = nullptr) const;
|
||||
ulong toULong(const QStringRef &s, bool *ok = nullptr) const;
|
||||
qlonglong toLongLong(const QStringRef &s, bool *ok = nullptr) const;
|
||||
qulonglong toULongLong(const QStringRef &s, bool *ok = nullptr) const;
|
||||
float toFloat(const QStringRef &s, bool *ok = nullptr) const;
|
||||
@ -980,6 +984,8 @@ public:
|
||||
ushort toUShort(QStringView s, bool *ok = nullptr) const;
|
||||
int toInt(QStringView s, bool *ok = nullptr) const;
|
||||
uint toUInt(QStringView s, bool *ok = nullptr) const;
|
||||
long toLong(QStringView s, bool *ok = nullptr) const;
|
||||
ulong toULong(QStringView s, bool *ok = nullptr) const;
|
||||
qlonglong toLongLong(QStringView s, bool *ok = nullptr) const;
|
||||
qulonglong toULongLong(QStringView s, bool *ok = nullptr) const;
|
||||
float toFloat(QStringView s, bool *ok = nullptr) const;
|
||||
@ -987,6 +993,8 @@ public:
|
||||
|
||||
QString toString(qlonglong i) const;
|
||||
QString toString(qulonglong i) const;
|
||||
inline QString toString(long i) const;
|
||||
inline QString toString(ulong i) const;
|
||||
inline QString toString(short i) const;
|
||||
inline QString toString(ushort i) const;
|
||||
inline QString toString(int i) const;
|
||||
@ -1107,6 +1115,10 @@ private:
|
||||
Q_DECLARE_SHARED(QLocale)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QLocale::NumberOptions)
|
||||
|
||||
inline QString QLocale::toString(long i) const
|
||||
{ return toString(qlonglong(i)); }
|
||||
inline QString QLocale::toString(ulong i) const
|
||||
{ return toString(qulonglong(i)); }
|
||||
inline QString QLocale::toString(short i) const
|
||||
{ return toString(qlonglong(i)); }
|
||||
inline QString QLocale::toString(ushort i) const
|
||||
|
@ -1163,6 +1163,30 @@
|
||||
currency string.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString QLocale::toString(long i) const
|
||||
|
||||
\overload
|
||||
|
||||
\sa toLong()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString QLocale::toString(ulong i) const
|
||||
|
||||
\overload
|
||||
|
||||
\sa toULong()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString QLocale::toString(ushort i) const
|
||||
|
||||
\overload
|
||||
|
||||
\sa toUShort()
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn QString QLocale::toString(short i) const
|
||||
|
Loading…
Reference in New Issue
Block a user