diff options
author | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:41 +0530 |
---|---|---|
committer | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:41 +0530 |
commit | 4e4de7284e6e4d89d182ea459823bbec1e408842 (patch) | |
tree | 47e0ed5216b48649b138f168f61fddca2b0c076a /src/irc/irc_user.cpp | |
parent | dfb3a6edfacf2f16a8a63690b3e8058b6295d1a3 (diff) | |
parent | eda4b75b1cff83336e87da90efca9fd6b4ced2c7 (diff) | |
download | biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.gz biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.bz2 biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.xz biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.zip |
Updated version 3.0 from 'upstream/3.0'
with Debian dir 0f18938e98f5a466f36719f60cef0490163ab845
Diffstat (limited to 'src/irc/irc_user.cpp')
-rw-r--r-- | src/irc/irc_user.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/irc/irc_user.cpp b/src/irc/irc_user.cpp new file mode 100644 index 0000000..9fa3612 --- /dev/null +++ b/src/irc/irc_user.cpp @@ -0,0 +1,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; +} |