From feb60674b43d9c0126858efdd18ab0c9590cfd28 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 2 May 2021 17:31:47 +0100 Subject: [PATCH] builtin.string: minor fixes in join() (#9952) --- vlib/builtin/string.v | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index c2848e41c5..da0fcc0ec6 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1606,17 +1606,17 @@ pub fn (s string) after_char(dot byte) string { return s[pos + 1..] } -// join joins a string array into a string using `del` delimiter. +// join joins a string array into a string using `sep` separator. // Example: assert ['Hello','V'].join(' ') == 'Hello V' -pub fn (a []string) join(del string) string { +pub fn (a []string) join(sep string) string { if a.len == 0 { return '' } mut len := 0 for val in a { - len += val.len + del.len + len += val.len + sep.len } - len -= del.len + len -= sep.len // Allocate enough memory mut res := string{ str: unsafe { malloc(len + 1) } @@ -1628,11 +1628,11 @@ pub fn (a []string) join(del string) string { C.memcpy(res.str + idx, val.str, val.len) idx += val.len } - // Add del if it's not last + // Add sep if it's not last if i != a.len - 1 { unsafe { - C.memcpy(res.str + idx, del.str, del.len) - idx += del.len + C.memcpy(res.str + idx, sep.str, sep.len) + idx += sep.len } } }