aboutsummaryrefslogtreecommitdiff
path: root/stdlib/shell.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-01-23 15:33:56 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-01-23 15:33:56 -0500
commitf93dde14496ef784df6b7b3e1de1030a868be985 (patch)
treee4f5bcc1852d13e2f2d853a1f6590ccdd93e18a2 /stdlib/shell.c
parentc60ea2079fb230213308904cd0966e5481d2d994 (diff)
Overhaul of Text implementation to be more like Cords and have much
better performance for long sequences of repeated concatenation.
Diffstat (limited to 'stdlib/shell.c')
-rw-r--r--stdlib/shell.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/stdlib/shell.c b/stdlib/shell.c
index 4a48f5c2..694d155b 100644
--- a/stdlib/shell.c
+++ b/stdlib/shell.c
@@ -14,24 +14,7 @@
public Shell_t Shell$escape_text(Text_t text)
{
- // TODO: optimize for ASCII and short strings
- Array_t shell_graphemes = {.atomic=1};
-#define add_char(c) Array$insert(&shell_graphemes, (uint32_t[1]){c}, I_small(0), sizeof(uint32_t))
- add_char('\'');
- const char *text_utf8 = Text$as_c_string(text);
- for (const char *p = text_utf8; *p; p++) {
- if (*p == '\'') {
- add_char('\'');
- add_char('"');
- add_char('\'');
- add_char('"');
- add_char('\'');
- } else
- add_char((uint8_t)*p);
- }
- add_char('\'');
-#undef add_char
- return (Text_t){.length=shell_graphemes.length, .tag=TEXT_GRAPHEMES, .graphemes=shell_graphemes.data};
+ return Text$replace(text, Text("'"), Text("'\"'\"'"), Text(""), false);
}
public Shell_t Shell$escape_text_array(Array_t texts)