1
0
Fork 0

Codechange: Use fmt::format instead of stringstream with iomanip flags. (#13964)

pull/13983/head
frosch 2025-04-08 22:57:50 +02:00 committed by GitHub
parent 5b9d171e63
commit 04246c530f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 8 additions and 43 deletions

View File

@ -19,8 +19,6 @@
#include "table/strings.h"
#include "table/cargo_const.h"
#include <sstream>
#include "safeguards.h"
CargoSpec CargoSpec::array[NUM_CARGO];

View File

@ -45,8 +45,6 @@
#include "company_cmd.h"
#include "misc_cmd.h"
#include <sstream>
#include "table/strings.h"
#include "safeguards.h"

View File

@ -17,7 +17,6 @@
#include "video/video_driver.hpp"
#include "string_func.h"
#include "fileio_func.h"
#include <sstream>
#include "table/strings.h"

View File

@ -25,7 +25,6 @@
#endif
#include <charconv>
#include <sys/stat.h>
#include <sstream>
#include <filesystem>
#include "safeguards.h"

View File

@ -11,9 +11,6 @@
#include "../rail_map.h"
#include "dbg_helpers.h"
#include <sstream>
#include <iomanip>
#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));
}
/**

View File

@ -36,9 +36,6 @@
#include "table/strings.h"
#include <sstream>
#include <iomanip>
#include "safeguards.h"
/** Method to open the OSK. */

View File

@ -41,8 +41,6 @@
# include "../fileio_func.h"
#endif
#include <charconv>
#include <sstream>
#include <iomanip>
#include "table/strings.h"

View File

@ -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;
}
}

View File

@ -28,7 +28,6 @@
#include "debug.h"
#include "core/alloc_type.hpp"
#include "language.h"
#include <sstream>
#include "table/strings.h"
#include "table/control_codes.h"

View File

@ -10,9 +10,6 @@
#ifndef YAPF_TYPE_HPP
#define YAPF_TYPE_HPP
#include <iomanip>
#include <sstream>
#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 */

View File

@ -11,7 +11,6 @@
#include "../string_func.h"
#include "../strings_func.h"
#include "saveload_internal.h"
#include <sstream>
#include "table/strings.h"

View File

@ -17,9 +17,6 @@
#include "table/control_codes.h"
#include <sstream>
#include <iomanip>
#ifdef _MSC_VER
# define strncasecmp strnicmp
#endif

View File

@ -50,8 +50,6 @@
#include "table/strings.h"
#include <sstream>
#include "safeguards.h"
TownKdtree _town_local_authority_kdtree{};

View File

@ -37,8 +37,7 @@
#include "roadveh_cmd.h"
#include "train_cmd.h"
#include "ship_cmd.h"
#include <sstream>
#include <iomanip>
#include <charconv>
#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;