mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
The is_num(), is_alpha(), and is_alnum() BiFs now return F on empty string
This commit is contained in:
parent
19bfa071e0
commit
b977e76ad5
2 changed files with 17 additions and 3 deletions
2
NEWS
2
NEWS
|
@ -15,6 +15,8 @@ New Functionality
|
|||
Changed Functionality
|
||||
---------------------
|
||||
|
||||
- The is_num(), is_alpha(), and is_alnum() BiFs now return F for the empty string.
|
||||
|
||||
Deprecated Functionality
|
||||
------------------------
|
||||
|
||||
|
|
|
@ -1254,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()));
|
||||
%}
|
||||
|
||||
## 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
|
||||
%{
|
||||
// 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
|
||||
// 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();
|
||||
for ( int i = 0; i < str->Len(); i++ )
|
||||
if ( ! std::isdigit(s[i]) )
|
||||
|
@ -1269,10 +1273,14 @@ function is_num%(str: string%) : bool
|
|||
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
|
||||
%{
|
||||
if ( str->Len() == 0 )
|
||||
return zeek::val_mgr->False();
|
||||
|
||||
const char* s = str->CheckString();
|
||||
for ( int i = 0; i < str->Len(); i++ )
|
||||
if ( ! std::isalpha(s[i]) )
|
||||
|
@ -1281,10 +1289,14 @@ function is_alpha%(str: string%) : bool
|
|||
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
|
||||
%{
|
||||
if ( str->Len() == 0 )
|
||||
return zeek::val_mgr->False();
|
||||
|
||||
const char* s = str->CheckString();
|
||||
for ( int i = 0; i < str->Len(); i++ )
|
||||
if ( ! std::isalnum(s[i]) )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue