diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-09 18:19:30 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-31 20:37:14 +0200 |
commit | 52473c7bf188f2803a44f0214e416ceb7e20841f (patch) | |
tree | dbb1c669d209cdc285f589003f8b85339efe897f /src/corelib/global | |
parent | c8612b156df4d77e9bfdc39750db415ba389ab56 (diff) |
Use QByteArrayView::toInt() instead of duplicating its implementation
The code in qEnvironmentVariableIntValue() to parse the text as an int
can now delegate it to QByteArrayView, so that keeping in sync with
QByteArray::toInt(), as a comment requested, is now automatic.
Change-Id: I09a6b7245ecd02f39a850a4ce187f86709282e8c
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index e613266d7b..f425942f96 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -40,6 +40,7 @@ #include "qplatformdefs.h" #include "qstring.h" +#include "qbytearrayview.h" #include "qlist.h" #include "qdir.h" #include "qdatetime.h" @@ -3548,37 +3549,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept return 0; } #endif - bool ok_ = true; - const char *endptr; - const qlonglong value = qstrntoll(buffer, size, &endptr, 0, &ok_); - - // Keep the following checks in sync with QByteArray::toInt() - if (!ok_) { - if (ok) - *ok = false; - return 0; - } - - if (*endptr != '\0') { - while (ascii_isspace(*endptr)) - ++endptr; - } - - if (*endptr != '\0') { - // we stopped at a non-digit character after converting some digits - if (ok) - *ok = false; - return 0; - } - - if (int(value) != value) { - if (ok) - *ok = false; - return 0; - } else if (ok) { - *ok = ok_; - } - return int(value); + return QByteArrayView(buffer, size).toInt(ok, 0); } /*! |