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 | |
| parent | 62745cda958116788164a245849e0b45622cc057 (diff) | |
Add shell escaping for arrays of text
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/shell.c | 11 | ||||
| -rw-r--r-- | stdlib/shell.h | 1 |
2 files changed, 12 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); diff --git a/stdlib/shell.h b/stdlib/shell.h index 16d0b10d..14a086ef 100644 --- a/stdlib/shell.h +++ b/stdlib/shell.h @@ -17,6 +17,7 @@ OptionalClosure_t Shell$by_line(Shell_t command); Shell_t Shell$escape_text(Text_t text); +Shell_t Shell$escape_text_array(Array_t texts); OptionalArray_t Shell$run_bytes(Shell_t command); OptionalText_t Shell$run(Shell_t command); |
