[Bro-Dev] #422: Array-style index accessor for strings

Bro Tracker bro at tracker.bro-ids.org
Fri Dec 21 19:44:53 PST 2012


#422: Array-style index accessor for strings
----------------------------+----------------------
  Reporter:  seth           |      Owner:  robin
      Type:  Merge Request  |     Status:  closed
  Priority:  Normal         |  Milestone:  Bro2.2
 Component:  Bro            |    Version:
Resolution:  fixed          |   Keywords:  language
----------------------------+----------------------

Comment (by vern):

 The {{{s[1,4]}}} syntax is '''ambiguous''' when scanned visually - does it
 mean a string range, or a reference into a 2-dimensional array?  Because
 of this, I strongly prefer {{{s[1:4]}}} syntax; and indeed the degree to
 which we can adopt {{{S}}}/{{{R}}}-style array semantics (I'm hoping
 Python's are similar, so we tone down the holy wars :-)), the better, as
 it kicks ass for manipulating arrays.

 For example, in {{{S}}}/{{{R}}} the expression {{{x[x > 3 & x <= 9]}}}
 returns an array of all elements in {{{x}}} in {{{(3,9]}}}, and in fact
 this works for any boolean mask, so if {{{y}}} is the same length as
 {{{x}}}, then {{{x[y != 0]}}} pulls out those elements in {{{x}}} that
 correspond to points where {{{y}}} is non-zero.  You can also use
 {{{x[-(1:4)]}}} to extract all elements of {{{x}}} ''except'' the first
 four; and {{{:}}} is itself a "sequence" operator, so {{{x:y}}} generates
 an array of all integer values in {{{[x,y]}}}.

 I'm not saying we should dive into this degree of array/vector semantics
 at this point, but keeping the current syntax consistent with that goal
 would be good ...

-- 
Ticket URL: <http://tracker.bro-ids.org/bro/ticket/422#comment:9>
Bro Tracker <http://tracker.bro-ids.org/bro>
Bro Issue Tracker



More information about the bro-dev mailing list