From 9cff275dc6aa90085bb2c336c4e056df0f87b186 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 15 Sep 2024 14:07:20 -0400 Subject: Slightly improve text quoting so it outputs "a$\r\nb" instead of "a$\r$\nb" --- stdlib/text.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'stdlib') diff --git a/stdlib/text.c b/stdlib/text.c index 1fb4c10b..39b97962 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -1027,8 +1027,12 @@ static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) add_char('$'); add_char(quote_char); -#define add_escaped(str) ({ if (colorize) add_str("\x1b[34;1m"); add_str("$\\"); add_str(str); if (colorize) add_str("\x1b[0;35m"); }) +#define add_escaped(str) ({ if (colorize) add_str("\x1b[34;1m"); \ + if (!just_escaped) add_char('$'); \ + add_char('\\'); add_str(str); just_escaped = true; \ + if (colorize) add_str("\x1b[0;35m"); }) TextIter_t state = {text, 0, 0}; + bool just_escaped = false; for (int64_t i = 0; i < text.length; i++) { int32_t g = Text$get_grapheme_fast(&state, i); switch (g) { -- cgit v1.2.3