From aec01e740736db267e452f0ed5947649f79e3408 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 28 Feb 2016 11:09:00 +1100 Subject: Replace strformat, strprintf and strcatprintf with type-safe steam_format and string_format Update MAME to use new function Instantiate ODR-used static constant members Make some of the UI code more localisable Remove use of retired functions in tools --- src/lib/util/hashing.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/lib/util/hashing.cpp') diff --git a/src/lib/util/hashing.cpp b/src/lib/util/hashing.cpp index 8e85e4a42d2..240e64af9ad 100644 --- a/src/lib/util/hashing.cpp +++ b/src/lib/util/hashing.cpp @@ -10,6 +10,8 @@ #include "hashing.h" #include +#include +#include //************************************************************************** @@ -81,10 +83,12 @@ bool sha1_t::from_string(const char *string, int length) std::string sha1_t::as_string() const { - std::string buffer; + std::ostringstream buffer; + buffer.fill('0'); + buffer << std::hex; for (auto & elem : m_raw) - strcatprintf(buffer, "%02x", elem); - return buffer; + buffer << std::setw(2) << unsigned(elem); + return buffer.str(); } @@ -124,10 +128,12 @@ bool md5_t::from_string(const char *string, int length) std::string md5_t::as_string() const { - std::string buffer; + std::ostringstream buffer; + buffer.fill('0'); + buffer << std::hex; for (auto & elem : m_raw) - strcatprintf(buffer, "%02x", elem); - return buffer; + buffer << std::setw(2) << unsigned(elem); + return buffer.str(); } @@ -168,7 +174,7 @@ bool crc32_t::from_string(const char *string, int length) std::string crc32_t::as_string() const { - return strformat("%08x", m_raw); + return string_format("%08x", m_raw); } @@ -225,7 +231,7 @@ bool crc16_t::from_string(const char *string, int length) std::string crc16_t::as_string() const { - return strformat("%04x", m_raw); + return string_format("%04x", m_raw); } /** -- cgit v1.2.3-70-g09d2