From ee85947c4cf363aa9b8e1f5b5712da9de9b29401 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 23 Jul 2021 12:23:56 +0200 Subject: [PATCH] Validate key for conforming to style rules. --- src/LocalizationFile.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/LocalizationFile.cpp b/src/LocalizationFile.cpp index 134182a..13a97f8 100644 --- a/src/LocalizationFile.cpp +++ b/src/LocalizationFile.cpp @@ -1,6 +1,16 @@ #include "LocalizationFile.hpp" #include #include +#include + +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) { if (!std::filesystem::exists(path)) { @@ -33,6 +43,9 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) { std::getline(linestream, value, sep); if (key.empty()) continue; + if (!IsKeyValid(key)){ + std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl; + } _map[key] = value; } file.close();