From c706357db7c93e146b885db055274396b753c0b0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 12 Sep 2016 15:07:35 -0700 Subject: [PATCH] ircd: Add empty() for empty line checks; retune ircd::line typedef. --- include/ircd/line.h | 23 ++--------------------- include/ircd/rfc1459.h | 6 ++++++ include/ircd/tape.h | 15 +++++++++++++++ ircd/rfc1459.cc | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/include/ircd/line.h b/include/ircd/line.h index 9c10c1bea..bdc3c0541 100644 --- a/include/ircd/line.h +++ b/include/ircd/line.h @@ -25,14 +25,7 @@ #ifdef __cplusplus namespace ircd { -struct line -:rfc1459::line -{ - auto &operator[](const size_t &pos) const; - auto &operator[](const size_t &pos); - - using rfc1459::line::line; -}; +using line = rfc1459::line; inline auto &pfx(const line &line) { return line.pfx; } inline auto &pfx(line &line) { return line.pfx; } @@ -47,6 +40,7 @@ inline auto &command(line &line) { return line.cmd; inline auto &parv(const line &line) { return line.parv; } inline auto &parv(line &line) { return line.parv; } inline auto parc(const line &line) { return parv(line).size(); } +inline bool empty(const line &line) { return line.empty(); } bool has(const line &line, const uint &argp); inline bool @@ -56,18 +50,5 @@ has(const line &line, return parc(line) > argp; } -inline auto & -line::operator[](const size_t &pos) -{ - return parv.at(pos); -} - -inline auto & -line::operator[](const size_t &pos) -const -{ - return parv.at(pos); -} - } // namespace ircd #endif diff --git a/include/ircd/rfc1459.h b/include/ircd/rfc1459.h index b2bbc3c9d..7a67717c6 100644 --- a/include/ircd/rfc1459.h +++ b/include/ircd/rfc1459.h @@ -151,6 +151,8 @@ struct pfx struct nick nick; struct user user; struct host host; + + bool empty() const; }; struct line @@ -159,6 +161,10 @@ struct line struct cmd cmd; struct parv parv; + bool empty() const; + auto &operator[](const size_t &pos) const { return parv.at(pos); } + auto &operator[](const size_t &pos) { return parv.at(pos); } + explicit line(const uint8_t *const &buf, const size_t &len); explicit line(const std::string &line); line(const char *const &line); diff --git a/include/ircd/tape.h b/include/ircd/tape.h index 491ebd19d..9dee54e4a 100644 --- a/include/ircd/tape.h +++ b/include/ircd/tape.h @@ -31,5 +31,20 @@ struct tape using rfc1459::tape::tape; }; +void remove_empty(tape &tape); + + +inline +void remove_empty(tape &tape) +{ + const auto eit(std::remove_if(begin(tape), end(tape), [] + (const auto &line) + { + return line.empty(); + })); + + tape.erase(eit, end(tape)); +} + } // namespace ircd #endif diff --git a/ircd/rfc1459.cc b/ircd/rfc1459.cc index 7b5a1823e..c559d4492 100644 --- a/ircd/rfc1459.cc +++ b/ircd/rfc1459.cc @@ -351,6 +351,24 @@ catch(const boost::spirit::qi::expectation_failure &e) string(e.what_).c_str()); } +bool +rfc1459::line::empty() +const +{ + return pfx.empty() && + cmd.empty() && + parv.empty(); +} + +bool +rfc1459::pfx::empty() +const +{ + return nick.empty() && + user.empty() && + host.empty(); +} + std::string rfc1459::character::gather(const attr &attr) {