Kea 2.7.5
|
Token that represents the substring operator (returns a portion of the supplied string) More...
#include <token.h>
Public Member Functions | |
TokenSubstring () | |
Constructor (does nothing) | |
virtual unsigned | evaluate (Pkt &pkt, ValueStack &values) |
Extract a substring from a string. | |
Public Member Functions inherited from isc::dhcp::Token | |
virtual | ~Token () |
Virtual destructor. | |
virtual unsigned | getLabel () const |
Return the label of this token. | |
Additional Inherited Members | |
Static Public Member Functions inherited from isc::dhcp::Token | |
static bool | toBool (std::string value) |
Coverts a (string) value to a boolean. | |
Token that represents the substring operator (returns a portion of the supplied string)
This token represents substring(str, start, len) An operator that takes three arguments: a string, the first character and the length.
|
inline |
|
virtual |
Extract a substring from a string.
Evaluation does not use packet information. It requires at least three values to be present on the stack. It will consume the top three values on the stack as parameters and push the resulting substring onto the stack. From the top it expects the values on the stack as:
str is the string to extract a substring from. If it is empty, an empty string is pushed onto the value stack.
start is the position from which the code starts extracting the substring. 0 is the first character and a negative number starts from the end, with -1 being the last character. If the starting point is outside of the original string an empty string is pushed onto the value stack.
length is the number of characters from the string to extract. "all" means all remaining characters from start to the end of string. A negative number means to go from start towards the beginning of the string, but doesn't include start. If length is longer than the remaining portion of string then the entire remaining portion is placed on the value stack.
The following examples all use the base string "foobar", the first number is the starting position and the second is the length. Note that a negative length only selects which characters to extract it does not indicate an attempt to reverse the string.
EvalBadStack | if there are less than 3 values on stack |
EvalTypeError | if start is not a number or length a number or the special value "all". |
pkt | (unused) |
values | - stack of values (3 arguments will be popped, 1 result will be pushed) |
Implements isc::dhcp::Token.
Definition at line 776 of file token.cc.
References isc::dhcp::EVAL_DBG_STACK, isc::dhcp::EVAL_DEBUG_SUBSTRING, isc::dhcp::EVAL_DEBUG_SUBSTRING_EMPTY, isc::dhcp::EVAL_DEBUG_SUBSTRING_RANGE, isc::dhcp::eval_logger, isc_throw, and LOG_DEBUG.