From d4d2185f522365ae18f8710ef5b1e25ca8afcee5 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 10 Feb 2022 19:03:03 +0100 Subject: [PATCH] Replacing boost string splitter with non-boost version --- src/client/logging.cpp | 50 ++++++++++++++++++++++++++++++------------ src/daemon/daemon.cpp | 3 ++- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/client/logging.cpp b/src/client/logging.cpp index dc09908a4..b5d6f0b89 100644 --- a/src/client/logging.cpp +++ b/src/client/logging.cpp @@ -30,8 +30,7 @@ #include #include #include - -#include +#include extern "C" { #include @@ -44,6 +43,38 @@ extern "C" { #endif +namespace { +enum class split_str_mode { + is_any_of, + is_exactly_of // not used at the moment +}; ///> Mode for string splitter + +/** + * @brief Splits a string by a given delimiter for a given split_mode + * @param input String to be splitted + * @param delimiter split token + * @param split_mode how the string is split + * @return vector entries for splitted string + */ +std::vector +split_str(const std::string& input, const std::string_view delimiter, + const split_str_mode split_mode) { + std::vector out{}; + std::string regex_builder{}; + if(split_mode == split_str_mode::is_any_of) { + regex_builder = fmt::format("[{}]+", delimiter); + } else { + regex_builder = delimiter; + } + const std::regex line_re(regex_builder, + std::regex::ECMAScript | std::regex::optimize); + std::copy( + std::sregex_token_iterator(input.begin(), input.end(), line_re, -1), + std::sregex_token_iterator(), std::back_inserter(out)); + return out; +} +} // namespace + namespace gkfs::log { struct opt_info { @@ -150,20 +181,16 @@ process_log_options(const std::string gkfs_debug) { return log::none; #endif // ! GKFS_ENABLE_LOGGING - log_level dm = log::none; - std::vector tokens; - // skip separating white spaces and commas - boost::split(tokens, gkfs_debug, boost::is_any_of(" ,")); + auto tokens = ::split_str(gkfs_debug, " ,", ::split_str_mode::is_any_of); for(const auto& t : tokens) { bool is_known = false; for(const auto& opt : debug_opts) { - // none disables any future and previous flags observed if(t == "none") { return log::none; @@ -225,17 +252,14 @@ process_log_options(const std::string gkfs_debug) { std::bitset<512> process_log_filter(const std::string& log_filter) { - std::bitset<512> filtered_syscalls; - std::vector tokens; if(log_filter.empty()) { return filtered_syscalls; } // skip separating white spaces and commas - boost::split(tokens, log_filter, - [](char c) { return c == ' ' || c == ','; }); + auto tokens = ::split_str(log_filter, " ,", ::split_str_mode::is_any_of); for(const auto& t : tokens) { const auto sc = syscall::lookup_by_name(t); @@ -373,9 +397,7 @@ logger::logger(const std::string& opts, const std::string& path, bool trunc // mercury message might contain one or more sub-messages // separated by '\n' - std::vector sub_msgs; - boost::split(sub_msgs, msg, boost::is_any_of("\n"), - boost::token_compress_on); + auto sub_msgs = ::split_str(msg, "\n", ::split_str_mode::is_any_of); for(const auto& m : sub_msgs) { if(!m.empty()) { diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 1a88b6833..d58c3106b 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -464,7 +464,8 @@ initialize_loggers() { /** * @brief Parses command line arguments from user * - * @param vm boost::program_options variable_map + * @param opts CLI values + * @param desc CLI allowed options * @throws std::runtime_error */ void -- GitLab