blob: 44286e98a3512bbd07a8d61bada1471be11781ce [file] [log] [blame]
Václav Kubernátcb3af402020-02-12 16:49:17 +01001/*
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
11bool 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
16bool 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
21std::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}