diff --git a/po/cs.po b/po/cs.po index ae83b560..7650364e 100644 --- a/po/cs.po +++ b/po/cs.po @@ -1211,8 +1211,8 @@ msgstr "Právě přehrávaná skladba" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/da.po b/po/da.po index 68ce79f8..4d983747 100644 --- a/po/da.po +++ b/po/da.po @@ -1209,8 +1209,8 @@ msgstr "Nummer der afspilles" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kb/sek" +msgid "{} kbps" +msgstr "{} kb/sek" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/de.po b/po/de.po index 445cc5ef..1061d711 100644 --- a/po/de.po +++ b/po/de.po @@ -1200,8 +1200,8 @@ msgstr "Gerade laufendes Lied" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kB/s" +msgid "{} kbps" +msgstr "{} kB/s" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/en.po b/po/en.po index f78f3768..5725d7e9 100644 --- a/po/en.po +++ b/po/en.po @@ -1191,8 +1191,8 @@ msgstr "Currently playing song" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/eo.po b/po/eo.po index b4ba7ef4..5a44bfdb 100644 --- a/po/eo.po +++ b/po/eo.po @@ -1196,8 +1196,8 @@ msgstr "Nuntempe ludata kanto" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kilobitoj/sek" +msgid "{} kbps" +msgstr "{} kilobitoj/sek" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/es.po b/po/es.po index 341f7e4a..34eb6a57 100644 --- a/po/es.po +++ b/po/es.po @@ -1205,8 +1205,8 @@ msgstr "Canción reproducida" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/fa.po b/po/fa.po index 8a073b51..1f462554 100644 --- a/po/fa.po +++ b/po/fa.po @@ -1185,7 +1185,7 @@ msgstr "" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" +msgid "{} kbps" msgstr "" #: src/SongPage.cxx:536 diff --git a/po/fi.po b/po/fi.po index 23dc0f5b..6a40581d 100644 --- a/po/fi.po +++ b/po/fi.po @@ -1198,8 +1198,8 @@ msgstr "" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kb/s" +msgid "{} kbps" +msgstr "{} kb/s" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/fr.po b/po/fr.po index 5cb9d8bb..be79b3a5 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1203,8 +1203,8 @@ msgstr "Chanson actuellement jouée" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d ko/s" +msgid "{} kbps" +msgstr "{} ko/s" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/gl.po b/po/gl.po index f7721a07..de1359b1 100644 --- a/po/gl.po +++ b/po/gl.po @@ -1209,8 +1209,8 @@ msgstr "Canción que se está reproducindo" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/he.po b/po/he.po index e6dd3da4..3b90b7ea 100644 --- a/po/he.po +++ b/po/he.po @@ -1190,8 +1190,8 @@ msgstr "שיר עכשווי" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/hu.po b/po/hu.po index 92b5741d..50353727 100644 --- a/po/hu.po +++ b/po/hu.po @@ -1205,8 +1205,8 @@ msgstr "Jelenlegi zene" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/ie.po b/po/ie.po index d1e08c6a..ad0a87bb 100644 --- a/po/ie.po +++ b/po/ie.po @@ -1195,8 +1195,8 @@ msgstr "Reproductet canzone" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kops" +msgid "{} kbps" +msgstr "{} kops" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/it.po b/po/it.po index f31228a4..addc604b 100644 --- a/po/it.po +++ b/po/it.po @@ -1198,8 +1198,8 @@ msgstr "Brano riprodotto" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kB/s" +msgid "{} kbps" +msgstr "{} kB/s" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/ja.po b/po/ja.po index fa6e3d4b..dc3d3bc4 100644 --- a/po/ja.po +++ b/po/ja.po @@ -1189,7 +1189,7 @@ msgstr "" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" +msgid "{} kbps" msgstr "" #: src/SongPage.cxx:536 diff --git a/po/ko.po b/po/ko.po index 4a9078da..f6ae17fe 100644 --- a/po/ko.po +++ b/po/ko.po @@ -1189,8 +1189,8 @@ msgstr "지금 연주 중인 곡" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/lt.po b/po/lt.po index 3bd8ed1e..055b4720 100644 --- a/po/lt.po +++ b/po/lt.po @@ -1194,8 +1194,8 @@ msgstr "Šiuo metu grojama daina" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/nb.po b/po/nb.po index fdef4c58..28c99d8e 100644 --- a/po/nb.po +++ b/po/nb.po @@ -1219,8 +1219,8 @@ msgstr "Sang som spilles nå" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/ncmpc.pot b/po/ncmpc.pot index 8a3167bd..1d804cf9 100644 --- a/po/ncmpc.pot +++ b/po/ncmpc.pot @@ -1186,7 +1186,7 @@ msgstr "" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" +msgid "{} kbps" msgstr "" #: src/SongPage.cxx:536 diff --git a/po/nl.po b/po/nl.po index baa3f24d..b9dc4f67 100644 --- a/po/nl.po +++ b/po/nl.po @@ -1201,8 +1201,8 @@ msgstr "" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/pl.po b/po/pl.po index 73d50dbf..145428c7 100644 --- a/po/pl.po +++ b/po/pl.po @@ -1193,8 +1193,8 @@ msgstr "Obecnie odtwarzany utwór" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/pt.po b/po/pt.po index 3878916d..1062e461 100644 --- a/po/pt.po +++ b/po/pt.po @@ -1201,8 +1201,8 @@ msgstr "Música atualmente em reprodução" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/pt_BR.po b/po/pt_BR.po index 05a54efb..56258e99 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -1201,8 +1201,8 @@ msgstr "Faixa atualmente em reprodução" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/ru.po b/po/ru.po index 5ec0dcd1..71cc393a 100644 --- a/po/ru.po +++ b/po/ru.po @@ -1193,8 +1193,8 @@ msgstr "Проигрываемая композиция" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d кбит/с" +msgid "{} kbps" +msgstr "{} кбит/с" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/sk.po b/po/sk.po index aacb61b6..79dd7d6d 100644 --- a/po/sk.po +++ b/po/sk.po @@ -1194,8 +1194,8 @@ msgstr "Momentálne prehrávaná pieseň" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/sv.po b/po/sv.po index 4c91b0a9..f94e5189 100644 --- a/po/sv.po +++ b/po/sv.po @@ -1197,8 +1197,8 @@ msgstr "Nuvarande spelar låt" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d kb/s" +msgid "{} kbps" +msgstr "{} kb/s" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/tr.po b/po/tr.po index a6b97c9b..28816db7 100644 --- a/po/tr.po +++ b/po/tr.po @@ -1151,8 +1151,8 @@ msgstr "Çalan şarkı" #: src/SongPage.cxx:472 #, c-format -msgid "%d kbps" -msgstr "%d kbps" +msgid "{} kbps" +msgstr "{} kbps" #: src/SongPage.cxx:556 msgid "Song" diff --git a/po/uk.po b/po/uk.po index ea4cab4e..522d8c8e 100644 --- a/po/uk.po +++ b/po/uk.po @@ -1204,8 +1204,8 @@ msgstr "Пісня, що зараз програється" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "%d кбіт/с" +msgid "{} kbps" +msgstr "{} кбіт/с" #: src/SongPage.cxx:536 msgid "Song" diff --git a/po/zh_CN.po b/po/zh_CN.po index e1991750..151fb87e 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -1197,8 +1197,8 @@ msgstr "当前播放曲目" #: src/SongPage.cxx:454 #, c-format -msgid "%d kbps" -msgstr "码率 %d kbps" +msgid "{} kbps" +msgstr "码率 {} kbps" #: src/SongPage.cxx:536 msgid "Song" diff --git a/src/SongPage.cxx b/src/SongPage.cxx index 7574d8f4..5ae54ee9 100644 --- a/src/SongPage.cxx +++ b/src/SongPage.cxx @@ -15,6 +15,7 @@ #include "charset.hxx" #include "time_format.hxx" #include "mpdclient.hxx" +#include "lib/fmt/ToSpan.hxx" #include "util/LocaleString.hxx" #include "util/StringAPI.hxx" #include "util/StringStrip.hxx" @@ -31,6 +32,8 @@ #include #include +using std::string_view_literals::operator""sv; + enum { LABEL_LENGTH = MPD_TAG_COUNT, LABEL_PATH, @@ -306,7 +309,7 @@ SongPage::AddSong(const struct mpd_song *song) noexcept char length[16]; format_duration_short(length, mpd_song_get_duration(song)); - const char *value = length; + std::string_view value = length; char buffer[64]; @@ -315,16 +318,12 @@ SongPage::AddSong(const struct mpd_song *song) noexcept format_duration_short(start, mpd_song_get_start(song)); format_duration_short(end, mpd_song_get_end(song)); - snprintf(buffer, sizeof(buffer), "%s [%s-%s]\n", - length, start, end); - value = buffer; + value = FmtTruncate(buffer, "{} [{}-{}]"sv, length, start, end); } else if (mpd_song_get_start(song) > 0) { char start[16]; format_duration_short(start, mpd_song_get_start(song)); - snprintf(buffer, sizeof(buffer), "%s [%s-]\n", - length, start); - value = buffer; + value = FmtTruncate(buffer, "{} [{}-]"sv, length, start); } AppendLine(get_tag_label(LABEL_LENGTH), value, @@ -380,37 +379,37 @@ SongPage::AddStats(struct mpd_connection *connection) noexcept return true; } -static void -audio_format_to_string(char *buffer, size_t size, - const struct mpd_audio_format *format) noexcept +[[nodiscard]] [[gnu::pure]] +static std::string_view +audio_format_to_string(std::span buffer, + const struct mpd_audio_format &format) noexcept { - if (format->bits == MPD_SAMPLE_FORMAT_FLOAT) { - snprintf(buffer, size, "%u:f:%u", - format->sample_rate, - format->channels); - return; + if (format.bits == MPD_SAMPLE_FORMAT_FLOAT) { + return FmtTruncate(buffer, "{}:f:{}"sv, + format.sample_rate, + format.channels); } - if (format->bits == MPD_SAMPLE_FORMAT_DSD) { - if (format->sample_rate > 0 && - format->sample_rate % 44100 == 0) { + if (format.bits == MPD_SAMPLE_FORMAT_DSD) { + if (format.sample_rate > 0 && + format.sample_rate % 44100 == 0) { /* use shortcuts such as "dsd64" which implies the sample rate */ - snprintf(buffer, size, "dsd%u:%u", - format->sample_rate * 8 / 44100, - format->channels); - return; + + return FmtTruncate(buffer, "dsd{}:{}"sv, + format.sample_rate * 8 / 44100, + format.channels); } - snprintf(buffer, size, "%u:dsd:%u", - format->sample_rate, - format->channels); - return; + return FmtTruncate(buffer, "{}:dsd:{}"sv, + format.sample_rate, + format.channels); } - snprintf(buffer, size, "%u:%u:%u", - format->sample_rate, format->bits, - format->channels); + return FmtTruncate(buffer, "{}:{}:{}"sv, + format.sample_rate, + format.bits, + format.channels); } void @@ -444,11 +443,11 @@ SongPage::Update(struct mpdclient &c, unsigned) noexcept lines.emplace_back(_("Currently playing song")); AddSong(played_song); - if (mpd_status_get_kbit_rate(c.status) > 0) { + if (const auto kbit_rate = mpd_status_get_kbit_rate(c.status); + kbit_rate > 0) { char buf[16]; - snprintf(buf, sizeof(buf), _("%d kbps"), - mpd_status_get_kbit_rate(c.status)); - AppendLine(get_tag_label(LABEL_BITRATE), buf, + AppendLine(get_tag_label(LABEL_BITRATE), + FmtTruncate(buf, _("{} kbps"), kbit_rate), max_tag_label_width); } @@ -456,8 +455,8 @@ SongPage::Update(struct mpdclient &c, unsigned) noexcept mpd_status_get_audio_format(c.status); if (format) { char buf[32]; - audio_format_to_string(buf, sizeof(buf), format); - AppendLine(get_tag_label(LABEL_FORMAT), buf, + AppendLine(get_tag_label(LABEL_FORMAT), + audio_format_to_string(buf, *format), max_tag_label_width); }