diff options
-rw-r--r-- | dist/changes-5.0.0 | 5 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 60 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.h | 12 | ||||
-rw-r--r-- | src/gui/util/qvalidator.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qspinbox.cpp | 4 |
6 files changed, 33 insertions, 52 deletions
diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0 index ea88471990..9df39260a6 100644 --- a/dist/changes-5.0.0 +++ b/dist/changes-5.0.0 @@ -193,6 +193,11 @@ information about a particular change. - QDir::NoDotAndDotDot is QDir::NoDot|QDir::NoDotDot therefore there is no need to use or check both. +- QLocale + * toShort(), toUShort(), toInt(), toUInt(), toLongLong() and toULongLong() no + longer take a parameter for base, they will only perform localised base 10 + conversions. For converting other bases use the QString methods instead. + **************************************************************************** * General * **************************************************************************** diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 8649690c72..3da7a37066 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4697,7 +4697,7 @@ int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionInde const int max = qMin(sectionmaxsize, sectiontextSize); for (int digits = max; digits >= 1; --digits) { digitsStr.truncate(digits); - int tmp = (int)loc.toUInt(digitsStr, &ok, 10); + int tmp = (int)loc.toUInt(digitsStr, &ok); if (ok && sn.type == Hour12Section) { if (tmp > 12) { tmp = -1; diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e09db5d7e4..6c52eb3827 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -1021,11 +1021,7 @@ QString QLocale::scriptToString(QLocale::Script script) } /*! - Returns the short int represented by the localized string \a s, - using base \a base. If \a base is 0 the base is determined - automatically using the following rules: If the string begins with - "0x", it is assumed to be hexadecimal; if it begins with "0", it - is assumed to be octal; otherwise it is assumed to be decimal. + Returns the short int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1037,9 +1033,9 @@ QString QLocale::scriptToString(QLocale::Script script) \sa toUShort(), toString() */ -short QLocale::toShort(const QString &s, bool *ok, int base) const +short QLocale::toShort(const QString &s, bool *ok) const { - qlonglong i = toLongLong(s, ok, base); + qlonglong i = toLongLong(s, ok); if (i < SHRT_MIN || i > SHRT_MAX) { if (ok != 0) *ok = false; @@ -1049,11 +1045,7 @@ short QLocale::toShort(const QString &s, bool *ok, int base) const } /*! - Returns the unsigned short int represented by the localized string - \a s, using base \a base. If \a base is 0 the base is determined - automatically using the following rules: If the string begins with - "0x", it is assumed to be hexadecimal; if it begins with "0", it - is assumed to be octal; otherwise it is assumed to be decimal. + Returns the unsigned short int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1065,9 +1057,9 @@ short QLocale::toShort(const QString &s, bool *ok, int base) const \sa toShort(), toString() */ -ushort QLocale::toUShort(const QString &s, bool *ok, int base) const +ushort QLocale::toUShort(const QString &s, bool *ok) const { - qulonglong i = toULongLong(s, ok, base); + qulonglong i = toULongLong(s, ok); if (i > USHRT_MAX) { if (ok != 0) *ok = false; @@ -1077,11 +1069,7 @@ ushort QLocale::toUShort(const QString &s, bool *ok, int base) const } /*! - Returns the int represented by the localized string \a s, using - base \a base. If \a base is 0 the base is determined automatically - using the following rules: If the string begins with "0x", it is - assumed to be hexadecimal; if it begins with "0", it is assumed to - be octal; otherwise it is assumed to be decimal. + Returns the int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1093,9 +1081,9 @@ ushort QLocale::toUShort(const QString &s, bool *ok, int base) const \sa toUInt(), toString() */ -int QLocale::toInt(const QString &s, bool *ok, int base) const +int QLocale::toInt(const QString &s, bool *ok) const { - qlonglong i = toLongLong(s, ok, base); + qlonglong i = toLongLong(s, ok); if (i < INT_MIN || i > INT_MAX) { if (ok != 0) *ok = false; @@ -1105,11 +1093,7 @@ int QLocale::toInt(const QString &s, bool *ok, int base) const } /*! - Returns the unsigned int represented by the localized string \a s, - using base \a base. If \a base is 0 the base is determined - automatically using the following rules: If the string begins with - "0x", it is assumed to be hexadecimal; if it begins with "0", it - is assumed to be octal; otherwise it is assumed to be decimal. + Returns the unsigned int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1121,9 +1105,9 @@ int QLocale::toInt(const QString &s, bool *ok, int base) const \sa toInt(), toString() */ -uint QLocale::toUInt(const QString &s, bool *ok, int base) const +uint QLocale::toUInt(const QString &s, bool *ok) const { - qulonglong i = toULongLong(s, ok, base); + qulonglong i = toULongLong(s, ok); if (i > UINT_MAX) { if (ok != 0) *ok = false; @@ -1133,11 +1117,7 @@ uint QLocale::toUInt(const QString &s, bool *ok, int base) const } /*! - Returns the long long int represented by the localized string \a - s, using base \a base. If \a base is 0 the base is determined - automatically using the following rules: If the string begins with - "0x", it is assumed to be hexadecimal; if it begins with "0", it - is assumed to be octal; otherwise it is assumed to be decimal. + Returns the long long int represented by the localized string \a s. If the conversion fails the function returns 0. @@ -1150,25 +1130,21 @@ uint QLocale::toUInt(const QString &s, bool *ok, int base) const */ -qlonglong QLocale::toLongLong(const QString &s, bool *ok, int base) const +qlonglong QLocale::toLongLong(const QString &s, bool *ok) const { QLocalePrivate::GroupSeparatorMode mode = p.numberOptions & RejectGroupSeparator ? QLocalePrivate::FailOnGroupSeparators : QLocalePrivate::ParseGroupSeparators; - return d()->stringToLongLong(s, base, ok, mode); + return d()->stringToLongLong(s, 10, ok, mode); } // ### Qt5: make the return type for toULongLong() qulonglong. /*! Returns the unsigned long long int represented by the localized - string \a s, using base \a base. If \a base is 0 the base is - determined automatically using the following rules: If the string - begins with "0x", it is assumed to be hexadecimal; if it begins - with "0", it is assumed to be octal; otherwise it is assumed to be - decimal. + string \a s. If the conversion fails the function returns 0. @@ -1180,14 +1156,14 @@ qlonglong QLocale::toLongLong(const QString &s, bool *ok, int base) const \sa toLongLong(), toInt(), toDouble(), toString() */ -qlonglong QLocale::toULongLong(const QString &s, bool *ok, int base) const +qlonglong QLocale::toULongLong(const QString &s, bool *ok) const { QLocalePrivate::GroupSeparatorMode mode = p.numberOptions & RejectGroupSeparator ? QLocalePrivate::FailOnGroupSeparators : QLocalePrivate::ParseGroupSeparators; - return d()->stringToUnsLongLong(s, base, ok, mode); + return d()->stringToUnsLongLong(s, 10, ok, mode); } /*! diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index a70b888ada..2255340b67 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -662,12 +662,12 @@ public: QString nativeLanguageName() const; QString nativeCountryName() const; - short toShort(const QString &s, bool *ok = 0, int base = 0) const; - ushort toUShort(const QString &s, bool *ok = 0, int base = 0) const; - int toInt(const QString &s, bool *ok = 0, int base = 0) const; - uint toUInt(const QString &s, bool *ok = 0, int base = 0) const; - qlonglong toLongLong(const QString &s, bool *ok = 0, int base = 0) const; - qlonglong toULongLong(const QString &s, bool *ok = 0, int base = 0) const; + short toShort(const QString &s, bool *ok = 0) const; + ushort toUShort(const QString &s, bool *ok = 0) const; + int toInt(const QString &s, bool *ok = 0) const; + uint toUInt(const QString &s, bool *ok = 0) const; + qlonglong toLongLong(const QString &s, bool *ok = 0) const; + qlonglong toULongLong(const QString &s, bool *ok = 0) const; float toFloat(const QString &s, bool *ok = 0) const; double toDouble(const QString &s, bool *ok = 0) const; diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index faff264723..02552f5a53 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -422,7 +422,7 @@ QValidator::State QIntValidator::validate(QString & input, int&) const return Invalid; if (entered >= b && entered <= t) { - locale().toInt(input, &ok, 10); + locale().toInt(input, &ok); return ok ? Acceptable : Intermediate; } diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 77c760d1e3..ee94368690 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -990,11 +990,11 @@ QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, state = QValidator::Invalid; // special-case -0 will be interpreted as 0 and thus not be invalid with a range from 0-100 } else { bool ok = false; - num = locale.toInt(copy, &ok, 10); + num = locale.toInt(copy, &ok); if (!ok && copy.contains(locale.groupSeparator()) && (max >= 1000 || min <= -1000)) { QString copy2 = copy; copy2.remove(locale.groupSeparator()); - num = locale.toInt(copy2, &ok, 10); + num = locale.toInt(copy2, &ok); } QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num; if (!ok) { |