aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 14:07:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 14:07:20 -0400
commit9cff275dc6aa90085bb2c336c4e056df0f87b186 (patch)
treee997a767a6813bbb805a8a300cf18eedc746627f /stdlib
parent75e0201fadacd29b3bbee1fdd6a1ba2c16c32bb8 (diff)
Slightly improve text quoting so it outputs "a$\r\nb" instead of
"a$\r$\nb"
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/text.c6
1 files changed, 5 insertions, 1 deletions
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) {