From 91112ead917c96b533685701de64d025bd00769d Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Thu, 3 Nov 2022 20:56:32 +0100 Subject: fix: Fix parsing of sloppiness with trailing delimiter --- src/Config.cpp | 11 ++++------- unittest/test_Config.cpp | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 3cec222f..275cdcb2 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -280,13 +281,9 @@ parse_compiler_type(const std::string& value) core::Sloppiness parse_sloppiness(const std::string& value) { - size_t start = 0; - size_t end = 0; core::Sloppiness result; - while (end != std::string::npos) { - end = value.find_first_of(", ", start); - std::string token = - util::strip_whitespace(value.substr(start, end - start)); + + for (const auto token : util::Tokenizer(value, ", ")) { if (token == "clang_index_store") { result.enable(core::Sloppy::clang_index_store); } else if (token == "file_stat_matches") { @@ -314,8 +311,8 @@ parse_sloppiness(const std::string& value) } else if (token == "time_macros") { result.enable(core::Sloppy::time_macros); } // else: ignore unknown value for forward compatibility - start = value.find_first_not_of(", ", end); } + return result; } diff --git a/unittest/test_Config.cpp b/unittest/test_Config.cpp index 559cc1b1..70a66dd2 100644 --- a/unittest/test_Config.cpp +++ b/unittest/test_Config.cpp @@ -135,7 +135,8 @@ TEST_CASE("Config::update_from_file") "run_second_cpp = false\n" "sloppiness = time_macros ,include_file_mtime" " include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_defines" - " , no_system_headers,system_headers,clang_index_store,ivfsoverlay,gcno_cwd\n" + " , no_system_headers,system_headers,clang_index_store,ivfsoverlay," + " gcno_cwd,\n" "stats = false\n" "temporary_dir = ${USER}_foo\n" "umask = 777"); // Note: no newline. @@ -424,7 +425,7 @@ TEST_CASE("Config::visit_items") "run_second_cpp = false\n" "sloppiness = include_file_mtime, include_file_ctime, time_macros," " file_stat_matches, file_stat_matches_ctime, pch_defines, system_headers," - " clang_index_store, ivfsoverlay, gcno_cwd\n" + " clang_index_store, ivfsoverlay, gcno_cwd \n" "stats = false\n" "stats_log = sl\n" "temporary_dir = td\n" -- cgit v1.2.1