diff --git a/src/cargotype.cpp b/src/cargotype.cpp index 72364e361b..f65e6f9186 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -19,8 +19,6 @@ #include "table/strings.h" #include "table/cargo_const.h" -#include - #include "safeguards.h" CargoSpec CargoSpec::array[NUM_CARGO]; diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 9ccc3a834e..ef863cc8c5 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -45,8 +45,6 @@ #include "company_cmd.h" #include "misc_cmd.h" -#include - #include "table/strings.h" #include "safeguards.h" diff --git a/src/driver.cpp b/src/driver.cpp index 28dec081f4..c790c9ebbb 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -17,7 +17,6 @@ #include "video/video_driver.hpp" #include "string_func.h" #include "fileio_func.h" -#include #include "table/strings.h" diff --git a/src/fileio.cpp b/src/fileio.cpp index 299e6cca18..3d05b2a3c5 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -25,7 +25,6 @@ #endif #include #include -#include #include #include "safeguards.h" diff --git a/src/misc/dbg_helpers.cpp b/src/misc/dbg_helpers.cpp index b2e743c7ea..647510ebd7 100644 --- a/src/misc/dbg_helpers.cpp +++ b/src/misc/dbg_helpers.cpp @@ -11,9 +11,6 @@ #include "../rail_map.h" #include "dbg_helpers.h" -#include -#include - #include "../safeguards.h" /** Trackdir & TrackdirBits short names. */ @@ -62,10 +59,7 @@ std::string ValueStr(SignalType t) /** Translate TileIndex into string. */ std::string TileStr(TileIndex tile) { - std::stringstream ss; - ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << tile.base(); // 0x%04X - ss << " (" << TileX(tile) << ", " << TileY(tile) << ")"; - return ss.str(); + return fmt::format("0x{:04X} ({}, {})", tile.base(), TileX(tile), TileY(tile)); } /** diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 68c4e5c4ff..bae49d57f3 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -36,9 +36,6 @@ #include "table/strings.h" -#include -#include - #include "safeguards.h" /** Method to open the OSK. */ diff --git a/src/network/network.cpp b/src/network/network.cpp index 87500f5411..de11f48eef 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -41,8 +41,6 @@ # include "../fileio_func.h" #endif #include -#include -#include #include "table/strings.h" diff --git a/src/newgrf_profiling.cpp b/src/newgrf_profiling.cpp index b2d9a0cf5e..4e0cfec0f9 100644 --- a/src/newgrf_profiling.cpp +++ b/src/newgrf_profiling.cpp @@ -113,7 +113,7 @@ uint32_t NewGRFProfiler::Finish() } else { fmt::print(*f, "Tick,Sprite,Feature,Item,CallbackID,Microseconds,Depth,Result\n"); for (const Call &c : this->calls) { - fmt::print(*f, "{},{},{:#X},{},{:#X},{},{},{}\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result); + fmt::print(*f, "{},{},0x{:X},{},0x{:X},{},{},{}\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result); total_microseconds += c.time; } } diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 30a07a5ed5..f866fc4760 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -28,7 +28,6 @@ #include "debug.h" #include "core/alloc_type.hpp" #include "language.h" -#include #include "table/strings.h" #include "table/control_codes.h" diff --git a/src/pathfinder/yapf/yapf_type.hpp b/src/pathfinder/yapf/yapf_type.hpp index fe2666b264..a39304fcfd 100644 --- a/src/pathfinder/yapf/yapf_type.hpp +++ b/src/pathfinder/yapf/yapf_type.hpp @@ -10,9 +10,6 @@ #ifndef YAPF_TYPE_HPP #define YAPF_TYPE_HPP -#include -#include - #include "../../core/enum_type.hpp" #include "../../misc/dbg_helpers.h" @@ -75,10 +72,7 @@ inline std::string ValueStr(EndSegmentReasons flags) "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED" }; - std::stringstream ss; - ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << flags.base(); // 0x%04X - ss << " (" << ComposeNameT(flags, end_segment_reason_names, "UNK") << ")"; - return ss.str(); + return fmt::format("0x{:04X} ({})", flags.base(), ComposeNameT(flags, end_segment_reason_names, "UNK")); } #endif /* YAPF_TYPE_HPP */ diff --git a/src/saveload/strings_sl.cpp b/src/saveload/strings_sl.cpp index f40721e074..2be7fe0f4a 100644 --- a/src/saveload/strings_sl.cpp +++ b/src/saveload/strings_sl.cpp @@ -11,7 +11,6 @@ #include "../string_func.h" #include "../strings_func.h" #include "saveload_internal.h" -#include #include "table/strings.h" diff --git a/src/string.cpp b/src/string.cpp index 966a3b6af7..b2e085536b 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -17,9 +17,6 @@ #include "table/control_codes.h" -#include -#include - #ifdef _MSC_VER # define strncasecmp strnicmp #endif diff --git a/src/town_gui.cpp b/src/town_gui.cpp index f0433bcc48..a5c4cc7560 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -50,8 +50,6 @@ #include "table/strings.h" -#include - #include "safeguards.h" TownKdtree _town_local_authority_kdtree{}; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 6a3a889f22..89bae13ccd 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -37,8 +37,7 @@ #include "roadveh_cmd.h" #include "train_cmd.h" #include "ship_cmd.h" -#include -#include +#include #include "table/strings.h" @@ -803,23 +802,19 @@ static void CloneVehicleName(const Vehicle *src, Vehicle *dst) /* Found digits, parse them and start at the next number. */ buf = src->name.substr(0, number_position); - auto num_str = src->name.substr(number_position); + auto num_str = std::string_view(src->name).substr(number_position); padding = (uint8_t)num_str.length(); - std::istringstream iss(num_str); - iss >> num; + [[maybe_unused]] auto err = std::from_chars(num_str.data(), num_str.data() + num_str.size(), num, 10).ec; + assert(err == std::errc()); num++; } /* Check if this name is already taken. */ for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) { - std::ostringstream oss; - - /* Attach the number to the temporary name. */ - oss << buf << std::setw(padding) << std::setfill('0') << std::internal << num; + std::string new_name = fmt::format("{}{:0{}}", buf, num, padding); /* Check the name is unique. */ - auto new_name = oss.str(); if (IsUniqueVehicleName(new_name)) { dst->name = std::move(new_name); break;