mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
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:
parent
31aeb58e10
commit
0e28a7faf5
6 changed files with 69 additions and 28 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue