mirror of
https://github.com/matrix-construct/construct
synced 2024-09-29 20:28:52 +02:00
ircd: Add empty() for empty line checks; retune ircd::line typedef.
This commit is contained in:
parent
e87a8cc5d2
commit
c706357db7
4 changed files with 41 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -351,6 +351,24 @@ catch(const boost::spirit::qi::expectation_failure<const uint8_t *> &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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue