From 2a9f262e6db5906db445d465e500d7ba8c90fab3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 5 May 2021 09:44:50 -0400 Subject: Implemented additional commands --- src/utils.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/utils.cc') diff --git a/src/utils.cc b/src/utils.cc index f58dc61..54fa38e 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -8,6 +8,7 @@ #include #include #include +#include nlohmann::json utils::loadJson(const std::string& path) { std::ifstream f(path); @@ -25,6 +26,15 @@ nlohmann::json utils::loadJson(const std::string& type, const std::string& name) throw std::invalid_argument("Unknown name: `" + name + "' for type `" + type + "'."); } +nlohmann::json utils::findByName(const std::string& name) { + for(auto type : settings::objectTypes) { + try { + return utils::loadJson(type, name); + } catch(std::exception& e) {} // eat. + } + throw std::invalid_argument("Could not find data matching: " + name); +} + void utils::saveJson(const nlohmann::json& data, const std::string& path) { std::ofstream f(path); f << std::setw(4) << data << std::endl; @@ -103,3 +113,8 @@ std::string utils::toOrdinal(std::size_t number) { } return std::to_string(number) + suffix; } + +std::string utils::lower(std::string& in) { + std::transform(in.begin(), in.end(), in.begin(), ::tolower); + return in; +} -- cgit v1.2.3