~singpolyma/biboumi

f6e6b8905be010d7329316cea4546900ad8a2d19 — Florent Le Coz 8 years ago 594bac1
Use C++14 string_literals
4 files changed, 22 insertions(+), 15 deletions(-)

M src/bridge/bridge.cpp
M src/bridge/colors.cpp
M src/irc/irc_client.cpp
M src/network/socket_handler.cpp
M src/bridge/bridge.cpp => src/bridge/bridge.cpp +5 -3
@@ 10,6 10,8 @@
#include <iostream>
#include <tuple>

using namespace std::string_literals;

static const char* action_prefix = "\01ACTION ";

Bridge::Bridge(const std::string& user_jid, XmppComponent* xmpp, Poller* poller):


@@ 243,9 245,9 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho
  if (!author.empty())
    {
      IrcUser user(author);
      body = std::string("\u000303") + user.nick + (user.host.empty()?
                                                    std::string("\u0003: "):
                                                    (" (\u000310" + user.host + std::string("\u000303)\u0003: "))) + msg;
      body = "\u000303"s + user.nick + (user.host.empty()?
                                                    "\u0003: ":
                                                    (" (\u000310" + user.host + "\u000303)\u0003: ")) + msg;
    }
  else
    body = msg;

M src/bridge/colors.cpp => src/bridge/colors.cpp +4 -2
@@ 6,6 6,8 @@

#include <string.h>

using namespace std::string_literals;

static const char IRC_NUM_COLORS = 16;

static const char* irc_colors_to_css[IRC_NUM_COLORS] = {


@@ 130,10 132,10 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
      if (styles.italic)
        styles_str += "font-style:italic;";
      if (styles.fg != -1)
        styles_str += std::string("color:") +
        styles_str += "color:"s +
          irc_colors_to_css[styles.fg % IRC_NUM_COLORS] + ";";
      if (styles.bg != -1)
        styles_str += std::string("background-color:") +
        styles_str += "background-color:"s +
          irc_colors_to_css[styles.bg % IRC_NUM_COLORS] + ";";
      if (!styles_str.empty())
        {

M src/irc/irc_client.cpp => src/irc/irc_client.cpp +11 -8
@@ 10,6 10,9 @@
#include <iostream>
#include <stdexcept>

#include <string>
using namespace std::string_literals;

IrcClient::IrcClient(const std::string& hostname, const std::string& username, Bridge* bridge):
  hostname(hostname),
  username(username),


@@ 36,7 39,7 @@ void IrcClient::start()
{
  if (this->connected || this->connecting)
    return ;
  this->bridge->send_xmpp_message(this->hostname, "", std::string("Connecting to ") +
  this->bridge->send_xmpp_message(this->hostname, "", "Connecting to "s +
                                  this->hostname + ":" + "6667");
  this->connect(this->hostname, "6667");
}


@@ 44,7 47,7 @@ void IrcClient::start()
void IrcClient::on_connection_failed(const std::string& reason)
{
  this->bridge->send_xmpp_message(this->hostname, "",
                                  std::string("Connection failed: ") + reason);
                                  "Connection failed: "s + reason);
}

void IrcClient::on_connected()


@@ 244,7 247,7 @@ void IrcClient::on_notice(const IrcMessage& message)
    this->bridge->send_xmpp_message(this->hostname, from, body);
  else
    {
      IrcMessage modified_message(std::move(from), "PRIVMSG", {to, std::string("\u000303[notice]\u0003 ") + body});
      IrcMessage modified_message(std::move(from), "PRIVMSG", {to, "\u000303[notice]\u0003 "s + body});
      this->on_channel_message(modified_message);
    }
}


@@ 344,7 347,7 @@ void IrcClient::on_channel_message(const IrcMessage& message)
    {
      if (body.substr(1, 6) == "ACTION")
        this->bridge->send_message(iid, nick,
                  std::string("/me") + body.substr(7, body.size() - 8), muc);
                  "/me"s + body.substr(7, body.size() - 8), muc);
    }
  else
    this->bridge->send_message(iid, nick, body, muc);


@@ 486,7 489,7 @@ void IrcClient::on_error(const IrcMessage& message)
    this->bridge->send_muc_leave(std::move(iid), std::move(own_nick), leave_message, true);
  }
  this->channels.clear();
  this->send_gateway_message(std::string("ERROR: ") + leave_message);
  this->send_gateway_message("ERROR: "s + leave_message);
}

void IrcClient::on_quit(const IrcMessage& message)


@@ 583,7 586,7 @@ void IrcClient::on_channel_mode(const IrcMessage& message)
          mode_arguments += message.arguments[i];
        }
    }
  this->bridge->send_message(iid, "", std::string("Mode ") + iid.chan +
  this->bridge->send_message(iid, "", "Mode "s + iid.chan +
                                      " [" + mode_arguments + "] by " + user.nick,
                             true);
  const IrcChannel* channel = this->get_channel(iid.chan);


@@ 661,7 664,7 @@ void IrcClient::on_channel_mode(const IrcMessage& message)
void IrcClient::on_user_mode(const IrcMessage& message)
{
  this->bridge->send_xmpp_message(this->hostname, "",
                                  std::string("User mode for ") + message.arguments[0] +
                                  "User mode for "s + message.arguments[0] +
                                  " is [" + message.arguments[1] + "]");
}



@@ 685,5 688,5 @@ void IrcClient::leave_dummy_channel(const std::string& exit_message)
  this->dummy_channel.joined = false;
  this->dummy_channel.joining = false;
  this->dummy_channel.remove_all_users();
  this->bridge->send_muc_leave(Iid(std::string("%") + this->hostname), std::string(this->current_nick), exit_message, true);
  this->bridge->send_muc_leave(Iid("%"s + this->hostname), std::string(this->current_nick), exit_message, true);
}

M src/network/socket_handler.cpp => src/network/socket_handler.cpp +2 -2
@@ 42,7 42,7 @@ void SocketHandler::init_socket()
  const int existing_flags = ::fcntl(this->socket, F_GETFL, 0);
  if ((existing_flags == -1) ||
      (::fcntl(this->socket, F_SETFL, existing_flags | O_NONBLOCK) == -1))
    throw std::runtime_error(std::string("Could not initialize socket: ") + strerror(errno));
    throw std::runtime_error("Could not initialize socket: "s + strerror(errno));
}

void SocketHandler::connect(const std::string& address, const std::string& port)


@@ 70,7 70,7 @@ void SocketHandler::connect(const std::string& address, const std::string& port)

      if (res != 0)
        {
          log_warning(std::string("getaddrinfo failed: ") + gai_strerror(res));
          log_warning("getaddrinfo failed: "s + gai_strerror(res));
          this->close();
          this->on_connection_failed(gai_strerror(res));
          return ;