| 39 | } |
| 40 | |
| 41 | auto Sorcery::StringStore::_load() -> bool { |
| 42 | |
| 43 | // Attempt to load the Strings File |
| 44 | _strings.clear(); |
| 45 | _strings["NONE"] = STRINGS_NOT_LOADED; |
| 46 | if (std::ifstream file{_filename, std::ifstream::binary}; file.good()) { |
| 47 | |
| 48 | // Iterate through the file |
| 49 | Json::Value root{}; |
| 50 | #pragma GCC diagnostic push |
| 51 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 52 | Json::Reader reader{}; |
| 53 | #pragma GCC diagnostic pop |
| 54 | Json::StreamWriterBuilder builder{}; |
| 55 | builder.settings_["indentation"] = ""; |
| 56 | if (reader.parse(file, root, false)) { |
| 57 | for (Json::Value::iterator it = root.begin(); it != root.end(); |
| 58 | ++it) { |
| 59 | Json::Value key{it.key()}; |
| 60 | Json::Value value{*it}; |
| 61 | auto string_key{Json::writeString(builder, key)}; |
| 62 | auto string_value{Json::writeString(builder, value)}; |
| 63 | |
| 64 | // Remove any Special Characters from the string |
| 65 | string_key.erase( |
| 66 | remove(string_key.begin(), string_key.end(), '\"'), |
| 67 | string_key.end()); |
| 68 | string_value.erase( |
| 69 | remove(string_value.begin(), string_value.end(), '\"'), |
| 70 | string_value.end()); |
| 71 | string_key.erase( |
| 72 | remove(string_key.begin(), string_key.end(), '\n'), |
| 73 | string_key.end()); |
| 74 | |
| 75 | // Insert it into the map |
| 76 | _strings[string_key] = string_value; |
| 77 | } |
| 78 | } else |
| 79 | return false; |
| 80 | } else |
| 81 | return false; |
| 82 | |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | auto Sorcery::StringStore::get(std::string_view key) const -> std::string { |
| 87 | |