diff --git a/src/client/logging.cpp b/src/client/logging.cpp index dc09908a4a3efa74b468c2282022dc5033d2d2b4..b5d6f0b89c0a84fdc8f157353dbbe0943efdac85 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 1a88b6833f348fcc5dfbb10add3e77ad51e22c14..d58c3106b5b99da9cbd29ea5a9731ffc7473b78e 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