# HG changeset patch # User Patric Stout # Date 2024-01-16 21:10:34 # Node ID 4df4e2dbb6705b7b9eee91436933bb69efe4d1bb # Parent 005e26a72bd24e50f66843721c80111c10401847 Codechange: minor bits and pieces related to fmt::format() (#11806) - Don't make run-time formatting what can be done compile-time. - Be explicit about run-time formatting. - Fix datetime printing. diff --git a/src/debug.cpp b/src/debug.cpp --- a/src/debug.cpp +++ b/src/debug.cpp @@ -95,7 +95,7 @@ void DumpDebugFacilityNames(std::back_in } else { fmt::format_to(output_iterator, ", "); } - fmt::format_to(output_iterator, i->name); + fmt::format_to(output_iterator, "{}", i->name); written = true; } if (written) { diff --git a/src/gamelog.cpp b/src/gamelog.cpp --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -242,7 +242,11 @@ void Gamelog::Print(std::functiongrfid); - fmt::format_to(output_iterator, action_type == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: "); + if (action_type == GLAT_LOAD) { + fmt::format_to(output_iterator, "Missing NewGRF: "); + } else { + fmt::format_to(output_iterator, "Removed NewGRF: "); + } AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); if (gm == grf_names.end()) { fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -93,7 +93,7 @@ static const char *GetAddressFormatStrin */ std::string NetworkAddress::GetAddressAsString(bool with_family) { - return fmt::format(GetAddressFormatString(this->GetAddress()->ss_family, with_family), this->GetHostname(), this->GetPort()); + return fmt::format(fmt::runtime(GetAddressFormatString(this->GetAddress()->ss_family, with_family)), this->GetHostname(), this->GetPort()); } /** diff --git a/src/newgrf_profiling.cpp b/src/newgrf_profiling.cpp --- a/src/newgrf_profiling.cpp +++ b/src/newgrf_profiling.cpp @@ -131,7 +131,7 @@ void NewGRFProfiler::Abort() */ std::string NewGRFProfiler::GetOutputFilename() const { - return fmt::format("{}grfprofile-{%Y%m%d-%H%M}-{:08X}.csv", FiosGetScreenshotDir(), fmt::localtime(time(nullptr)), BSWAP32(this->grffile->grfid)); + return fmt::format("{}grfprofile-{:%Y%m%d-%H%M}-{:08X}.csv", FiosGetScreenshotDir(), fmt::localtime(time(nullptr)), BSWAP32(this->grffile->grfid)); } /* static */ uint32_t NewGRFProfiler::FinishAll()