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

Function config_parse_ranges

less_slow.cpp:4403–4422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4401#include <range/v3/view/transform.hpp>
4402
4403void config_parse_ranges(std::string_view config_text, std::vector<std::pair<std::string, std::string>> &settings) {
4404 namespace rv = ranges::views;
4405 auto lines = //
4406 config_text | //
4407 rv::split_when(is_newline) | //
4408 rv::transform([](auto &&subrange) {
4409 // We need to transfrom a sequence of characters back into string-views!
4410 // https://stackoverflow.com/a/48403210/2766161
4411 auto const size = ranges::distance(subrange);
4412 // `&*subrange.begin()` is UB if the range is empty:
4413 return size ? std::string_view(&*subrange.begin(), size) : std::string_view();
4414 }) |
4415 rv::transform(strip_spaces) |
4416 // Skip comments and empty lines
4417 rv::filter([](std::string_view line) { return !line.empty() && line.front() != '#'; }) |
4418 rv::transform(split_key_value) |
4419 // Skip invalid lines
4420 rv::filter([](auto &&kv) { return !kv.first.empty() && !kv.second.empty(); });
4421 for (auto [key, value] : std::move(lines)) settings.emplace_back(key, value);
4422}
4423
4424void parse_ranges(bm::State &state, std::string_view config_text) {
4425 std::size_t pairs = 0, bytes = 0;

Callers 1

parse_rangesFunction · 0.85

Calls 1

beginMethod · 0.45

Tested by

no test coverage detected