commit 157c3599983c93b5df5fb2355470ceaa0e47c7a0
parent 2c896e77c9b4aa0910eed27ef1d55a0575653ea5
Author: Alexey Yerin <yyp@disroot.org>
Date: Tue, 23 Nov 2021 12:16:30 +0300
shlex: drop splitfree in favor of strings::freeall
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
2 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/shlex/+test.ha b/shlex/+test.ha
@@ -1,46 +1,48 @@
+use strings;
+
@test fn split() void = {
const s = split("hello\\ world")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 1);
assert(s[0] == "hello world");
const s = split("'hello\\ world'")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 1);
assert(s[0] == "hello\\ world");
const s = split("\"hello\\\\world\"")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 1);
assert(s[0] == "hello\\world");
const s = split("\"hello \"'\"'\"world\"'\"'")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 1);
assert(s[0] == "hello \"world\"");
const s = split("hello '' world")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 3);
assert(s[0] == "hello");
assert(s[1] == "");
assert(s[2] == "world");
const s = split("Empty ''")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 2);
assert(s[0] == "Empty");
assert(s[1] == "");
const s = split("with\\ backslashes 'single quoted' \"double quoted\"")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 3);
assert(s[0] == "with backslashes");
assert(s[1] == "single quoted");
assert(s[2] == "double quoted");
const s = split("'multiple spaces' 42")!;
- defer splitfree(s);
+ defer strings::freeall(s);
assert(len(s) == 2);
assert(s[0] == "multiple spaces");
assert(s[1] == "42");
diff --git a/shlex/split.ha b/shlex/split.ha
@@ -6,7 +6,7 @@ use strio;
export type syntaxerr = !void;
// Splits a string of arguments according to shell quoting. The result must be
-// freed using [[splitfree]] when the caller is done processing it.
+// freed using [[strings::freeall]] when the caller is done processing it.
export fn split(in: const str) ([]str | syntaxerr) = {
let iter = strings::iter(in);
@@ -109,13 +109,3 @@ fn scan_single(out: io::handle, in: *strings::iterator) (void | syntaxerr) = {
strio::appendrune(out, r)!;
};
};
-
-// TODO: rehome a more generic version into strings/?
-
-// Frees a slice of allocated strings returned from [[split]].
-export fn splitfree(s: const []str) void = {
- for (let i = 0z; i < len(s); i += 1) {
- free(s[i]);
- };
- free(s);
-};