Clean up and simplify code
This commit is contained in:
parent
c1f8016f66
commit
24450dc07d
1 changed files with 9 additions and 20 deletions
29
src/main.cpp
29
src/main.cpp
|
@ -116,18 +116,8 @@ struct FindStringVisitor : boost::static_visitor<std::string_view> {
|
|||
}
|
||||
}
|
||||
|
||||
bool is_prefix_path (std::string_view curr_element) const {
|
||||
if (path.size() + 1 > search.size())
|
||||
return false;
|
||||
|
||||
return std::equal(path.cbegin(), path.cend(), search.cbegin()) and (search[path.size()] == curr_element);
|
||||
}
|
||||
|
||||
bool is_path_found() const {
|
||||
if (path.size() != search.size())
|
||||
return false;
|
||||
|
||||
return std::equal(path.cbegin(), path.cend(), search.cbegin());
|
||||
return search.size() == search_match_count;
|
||||
}
|
||||
|
||||
std::string_view operator() (long long value) {
|
||||
|
@ -141,7 +131,7 @@ struct FindStringVisitor : boost::static_visitor<std::string_view> {
|
|||
return {};
|
||||
}
|
||||
|
||||
std::string_view operator() (const std::vector<duck::TorrentValue>& value) {
|
||||
std::string_view operator() (const std::vector<duck::TorrentValue>&) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -149,17 +139,16 @@ struct FindStringVisitor : boost::static_visitor<std::string_view> {
|
|||
if (is_path_found())
|
||||
return {};
|
||||
|
||||
for (const auto& item : value) {
|
||||
if (is_prefix_path(item.first)) {
|
||||
path.push_back(item.first);
|
||||
return boost::apply_visitor(*this, item.second);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
auto it_found = value.find(search[search_match_count]);
|
||||
if (value.end() == it_found)
|
||||
return {};
|
||||
|
||||
++search_match_count;
|
||||
return boost::apply_visitor(*this, it_found->second);
|
||||
}
|
||||
|
||||
std::vector<std::string_view> path;
|
||||
std::vector<std::string> search;
|
||||
std::size_t search_match_count{0};
|
||||
};
|
||||
|
||||
std::vector<std::array<std::uint32_t, 5>> collect_hashes (std::string_view hashes) {
|
||||
|
|
Loading…
Add table
Reference in a new issue