Validate key for conforming to style rules.
This commit is contained in:
parent
a56ccf68ec
commit
ee85947c4c
|
@ -1,6 +1,16 @@
|
|||
#include "LocalizationFile.hpp"
|
||||
#include <fstream>
|
||||
#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) {
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue