~singpolyma/biboumi

ref: 1a09c965eb3723cdaab9ea556f30ffbc7f09a6dd biboumi/src/irc/irc_message.cpp -rw-r--r-- 1.5 KiB
1a09c965 — louiz’ Remove two sneaky log_debug 6 years ago
                                                                                
87aaacdb Florent Le Coz
7f580dbc Florent Le Coz
1a09c965 louiz’
b11126a1 Florent Le Coz
7f580dbc Florent Le Coz
1a09c965 louiz’
7f580dbc Florent Le Coz
1a09c965 louiz’
7f580dbc Florent Le Coz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}