mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Add array-style index accessor for strings. Addresses #422.
The index expression can take up to two indices for the start and end index of the substring to return (e.g. "mystring[1,3]"). Negative indices are allowed, with -1 representing the last character in the string. The indexing is not cyclic -- if the starting index is >= the length of the string an empty string is returned, and if the ending index is >= the length of the string then it's interpreted as the last index of the string. Assigning to substrings accessed like this isn't allowed.
This commit is contained in:
parent
ea6b62f586
commit
55c515d50a
5 changed files with 115 additions and 10 deletions
10
src/Type.cc
10
src/Type.cc
|
@ -114,8 +114,16 @@ BroType::~BroType()
|
|||
delete [] type_id;
|
||||
}
|
||||
|
||||
int BroType::MatchesIndex(ListExpr*& /* index */) const
|
||||
int BroType::MatchesIndex(ListExpr*& index) const
|
||||
{
|
||||
if ( Tag() == TYPE_STRING )
|
||||
{
|
||||
if ( index->Exprs().length() != 1 && index->Exprs().length() != 2 )
|
||||
return DOES_NOT_MATCH_INDEX;
|
||||
if ( check_and_promote_exprs_to_type(index, ::base_type(TYPE_INT)) )
|
||||
return MATCHES_INDEX_SCALAR;
|
||||
}
|
||||
|
||||
return DOES_NOT_MATCH_INDEX;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue