commit deca8168ea855f7ab7b95c4f9f00d542596b4e51
parent 9214fb26ec2debd1cfe98c6a615726cf726d25bf
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Fri, 3 May 2024 17:49:29 +0200
strings::sub: end as default parameter
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/strings/sub.ha b/strings/sub.ha
@@ -25,7 +25,7 @@ fn utf8_byte_len_bounded(iter: *iterator, end: size) size = {
// Note that substringing runewise is not always the correct thing to do, and it
// may cause unexpected linguistic errors to arise. You may want to use a
// third-party Unicode module instead.
-export fn sub(s: str, start: size, end: (size | end)) str = {
+export fn sub(s: str, start: size, end: (size | end) = end) str = {
let iter = iter(s);
let starti = utf8_byte_len_bounded(&iter, start);
let endi = match (end) {
@@ -40,6 +40,7 @@ export fn sub(s: str, start: size, end: (size | end)) str = {
};
@test fn sub() void = {
+ assert(sub("a string", 2) == "string");
assert(sub("a string", 2, end) == "string");
assert(sub("a string", 0, 1) == "a");
assert(sub("a string", 0, 3) == "a s");