mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 12:10:52 -06:00
Sort json
This commit is contained in:
@@ -41,6 +41,19 @@
|
||||
namespace {
|
||||
constexpr std::string_view _loggerCat = "PropertyOwner";
|
||||
|
||||
void sortJson(nlohmann::json& json) {
|
||||
std::sort(json.begin(), json.end(), []
|
||||
(const nlohmann::json& lhs, const nlohmann::json& rhs) {
|
||||
std::string lhsString = lhs["Name"];
|
||||
std::string rhsString = rhs["Name"];
|
||||
std::transform(lhsString.begin(), lhsString.end(), lhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
std::transform(rhsString.begin(), rhsString.end(), rhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
return rhsString > lhsString;
|
||||
});
|
||||
}
|
||||
|
||||
nlohmann::json createJson(openspace::properties::PropertyOwner* owner) {
|
||||
ZoneScoped
|
||||
|
||||
@@ -65,12 +78,14 @@ namespace {
|
||||
|
||||
json["Properties"].push_back(propertyJson);
|
||||
}
|
||||
sortJson(json["Properties"]);
|
||||
|
||||
auto propertyOwners = owner->propertySubOwners();
|
||||
for (properties::PropertyOwner* o : propertyOwners) {
|
||||
nlohmann::json propertyOwner;
|
||||
json["PropertyOwners"].push_back(createJson(o));
|
||||
}
|
||||
sortJson(json["PropertyOwners"]);
|
||||
|
||||
return json;
|
||||
}
|
||||
@@ -414,6 +429,7 @@ nlohmann::json PropertyOwner::generateJsonJson() const {
|
||||
json.push_back(createJson(owner));
|
||||
}
|
||||
}
|
||||
sortJson(json);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,19 @@ SceneLicenseWriter::SceneLicenseWriter()
|
||||
)
|
||||
{}
|
||||
|
||||
void sortJson(nlohmann::json& json) {
|
||||
std::sort(json.begin(), json.end(), []
|
||||
(const nlohmann::json& lhs, const nlohmann::json& rhs) {
|
||||
std::string lhsString = lhs["Name"];
|
||||
std::string rhsString = rhs["Name"];
|
||||
std::transform(lhsString.begin(), lhsString.end(), lhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
std::transform(rhsString.begin(), rhsString.end(), rhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
return rhsString > lhsString;
|
||||
});
|
||||
}
|
||||
|
||||
nlohmann::json SceneLicenseWriter::generateJsonJson() const {
|
||||
nlohmann::json json;
|
||||
|
||||
@@ -108,6 +121,7 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const {
|
||||
|
||||
assetLicenses[license].push_back(assetJson);
|
||||
}
|
||||
|
||||
nlohmann::json assetsJson;
|
||||
assetsJson["Name"] = "Assets";
|
||||
assetsJson["Type"] = "Licenses";
|
||||
@@ -116,10 +130,10 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const {
|
||||
nlohmann::json entry;
|
||||
entry["Name"] = assetLicense.first;
|
||||
entry["Assets"] = assetLicense.second;
|
||||
sortJson(entry["Assets"]);
|
||||
assetsJson["Licenses"].push_back(entry);
|
||||
}
|
||||
json.push_back(assetsJson);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,19 @@ namespace {
|
||||
return result;
|
||||
}
|
||||
|
||||
void sortJson(nlohmann::json& json) {
|
||||
std::sort(json.begin(), json.end(), []
|
||||
(const nlohmann::json& lhs, const nlohmann::json& rhs) {
|
||||
std::string lhsString = lhs["Name"];
|
||||
std::string rhsString = rhs["Name"];
|
||||
std::transform(lhsString.begin(), lhsString.end(), lhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
std::transform(rhsString.begin(), rhsString.end(), rhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
return rhsString > lhsString;
|
||||
});
|
||||
}
|
||||
|
||||
nlohmann::json toJson(const openspace::scripting::LuaLibrary::Function& f) {
|
||||
using namespace openspace;
|
||||
using namespace openspace::scripting;
|
||||
@@ -98,6 +111,7 @@ namespace {
|
||||
}
|
||||
function["Return Type"] = f.returnType;
|
||||
function["Help"] = f.helpText;
|
||||
sortJson(function["Arguments"]);
|
||||
|
||||
return function;
|
||||
}
|
||||
@@ -472,7 +486,10 @@ nlohmann::json ScriptEngine::generateJsonJson() const {
|
||||
for (const LuaLibrary::Function& f : l.documentations) {
|
||||
library["Functions"].push_back(toJson(f));
|
||||
}
|
||||
sortJson(library["Functions"]);
|
||||
json.push_back(library);
|
||||
|
||||
sortJson(json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,19 @@ namespace {
|
||||
using namespace openspace;
|
||||
using namespace openspace::documentation;
|
||||
|
||||
void sortJson(nlohmann::json& json) {
|
||||
std::sort(json.begin(), json.end(), []
|
||||
(const nlohmann::json& lhs, const nlohmann::json& rhs) {
|
||||
std::string lhsString = lhs["Name"];
|
||||
std::string rhsString = rhs["Name"];
|
||||
std::transform(lhsString.begin(), lhsString.end(), lhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
std::transform(rhsString.begin(), rhsString.end(), rhsString.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
return rhsString > lhsString;
|
||||
});
|
||||
}
|
||||
|
||||
nlohmann::json generateJsonDocumentation(const Documentation& d) {
|
||||
nlohmann::json json;
|
||||
|
||||
@@ -89,6 +102,7 @@ nlohmann::json generateJsonDocumentation(const Documentation& d) {
|
||||
}
|
||||
json["Members"].push_back(entry);
|
||||
}
|
||||
sortJson(json["Members"]);
|
||||
|
||||
return json;
|
||||
}
|
||||
@@ -216,6 +230,7 @@ nlohmann::json FactoryManager::generateJsonJson() const {
|
||||
factory["Classes"].push_back(documentation);
|
||||
}
|
||||
}
|
||||
sortJson(factory["Classes"]);
|
||||
json.push_back(factory);
|
||||
}
|
||||
// Add all leftover docs
|
||||
@@ -226,8 +241,9 @@ nlohmann::json FactoryManager::generateJsonJson() const {
|
||||
for (const Documentation& doc : docs) {
|
||||
leftovers["Classes"].push_back(generateJsonDocumentation(doc));
|
||||
}
|
||||
sortJson(leftovers["Classes"]);
|
||||
json.push_back(leftovers);
|
||||
|
||||
sortJson(json);
|
||||
// I did not check the output of this for correctness ---abock
|
||||
return json;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user