SIC: QLocale: Remove base argument from conversion to number api
authorJohn Layt <jlayt@kde.org>
Fri, 27 Jan 2012 19:04:42 +0000 (19:04 +0000)
committerQt by Nokia <qt-info@nokia.com>
Sun, 5 Feb 2012 16:49:56 +0000 (17:49 +0100)
As discussed on list and approved by Lars and Thiago.

Remove the option to use QLocale to convert strings to non-decimal
numbers as they are not localised and the api is available in QString.

Change-Id: Ib810505ba86fb08ad23571b39f1520e86fde6787
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
dist/changes-5.0.0
src/corelib/tools/qdatetime.cpp
src/corelib/tools/qlocale.cpp
src/corelib/tools/qlocale.h
src/gui/util/qvalidator.cpp
src/widgets/widgets/qspinbox.cpp

index ea88471..9df3926 100644 (file)
@@ -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                                        *
 ****************************************************************************
index 8649690..3da7a37 100644 (file)
@@ -4697,7 +4697,7 @@ int QDateTimeParser::parseSection(const QDateTime &currentValue, 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;
index e09db5d..6c52eb3 100644 (file)
@@ -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);
 }
 
 /*!
index a70b888..2255340 100644 (file)
@@ -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;
 
index faff264..02552f5 100644 (file)
@@ -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;
     }
 
index 77c760d..ee94368 100644 (file)
@@ -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) {