Changeset - r28481:4df4e2dbb670
[Not reviewed]
master
0 4 0
Patric Stout - 11 months ago 2024-01-16 21:10:34
truebrain@openttd.org
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.
4 files changed with 8 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/debug.cpp
Show inline comments
 
@@ -92,13 +92,13 @@ void DumpDebugFacilityNames(std::back_in
 
	for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) {
 
		if (!written) {
 
			fmt::format_to(output_iterator, "List of debug facility names:\n");
 
		} else {
 
			fmt::format_to(output_iterator, ", ");
 
		}
 
		fmt::format_to(output_iterator, i->name);
 
		fmt::format_to(output_iterator, "{}", i->name);
 
		written = true;
 
	}
 
	if (written) {
 
		fmt::format_to(output_iterator, "\n\n");
 
	}
 
}
src/gamelog.cpp
Show inline comments
 
@@ -239,13 +239,17 @@ void Gamelog::Print(std::function<void(c
 
}
 

	
 
/* virtual */ void LoggedChangeGRFRemoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
 
{
 
	/* A NewGRF got removed from the game, either manually or by it missing when loading the game. */
 
	auto gm = grf_names.find(this->grfid);
 
	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!");
 
	} else {
 
		if (action_type == GLAT_LOAD) {
 
			/* Missing grfs on load are not removed from the configuration */
src/network/core/address.cpp
Show inline comments
 
@@ -90,13 +90,13 @@ static const char *GetAddressFormatStrin
 
 * Get the address as a string, e.g. 127.0.0.1:12345.
 
 * @param with_family whether to add the family (e.g. IPvX).
 
 * @return the address
 
 */
 
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());
 
}
 

	
 
/**
 
 * Helper function to resolve without opening a socket.
 
 * @return the opened socket or INVALID_SOCKET
 
 */
src/newgrf_profiling.cpp
Show inline comments
 
@@ -128,13 +128,13 @@ void NewGRFProfiler::Abort()
 
/**
 
 * Get name of the file that will be written.
 
 * @return File name of profiling output file.
 
 */
 
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()
 
{
 
	NewGRFProfiler::AbortTimer();
 

	
0 comments (0 inline, 0 general)