From 2559983e7a1f61617f92023b60e8865c179baf2f Mon Sep 17 00:00:00 2001 From: Spirrwell Date: Tue, 17 Mar 2020 09:24:42 -0400 Subject: [PATCH] Color formatting fixed for wide strings (fixes issue #1594) (#1596) * Use std::char_traits::length for ansi_color_escape::begin -Fixes issue #1594 https://github.com/fmtlib/fmt/issues/1594 --- include/fmt/color.h | 2 +- test/color-test.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 3756ba3f..96d9ab6b 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -412,7 +412,7 @@ template struct ansi_color_escape { FMT_CONSTEXPR const Char* begin() const FMT_NOEXCEPT { return buffer; } FMT_CONSTEXPR const Char* end() const FMT_NOEXCEPT { - return buffer + std::strlen(buffer); + return buffer + std::char_traits::length(buffer); } private: diff --git a/test/color-test.cc b/test/color-test.cc index fde3a0c5..c1113a2e 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -50,6 +50,8 @@ TEST(ColorsTest, ColorsPrint) { TEST(ColorsTest, Format) { EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); + EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), L"rgb(255,20,30) wide"), + L"\x1b[38;2;255;020;030mrgb(255,20,30) wide\x1b[0m"); EXPECT_EQ(fmt::format(fg(fmt::color::blue), "blue"), "\x1b[38;2;000;000;255mblue\x1b[0m"); EXPECT_EQ(