aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-16 00:15:54 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-16 00:15:54 -0400
commit10a51ad996482d07ecfe4bcd3251b4e8701a30df (patch)
treea4f39a3d771dcf9a2a3f4c026054cc3b56dbb6ad
parentb1f882af91ca17703f57589b88191dabe2c42f78 (diff)
Bugfix for string escaping in printouts
-rw-r--r--parse.c2
-rw-r--r--stdlib/text.c23
2 files changed, 19 insertions, 6 deletions
diff --git a/parse.c b/parse.c
index 6f1d4b10..7e86d31a 100644
--- a/parse.c
+++ b/parse.c
@@ -1276,7 +1276,7 @@ PARSER(parse_text) {
++pos;
close_quote = closing[(int)open_quote] ? closing[(int)open_quote] : open_quote;
- if (!lang && open_quote == '/')
+ if (!lang && (open_quote == '/' || open_quote == '|'))
lang = "Pattern";
else if (!lang && open_quote == '(')
lang = "Shell";
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;
}
}