From d7beb77f1d4a3dd53a2f10440971d066d373a5c9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 7 Sep 2021 18:38:19 +0200 Subject: [PATCH] Better handling of detecting csv separator. --- src/LocalizationFile.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/LocalizationFile.cpp b/src/LocalizationFile.cpp index 13a97f8..f9a962d 100644 --- a/src/LocalizationFile.cpp +++ b/src/LocalizationFile.cpp @@ -12,6 +12,10 @@ static bool IsKeyValid(const std::string_view & key){ return true; } +const char PossibleSeparators[] = { + ',', ';', '|', '\t', ':' +}; + void LocalizationFile::LoadFile(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { std::stringstream ss; @@ -31,9 +35,11 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) { while (std::getline(file, line)) { if (firstLine) { firstLine = false; - if (line.substr(0, 4) == "sep=") { - sep = line[4]; - continue; + for (auto& s :PossibleSeparators) { + if (line.find(s) != std::string::npos){ + sep = s; + break; + } } } std::string key;