Kea 2.5.8
isc::dhcp::TokenSubstring Class Reference

Token that represents the substring operator (returns a portion of the supplied string) More...

#include <token.h>

+ Inheritance diagram for isc::dhcp::TokenSubstring:

Public Member Functions

 TokenSubstring ()
 Constructor (does nothing)
 
void evaluate (Pkt &pkt, ValueStack &values)
 Extract a substring from a string.
 
- Public Member Functions inherited from isc::dhcp::Token
virtual ~Token ()
 Virtual destructor.
 
virtual void evaluate (Pkt &pkt, ValueStack &values)=0
 This is a generic method for evaluating a packet.
 

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.
 

Detailed Description

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.

Definition at line 776 of file token.h.

Constructor & Destructor Documentation

◆ TokenSubstring()

isc::dhcp::TokenSubstring::TokenSubstring ( )
inline

Constructor (does nothing)

Definition at line 779 of file token.h.

Member Function Documentation

◆ evaluate()

void TokenSubstring::evaluate ( Pkt pkt,
ValueStack values 
)
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:

  • len
  • start
  • str

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.

  • 0, all => "foobar"
  • 0, 6 => "foobar"
  • 0, 4 => "foob"
  • 2, all => "obar"
  • 2, 6 => "obar"
  • -1, all => "r"
  • -1, -4 => "ooba"
Exceptions
EvalBadStackif there are less than 3 values on stack
EvalTypeErrorif start is not a number or length a number or the special value "all".
Parameters
pkt(unused)
values- stack of values (3 arguments will be popped, 1 result will be pushed)

Implements isc::dhcp::Token.

Definition at line 718 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.


The documentation for this class was generated from the following files: