summaryrefslogtreecommitdiff
path: root/src/irc/irc_message.cpp
diff options
context:
space:
mode:
authorVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:40 +0530
committerVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:40 +0530
commiteda4b75b1cff83336e87da90efca9fd6b4ced2c7 (patch)
tree491317ce50b5d19bc434ccc4b448d1bc70520177 /src/irc/irc_message.cpp
parent716c40e4ec45f8d538695225f4f06d541d959084 (diff)
parent0f14fe83ef53b08bd8fa09670c82f4996c329bdc (diff)
downloadbiboumi-upstream/3.0.tar.gz
biboumi-upstream/3.0.tar.bz2
biboumi-upstream/3.0.tar.xz
biboumi-upstream/3.0.zip
New upstream version 3.0upstream/3.0
Diffstat (limited to 'src/irc/irc_message.cpp')
-rw-r--r--src/irc/irc_message.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/irc/irc_message.cpp b/src/irc/irc_message.cpp
new file mode 100644
index 0000000..966a47c
--- /dev/null
+++ b/src/irc/irc_message.cpp
@@ -0,0 +1,61 @@
+#include <irc/irc_message.hpp>
+#include <iostream>
+
+IrcMessage::IrcMessage(std::string&& line)
+{
+ std::string::size_type pos;
+
+ // optional prefix
+ if (line[0] == ':')
+ {
+ pos = line.find(" ");
+ this->prefix = line.substr(1, pos - 1);
+ line = line.substr(pos + 1, std::string::npos);
+ }
+ // command
+ pos = line.find(" ");
+ this->command = line.substr(0, pos);
+ line = line.substr(pos + 1, std::string::npos);
+ // arguments
+ do
+ {
+ if (line[0] == ':')
+ {
+ this->arguments.emplace_back(line.substr(1, std::string::npos));
+ break ;
+ }
+ pos = line.find(" ");
+ this->arguments.emplace_back(line.substr(0, pos));
+ line = line.substr(pos + 1, std::string::npos);
+ } while (pos != std::string::npos);
+}
+
+IrcMessage::IrcMessage(std::string&& prefix,
+ std::string&& command,
+ std::vector<std::string>&& args):
+ prefix(std::move(prefix)),
+ command(std::move(command)),
+ arguments(std::move(args))
+{
+}
+
+IrcMessage::IrcMessage(std::string&& command,
+ std::vector<std::string>&& args):
+ prefix(),
+ command(std::move(command)),
+ arguments(std::move(args))
+{
+}
+
+std::ostream& operator<<(std::ostream& os, const IrcMessage& message)
+{
+ os << "IrcMessage";
+ os << "[" << message.command << "]";
+ for (const std::string& arg: message.arguments)
+ {
+ os << "{" << arg << "}";
+ }
+ if (!message.prefix.empty())
+ os << "(from: " << message.prefix << ")";
+ return os;
+}