diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-23 14:36:20 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-23 14:36:20 -0400 |
| commit | b432fc82c78bb890eca5938c7754950f089c7abe (patch) | |
| tree | 44731b975c600ce33e87482de7e0337211efab98 /stdlib/shell.c | |
| parent | 62745cda958116788164a245849e0b45622cc057 (diff) | |
Add shell escaping for arrays of text
Diffstat (limited to 'stdlib/shell.c')
| -rw-r--r-- | stdlib/shell.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/stdlib/shell.c b/stdlib/shell.c index 977fa512..28c85fb1 100644 --- a/stdlib/shell.c +++ b/stdlib/shell.c @@ -33,6 +33,17 @@ public Shell_t Shell$escape_text(Text_t text) return (Text_t){.length=shell_graphemes.length, .tag=TEXT_GRAPHEMES, .graphemes=shell_graphemes.data}; } +public Shell_t Shell$escape_text_array(Array_t texts) +{ + Array_t all_escaped = {}; + for (int64_t i = 0; i < texts.length; i++) { + Text_t raw = *(Text_t*)(texts.data + i*texts.stride); + Text_t escaped = Shell$escape_text(raw); + Array$insert(&all_escaped, &escaped, I(0), sizeof(Text_t)); + } + return Text$join(Text(" "), all_escaped); +} + public OptionalArray_t Shell$run_bytes(Shell_t command) { const char *cmd_str = Text$as_c_string(command); |
