mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 19:48:20 +00:00
parent
43752b3d9f
commit
c36a449c76
6 changed files with 51 additions and 1 deletions
4
CHANGES
4
CHANGES
|
@ -1,4 +1,8 @@
|
||||||
|
|
||||||
|
2.0-851 | 2012-07-24 15:04:14 -0700
|
||||||
|
|
||||||
|
* New built-in function to_double(s: string). (Scott Campbell)
|
||||||
|
|
||||||
2.0-849 | 2012-07-24 11:06:16 -0700
|
2.0-849 | 2012-07-24 11:06:16 -0700
|
||||||
|
|
||||||
* Adding missing include needed on some systems. (Robin Sommer)
|
* Adding missing include needed on some systems. (Robin Sommer)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.0-849
|
2.0-851
|
||||||
|
|
23
src/bro.bif
23
src/bro.bif
|
@ -2604,6 +2604,29 @@ function to_subnet%(sn: string%): subnet
|
||||||
return ret;
|
return ret;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
## Converts a :bro:type:`string` to a :bro:type:`double`.
|
||||||
|
##
|
||||||
|
## str: The :bro:type:`string` to convert.
|
||||||
|
##
|
||||||
|
## Returns: The :bro:type:`string` *str* as double, or 0 if *str* has
|
||||||
|
## an invalid format.
|
||||||
|
##
|
||||||
|
function to_double%(str: string%): double
|
||||||
|
%{
|
||||||
|
const char* s = str->CheckString();
|
||||||
|
char* end_s;
|
||||||
|
|
||||||
|
double d = strtod(s, &end_s);
|
||||||
|
|
||||||
|
if ( s[0] == '\0' || end_s[0] != '\0' )
|
||||||
|
{
|
||||||
|
builtin_error("bad conversion to count", @ARG@[0]);
|
||||||
|
d = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Val(d, TYPE_DOUBLE);
|
||||||
|
%}
|
||||||
|
|
||||||
## Converts a :bro:type:`count` to an :bro:type:`addr`.
|
## Converts a :bro:type:`count` to an :bro:type:`addr`.
|
||||||
##
|
##
|
||||||
## ip: The :bro:type:`count` to convert.
|
## ip: The :bro:type:`count` to convert.
|
||||||
|
|
2
testing/btest/Baseline/bifs.to_double_from_string/error
Normal file
2
testing/btest/Baseline/bifs.to_double_from_string/error
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
error in /da/home/robin/bro/master/testing/btest/.tmp/bifs.to_double_from_string/to_double_from_string.bro, line 7 and /da/home/robin/bro/master/testing/btest/.tmp/bifs.to_double_from_string/to_double_from_string.bro, line 15: bad conversion to count (to_double(d) and NotADouble)
|
||||||
|
error in /da/home/robin/bro/master/testing/btest/.tmp/bifs.to_double_from_string/to_double_from_string.bro, line 7 and /da/home/robin/bro/master/testing/btest/.tmp/bifs.to_double_from_string/to_double_from_string.bro, line 16: bad conversion to count (to_double(d) and )
|
5
testing/btest/Baseline/bifs.to_double_from_string/output
Normal file
5
testing/btest/Baseline/bifs.to_double_from_string/output
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
to_double(3.14) = 3.14 (SUCCESS)
|
||||||
|
to_double(-3.14) = -3.14 (SUCCESS)
|
||||||
|
to_double(0) = 0.0 (SUCCESS)
|
||||||
|
to_double(NotADouble) = 0.0 (SUCCESS)
|
||||||
|
to_double() = 0.0 (SUCCESS)
|
16
testing/btest/bifs/to_double_from_string.bro
Normal file
16
testing/btest/bifs/to_double_from_string.bro
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# @TEST-EXEC: bro -b %INPUT >output 2>error
|
||||||
|
# @TEST-EXEC: btest-diff output
|
||||||
|
# @TEST-EXEC: btest-diff error
|
||||||
|
|
||||||
|
function test_to_double(d: string, expect: double)
|
||||||
|
{
|
||||||
|
local result = to_double(d);
|
||||||
|
print fmt("to_double(%s) = %s (%s)", d, result,
|
||||||
|
result == expect ? "SUCCESS" : "FAILURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
test_to_double("3.14", 3.14);
|
||||||
|
test_to_double("-3.14", -3.14);
|
||||||
|
test_to_double("0", 0);
|
||||||
|
test_to_double("NotADouble", 0);
|
||||||
|
test_to_double("", 0);
|
Loading…
Add table
Add a link
Reference in a new issue