ROPE Language Reference - "expect_while"

The expect_while action lifts data from the packet, one byte at a time and submits each one to a block for checking. If the block leaves a TRUE value on the stack, then expect_while advances to the next byte, but if the block leaves a FALSE value, then expect_while stops.

All the bytes thus collected are pushed onto the stack as a single string.

If the result is a zero-length string (ie: the block returned FALSE for the first byte inspected) then expect_while invokes the "no" action, terminating the script and indicating that the packet does not match.

For example:

expect_while( { isdigit } )

expects one or more digit characters in the packet at $offset. If no digits are found, the script terminates with a "no" status. If one or more digits are found, then $offset is left pointing to the first non-digit in the packet and the collected digits are pushed onto the stack as a single string.

Optimized Loops

If the block to be executed contains just one action keyword, and the action is from the set of character tests in the "is....." set (like isdigit, isalpha .. etc) then expect_while doesnt actually call the block at all, but uses the matching C language function internally - this means that the expect loop is highly optimised in these cases.

For example..

expect_while( {isdigit} )                 -- optimized
expect_while( {dup isdigit isalpha or} )  -- not optimized
expect_while( {isalnum} )                 -- optimized

From version 20041201 onwards, the use of "not" with an "is..." function is also optimised in this same way. For example..

expect_while( {isdigit not} )

See Also