|
|
|
@ -19,30 +19,49 @@ IRCMessage::IRCMessage(const IRCPrefix& defaultSender, const std::string& messag |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
enum class S { |
|
|
|
|
IRCv3Tags, |
|
|
|
|
Prefix, |
|
|
|
|
Command, |
|
|
|
|
Argument, |
|
|
|
|
Message |
|
|
|
|
} parseState = S::Prefix; |
|
|
|
|
} parseState = S::IRCv3Tags; |
|
|
|
|
|
|
|
|
|
auto it = message.begin() + 1; |
|
|
|
|
|
|
|
|
|
if (message[0] != ':') { |
|
|
|
|
if (message[0] != '@') { |
|
|
|
|
parseState = S::Prefix; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (message[0] != ':' && message[0] != '@') { |
|
|
|
|
// Set up parser for the format: "cmd arg :msg"
|
|
|
|
|
it = message.begin(); |
|
|
|
|
parseState = S::Command; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tokenize the message. Two formats may occur: |
|
|
|
|
* Tokenize the message. Three formats may occur: |
|
|
|
|
* :server.addr cmd arg :msg |
|
|
|
|
* @IRCv3Tag;tag2;tag3 :server.addr cmd arg :msg |
|
|
|
|
* cmd arg :msg |
|
|
|
|
*/ |
|
|
|
|
while (it != message.end()) { |
|
|
|
|
auto next = std::find(it, message.end(), ' '); |
|
|
|
|
|
|
|
|
|
switch (parseState) { |
|
|
|
|
case S::IRCv3Tags: |
|
|
|
|
{ |
|
|
|
|
std::string tagstr; |
|
|
|
|
std::copy(it, next, std::back_inserter(tagstr)); |
|
|
|
|
parseIRCv3Tags(tagstr); |
|
|
|
|
parseState = S::Prefix; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case S::Prefix: |
|
|
|
|
/* This condition happens if parseState started on IRCv3Tags. */ |
|
|
|
|
if (*it == ':') |
|
|
|
|
++it; |
|
|
|
|
|
|
|
|
|
m_sender = IRCPrefix(std::string(it, next)); |
|
|
|
|
parseState = S::Command; |
|
|
|
|
break; |
|
|
|
@ -82,3 +101,13 @@ const std::string& IRCMessage::operator[](int idx) const |
|
|
|
|
else |
|
|
|
|
return m_args[idx]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void IRCMessage::parseIRCv3Tags(const std::string& tagstr) |
|
|
|
|
{ |
|
|
|
|
auto it = tagstr.begin(); |
|
|
|
|
while (it != tagstr.end()) { |
|
|
|
|
auto next = std::find(it, tagstr.end(), ';'); |
|
|
|
|
m_tags.emplace_back(it, next); |
|
|
|
|
it = (next == tagstr.end()) ? next : next + 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|