diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-11-17 22:48:29 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-11-17 23:06:40 +0000 |
| commit | 2b9b161d424c1168636042adc6678bb3df2be3f9 (patch) | |
| tree | e103e27252b1a83575f6c7b6820f44a47fb9ee4c /src/completion.hh | |
| parent | c764fa7e2560fa86b5d931126fdaea830c3e6914 (diff) | |
remove idvaluemap, use unordered_map in place
Diffstat (limited to 'src/completion.hh')
| -rw-r--r-- | src/completion.hh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/completion.hh b/src/completion.hh index 44726dd3..eb1d4fa6 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -5,6 +5,7 @@ #include <vector> #include <functional> +#include <unordered_map> namespace Kakoune { @@ -40,5 +41,34 @@ inline Completions complete_nothing(const Context& context, CompletionFlags, return Completions(cursor_pos, cursor_pos); } +template<typename Condition, typename Value> +CandidateList complete_key_if(const std::unordered_map<String, Value>& map, + const String& prefix, + ByteCount cursor_pos, + Condition condition) +{ + String real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& value : map) + { + if (not condition(value)) + continue; + + if (prefix_match(value.first, real_prefix)) + result.push_back(value.first); + } + return result; +} + +template<typename Value> +CandidateList complete_key(const std::unordered_map<String, Value>& map, + const String& prefix, + ByteCount cursor_pos) +{ + return complete_key_if( + map, prefix, cursor_pos, + [](const std::pair<String, Value>&) { return true; }); +} + } #endif // completion_hh_INCLUDED |
