0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd: Add empty() for empty line checks; retune ircd::line typedef.

This commit is contained in:
Jason Volk 2016-09-12 15:07:35 -07:00
parent e87a8cc5d2
commit c706357db7
4 changed files with 41 additions and 21 deletions

View file

@ -25,14 +25,7 @@
#ifdef __cplusplus #ifdef __cplusplus
namespace ircd { namespace ircd {
struct line using line = rfc1459::line;
:rfc1459::line
{
auto &operator[](const size_t &pos) const;
auto &operator[](const size_t &pos);
using rfc1459::line::line;
};
inline auto &pfx(const line &line) { return line.pfx; } inline auto &pfx(const line &line) { return line.pfx; }
inline auto &pfx(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(const line &line) { return line.parv; }
inline auto &parv(line &line) { return line.parv; } inline auto &parv(line &line) { return line.parv; }
inline auto parc(const line &line) { return parv(line).size(); } 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); bool has(const line &line, const uint &argp);
inline bool inline bool
@ -56,18 +50,5 @@ has(const line &line,
return parc(line) > argp; 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 } // namespace ircd
#endif #endif

View file

@ -151,6 +151,8 @@ struct pfx
struct nick nick; struct nick nick;
struct user user; struct user user;
struct host host; struct host host;
bool empty() const;
}; };
struct line struct line
@ -159,6 +161,10 @@ struct line
struct cmd cmd; struct cmd cmd;
struct parv parv; 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 uint8_t *const &buf, const size_t &len);
explicit line(const std::string &line); explicit line(const std::string &line);
line(const char *const &line); line(const char *const &line);

View file

@ -31,5 +31,20 @@ struct tape
using rfc1459::tape::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 } // namespace ircd
#endif #endif

View file

@ -351,6 +351,24 @@ catch(const boost::spirit::qi::expectation_failure<const uint8_t *> &e)
string(e.what_).c_str()); 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 std::string
rfc1459::character::gather(const attr &attr) rfc1459::character::gather(const attr &attr)
{ {