From 8b23715ddd46049ec54b9f6ae08190b77d2e6fd2 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 1 Apr 2025 19:58:06 -0400 Subject: [PATCH] logger patch hack --- CMakeLists.txt | 2 +- include/blt/logging/logging.h | 1 + src/blt/logging/logging.cpp | 25 ++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a6a7ac..af6a982 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 5.2.31) +set(BLT_VERSION 5.2.32) set(BLT_TARGET BLT) diff --git a/include/blt/logging/logging.h b/include/blt/logging/logging.h index 778a2b4..bc2e7a4 100644 --- a/include/blt/logging/logging.h +++ b/include/blt/logging/logging.h @@ -140,6 +140,7 @@ namespace blt::logging [[nodiscard]] size_t find_ending_brace(size_t begin) const; void setup_stream(const fmt_spec_t& spec) const; + std::string process_string(std::string_view str); void process_strings(); static void handle_type(std::ostream& stream, const fmt_spec_t& spec); diff --git a/src/blt/logging/logging.cpp b/src/blt/logging/logging.cpp index dae74f2..a2f2d68 100644 --- a/src/blt/logging/logging.cpp +++ b/src/blt/logging/logging.cpp @@ -108,13 +108,30 @@ namespace blt::logging m_stream << std::noshowpos; } + std::string logger_t::process_string(const std::string_view str) + { + auto result = std::string(str); + size_t pos = 0; + while (pos = result.find('{', pos), pos != std::string::npos) + { + if (pos > 0 && result[pos - 1] == '\\') + { + auto before = result.substr(0, pos - 1); + auto after = result.substr(pos); + result = before + after; + } else + ++pos; + } + return result; + } + void logger_t::process_strings() { auto spec_it = m_fmt_specs.begin(); auto str_it = m_string_sections.begin(); for (; spec_it != m_fmt_specs.end(); ++spec_it, ++str_it) { - m_stream << *str_it; + m_stream << process_string(*str_it); auto arg_pos = spec_it->arg_id; if (arg_pos == -1) arg_pos = static_cast(m_arg_pos++); @@ -122,7 +139,7 @@ namespace blt::logging setup_stream(*spec_it); m_arg_print_funcs[arg_pos](m_stream, *spec_it); } - m_stream << *str_it; + m_stream << process_string(*str_it); } void logger_t::handle_type(std::ostream& stream, const fmt_spec_t& spec) @@ -197,7 +214,9 @@ namespace blt::logging std::optional> logger_t::consume_to_next_fmt() { - const auto begin = m_fmt.find('{', m_last_fmt_pos); + auto begin = m_fmt.find('{', m_last_fmt_pos); + while (begin > 0 && m_fmt[begin - 1] == '\\') + begin = m_fmt.find('{', begin + 1);; if (begin == std::string::npos) return {}; const auto end = find_ending_brace(begin);