DNS Lookup: Use std::optional instead of casting enum to int
Task-number: QTBUG-108873 Change-Id: I0bd5dc004154c1c4026be2feb6187c53e5e77801 Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit b300c6b777cda86782b35976fa8babdc238984ce) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d1bec6768c
commit
02dbd5da52
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static int typeFromParameter(QStringView type)
|
static std::optional<QDnsLookup::Type> typeFromParameter(QStringView type)
|
||||||
{
|
{
|
||||||
if (type.compare(u"a", Qt::CaseInsensitive) == 0)
|
if (type.compare(u"a", Qt::CaseInsensitive) == 0)
|
||||||
return QDnsLookup::A;
|
return QDnsLookup::A;
|
||||||
@ -33,7 +33,7 @@ static int typeFromParameter(QStringView type)
|
|||||||
return QDnsLookup::SRV;
|
return QDnsLookup::SRV;
|
||||||
if (type.compare(u"txt", Qt::CaseInsensitive) == 0)
|
if (type.compare(u"txt", Qt::CaseInsensitive) == 0)
|
||||||
return QDnsLookup::TXT;
|
return QDnsLookup::TXT;
|
||||||
return -1;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -79,12 +79,12 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
|
|||||||
|
|
||||||
if (parser.isSet(typeOption)) {
|
if (parser.isSet(typeOption)) {
|
||||||
const QString typeParameter = parser.value(typeOption);
|
const QString typeParameter = parser.value(typeOption);
|
||||||
const int type = typeFromParameter(typeParameter);
|
if (std::optional<QDnsLookup::Type> type = typeFromParameter(typeParameter)) {
|
||||||
if (type < 0) {
|
query->type = *type;
|
||||||
|
} else {
|
||||||
*errorMessage = "Bad record type: " + typeParameter;
|
*errorMessage = "Bad record type: " + typeParameter;
|
||||||
return CommandLineError;
|
return CommandLineError;
|
||||||
}
|
}
|
||||||
query->type = static_cast<QDnsLookup::Type>(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList positionalArguments = parser.positionalArguments();
|
const QStringList positionalArguments = parser.positionalArguments();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user