iid.cpp 1.07 KB
Newer Older
louiz’'s avatar
louiz’ committed
1 2
#include <utils/tolower.hpp>

3 4
#include <irc/iid.hpp>

louiz’'s avatar
louiz’ committed
5 6 7
Iid::Iid(const std::string& iid):
  is_channel(false),
  is_user(false)
8
{
louiz’'s avatar
louiz’ committed
9
  const std::string::size_type sep = iid.find_first_of("%!");
10 11
  if (sep != std::string::npos)
    {
louiz’'s avatar
louiz’ committed
12 13 14 15 16 17
      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));
18 19
    }
  else
louiz’'s avatar
louiz’ committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    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;
42
}
louiz’'s avatar
louiz’ committed
43

louiz’'s avatar
louiz’ committed
44
const std::string& Iid::get_server() const
louiz’'s avatar
louiz’ committed
45
{
louiz’'s avatar
louiz’ committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  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();
  }
louiz’'s avatar
louiz’ committed
63
}