mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Rework starts_with BIF similarly to ends_with changes in 1649e3e7cc
This commit is contained in:
parent
822ca99e80
commit
94ad676db0
1 changed files with 8 additions and 2 deletions
|
@ -1355,8 +1355,14 @@ function rfind_str%(str: string, sub: string, start: count &default=0, end: int
|
|||
##
|
||||
function starts_with%(str: string, sub: string%) : bool
|
||||
%{
|
||||
string s = str->ToStdString();
|
||||
return zeek::val_mgr->Bool(s.find(sub->ToStdString()) == 0);
|
||||
if ( sub->Len() > str->Len() )
|
||||
return zeek::val_mgr->Bool(false);
|
||||
|
||||
auto sub_s = sub->ToStdStringView();
|
||||
auto s = str->ToStdStringView();
|
||||
auto start_s = std::string_view{s.data(), sub_s.size()};
|
||||
|
||||
return zeek::val_mgr->Bool(start_s == sub_s);
|
||||
%}
|
||||
|
||||
## Returns whether a string ends with a substring.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue