Move JSON helpers to lib

This commit is contained in:
WarmUpTill
2025-04-17 11:51:00 +02:00
committed by WarmUpTill
parent 7c4c0056ce
commit 5568f92ad0
13 changed files with 64 additions and 58 deletions

View File

@@ -1,40 +0,0 @@
#include "json-helpers.hpp"
#include <QJsonDocument>
namespace advss {
QString FormatJsonString(std::string s)
{
return FormatJsonString(QString::fromStdString(s));
}
QString FormatJsonString(QString json)
{
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
if (doc.isNull()) {
return "";
}
return QString::fromUtf8(doc.toJson(QJsonDocument::Indented));
}
bool MatchJson(const std::string &json1, const std::string &json2,
const RegexConfig &regex)
{
auto j1 = FormatJsonString(json1).toStdString();
auto j2 = FormatJsonString(json2).toStdString();
if (j1.empty()) {
j1 = json1;
}
if (j2.empty()) {
j2 = json2;
}
if (regex.Enabled()) {
return regex.Matches(j1, j2);
}
return j1 == j2;
}
} // namespace advss

View File

@@ -1,13 +0,0 @@
#pragma once
#include <QString>
#include <string>
#include <regex-config.hpp>
namespace advss {
QString FormatJsonString(std::string);
QString FormatJsonString(QString);
bool MatchJson(const std::string &json1, const std::string &json2,
const RegexConfig &regex);
} // namespace advss

View File

@@ -1,7 +1,7 @@
#include "source-setting.hpp"
#include "json-helpers.hpp"
#include "obs-module-helper.hpp"
#include "math-helpers.hpp"
#include "utility.hpp"
#include <nlohmann/json.hpp>
#include <QLayout>

View File

@@ -1,8 +1,8 @@
#include "transform-setting.hpp"
#include "json-helpers.hpp"
#include "obs-module-helper.hpp"
#include "math-helpers.hpp"
#include "scene-item-transform-helpers.hpp"
#include "utility.hpp"
#include <nlohmann/json.hpp>
#include <QLayout>