1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

IRCClient: Use new format functions.

This commit is contained in:
asynts 2020-10-06 14:16:35 +02:00 committed by Andreas Kling
parent d2ca7ca017
commit da9c995a8c
7 changed files with 35 additions and 29 deletions

View file

@ -188,4 +188,10 @@ TEST_CASE(format_string_literal_as_pointer)
EXPECT_EQ(String::formatted("{:p}", literal), String::formatted("{:p}", reinterpret_cast<FlatPtr>(literal))); EXPECT_EQ(String::formatted("{:p}", literal), String::formatted("{:p}", reinterpret_cast<FlatPtr>(literal)));
} }
TEST_CASE(format_character)
{
char a = 'a';
EXPECT_EQ(String::formatted("{}", true ? a : 'b'), "a");
}
TEST_MAIN(Format) TEST_MAIN(Format)

View file

@ -71,7 +71,7 @@ IRCAppWindow::~IRCAppWindow()
void IRCAppWindow::update_title() void IRCAppWindow::update_title()
{ {
set_title(String::format("%s@%s:%d - IRC Client", m_client->nickname().characters(), m_client->hostname().characters(), m_client->port())); set_title(String::formatted("{}@{}:{} - IRC Client", m_client->nickname(), m_client->hostname(), m_client->port()));
} }
void IRCAppWindow::setup_client() void IRCAppWindow::setup_client()

View file

@ -92,7 +92,7 @@ void IRCChannel::handle_join(const String& nick, const String& hostmask)
add_member(nick, (char)0); add_member(nick, (char)0);
m_member_model->update(); m_member_model->update();
if (m_client.show_join_part_messages()) if (m_client.show_join_part_messages())
add_message(String::format("*** %s [%s] has joined %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::MidGreen); add_message(String::formatted("*** {} [{}] has joined {}", nick, hostmask, m_name), Color::MidGreen);
} }
void IRCChannel::handle_part(const String& nick, const String& hostmask) void IRCChannel::handle_part(const String& nick, const String& hostmask)
@ -106,7 +106,7 @@ void IRCChannel::handle_part(const String& nick, const String& hostmask)
} }
m_member_model->update(); m_member_model->update();
if (m_client.show_join_part_messages()) if (m_client.show_join_part_messages())
add_message(String::format("*** %s [%s] has parted from %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::MidGreen); add_message(String::formatted("*** {} [{}] has parted from {}", nick, hostmask, m_name), Color::MidGreen);
} }
void IRCChannel::handle_quit(const String& nick, const String& hostmask, const String& message) void IRCChannel::handle_quit(const String& nick, const String& hostmask, const String& message)
@ -119,15 +119,15 @@ void IRCChannel::handle_quit(const String& nick, const String& hostmask, const S
remove_member(nick); remove_member(nick);
} }
m_member_model->update(); m_member_model->update();
add_message(String::format("*** %s [%s] has quit (%s)", nick.characters(), hostmask.characters(), message.characters()), Color::MidGreen); add_message(String::formatted("*** {} [{}] has quit ({})", nick, hostmask, message), Color::MidGreen);
} }
void IRCChannel::handle_topic(const String& nick, const String& topic) void IRCChannel::handle_topic(const String& nick, const String& topic)
{ {
if (nick.is_null()) if (nick.is_null())
add_message(String::format("*** Topic is \"%s\"", topic.characters()), Color::MidBlue); add_message(String::formatted("*** Topic is \"{}\"", topic), Color::MidBlue);
else else
add_message(String::format("*** %s set topic to \"%s\"", nick.characters(), topic.characters()), Color::MidBlue); add_message(String::formatted("*** {} set topic to \"{}\"", nick, topic), Color::MidBlue);
} }
void IRCChannel::notify_nick_changed(const String& old_nick, const String& new_nick) void IRCChannel::notify_nick_changed(const String& old_nick, const String& new_nick)
@ -137,7 +137,7 @@ void IRCChannel::notify_nick_changed(const String& old_nick, const String& new_n
member.name = new_nick; member.name = new_nick;
m_member_model->update(); m_member_model->update();
if (m_client.show_nick_change_messages()) if (m_client.show_nick_change_messages())
add_message(String::format("~ %s changed nickname to %s", old_nick.characters(), new_nick.characters()), Color::MidMagenta); add_message(String::formatted("~ {} changed nickname to {}", old_nick, new_nick), Color::MidMagenta);
return; return;
} }
} }

View file

@ -134,7 +134,7 @@ void IRCClient::receive_from_server()
auto line = m_socket->read_line(PAGE_SIZE); auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) { if (line.is_null()) {
if (!m_socket->is_connected()) { if (!m_socket->is_connected()) {
out() << "IRCClient: Connection closed!"; outln("IRCClient: Connection closed!");
exit(1); exit(1);
} }
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -62,22 +62,22 @@ static String timestamp_string()
{ {
auto now = time(nullptr); auto now = time(nullptr);
auto* tm = localtime(&now); auto* tm = localtime(&now);
return String::format("%02u:%02u:%02u ", tm->tm_hour, tm->tm_min, tm->tm_sec); return String::formatted("{:02}:{:02}:{:02} ", tm->tm_hour, tm->tm_min, tm->tm_sec);
} }
void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color) void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color)
{ {
auto nick_string = String::format("<%c%s> ", prefix ? prefix : ' ', name.characters()); auto nick_string = String::formatted("<{}{}> ", prefix ? prefix : ' ', name.characters());
auto html = String::format( auto html = String::formatted(
"<span>%s</span>" "<span>{}</span>"
"<b>%s</b>" "<b>{}</b>"
"<span>%s</span>", "<span>{}</span>",
timestamp_string().characters(), timestamp_string(),
escape_html_entities(nick_string).characters(), escape_html_entities(nick_string),
escape_html_entities(text).characters()); escape_html_entities(text));
auto wrapper = Web::DOM::create_element(*m_document, Web::HTML::TagNames::div); auto wrapper = Web::DOM::create_element(*m_document, Web::HTML::TagNames::div);
wrapper->set_attribute(Web::HTML::AttributeNames::style, String::format("color: %s", color.to_string().characters())); wrapper->set_attribute(Web::HTML::AttributeNames::style, String::formatted("color: {}", color.to_string()));
wrapper->set_inner_html(html); wrapper->set_inner_html(html);
m_container_element->append_child(wrapper); m_container_element->append_child(wrapper);
m_document->force_layout(); m_document->force_layout();
@ -85,13 +85,13 @@ void IRCLogBuffer::add_message(char prefix, const String& name, const String& te
void IRCLogBuffer::add_message(const String& text, Color color) void IRCLogBuffer::add_message(const String& text, Color color)
{ {
auto html = String::format( auto html = String::formatted(
"<span>%s</span>" "<span>{}</span>"
"<span>%s</span>", "<span>{}</span>",
timestamp_string().characters(), timestamp_string(),
escape_html_entities(text).characters()); escape_html_entities(text));
auto wrapper = Web::DOM::create_element(*m_document, Web::HTML::TagNames::div); auto wrapper = Web::DOM::create_element(*m_document, Web::HTML::TagNames::div);
wrapper->set_attribute(Web::HTML::AttributeNames::style, String::format("color: %s", color.to_string().characters())); wrapper->set_attribute(Web::HTML::AttributeNames::style, String::formatted("color: {}", color.to_string()));
wrapper->set_inner_html(html); wrapper->set_inner_html(html);
m_container_element->append_child(wrapper); m_container_element->append_child(wrapper);
m_document->force_layout(); m_document->force_layout();

View file

@ -65,7 +65,7 @@ GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, GUI::ModelRo
case Column::Name: { case Column::Name: {
auto& window = m_client->window_at(index.row()); auto& window = m_client->window_at(index.row());
if (window.unread_count()) if (window.unread_count())
return String::format("%s (%d)", window.name().characters(), window.unread_count()); return String::formatted("{} ({})", window.name(), window.unread_count());
return window.name(); return window.name();
} }
} }

View file

@ -38,7 +38,7 @@ int main(int argc, char** argv)
} }
if (getuid() == 0) { if (getuid() == 0) {
warn() << "Refusing to run as root"; warnln("Refusing to run as root");
return 1; return 1;
} }
@ -54,17 +54,17 @@ int main(int argc, char** argv)
url = URL::create_with_url_or_path(app->args()[0]); url = URL::create_with_url_or_path(app->args()[0]);
if (url.protocol().to_lowercase() == "ircs") { if (url.protocol().to_lowercase() == "ircs") {
warn() << "Secure IRC over SSL/TLS (ircs) is not supported"; warnln("Secure IRC over SSL/TLS (ircs) is not supported");
return 1; return 1;
} }
if (url.protocol().to_lowercase() != "irc") { if (url.protocol().to_lowercase() != "irc") {
warn() << "Unsupported protocol"; warnln("Unsupported protocol");
return 1; return 1;
} }
if (url.host().is_empty()) { if (url.host().is_empty()) {
warn() << "Invalid URL"; warnln("Invalid URL");
return 1; return 1;
} }