mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
29 lines
746 B
JavaScript
29 lines
746 B
JavaScript
%extern{
|
|
#include <cstring>
|
|
#include <binpac_bytestring.h>
|
|
%}
|
|
|
|
function bytestring_casecmp(s1: const_bytestring, s2: const_charptr): int
|
|
%{
|
|
int r = strncasecmp((const char*) s1.begin(), s2, s1.length());
|
|
if ( r == 0 )
|
|
return s2[s1.length()] == '\0' ? 0 : -1;
|
|
else
|
|
return r;
|
|
%}
|
|
|
|
# True if s2 is a (case-insensitive) prefix of s1.
|
|
function bytestring_caseprefix(s1: const_bytestring, s2: const_charptr): bool
|
|
%{
|
|
return strncasecmp((const char*) s1.begin(), s2, strlen(s2)) == 0;
|
|
%}
|
|
|
|
function bytestring_to_int(s: const_bytestring, base: int): int
|
|
%{
|
|
return strtol((const char*) std_str(s).c_str(), nullptr, base);
|
|
%}
|
|
|
|
function bytestring_to_double(s: const_bytestring): double
|
|
%{
|
|
return atof((const char*) std_str(s).c_str());
|
|
%}
|