Spicy
Public Member Functions | Friends | List of all members
hilti::rt::RegExp Class Reference

#include <regexp.h>

Public Member Functions

 RegExp (regexp::Pattern pattern, regexp::Flags flags=regexp::Flags())
 
 RegExp (const regexp::Patterns &patterns, regexp::Flags flags=regexp::Flags())
 
 RegExp ()
 
const auto & patterns () const
 
const auto & flags () const
 
int32_t match (const Bytes &data) const
 
Vector< BytesmatchGroups (const Bytes &data) const
 
Tuple< int32_t, Bytesfind (const Bytes &data) const
 
regexp::MatchState tokenMatcher () const
 
jrx_regex_t * jrx () const
 
bool operator== (const RegExp &other) const
 

Friends

class regexp::MatchState
 

Detailed Description

A regular expression instance. A regular expression can be compiled from one or more individual patterns. All provided patterns will be matched in parallel.

Constructor & Destructor Documentation

◆ RegExp() [1/3]

RegExp::RegExp ( regexp::Pattern  pattern,
regexp::Flags  flags = regexp::Flags() 
)

Instantiates a new regular expression instance.

Parameters
patterna single regular expression pattern to compile
flagscompilation flags for the regexp pattern
Exceptions
<tt>PatternError</tt>if the pattern cannot be compiled

◆ RegExp() [2/3]

RegExp::RegExp ( const regexp::Patterns &  patterns,
regexp::Flags  flags = regexp::Flags() 
)

Instantiates a new regular expression instance performing parallel set matching on multiple patterns.

Parameters
patternsregular expression patterns to compile jointly
flagscompilation flags, affecting all patterns
Exceptions
<tt>PatternError</tt>if a pattern cannot be compiled

◆ RegExp() [3/3]

RegExp::RegExp ( )

Instantiates an empty regular expression without any patterns. This is a valid instance that however cannot be used with any matching functionality. Doing will produce runtime errors.

Member Function Documentation

◆ find()

Tuple< int32_t, Bytes > RegExp::find ( const Bytes data) const

Searches a pattern within a bytes view and returns the matching part. The expression is not considered anchored to the beginning of the data, it will be found at any position.

Note
This method is currently quadratic in the size of data.
Returns
A tuple where the 1st element corresponds to the result of find(). If that's larger than zero, the 2nd is the matching data.

◆ jrx()

jrx_regex_t* hilti::rt::RegExp::jrx ( ) const
inline

Accessor to underlying JRX state. Intended for internal use and testing.

◆ match()

int32_t RegExp::match ( const Bytes data) const

Searches a pattern within a bytes view. The expression is considered anchored to the beginning of the data.

Returns
If the returned integer is larger than zero, the regexp was found; for sets compiled via compileSet the integer value then indicates the ID of the pattern that was found. If the function returns zero, no match was found and that won't change if further data gets added to the input data. If the returned value is smaller than 0, a partial match was found (i.e., no match yet but adding further data could change that).

◆ matchGroups()

Vector< Bytes > RegExp::matchGroups ( const Bytes data) const

Searches a pattern within a bytes view and returns the matching data for all matching capture groups. The expression is considered anchored to the beginning of the data.

Returns
A vector of containing the matching data for all capture groups. The vector's index 0 corresponds to the whole expression, index 1 to the first capture group etc. If no match is found, the returned vector is empty.
Todo:
This function does not yet support sets compiled via compileSet().

◆ tokenMatcher()

regexp::MatchState RegExp::tokenMatcher ( ) const

Returns matching state initializes for incremental token matching. For token matching the regular expression will be considered implicitly anchored.


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