Switch json library to rei-json

This commit is contained in:
Vyn 2024-11-22 17:56:31 +01:00
parent 1872ab7b18
commit 7ce7ad3ee1
5 changed files with 36 additions and 24790 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "cpp/external/rei-json"]
path = cpp/external/rei-json
url = https://codeberg.org/vyn/rei-json.git

View file

@ -10,4 +10,4 @@ add_library(selenite
src/palette.cpp src/palette.cpp
) )
target_include_directories(selenite PRIVATE "include") target_include_directories(selenite PRIVATE "external/rei-json/include")

1
cpp/external/rei-json vendored Submodule

@ -0,0 +1 @@
Subproject commit 2041a0aafe85085dcf35a37437db493898f1be3c

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,9 @@
#include "selenite/palette.h" #include "selenite/palette.h"
#include "json.hpp" #include "rei-json/Object.h"
#include "rei-json/json.h"
#include <fstream> #include <fstream>
#include <optional> #include <optional>
#include <sstream>
#include <string> #include <string>
namespace selenite namespace selenite
@ -24,30 +26,37 @@ std::optional<Palette> parseJson(const std::string &path)
if (!file) { if (!file) {
return std::nullopt; return std::nullopt;
} }
auto json = nlohmann::json::parse(file);
if (!json.is_object() || !json["primary"].is_string() || !json["secondary"].is_string() || std::stringstream buffer;
!json["background"].is_string() || !json["background2"].is_string() || buffer << file.rdbuf();
!json["background4"].is_string() || !json["background3"].is_string() || auto jsonStr = buffer.str();
!json["pane"].is_string() || !json["foreground"].is_string() ||
!json["foregroundHint"].is_string() || !json["green"].is_string() || auto jsonOpt = rei::json::parse(jsonStr);
!json["orange"].is_string() || !json["red"].is_string()) { auto json = std::get<rei::json::JsonObject>(jsonOpt);
return std::nullopt;
}
/*if (!json.is_object() || !json["primary"].is_string() || !json["secondary"].is_string() ||*/
/*!json["background"].is_string() || !json["background2"].is_string() ||*/
/*!json["background4"].is_string() || !json["background3"].is_string() ||*/
/*!json["pane"].is_string() || !json["foreground"].is_string() ||*/
/*!json["foregroundHint"].is_string() || !json["green"].is_string() ||*/
/*!json["orange"].is_string() || !json["red"].is_string()) {*/
/*return std::nullopt;*/
/*}*/
Palette palette{ Palette palette{
.primary = hexStringToColor(json["primary"].get<std::string>()), .primary = hexStringToColor(json.getString("primary")),
.secondary = hexStringToColor(json["secondary"].get<std::string>()), .secondary = hexStringToColor(json.getString("secondary")),
.background = hexStringToColor(json["background"].get<std::string>()), .background = hexStringToColor(json.getString("background")),
.background2 = hexStringToColor(json["background2"].get<std::string>()), .background2 = hexStringToColor(json.getString("background2")),
.background3 = hexStringToColor(json["background3"].get<std::string>()), .background3 = hexStringToColor(json.getString("background3")),
.background4 = hexStringToColor(json["background4"].get<std::string>()), .background4 = hexStringToColor(json.getString("background4")),
.pane = hexStringToColor(json["pane"].get<std::string>()), .pane = hexStringToColor(json.getString("pane")),
.foreground = hexStringToColor(json["foreground"].get<std::string>()), .foreground = hexStringToColor(json.getString("foreground")),
.foregroundHint = hexStringToColor(json["foregroundHint"].get<std::string>()), .foregroundHint = hexStringToColor(json.getString("foregroundHint")),
.green = hexStringToColor(json["green"].get<std::string>()), .green = hexStringToColor(json.getString("green")),
.orange = hexStringToColor(json["orange"].get<std::string>()), .orange = hexStringToColor(json.getString("orange")),
.red = hexStringToColor(json["red"].get<std::string>()), .red = hexStringToColor(json.getString("red")),
}; };
return palette; return palette;
} }