mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/christian/gh-1982'
* origin/topic/christian/gh-1982: The is_num(), is_alpha(), and is_alnum() BiFs now return F on empty string Expand testcases around is_num(), is_alpha(), is_alnum(), is_ascii() BiFs Clarify is_ascii() BiF docstring re behavior on empty strings Fix minor indentation bugs in strings.bif
This commit is contained in:
commit
f264a9eccf
8 changed files with 35 additions and 6 deletions
6
CHANGES
6
CHANGES
|
@ -1,3 +1,9 @@
|
||||||
|
5.0.0-dev.156 | 2022-03-02 08:23:50 +0000
|
||||||
|
|
||||||
|
* The is_num(), is_alpha(), and is_alnum() BiFs now return F on empty string.
|
||||||
|
The testcases for these functions, and for is_ascii() were expanded. The documentation of is_ascii()
|
||||||
|
concerning behavior of an empty string was clarified (Christian Kreibich, Corelight)
|
||||||
|
|
||||||
5.0.0-dev.151 | 2022-03-02 08:09:28 +0000
|
5.0.0-dev.151 | 2022-03-02 08:09:28 +0000
|
||||||
|
|
||||||
* SSL: rudimentary decryption for TLS 1.2 (Florian Wilkens, Johanna Amann)
|
* SSL: rudimentary decryption for TLS 1.2 (Florian Wilkens, Johanna Amann)
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -15,6 +15,8 @@ New Functionality
|
||||||
Changed Functionality
|
Changed Functionality
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
- The is_num(), is_alpha(), and is_alnum() BiFs now return F for the empty string.
|
||||||
|
|
||||||
Deprecated Functionality
|
Deprecated Functionality
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
5.0.0-dev.151
|
5.0.0-dev.156
|
||||||
|
|
|
@ -541,7 +541,7 @@ function to_lower%(str: string%): string
|
||||||
*ls++ = s[i];
|
*ls++ = s[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
*ls++ = '\0';
|
*ls++ = '\0';
|
||||||
|
|
||||||
return zeek::make_intrusive<zeek::StringVal>(new zeek::String(1, lower_s, n));
|
return zeek::make_intrusive<zeek::StringVal>(new zeek::String(1, lower_s, n));
|
||||||
%}
|
%}
|
||||||
|
@ -570,7 +570,7 @@ function to_upper%(str: string%): string
|
||||||
*us++ = s[i];
|
*us++ = s[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
*us++ = '\0';
|
*us++ = '\0';
|
||||||
|
|
||||||
return zeek::make_intrusive<zeek::StringVal>(new zeek::String(1, upper_s, n));
|
return zeek::make_intrusive<zeek::StringVal>(new zeek::String(1, upper_s, n));
|
||||||
%}
|
%}
|
||||||
|
@ -614,6 +614,7 @@ function to_string_literal%(str: string%): string
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Determines whether a given string contains only ASCII characters.
|
## Determines whether a given string contains only ASCII characters.
|
||||||
|
## The empty string is ASCII.
|
||||||
##
|
##
|
||||||
## str: The string to examine.
|
## str: The string to examine.
|
||||||
##
|
##
|
||||||
|
@ -1253,13 +1254,17 @@ function ends_with%(str: string, sub: string%) : bool
|
||||||
return zeek::val_mgr->Bool(s.rfind(sub_s) == (s.size() - sub_s.size()));
|
return zeek::val_mgr->Bool(s.rfind(sub_s) == (s.size() - sub_s.size()));
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Returns whether an entire string consists only of digits.
|
## Returns whether a string consists entirely of digits.
|
||||||
|
## The empty string is not numeric.
|
||||||
##
|
##
|
||||||
function is_num%(str: string%) : bool
|
function is_num%(str: string%) : bool
|
||||||
%{
|
%{
|
||||||
// Python's version of this method (which this is based on) just checks to see if every
|
// Python's version of this method (which this is based on) just checks to see if every
|
||||||
// character in the string is a numeric value. If something more than this is desired, we
|
// character in the string is a numeric value. If something more than this is desired, we
|
||||||
// could use something like std::from_chars or std::strto{ul,f} to check it.
|
// could use something like std::from_chars or std::strto{ul,f} to check it.
|
||||||
|
if ( str->Len() == 0 )
|
||||||
|
return zeek::val_mgr->False();
|
||||||
|
|
||||||
const char* s = str->CheckString();
|
const char* s = str->CheckString();
|
||||||
for ( int i = 0; i < str->Len(); i++ )
|
for ( int i = 0; i < str->Len(); i++ )
|
||||||
if ( ! std::isdigit(s[i]) )
|
if ( ! std::isdigit(s[i]) )
|
||||||
|
@ -1268,10 +1273,14 @@ function is_num%(str: string%) : bool
|
||||||
return zeek::val_mgr->True();
|
return zeek::val_mgr->True();
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Returns whether an entire string is alphabetic characters.
|
## Returns whether a string consists entirely of alphabetic characters.
|
||||||
|
## The empty string is not alphabetic.
|
||||||
##
|
##
|
||||||
function is_alpha%(str: string%) : bool
|
function is_alpha%(str: string%) : bool
|
||||||
%{
|
%{
|
||||||
|
if ( str->Len() == 0 )
|
||||||
|
return zeek::val_mgr->False();
|
||||||
|
|
||||||
const char* s = str->CheckString();
|
const char* s = str->CheckString();
|
||||||
for ( int i = 0; i < str->Len(); i++ )
|
for ( int i = 0; i < str->Len(); i++ )
|
||||||
if ( ! std::isalpha(s[i]) )
|
if ( ! std::isalpha(s[i]) )
|
||||||
|
@ -1280,10 +1289,14 @@ function is_alpha%(str: string%) : bool
|
||||||
return zeek::val_mgr->True();
|
return zeek::val_mgr->True();
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Returns whether an entire string is alphanumeric characters
|
## Returns whether a string consists entirely of alphanumeric characters.
|
||||||
|
## The empty string is not alphanumeric.
|
||||||
##
|
##
|
||||||
function is_alnum%(str: string%) : bool
|
function is_alnum%(str: string%) : bool
|
||||||
%{
|
%{
|
||||||
|
if ( str->Len() == 0 )
|
||||||
|
return zeek::val_mgr->False();
|
||||||
|
|
||||||
const char* s = str->CheckString();
|
const char* s = str->CheckString();
|
||||||
for ( int i = 0; i < str->Len(); i++ )
|
for ( int i = 0; i < str->Len(); i++ )
|
||||||
if ( ! std::isalnum(s[i]) )
|
if ( ! std::isalnum(s[i]) )
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
### 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.
|
||||||
F
|
F
|
||||||
T
|
T
|
||||||
|
T
|
||||||
|
|
|
@ -17,14 +17,17 @@ Content checking
|
||||||
----------------
|
----------------
|
||||||
is_num abc : 0
|
is_num abc : 0
|
||||||
is_num 123 : 1
|
is_num 123 : 1
|
||||||
|
is_num '' : 0
|
||||||
is_alpha ab : 1
|
is_alpha ab : 1
|
||||||
is_alpha 1a : 0
|
is_alpha 1a : 0
|
||||||
is_alpha a1 : 0
|
is_alpha a1 : 0
|
||||||
|
is_alpha '' : 0
|
||||||
is_alnum ab : 1
|
is_alnum ab : 1
|
||||||
is_alnum 1a : 1
|
is_alnum 1a : 1
|
||||||
is_alnum a1 : 1
|
is_alnum a1 : 1
|
||||||
is_alnum 12 : 1
|
is_alnum 12 : 1
|
||||||
is_alnum ##12: 0
|
is_alnum ##12: 0
|
||||||
|
is_alnum '' : 0
|
||||||
|
|
||||||
String counting (input str 'aabbaa')
|
String counting (input str 'aabbaa')
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
|
|
@ -9,4 +9,5 @@ event zeek_init()
|
||||||
|
|
||||||
print is_ascii(a);
|
print is_ascii(a);
|
||||||
print is_ascii(b);
|
print is_ascii(b);
|
||||||
|
print is_ascii("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,17 @@ event zeek_init()
|
||||||
print "----------------";
|
print "----------------";
|
||||||
print fmt("is_num abc : %d", is_num("abc"));
|
print fmt("is_num abc : %d", is_num("abc"));
|
||||||
print fmt("is_num 123 : %d", is_num("123"));
|
print fmt("is_num 123 : %d", is_num("123"));
|
||||||
|
print fmt("is_num '' : %d", is_num(""));
|
||||||
print fmt("is_alpha ab : %d", is_alpha("ab"));
|
print fmt("is_alpha ab : %d", is_alpha("ab"));
|
||||||
print fmt("is_alpha 1a : %d", is_alpha("1a"));
|
print fmt("is_alpha 1a : %d", is_alpha("1a"));
|
||||||
print fmt("is_alpha a1 : %d", is_alpha("a1"));
|
print fmt("is_alpha a1 : %d", is_alpha("a1"));
|
||||||
|
print fmt("is_alpha '' : %d", is_alpha(""));
|
||||||
print fmt("is_alnum ab : %d", is_alnum("ab"));
|
print fmt("is_alnum ab : %d", is_alnum("ab"));
|
||||||
print fmt("is_alnum 1a : %d", is_alnum("1a"));
|
print fmt("is_alnum 1a : %d", is_alnum("1a"));
|
||||||
print fmt("is_alnum a1 : %d", is_alnum("a1"));
|
print fmt("is_alnum a1 : %d", is_alnum("a1"));
|
||||||
print fmt("is_alnum 12 : %d", is_alnum("12"));
|
print fmt("is_alnum 12 : %d", is_alnum("12"));
|
||||||
print fmt("is_alnum ##12: %d", is_alnum("##12"));
|
print fmt("is_alnum ##12: %d", is_alnum("##12"));
|
||||||
|
print fmt("is_alnum '' : %d", is_alnum(""));
|
||||||
print "";
|
print "";
|
||||||
|
|
||||||
print "String counting (input str 'aabbaa')";
|
print "String counting (input str 'aabbaa')";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue