From d7beb77f1d4a3dd53a2f10440971d066d373a5c9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 7 Sep 2021 18:38:19 +0200 Subject: [PATCH 1/3] 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; From 5311df51adf9cc5f7c1a4d6638fe4c48571ce0f9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 7 Sep 2021 18:47:51 +0200 Subject: [PATCH 2/3] Link exe statically. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da938ef..074ae56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,9 @@ project(LangBuilder) add_compile_options(-Wall -Wextra -Werror) # We like new stuff, so set the c++ standard to c++20. set(CMAKE_CXX_STANDARD 20) +set(BUILD_SHARED_LIBS OFF) file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp") add_executable(LangBuilder ${SRC_FILES}) -target_link_libraries(LangBuilder -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) \ No newline at end of file +target_link_libraries(LangBuilder -static -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) \ No newline at end of file From 003e33c05ac01e90f056f189d092fb34b46e0077 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 12 Nov 2021 12:20:53 +0100 Subject: [PATCH 3/3] If key is "key" and value is "value" ignore the line. --- src/LocalizationFile.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/LocalizationFile.cpp b/src/LocalizationFile.cpp index f9a962d..c832c7d 100644 --- a/src/LocalizationFile.cpp +++ b/src/LocalizationFile.cpp @@ -49,6 +49,8 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) { std::getline(linestream, value, sep); if (key.empty()) continue; + if (key == "key" && value == "value") + continue; if (!IsKeyValid(key)){ std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl; }