diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 00:15:54 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 00:15:54 -0400 |
| commit | 10a51ad996482d07ecfe4bcd3251b4e8701a30df (patch) | |
| tree | a4f39a3d771dcf9a2a3f4c026054cc3b56dbb6ad /stdlib | |
| parent | b1f882af91ca17703f57589b88191dabe2c42f78 (diff) | |
Bugfix for string escaping in printouts
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/text.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/stdlib/text.c b/stdlib/text.c index ec54a5d1..fd54204b 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -1045,13 +1045,23 @@ static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) case '\t': add_escaped("t"); break; case '\v': add_escaped("v"); break; case '\\': { - if (just_escaped) + if (just_escaped) { add_escaped("\\"); - else + } else { add_char('\\'); + just_escaped = false; + } + break; + } + case '$': { + if (quote_char == '\'') { + add_char('$'); + just_escaped = false; + } else { + add_escaped("$"); + } break; } - case '$': if (quote_char == '\'') add_char('$'); else add_escaped("$"); break; case '\x00' ... '\x06': case '\x0E' ... '\x1A': case '\x1C' ... '\x1F': case '\x7F' ... '\x7F': { if (colorize) add_str("\x1b[34;1m"); @@ -1062,13 +1072,16 @@ static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) add_str(tmp); if (colorize) add_str("\x1b[0;35m"); + just_escaped = true; break; } default: { - if (g == quote_char) + if (g == quote_char) { add_escaped(((char[2]){quote_char, 0})); - else + } else { add_char(g); + just_escaped = false; + } break; } } |
