hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 991b9323d6c52e02b96f54a16b7032e39560e53b
parent de0a7d93c36e055470fbbbd932a96f9ee2167b92
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 27 May 2022 18:08:36 +0200

shlex: quote with ' instead of "

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mshlex/+test.ha | 7++++---
Mshlex/escape.ha | 13+++++++------
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/shlex/+test.ha b/shlex/+test.ha @@ -1,5 +1,6 @@ // License: MPL-2.0 // (c) 2021 Alexey Yerin <yyp@disroot.org> +// (c) 2022 Drew DeVault <sir@cmpwn.com> use io; use strings; use strio; @@ -73,7 +74,7 @@ fn testquote(sink: *strio::stream, s: str, expected: str) void = { const sink = strio::dynamic(); defer io::close(&sink)!; testquote(&sink, `hello`, `hello`); - testquote(&sink, `hello world`, `"hello world"`); - testquote(&sink, `'hello' "world"`, `"'hello' "'"'"world"'"'""`); - testquote(&sink, `hello\world`, `"hello\\world"`); + testquote(&sink, `hello world`, `'hello world'`); + testquote(&sink, `'hello' "world"`, `''"'"'hello'"'"' "world"'`); + testquote(&sink, `hello\world`, `'hello\world'`); }; diff --git a/shlex/escape.ha b/shlex/escape.ha @@ -1,3 +1,6 @@ +// License: MPL-2.0 +// (c) 2021 Alexey Yerin <yyp@disroot.org> +// (c) 2022 Drew DeVault <sir@cmpwn.com> use ascii; use encoding::utf8; use io; @@ -36,7 +39,7 @@ export fn quote(sink: io::handle, s: str) (size | io::error) = { return io::writeall(sink, strings::toutf8(s))?; }; - let z = io::writeall(sink, ['"'])?; + let z = io::writeall(sink, ['\''])?; const iter = strings::iter(s); for (true) { @@ -47,16 +50,14 @@ export fn quote(sink: io::handle, s: str) (size | io::error) = { break; }; - if (rn == '"') { - z += io::writeall(sink, strings::toutf8(`"'"'"`))?; - } else if (rn == '\\') { - z += io::writeall(sink, strings::toutf8(`\\`))?; + if (rn == '\'') { + z += io::writeall(sink, strings::toutf8(`'"'"'`))?; } else { z += io::writeall(sink, utf8::encoderune(rn))?; }; }; - z += io::writeall(sink, ['"'])?; + z += io::writeall(sink, ['\''])?; return z; };