Validate key for conforming to style rules.
This commit is contained in:
		| @@ -1,6 +1,16 @@ | |||||||
| #include "LocalizationFile.hpp" | #include "LocalizationFile.hpp" | ||||||
| #include <fstream> | #include <fstream> | ||||||
| #include <iostream> | #include <iostream> | ||||||
|  | #include <regex> | ||||||
|  |  | ||||||
|  | const std::regex keyChecker = std::regex("[^a-z0-9_]+"); | ||||||
|  |  | ||||||
|  | static bool IsKeyValid(const std::string_view & key){ | ||||||
|  |     if (std::regex_search(key.begin(), key.end(), keyChecker)){ | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
| void LocalizationFile::LoadFile(const std::filesystem::path& path) { | void LocalizationFile::LoadFile(const std::filesystem::path& path) { | ||||||
|     if (!std::filesystem::exists(path)) { |     if (!std::filesystem::exists(path)) { | ||||||
| @@ -33,6 +43,9 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) { | |||||||
|         std::getline(linestream, value, sep); |         std::getline(linestream, value, sep); | ||||||
|         if (key.empty()) |         if (key.empty()) | ||||||
|             continue; |             continue; | ||||||
|  |         if (!IsKeyValid(key)){ | ||||||
|  |             std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl; | ||||||
|  |         } | ||||||
|         _map[key] = value; |         _map[key] = value; | ||||||
|     } |     } | ||||||
|     file.close(); |     file.close(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user