~singpolyma/biboumi

ref: ba61d2034058818fe76cef6b23f311259d37b3fe biboumi/src/irc/irc_user.cpp -rw-r--r-- 1.2 KiB
ba61d203 — louiz’ Empty the <command/> nodes before reusing them in our responses 4 years ago
                                                                                
bf7b05ef Florent Le Coz
acf769d8 Florent Le Coz
bf7b05ef Florent Le Coz
acf769d8 Florent Le Coz
a38b1769 Florent Le Coz
1a09c965 louiz’
bf7b05ef Florent Le Coz
acf769d8 Florent Le Coz
bf7b05ef Florent Le Coz
712b7bdf Florent Le Coz
bf7b05ef Florent Le Coz
acf769d8 Florent Le Coz
bf7b05ef Florent Le Coz
e840704b 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
#include <irc/irc_user.hpp>

#include <iostream>

IrcUser::IrcUser(const std::string& name,
                 const std::map<char, char>& prefix_to_mode)
{
  if (name.empty())
    return ;

  // One or more prefix (with multi-prefix support) may come before the
  // actual nick
  std::string::size_type name_begin = 0;
  while (name_begin != name.size())
    {
      const auto prefix = prefix_to_mode.find(name[name_begin]);
      // This is not a prefix
      if (prefix == prefix_to_mode.end())
        break;
      this->modes.insert(prefix->second);
      name_begin++;
    }

  const std::string::size_type sep = name.find('!', name_begin);
  if (sep == std::string::npos)
    this->nick = name.substr(name_begin);
  else
    {
      this->nick = name.substr(name_begin, sep-name_begin);
      this->host = name.substr(sep+1);
    }
}

IrcUser::IrcUser(const std::string& name):
  IrcUser(name, {})
{
}

void IrcUser::add_mode(const char mode)
{
  this->modes.insert(mode);
}

void IrcUser::remove_mode(const char mode)
{
  this->modes.erase(mode);
}

char IrcUser::get_most_significant_mode(const std::vector<char>& modes) const
{
  for (const char mode: modes)
    {
      if (this->modes.find(mode) != this->modes.end())
        return mode;
    }
  return 0;
}