/usr/share/bro/base/utils/strings.bro is in bro-common 2.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ##! Functions to assist with small string analysis and manipulation that can
##! be implemented as Bro functions and don't need to be implemented as built-in
##! functions.
## Returns true if the given string is at least 25% composed of 8-bit
## characters.
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.
##
## chars: a string containing all the characters that need to be escaped.
##
## Returns: a string with all occurrences of any character in *chars* escaped
## using ``\``, and any literal ``\`` characters likewise escaped.
function string_escape(s: string, chars: string): string
{
s = subst_string(s, "\\", "\\\\");
for ( c in chars )
s = subst_string(s, c, cat("\\", c));
return s;
}
## Cut a number of characters from the end of the given string.
##
## s: a string to trim.
##
## tail_len: the number of characters to remove from the end of the string.
##
## Returns: the given string with *tail_len* characters removed from the end.
function cut_tail(s: string, tail_len: count): string
{
if ( tail_len > |s| )
tail_len = |s|;
return sub_bytes(s, 1, int_to_count(|s| - tail_len));
}
|