From 7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 11 Jun 2014 02:37:11 +0200 Subject: Rewrite the whole IID usage IRC users and channels are now distinguished by the separator used in the IID (% or !). ref #2468 --- src/irc/iid.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/irc/iid.cpp') diff --git a/src/irc/iid.cpp b/src/irc/iid.cpp index 4694c0c..4893e9e 100644 --- a/src/irc/iid.cpp +++ b/src/irc/iid.cpp @@ -1,21 +1,63 @@ +#include + #include -Iid::Iid(const std::string& iid) +Iid::Iid(const std::string& iid): + is_channel(false), + is_user(false) { - std::string::size_type sep = iid.find("%"); + const std::string::size_type sep = iid.find_first_of("%!"); if (sep != std::string::npos) { - this->chan = iid.substr(0, sep); - sep++; + if (iid[sep] == '%') + this->is_channel = true; + else + this->is_user = true; + this->set_local(iid.substr(0, sep)); + this->set_server(iid.substr(sep + 1)); } else - { - this->chan = iid; - return; - } - this->server = iid.substr(sep); + this->set_server(iid); +} + +Iid::Iid(): + is_channel(false), + is_user(false) +{ +} + +void Iid::set_local(const std::string& loc) +{ + this->local = utils::tolower(loc); +} + +void Iid::set_server(const std::string& serv) +{ + this->server = utils::tolower(serv); +} + +const std::string& Iid::get_local() const +{ + return this->local; } -Iid::Iid() +const std::string& Iid::get_server() const { + return this->server; +} + +std::string Iid::get_sep() const +{ + if (this->is_channel) + return "%"; + else if (this->is_user) + return "!"; + return ""; +} + +namespace std { + const std::string to_string(const Iid& iid) + { + return iid.get_local() + iid.get_sep() + iid.get_server(); + } } -- cgit v1.2.3