mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/timw/ends-with-rework'
* origin/topic/timw/ends-with-rework: Squeeze a bit more performance out of the ends_with bif
This commit is contained in:
commit
1649e3e7cc
5 changed files with 17 additions and 5 deletions
4
CHANGES
4
CHANGES
|
@ -1,3 +1,7 @@
|
||||||
|
6.2.0-dev.405 | 2024-01-16 12:07:11 -0700
|
||||||
|
|
||||||
|
* Squeeze a bit more performance out of the ends_with bif (Tim Wojtulewicz)
|
||||||
|
|
||||||
6.2.0-dev.403 | 2024-01-16 18:03:54 +0100
|
6.2.0-dev.403 | 2024-01-16 18:03:54 +0100
|
||||||
|
|
||||||
* SMTP: No state update for bad BDAT commands (Arne Welzel, Corelight)
|
* SMTP: No state update for bad BDAT commands (Arne Welzel, Corelight)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
6.2.0-dev.403
|
6.2.0-dev.405
|
||||||
|
|
|
@ -1366,9 +1366,15 @@ function ends_with%(str: string, sub: string%) : bool
|
||||||
if ( sub->Len() > str->Len() )
|
if ( sub->Len() > str->Len() )
|
||||||
return zeek::val_mgr->Bool(false);
|
return zeek::val_mgr->Bool(false);
|
||||||
|
|
||||||
string s = str->ToStdString();
|
auto sub_s = sub->ToStdStringView();
|
||||||
string sub_s = sub->ToStdString();
|
auto s = str->ToStdStringView();
|
||||||
return zeek::val_mgr->Bool(s.rfind(sub_s) == (s.size() - sub_s.size()));
|
|
||||||
|
// Create a string_view that only looks at the end of the string being searched
|
||||||
|
// with the same number of characters as the search string. This avoids possible
|
||||||
|
// pathological searches of big strings if the search string doesn't exist.
|
||||||
|
auto end_s = std::string_view{s.data() + s.size() - sub_s.size(), sub_s.size()};
|
||||||
|
|
||||||
|
return zeek::val_mgr->Bool(end_s == sub_s);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Returns whether a string consists entirely of digits.
|
## Returns whether a string consists entirely of digits.
|
||||||
|
|
|
@ -41,6 +41,7 @@ starts_with bro: 1
|
||||||
starts_with ids: 0
|
starts_with ids: 0
|
||||||
ends_with ids: 1
|
ends_with ids: 1
|
||||||
ends_with bro: 0
|
ends_with bro: 0
|
||||||
|
ends_with containing null: 1
|
||||||
|
|
||||||
Transformations
|
Transformations
|
||||||
---------------
|
---------------
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# @TEST-EXEC: zeek -b %INPUT >out
|
# @TEST-EXEC: zeek -b %INPUT >out 2>&1
|
||||||
# @TEST-EXEC: btest-diff out
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
|
@ -51,6 +51,7 @@ event zeek_init()
|
||||||
print fmt("starts_with ids: %d", starts_with(s3, "ghi"));
|
print fmt("starts_with ids: %d", starts_with(s3, "ghi"));
|
||||||
print fmt("ends_with ids: %d", ends_with(s3, "ghi"));
|
print fmt("ends_with ids: %d", ends_with(s3, "ghi"));
|
||||||
print fmt("ends_with bro: %d", ends_with(s3, "abc"));
|
print fmt("ends_with bro: %d", ends_with(s3, "abc"));
|
||||||
|
print fmt("ends_with containing null: %d", ends_with("a\x00\x00b", "\x00b"));
|
||||||
print "";
|
print "";
|
||||||
|
|
||||||
print "Transformations";
|
print "Transformations";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue