From a5d1d39f19c0000e60be9ec2f504d3717d570da4 Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Wed, 17 Apr 2024 23:39:00 +0200 Subject: [PATCH] Print char32_t unicode characters as UTF-8 for debugging Signed-off-by: Alexander Borsuk --- base/internal/message.cpp | 2 +- base/internal/message.hpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/base/internal/message.cpp b/base/internal/message.cpp index 57397786df..d022b53453 100644 --- a/base/internal/message.cpp +++ b/base/internal/message.cpp @@ -14,7 +14,7 @@ std::string ToUtf8(std::u16string_view utf16) std::string ToUtf8(std::u32string_view utf32) { std::string utf8; - utf8::unchecked::utf32to8(utf32.begin(), utf32.end(), utf8.begin()); + utf8::unchecked::utf32to8(utf32.begin(), utf32.end(), std::back_inserter(utf8)); return utf8; } } // namespace internal diff --git a/base/internal/message.hpp b/base/internal/message.hpp index 04d8968d85..ee51a6d6bc 100644 --- a/base/internal/message.hpp +++ b/base/internal/message.hpp @@ -100,9 +100,7 @@ inline std::string DebugPrint(std::u32string_view utf32) inline std::string DebugPrint(char32_t t) { - std::ostringstream out; - out << std::hex << static_cast(t); - return out.str(); + return internal::ToUtf8(std::u32string_view{&t, 1}); } inline std::string DebugPrint(std::chrono::time_point const & ts)