diff options
Diffstat (limited to 'src/utils.cc')
-rw-r--r-- | src/utils.cc | 15 |
1 files changed, 15 insertions, 0 deletions
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 <filesystem> #include <stdexcept> #include <map> +#include <algorithm> 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; +} |