strings: Implement join_string_set() as bif

Haven't measured speed, but this is probably faster than
the cat() and string invocations.
This commit is contained in:
Arne Welzel 2022-09-06 17:15:11 +02:00
parent 31aeb58e10
commit 0e28a7faf5
6 changed files with 69 additions and 28 deletions

View file

@ -9,29 +9,6 @@ function is_string_binary(s: string): bool
return |gsub(s, /[\x00-\x7f]/, "")| * 100 / |s| >= 25;
}
## Join a set of strings together, with elements delimited by a constant string.
##
## ss: a set of strings to join.
##
## j: the string used to join set elements.
##
## Returns: a string composed of all elements of the set, delimited by the
## joining string.
function join_string_set(ss: set[string], j: string): string
{
local output="";
local i=0;
for ( s in ss )
{
if ( i > 0 )
output = cat(output, j);
output = cat(output, s);
++i;
}
return output;
}
## Given a string, returns an escaped version.
##
## s: a string to escape.