aboutsummaryrefslogtreecommitdiff
path: root/src/utils.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-05 09:44:50 -0400
committerYour Name <you@example.com>2021-05-05 09:44:50 -0400
commit2a9f262e6db5906db445d465e500d7ba8c90fab3 (patch)
tree34f850754b0c9114ede9d7b2bb8da90dffddc4fe /src/utils.cc
parent8614137f7f32f2c9f3c11419110cd70dd7f3b505 (diff)
downloaddmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.gz
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.bz2
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.zip
Implemented additional commands
Diffstat (limited to 'src/utils.cc')
-rw-r--r--src/utils.cc15
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;
+}