From ffa59d4b368db7c4da3437d9ac28698ec50e4ee3 Mon Sep 17 00:00:00 2001 From: "Albert S." Date: Mon, 3 Nov 2025 19:59:26 +0100 Subject: [PATCH] utils: Introduce catv() --- utils.cpp | 24 ++++++++++++++++++++++++ utils.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/utils.cpp b/utils.cpp index e1cb3ed..b18ce88 100644 --- a/utils.cpp +++ b/utils.cpp @@ -214,3 +214,27 @@ std::string utils::trim(std::string_view view) } return std::string{view}; } + +std::string utils::catv(std::string_view view) +{ + std::string result; + result.reserve(view.length()); + for(auto c : view) + { + if (!isascii(c)) + { + result += "M-"; + result += toascii(c); + } + else if(iscntrl(c)) + { + result += '^'; + result += c == '\177' ? '?': c | 0100; + } + else + { + result += c; + } + } + return result; +} diff --git a/utils.h b/utils.h index 0e6816c..a1c21c2 100644 --- a/utils.h +++ b/utils.h @@ -91,6 +91,8 @@ template inline std::string toString(const T &v) } std::string trim(std::string_view view); +std::string catv(std::string_view view); + } // namespace utils #endif