From dc7d7bc45d9b6cb3a052d69fbdacbd33b9ff3796 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 5 Jun 2026 15:45:24 +0200 Subject: upgrade to std::format --- src/call_stack.cpp | 6 ++---- src/module.cpp | 18 +++++++++--------- src/post_mortem.cpp | 35 +++++++++++++---------------------- 3 files changed, 24 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/call_stack.cpp b/src/call_stack.cpp index e69c10d..6e4bd29 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -10,8 +10,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -21,9 +21,7 @@ namespace { template static std::string put_between_brackets(const T& x) { - std::ostringstream oss; - oss << "[" << x << "]"; - return oss.str(); + return std::format("[{}]", x); } std::string format_address_fallback(Address addr) { diff --git a/src/module.cpp b/src/module.cpp index 47d8eaf..ae4a95f 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -7,8 +7,8 @@ #include #include +#include #include -#include #include #include @@ -59,17 +59,17 @@ Address Module::translate_online_address(Address online) const { } std::string Module::invalid_offline_address(Address offline) const { - std::ostringstream oss; - oss << "offline address " << address::format(offline) << " doesn't belong to module " - << get_name() << " (base offline address " << address::format(get_offline_base()) << ')'; - return oss.str(); + return std::format("offline address {} doesn't belong to module {} (base offline address {})", + address::format(offline), + get_name(), + address::format(get_offline_base())); } std::string Module::invalid_online_address(Address online) const { - std::ostringstream oss; - oss << "online address " << address::format(online) << " doesn't belong to module " - << get_name() << " (base online address " << address::format(get_online_base()) << ')'; - return oss.str(); + return std::format("online address {} doesn't belong to module {} (base online address {})", + address::format(online), + get_name(), + address::format(get_online_base())); } } // namespace winapi diff --git a/src/post_mortem.cpp b/src/post_mortem.cpp index 01f180a..2db7ee9 100644 --- a/src/post_mortem.cpp +++ b/src/post_mortem.cpp @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include #include #include @@ -16,42 +16,33 @@ namespace winapi { namespace { std::string pdb_already_loaded(Address online_base, const std::string& path) { - std::ostringstream oss; - oss << "module with online base address " << address::format(online_base) - << " has already been loaded: " << path; - return oss.str(); + return std::format("module with online base address {} has already been loaded: {}", + address::format(online_base), + path); } std::string pdb_already_loaded(const std::string& path) { - std::ostringstream oss; - oss << "module has already been loaded: " << path; - return oss.str(); + return std::format("module has already been loaded: {}", path); } std::string offline_base_already_used(Address base) { - std::ostringstream oss; - oss << "module with offline base address " << address::format(base) - << " has already been loaded (shouldn't happen)"; - return oss.str(); + return std::format( + "module with offline base address {} has already been loaded (shouldn't happen)", + address::format(base)); } std::string module_not_found(Address base) { - std::ostringstream oss; - oss << "module with base address " << address::format(base) << " wasn't found"; - return oss.str(); + return std::format("module with base address {} wasn't found", address::format(base)); } std::string guess_module_no_modules(Address pivot) { - std::ostringstream oss; - oss << "couldn't select a module for address " << address::format(pivot) - << ": no modules have been loaded yet"; - return oss.str(); + return std::format("couldn't select a module for address {}: no modules have been loaded yet", + address::format(pivot)); } std::string guess_module_address_too_low(Address pivot) { - std::ostringstream oss; - oss << "couldn't select a module for address " << address::format(pivot) << ": it's too low"; - return oss.str(); + return std::format("couldn't select a module for address {}: it's too low", + address::format(pivot)); } template -- cgit v1.3