From e784db4ad6637e3dabfd4c6805fdd977332dff1b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 17 Apr 2016 19:21:08 +0100 Subject: [PATCH] Use common completion system for OptionManager::complete_option_name --- src/option_manager.cc | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/option_manager.cc b/src/option_manager.cc index 04fb3e84..7c98daff 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -112,31 +112,15 @@ void OptionManager::on_option_changed(const Option& option) watcher->on_option_changed(option); } -template -static CandidateList get_matching_names(const Container& options, MatchingFunc func) -{ - CandidateList result; - for (auto& option : options) - { - if (option->flags() & OptionFlags::Hidden) - continue; - - const auto& name = option->name(); - if (func(name)) - result.push_back(name); - } - return result; -} - CandidateList OptionsRegistry::complete_option_name(StringView prefix, ByteCount cursor_pos) const { - using namespace std::placeholders; - auto real_prefix = prefix.substr(0, cursor_pos); - auto result = get_matching_names(m_descs, std::bind(prefix_match, _1, real_prefix)); - if (result.empty()) - result = get_matching_names(m_descs, std::bind(subsequence_match, _1, real_prefix)); - return result; + using OptionPtr = std::unique_ptr; + return complete(prefix, cursor_pos, m_descs | + filter([](const OptionPtr& desc) + { return not (desc->flags() & OptionFlags::Hidden); }) | + transform([](const OptionPtr& desc) -> const String& + { return desc->name(); })); } }