MCPcopy Create free account
hub / github.com/ashvardanian/less_slow.cpp / config_parse_regex

Function config_parse_regex

less_slow.cpp:4549–4568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4547static constexpr std::string_view regex_for_config = R"(^\s*([^#:\s]+)\s*:\s*([^#:\s]+)\s*$)";
4548
4549void config_parse_regex(std::string_view config_text, std::vector<std::pair<std::string, std::string>> &settings,
4550 std::regex const &regex_fsm) {
4551 auto begin_ptr = config_text.data();
4552 auto end_ptr = begin_ptr + config_text.size();
4553
4554 // Use `std::cregex_iterator` to find all non-overlapping matches
4555 // across multiple lines. We rely on "multiline" mode to treat
4556 // ^ and $ as line boundaries.
4557 std::cregex_iterator it(begin_ptr, end_ptr, regex_fsm);
4558 std::cregex_iterator end_it;
4559
4560 // For each match, capture the "key" and "value" groups.
4561 // Group 0 is the full match, 1 and 2 are our key and value.
4562 for (; it != end_it; ++it) {
4563 std::cmatch const &match = *it;
4564 std::string key = match.str(1);
4565 std::string value = match.str(2);
4566 settings.emplace_back(std::move(key), std::move(value));
4567 }
4568}
4569
4570void parse_regex(bm::State &state, std::string_view config_text) {
4571 std::size_t pairs = 0, bytes = 0;

Callers 1

parse_regexFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected