mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
zeek.bif: Remove cat_sep() fully var_arg changes
These were introduced to better catch type violations at runtime. With bifcl doing these checks, revert to a better documented version.
This commit is contained in:
parent
f44279cc3e
commit
10dc1c4bc2
6 changed files with 11 additions and 37 deletions
38
src/zeek.bif
38
src/zeek.bif
|
@ -1541,44 +1541,18 @@ function cat%(...%): string
|
||||||
## Concatenates all arguments, with a separator placed between each one. This
|
## Concatenates all arguments, with a separator placed between each one. This
|
||||||
## function is similar to :zeek:id:`cat`, but places a separator between each
|
## function is similar to :zeek:id:`cat`, but places a separator between each
|
||||||
## given argument. If any of the variable arguments is an empty string it is
|
## given argument. If any of the variable arguments is an empty string it is
|
||||||
## replaced by the given default string instead. This function takes at least
|
## replaced by the given default string instead.
|
||||||
## two arguments. The first argument is the separator *sep* placed between
|
##
|
||||||
## each argument, the second argument is the default string *def* used when
|
## sep: The separator to place between each argument.
|
||||||
## an argument is the empty string.
|
##
|
||||||
|
## def: The default string to use when an argument is the empty string.
|
||||||
##
|
##
|
||||||
## Returns: A concatenation of all arguments with *sep* between each one and
|
## Returns: A concatenation of all arguments with *sep* between each one and
|
||||||
## empty strings replaced with *def*.
|
## empty strings replaced with *def*.
|
||||||
##
|
##
|
||||||
## .. zeek:see:: cat string_cat
|
## .. zeek:see:: cat string_cat
|
||||||
function cat_sep%(...%): string
|
function cat_sep%(sep: string, def: string, ...%): string
|
||||||
%{
|
%{
|
||||||
if ( @ARGC@ < 2 )
|
|
||||||
{
|
|
||||||
zeek::emit_builtin_error(zeek::util::fmt("cat_sep() takes at least 2 arguments, got %ld",
|
|
||||||
@ARGC@));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
zeek::ValPtr sep_arg = @ARG@[0];
|
|
||||||
zeek::ValPtr def_arg = @ARG@[1];
|
|
||||||
|
|
||||||
if ( sep_arg->GetType()->Tag() != zeek::TYPE_STRING )
|
|
||||||
{
|
|
||||||
zeek::emit_builtin_error(zeek::util::fmt("expected type string for separator, got %s",
|
|
||||||
zeek::type_name(sep_arg->GetType()->Tag())));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( def_arg->GetType()->Tag() != zeek::TYPE_STRING )
|
|
||||||
{
|
|
||||||
zeek::emit_builtin_error(zeek::util::fmt("expected type string for default, got %s",
|
|
||||||
zeek::type_name(def_arg->GetType()->Tag())));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
zeek::StringVal* sep = sep_arg->AsStringVal();
|
|
||||||
zeek::StringVal* def = def_arg->AsStringVal();
|
|
||||||
|
|
||||||
zeek::ODesc d;
|
zeek::ODesc d;
|
||||||
d.SetStyle(RAW_STYLE);
|
d.SetStyle(RAW_STYLE);
|
||||||
int pre_size = 0;
|
int pre_size = 0;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in <...>/cat_sep_errors.zeek, line 3: cat_sep() takes at least 2 arguments, got 1 (cat_sep(sep))
|
error in <...>/cat_sep_errors.zeek, line 3: cat_sep() takes at least 2 argument(s), got 1 (cat_sep(sep))
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in <...>/cat_sep_errors.zeek, line 4: expected type string for default, got count (cat_sep(sep, 1))
|
error in <...>/cat_sep_errors.zeek, line 4: expected type string for def, got count (cat_sep(sep, 1))
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in <...>/cat_sep_errors.zeek, line 4: expected type string for separator, got count (cat_sep(1, default))
|
error in <...>/cat_sep_errors.zeek, line 4: expected type string for sep, got count (cat_sep(1, default))
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in <...>/cat_sep_errors.zeek, line 3: expected type string for separator, got record (cat_sep([$a=1], default))
|
error in <...>/cat_sep_errors.zeek, line 3: expected type string for sep, got record (cat_sep([$a=1], default))
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in <...>/cat_sep_errors.zeek, line 6: cat_sep() takes at least 2 arguments, got 0 (cat_sep())
|
error in <...>/cat_sep_errors.zeek, line 6: cat_sep() takes at least 2 argument(s), got 0 (cat_sep())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue