Skip to content

Commit

Permalink
lib/fmt: remove even more now-broken uses of FMT_STRING
Browse files Browse the repository at this point in the history
MPD stopped building since fmt 11.1.0; see
<fmtlib/fmt#4304>. The first commit
fixing this was 9db7144, followed by 5de0909 (both on the
unstable branch).

This commit removes what the author believes to be the remaining
uses in the MPD codebase.
  • Loading branch information
sp1ff committed Jan 21, 2025
1 parent b24b3c1 commit 194ecd6
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/PlaylistDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void
playlist_vector_save(BufferedOutputStream &os, const PlaylistVector &pv)
{
for (const PlaylistInfo &pi : pv) {
os.Fmt(FMT_STRING(PLAYLIST_META_BEGIN "{}\n"), pi.name);
os.Fmt(PLAYLIST_META_BEGIN "{}\n", pi.name);
if (!IsNegative(pi.mtime))
os.Fmt(FMT_STRING("mtime: {}\n"),
os.Fmt("mtime: {}\n",
std::chrono::system_clock::to_time_t(pi.mtime));
os.Write("playlist_end\n");
}
Expand Down
4 changes: 2 additions & 2 deletions src/PlaylistSave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ playlist_print_path(BufferedOutputStream &os, const Path path)
"narrow" charset (i.e. CP_ACP) is incapable of storing all
Unicode paths */
try {
os.Fmt(FMT_STRING("{}\n"), path.ToUTF8Throw());
os.Fmt("{}\n", path.ToUTF8Throw());
} catch (...) {
}
#else
os.Fmt(FMT_STRING("{}\n"), path.c_str());
os.Fmt("{}\n", path.c_str());
#endif
}

Expand Down
20 changes: 10 additions & 10 deletions src/SongSave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,54 @@ static void
range_save(BufferedOutputStream &os, unsigned start_ms, unsigned end_ms)
{
if (end_ms > 0)
os.Fmt(FMT_STRING("Range: {}-{}\n"), start_ms, end_ms);
os.Fmt("Range: {}-{}\n", start_ms, end_ms);
else if (start_ms > 0)
os.Fmt(FMT_STRING("Range: {}-\n"), start_ms);
os.Fmt("Range: {}-\n", start_ms);
}

void
song_save(BufferedOutputStream &os, const Song &song)
{
os.Fmt(FMT_STRING(SONG_BEGIN "{}\n"), song.filename);
os.Fmt(SONG_BEGIN "{}\n", song.filename);

if (!song.target.empty())
os.Fmt(FMT_STRING("Target: {}\n"), song.target);
os.Fmt("Target: {}\n", song.target);

range_save(os, song.start_time.ToMS(), song.end_time.ToMS());

tag_save(os, song.tag);

if (song.audio_format.IsDefined())
os.Fmt(FMT_STRING("Format: {}\n"), song.audio_format);
os.Fmt("Format: {}\n", song.audio_format);

if (song.in_playlist)
os.Write("InPlaylist: yes\n");

if (!IsNegative(song.mtime))
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
os.Fmt(SONG_MTIME ": {}\n",
std::chrono::system_clock::to_time_t(song.mtime));

if (!IsNegative(song.added))
os.Fmt(FMT_STRING(SONG_ADDED ": {}\n"),
os.Fmt(SONG_ADDED ": {}\n",
std::chrono::system_clock::to_time_t(song.added));
os.Write(SONG_END "\n");
}

void
song_save(BufferedOutputStream &os, const DetachedSong &song)
{
os.Fmt(FMT_STRING(SONG_BEGIN "{}\n"), song.GetURI());
os.Fmt(SONG_BEGIN "{}\n", song.GetURI());

range_save(os, song.GetStartTime().ToMS(), song.GetEndTime().ToMS());

tag_save(os, song.GetTag());

if (!IsNegative(song.GetLastModified()))
os.Fmt(FMT_STRING(SONG_MTIME ": {}\n"),
os.Fmt(SONG_MTIME ": {}\n",
std::chrono::system_clock::to_time_t(song.GetLastModified()));

if (!IsNegative(song.GetAdded()))
os.Fmt(FMT_STRING(SONG_ADDED ": {}\n"),
os.Fmt(SONG_ADDED ": {}\n",
std::chrono::system_clock::to_time_t(song.GetAdded()));
os.Write(SONG_END "\n");
}
Expand Down
4 changes: 2 additions & 2 deletions src/TagPrint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ tag_print_types_available(Response &r) noexcept
{
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
if (global_tag_mask.Test(TagType(i)))
r.Fmt(FMT_STRING("tagtype: {}\n"), tag_item_names[i]);
r.Fmt("tagtype: {}\n", tag_item_names[i]);
}

void
tag_print(Response &r, TagType type, std::string_view value) noexcept
tag_print(Response &r, TagType type, std::string_view _value) noexcept
{
const std::string_view value{_value};
r.Fmt("{}: {}\n", tag_item_names[type], value);
Expand Down
4 changes: 2 additions & 2 deletions src/TagSave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ void
tag_save(BufferedOutputStream &os, const Tag &tag)
{
if (!tag.duration.IsNegative())
os.Fmt(FMT_STRING(SONG_TIME "{}\n"), tag.duration.ToDoubleS());
os.Fmt(SONG_TIME "{}\n", tag.duration.ToDoubleS());

if (tag.has_playlist)
os.Write("Playlist: yes\n");

for (const auto &i : tag)
os.Fmt(FMT_STRING("{}: {}\n"),
os.Fmt("{}: {}\n",
tag_item_names[i.type], i.value);
}
4 changes: 2 additions & 2 deletions src/client/ProtocolFeature.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ protocol_features_print(Client &client, Response &r) noexcept
const auto protocol_feature = client.GetProtocolFeatures();
for (unsigned i = 0; i < PF_NUM_OF_ITEM_TYPES; i++)
if (protocol_feature.Test(ProtocolFeatureType(i)))
r.Fmt(FMT_STRING("feature: {}\n"), protocol_feature_names[i]);
r.Fmt("feature: {}\n", protocol_feature_names[i]);
}

void
protocol_features_print_all(Response &r) noexcept
{
for (unsigned i = 0; i < PF_NUM_OF_ITEM_TYPES; i++)
r.Fmt(FMT_STRING("feature: {}\n"), protocol_feature_names[i]);
r.Fmt("feature: {}\n", protocol_feature_names[i]);
}

ProtocolFeatureType
Expand Down
2 changes: 1 addition & 1 deletion src/command/OtherCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ handle_config(Client &client, [[maybe_unused]] Request args, Response &r)
#endif

if (const auto spl_path = map_spl_path(); !spl_path.IsNull())
r.Fmt(FMT_STRING("playlist_directory: {}\n"), spl_path.ToUTF8());
r.Fmt("playlist_directory: {}\n", spl_path.ToUTF8());

#ifdef HAVE_PCRE
r.Write("pcre: 1\n");
Expand Down
4 changes: 2 additions & 2 deletions src/command/StickerCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ handle_sticker(Client &client, Request args, Response &r)
/* set */
if (args.size() == 5 && StringIsEqual(cmd, "set"))
return handler->Set(uri, sticker_name, args[4]);

/* inc */
if (args.size() == 5 && StringIsEqual(cmd, "inc"))
return handler->Inc(uri, sticker_name, args[4]);
Expand Down Expand Up @@ -550,6 +550,6 @@ handle_sticker_types(Client &client, Request args, Response &r)
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
if (sticker_allowed_tags.Test(TagType(i)) &&
tag_mask.Test(TagType(i)))
r.Fmt(FMT_STRING("stickertype: {}\n"), tag_item_names[i]);
r.Fmt("stickertype: {}\n", tag_item_names[i]);
return CommandResult::OK;
}
6 changes: 3 additions & 3 deletions src/db/plugins/simple/DatabaseSave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ void
db_save_internal(BufferedOutputStream &os, const Directory &music_root)
{
os.Write(DIRECTORY_INFO_BEGIN "\n");
os.Fmt(FMT_STRING(DB_FORMAT_PREFIX "{}\n"), DB_FORMAT);
os.Fmt(DB_FORMAT_PREFIX "{}\n", DB_FORMAT);
os.Write(DIRECTORY_MPD_VERSION VERSION "\n");
os.Fmt(FMT_STRING(DIRECTORY_FS_CHARSET "{}\n"), GetFSCharset());
os.Fmt(DIRECTORY_FS_CHARSET "{}\n", GetFSCharset());

for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
if (IsTagEnabled(i))
os.Fmt(FMT_STRING(DB_TAG_PREFIX "{}\n"),
os.Fmt(DB_TAG_PREFIX "{}\n",
tag_item_names[i]);

os.Write(DIRECTORY_INFO_END "\n");
Expand Down
10 changes: 5 additions & 5 deletions src/db/plugins/simple/DirectorySave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
if (!directory.IsRoot()) {
const char *type = DeviceToTypeString(directory.device);
if (type != nullptr)
os.Fmt(FMT_STRING(DIRECTORY_TYPE "{}\n"), type);
os.Fmt(DIRECTORY_TYPE "{}\n", type);

if (!IsNegative(directory.mtime))
os.Fmt(FMT_STRING(DIRECTORY_MTIME "{}\n"),
os.Fmt(DIRECTORY_MTIME "{}\n",
std::chrono::system_clock::to_time_t(directory.mtime));

os.Fmt(FMT_STRING(DIRECTORY_BEGIN "{}\n"), directory.GetPath());
os.Fmt(DIRECTORY_BEGIN "{}\n", directory.GetPath());
}

for (const auto &child : directory.children) {
if (child.IsMount())
continue;

os.Fmt(FMT_STRING(DIRECTORY_DIR "{}\n"), child.GetName());
os.Fmt(DIRECTORY_DIR "{}\n", child.GetName());
directory_save(os, child);
}

Expand All @@ -90,7 +90,7 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
playlist_vector_save(os, directory.playlists);

if (!directory.IsRoot())
os.Fmt(FMT_STRING(DIRECTORY_END "{}\n"), directory.GetPath());
os.Fmt(DIRECTORY_END "{}\n", directory.GetPath());
}

static bool
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/DecoderPrint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ decoder_plugin_print(Response &r,

if (plugin.suffixes_function != nullptr)
for (const auto &i : plugin.suffixes_function())
r.Fmt(FMT_STRING("suffix: {}\n"), i);
r.Fmt("suffix: {}\n", i);

if (plugin.mime_types != nullptr)
for (p = plugin.mime_types; *p != nullptr; ++p)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/icu/Converter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IcuConverter::Create(const char *charset)
UConverter *converter = ucnv_open(charset, &code);
if (converter == nullptr)
throw ICU::MakeError(code,
FmtBuffer<256>(FMT_STRING("Failed to initialize charset {:?}"),
FmtBuffer<256>("Failed to initialize charset {:?}",
charset));

return std::unique_ptr<IcuConverter>(new IcuConverter(converter));
Expand All @@ -54,7 +54,7 @@ IcuConverter::Create(const char *charset)
iconv_close(to);
if (from != (iconv_t)-1)
iconv_close(from);
throw FmtErrno(e, FMT_STRING("Failed to initialize charset {:?}"),
throw FmtErrno(e, "Failed to initialize charset {:?}",
charset);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mixer/Memento.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ MixerMemento::LoadSoftwareVolumeState(const char *line, MultipleOutputs &outputs
void
MixerMemento::SaveSoftwareVolumeState(BufferedOutputStream &os) const
{
os.Fmt(FMT_STRING(SW_VOLUME_STATE "{}\n"), volume_software_set);
os.Fmt(SW_VOLUME_STATE "{}\n", volume_software_set);
}
2 changes: 1 addition & 1 deletion src/output/State.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ audio_output_state_save(BufferedOutputStream &os,
const auto &ao = outputs.Get(i);
const std::scoped_lock lock{ao.mutex};

os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"),
os.Fmt(AUDIO_DEVICE_STATE "{}:{}\n",
(unsigned)ao.IsEnabled(), ao.GetName());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/playlist/Length.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ playlist_provider_length(Response &r,
playtime += get_duration(*song);
i++;
}
r.Fmt(FMT_STRING("songs: {}\n"), i);
r.Fmt("songs: {}\n", i);
const auto seconds = std::chrono::round<std::chrono::seconds>(playtime);
r.Fmt(FMT_STRING("playtime: {}\n"), seconds.count());
r.Fmt("playtime: {}\n", seconds.count());
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/playlist/Print.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ playlist_provider_search_print(Response &r,

if (detail) {
song_print_info(r, *song);
r.Fmt(FMT_STRING("Pos: {}\n"), position);
r.Fmt("Pos: {}\n", position);
} else
/* fallback if no detail was requested or no
detail was available */
Expand Down
22 changes: 11 additions & 11 deletions src/queue/PlaylistState.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,33 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
default:
os.Write(PLAYLIST_STATE_FILE_STATE_PLAY "\n");
}
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_CURRENT "{}\n",
playlist.queue.OrderToPosition(playlist.current));
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_TIME "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_TIME "{}\n",
player_status.elapsed_time.ToDoubleS());
} else {
os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n");

if (playlist.current >= 0)
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CURRENT "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_CURRENT "{}\n",
playlist.queue.OrderToPosition(playlist.current));
}

os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_RANDOM "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_RANDOM "{}\n",
(unsigned)playlist.queue.random);
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_REPEAT "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_REPEAT "{}\n",
(unsigned)playlist.queue.repeat);
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_SINGLE "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_SINGLE "{}\n",
SingleToString(playlist.queue.single));
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CONSUME "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_CONSUME "{}\n",
ConsumeToString(playlist.queue.consume));
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_CROSSFADE "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_CROSSFADE "{}\n",
pc.GetCrossFade().count());
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDB "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_MIXRAMPDB "{}\n",
pc.GetMixRampDb());
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDELAY "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_MIXRAMPDELAY "{}\n",
pc.GetMixRampDelay().count());
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_LOADED_PLAYLIST "{}\n"),
os.Fmt(PLAYLIST_STATE_FILE_LOADED_PLAYLIST "{}\n",
playlist.GetLastLoadedPlaylist());
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n");
queue_save(os, playlist.queue);
Expand Down
8 changes: 4 additions & 4 deletions src/queue/Print.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ queue_print_song_info(Response &r, const Queue &queue,
unsigned position)
{
song_print_info(r, queue.Get(position));
r.Fmt(FMT_STRING("Pos: {}\nId: {}\n"),
r.Fmt("Pos: {}\nId: {}\n",
position, queue.PositionToId(position));

uint8_t priority = queue.GetPriorityAtPosition(position);
if (priority != 0)
r.Fmt(FMT_STRING("Prio: {}\n"), priority);
r.Fmt("Prio: {}\n", priority);
}

void
Expand All @@ -56,7 +56,7 @@ queue_print_uris(Response &r, const Queue &queue,
assert(end <= queue.GetLength());

for (unsigned i = start; i < end; ++i) {
r.Fmt(FMT_STRING("{}:"), i);
r.Fmt("{}:", i);
song_print_uri(r, queue.Get(i));
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ queue_print_changes_position(Response &r, const Queue &queue,

for (unsigned i = start; i < end; i++)
if (queue.IsNewerAtPosition(i, version))
r.Fmt(FMT_STRING("cpos: {}\nId: {}\n"),
r.Fmt("cpos: {}\nId: {}\n",
i, queue.PositionToId(i));
}

Expand Down
4 changes: 2 additions & 2 deletions src/queue/Save.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void
queue_save_database_song(BufferedOutputStream &os,
int idx, const DetachedSong &song)
{
os.Fmt(FMT_STRING("{}:{}\n"), idx, song.GetURI());
os.Fmt("{}:{}\n", idx, song.GetURI());
}

static void
Expand Down Expand Up @@ -53,7 +53,7 @@ queue_save(BufferedOutputStream &os, const Queue &queue)
for (unsigned i = 0; i < queue.GetLength(); i++) {
uint8_t prio = queue.GetPriorityAtPosition(i);
if (prio != 0)
os.Fmt(FMT_STRING(PRIO_LABEL "{}\n"), prio);
os.Fmt(PRIO_LABEL "{}\n", prio);

queue_save_song(os, i, queue.Get(i));
}
Expand Down
2 changes: 1 addition & 1 deletion src/song/PrioritySongFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
std::string
PrioritySongFilter::ToExpression() const noexcept
{
return fmt::format(FMT_STRING("(prio >= {})"), value);
return fmt::format("(prio >= {})", value);
}

bool
Expand Down
Loading

0 comments on commit 194ecd6

Please sign in to comment.