summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-02-07 14:52:41 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 05:11:18 +0100
commit1e43b64a7a5c3823a6bdcb8d0cd28a17955939a2 (patch)
treed04a48ee55209ee5dccfc59863aa4f5df959e51f /src/corelib/tools/qstring.cpp
parentc0791ac76ec7cfdc3945efa67a6f72ee3623413c (diff)
Centralize the merging toFloat conversions
The QByteArray version was missing the overflow check that the other versions had. Change-Id: I03cd92e5e5a84c038bee1f1ee217e93e9d9a675a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 5bc485be7a..673363c66f 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -6341,27 +6341,9 @@ double QString::toDouble(bool *ok) const
\sa number(), toDouble(), toInt(), QLocale::toFloat()
*/
-#define QT_MAX_FLOAT 3.4028234663852886e+38
-
float QString::toFloat(bool *ok) const
{
- bool myOk;
- double d = toDouble(&myOk);
- if (!myOk) {
- if (ok != 0)
- *ok = false;
- return 0.0;
- }
- if (qIsInf(d))
- return float(d);
- if (d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) {
- if (ok != 0)
- *ok = false;
- return 0.0;
- }
- if (ok != 0)
- *ok = true;
- return float(d);
+ return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
/*! \fn QString &QString::setNum(int n, int base)
@@ -9806,23 +9788,7 @@ double QStringRef::toDouble(bool *ok) const
float QStringRef::toFloat(bool *ok) const
{
- bool myOk;
- double d = toDouble(&myOk);
- if (!myOk) {
- if (ok != 0)
- *ok = false;
- return 0.0;
- }
- if (qIsInf(d))
- return float(d);
- if (d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) {
- if (ok != 0)
- *ok = false;
- return 0.0;
- }
- if (ok)
- *ok = true;
- return float(d);
+ return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
/*!