GitLab: Limit the usage of std::make_pair

Make the code less verbose.

Change-Id: If938923022f8bcdb2559328e03035b8b38145f3e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-09-30 15:04:01 +02:00
parent eeb1cd22ce
commit 4857a58fdd

View File

@@ -60,7 +60,7 @@ static std::pair<QByteArray, QByteArray> splitHeaderAndBody(const QByteArray &in
} else { } else {
json = input; json = input;
} }
return std::make_pair(header, json); return {header, json};
} }
static std::pair<Error, QJsonObject> preHandleSingle(const QByteArray &json) static std::pair<Error, QJsonObject> preHandleSingle(const QByteArray &json)
@@ -87,7 +87,7 @@ static std::pair<Error, QJsonObject> preHandleSingle(const QByteArray &json)
} }
} }
return std::make_pair(result, object); return {result, object};
} }
static std::pair<Error, QJsonDocument> preHandleHeaderAndBody(const QByteArray &header, static std::pair<Error, QJsonDocument> preHandleHeaderAndBody(const QByteArray &header,
@@ -96,33 +96,33 @@ static std::pair<Error, QJsonDocument> preHandleHeaderAndBody(const QByteArray &
Error result; Error result;
if (header.isEmpty()) { if (header.isEmpty()) {
result.message = "Missing Expected Header"; result.message = "Missing Expected Header";
return std::make_pair(result, QJsonDocument()); return {result, {}};
} }
QJsonParseError error; QJsonParseError error;
const QJsonDocument doc = QJsonDocument::fromJson(json, &error); const QJsonDocument doc = QJsonDocument::fromJson(json, &error);
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
result.message = error.errorString(); result.message = error.errorString();
return std::make_pair(result, doc); return {result, doc};
} }
if (doc.isObject()) { if (doc.isObject()) {
const QJsonObject obj = doc.object(); const QJsonObject obj = doc.object();
if (obj.contains("message")) { if (obj.contains("message")) {
result = parseErrorMessage(obj.value("message").toString()); result = parseErrorMessage(obj.value("message").toString());
return std::make_pair(result, doc); return {result, doc};
} else if (obj.contains("error")) { } else if (obj.contains("error")) {
if (obj.value("error").toString() == "insufficient_scope") if (obj.value("error").toString() == "insufficient_scope")
result.code = 1; result.code = 1;
result.message = obj.value("error_description").toString(); result.message = obj.value("error_description").toString();
return std::make_pair(result, doc); return {result, doc};
} }
} }
if (!doc.isArray()) if (!doc.isArray())
result.message = "Not an Array"; result.message = "Not an Array";
return std::make_pair(result, doc); return {result, doc};
} }
static User userFromJson(const QJsonObject &jsonObj) static User userFromJson(const QJsonObject &jsonObj)