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>
This commit is contained in:
parent
c8612b156d
commit
52473c7bf1
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#include "qplatformdefs.h"
|
#include "qplatformdefs.h"
|
||||||
#include "qstring.h"
|
#include "qstring.h"
|
||||||
|
#include "qbytearrayview.h"
|
||||||
#include "qlist.h"
|
#include "qlist.h"
|
||||||
#include "qdir.h"
|
#include "qdir.h"
|
||||||
#include "qdatetime.h"
|
#include "qdatetime.h"
|
||||||
@ -3548,37 +3549,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
bool ok_ = true;
|
return QByteArrayView(buffer, size).toInt(ok, 0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user