qt5base-lts/qmake/propertyprinter.cpp
Giuseppe D'Angelo 04f2acf93a qtpaths: generate proper JSON
The "manual" generation left a trailing comma in the object definition.
This is illegal, as per RFC 8259:

      object = begin-object [ member *( value-separator member ) ]
               end-object

Hence, the resulting JSON does not get accepted by any parser.

Let's just not do that and use QJsonDocument.

Change-Id: I882486e55f66c52d142638f37584088091bbc123
Pick-to: 6.2 6.5 6.6
Fixes: QTBUG-115124
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-07-08 10:50:41 +02:00

38 lines
938 B
C++

// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "propertyprinter.h"
#include <iostream>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
QT_BEGIN_NAMESPACE
void qmakePropertyPrinter(const QList<QPair<QString, QString>> &values)
{
// Assume single property request
if (values.size() == 1) {
std::cout << qPrintable(values.at(0).second) << std::endl;
return;
}
for (const auto &val : values) {
std::cout << qPrintable(val.first) << ":" << qPrintable(val.second) << std::endl;
}
}
void jsonPropertyPrinter(const QList<QPair<QString, QString>> &values)
{
QJsonObject object;
for (const auto &val : values)
object.insert(val.first, val.second);
QJsonDocument document(object);
std::cout << document.toJson().constData();
}
QT_END_NAMESPACE