Skip to content

Commit

Permalink
ChatPage: use libfmt to concatenate strings
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 1, 2024
1 parent 99ed296 commit 67b4a92
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ChatPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

#include <mpd/idle.h>

#include <fmt/core.h>

#include <string.h>
#include <stdlib.h>

using std::string_view_literals::operator""sv;

static constexpr char chat_channel[] = "chat";

class ChatPage final : public TextPage {
Expand Down Expand Up @@ -126,14 +130,14 @@ ChatPage::GetPrefix() noexcept
if (user == nullptr)
user = "nobody";

prefix = std::string("<") + user + "> ";
prefix = fmt::format("<{}>"sv, user);
return prefix;
}

void
ChatPage::SendMessage(struct mpdclient &c, const char *msg) noexcept
{
const std::string full_msg = GetPrefix() + LocaleToUtf8(msg).c_str();
const std::string full_msg = fmt::format("{}{}"sv, GetPrefix(), LocaleToUtf8(msg).c_str());

(void) mpdclient_cmd_send_message(c, chat_channel, full_msg.c_str());
}
Expand Down

0 comments on commit 67b4a92

Please sign in to comment.