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 {
|
bool is_path_found() const {
|
||||||
if (path.size() != search.size())
|
return search.size() == search_match_count;
|
||||||
return false;
|
|
||||||
|
|
||||||
return std::equal(path.cbegin(), path.cend(), search.cbegin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view operator() (long long value) {
|
std::string_view operator() (long long value) {
|
||||||
|
@ -141,7 +131,7 @@ struct FindStringVisitor : boost::static_visitor<std::string_view> {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view operator() (const std::vector<duck::TorrentValue>& value) {
|
std::string_view operator() (const std::vector<duck::TorrentValue>&) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,17 +139,16 @@ struct FindStringVisitor : boost::static_visitor<std::string_view> {
|
||||||
if (is_path_found())
|
if (is_path_found())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
for (const auto& item : value) {
|
auto it_found = value.find(search[search_match_count]);
|
||||||
if (is_prefix_path(item.first)) {
|
if (value.end() == it_found)
|
||||||
path.push_back(item.first);
|
return {};
|
||||||
return boost::apply_visitor(*this, item.second);
|
|
||||||
}
|
++search_match_count;
|
||||||
}
|
return boost::apply_visitor(*this, it_found->second);
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string_view> path;
|
|
||||||
std::vector<std::string> search;
|
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) {
|
std::vector<std::array<std::uint32_t, 5>> collect_hashes (std::string_view hashes) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue