mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00

The server-reported file size was being collected poorly and if a file name had a number in it, that was reported as the file size instead of the actual size. A new test is included to avoid reintroducing the problem.
26 lines
685 B
Text
26 lines
685 B
Text
|
|
## Extract an integer from a string.
|
|
##
|
|
## s: The string to search for a number.
|
|
##
|
|
## get_first: Provide `F` if you would like the last number found.
|
|
##
|
|
## Returns: The request integer from the given string or 0 if
|
|
## no integer was found.
|
|
function extract_count(s: string, get_first: bool &default=T): count
|
|
{
|
|
local extract_num_pattern = /[0-9]+/;
|
|
if ( get_first )
|
|
{
|
|
local first_parts = split_string_n(s, extract_num_pattern, T, 1);
|
|
if ( 1 in first_parts )
|
|
return to_count(first_parts[1]);
|
|
}
|
|
else
|
|
{
|
|
local last_parts = split_string_all(s, extract_num_pattern);
|
|
if ( |last_parts| > 1 )
|
|
return to_count(last_parts[|last_parts|-2]);
|
|
}
|
|
return 0;
|
|
}
|