From 0ade18828df7878ce8283388a6905a3800a29267 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 13 Feb 2021 23:53:36 +0200 Subject: [PATCH] Remove switch statement from wincolor_sink::set_color_mode_impl --- include/spdlog/sinks/wincolor_sink-inl.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 04a9e788..21abca43 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -60,7 +60,7 @@ void SPDLOG_INLINE wincolor_sink::log(const details::log_msg &msg) msg.color_range_start = 0; msg.color_range_end = 0; memory_buf_t formatted; - formatter_->format(msg, formatted); + formatter_->format(msg, formatted); if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { // before color range @@ -108,20 +108,16 @@ void SPDLOG_INLINE wincolor_sink::set_color_mode(color_mode mode) template void SPDLOG_INLINE wincolor_sink::set_color_mode_impl(color_mode mode) { - switch (mode) + if (mode == color_mode::automatic) { - case color_mode::always: - should_do_colors_ = true; - break; - case color_mode::never: - should_do_colors_ = false; - break; - default: - // should do colors only if out_handle_ points to actual console. + // should do colors only if out_handle_ points to actual console. DWORD console_mode; bool in_console = ::GetConsoleMode(static_cast(out_handle_), &console_mode) != 0; should_do_colors_ = in_console; - break; + } + else + { + should_do_colors_ = mode == color_mode::always ? true : false; } }