Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | #include <boost/algorithm/string/predicate.hpp> |
| 8 | #include <tuple> |
| 9 | #include "completion.hpp" |
| 10 | |
| 11 | bool Completion::operator<(const Completion& b) const |
| 12 | { |
| 13 | return std::tie(this->m_value, this->m_suffix, this->m_whenToAdd) < std::tie(b.m_value, b.m_suffix, b.m_whenToAdd); |
| 14 | } |
| 15 | |
| 16 | bool Completion::operator==(const Completion& b) const |
| 17 | { |
| 18 | return std::tie(this->m_value, this->m_suffix, this->m_whenToAdd) == std::tie(b.m_value, b.m_suffix, b.m_whenToAdd); |
| 19 | } |
| 20 | |
| 21 | std::set<Completion> filterByPrefix(const std::set<Completion>& set, const std::string_view prefix) |
| 22 | { |
| 23 | std::set<Completion> filtered; |
| 24 | std::copy_if(set.begin(), set.end(), std::inserter(filtered, filtered.end()), [prefix](Completion it) { return boost::starts_with(it.m_value, prefix); }); |
| 25 | return filtered; |
| 26 | } |