diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/misc.cpp | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index b6891d669..c347b76a4 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -28,11 +28,13 @@ #include <netdb.h> #endif -NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending) +NumberList::NumberList(const Anope::string &list, bool descending, std::function<void(unsigned int)> nf, std::function<void(void)> ef) : endf(ef) { Anope::string error; commasepstream sep(list); Anope::string token; + bool is_valid = true; + std::set<unsigned> numbers; sep.GetToken(token); if (token.empty()) @@ -56,11 +58,8 @@ NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(tr if (!error.empty()) { - if (!this->InvalidRange(list)) - { - is_valid = false; - return; - } + is_valid = false; + return; } } else @@ -81,44 +80,24 @@ NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(tr if (!error.empty() || !error2.empty()) { - if (!this->InvalidRange(list)) - { - is_valid = false; - return; - } + is_valid = false; + return; } } } while (sep.GetToken(token)); -} - -NumberList::~NumberList() -{ -} -void NumberList::Process() -{ if (!is_valid) return; - if (this->desc) - { - for (std::set<unsigned>::reverse_iterator it = numbers.rbegin(), it_end = numbers.rend(); it != it_end; ++it) - this->HandleNumber(*it); - } + if (descending) + std::for_each(numbers.rbegin(), numbers.rend(), nf); else - { - for (std::set<unsigned>::iterator it = numbers.begin(), it_end = numbers.end(); it != it_end; ++it) - this->HandleNumber(*it); - } + std::for_each(numbers.begin(), numbers.end(), nf); } -void NumberList::HandleNumber(unsigned) -{ -} - -bool NumberList::InvalidRange(const Anope::string &) +NumberList::~NumberList() { - return true; + endf(); } ListFormatter::ListFormatter(NickServ::Account *acc) : nc(acc) |