diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-12-08 10:43:50 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-12-08 10:43:50 +0100 |
| commit | 0c1d1a0f24655c22a373c19aac90a6a225a353e6 (patch) | |
| tree | e65fe3c5f8b80bb59910c81c700eb3ed545848bb /src/message.cpp | |
| parent | f22d1b76c9a957a679b57ddcb67b33cc73a15de1 (diff) | |
| download | wanda-0c1d1a0f24655c22a373c19aac90a6a225a353e6.tar.xz wanda-0c1d1a0f24655c22a373c19aac90a6a225a353e6.zip | |
wanda: reformat source code
Diffstat (limited to 'src/message.cpp')
| -rw-r--r-- | src/message.cpp | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/message.cpp b/src/message.cpp index 47a4414..4c152fa 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -1,59 +1,58 @@ #include "message.hpp" -#include <iterator> #include <ios> +#include <iterator> #include <sstream> namespace wanda { - -message::operator std::string() const -{ + message::operator std::string() const + { std::ostringstream buffer{}; buffer << source << ':' << command; - if(argument.has_value()) + if (argument.has_value()) { - buffer << ':' << *argument; + buffer << ':' << *argument; } return buffer.str(); -} + } -std::size_t message::size() const -{ + std::size_t message::size() const + { return static_cast<std::string>(*this).size(); -} + } -template <typename InputIt, typename OutputIt, typename UnaryPredicate> -OutputIt copy_until(InputIt first, InputIt last, OutputIt out, UnaryPredicate predicate) -{ + template<typename InputIt, typename OutputIt, typename UnaryPredicate> + OutputIt copy_until(InputIt first, InputIt last, OutputIt out, UnaryPredicate predicate) + { while (first != last && !predicate(*first)) { - *out++ = *first++; + *out++ = *first++; } return out; -} + } -std::istream &operator>>(std::istream &in, message &message) -{ + std::istream & operator>>(std::istream & in, message & message) + { auto pos = std::istream_iterator<char>{in}; auto end = std::istream_iterator<char>{}; auto buffer = std::string{}; - copy_until(pos, end, std::back_inserter(buffer), [](auto const &c) { return c == ':'; }); + copy_until(pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; }); if (in.eof() || buffer.size() != 1) { - in.setstate(std::ios_base::failbit); - return in; + in.setstate(std::ios_base::failbit); + return in; } message.source = buffer; buffer.clear(); - copy_until(++pos, end, std::back_inserter(buffer), [](auto const &c) { return c == ':'; }); + copy_until(++pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; }); if (in.eof()) { - in.setstate(std::ios_base::failbit); + in.setstate(std::ios_base::failbit); } message.command = buffer; @@ -61,16 +60,16 @@ std::istream &operator>>(std::istream &in, message &message) copy(++pos, end, std::back_inserter(buffer)); if (buffer.size()) { - message.argument = std::optional{std::move(buffer)}; + message.argument = std::optional{std::move(buffer)}; } in.clear(in.rdstate() ^ std::ios_base::failbit); return in; -} + } -std::ostream & operator<<(std::ostream & out, message const & message) -{ + std::ostream & operator<<(std::ostream & out, message const & message) + { return out << static_cast<std::string>(message); -} + } -} // namespace wanda
\ No newline at end of file +} // namespace wanda
\ No newline at end of file |
