Validate key for conforming to style rules.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
Deukhoofd 2021-07-23 12:23:56 +02:00
parent a56ccf68ec
commit ee85947c4c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 13 additions and 0 deletions

View File

@ -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();