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

#include <regexp.h>

Public Member Functions

 RegExp (std::string pattern, regexp::Flags flags=regexp::Flags())
 
 RegExp (const std::vector< std::string > &patterns, regexp::Flags flags=regexp::Flags())
 
const auto & patterns () const
 
const auto & flags () const
 
int32_t match (const Bytes &data) const
 
Vector< BytesmatchGroups (const Bytes &data) const
 
std::tuple< int32_t, Bytesfind (const Bytes &data) const
 
regexp::MatchState tokenMatcher () const
 

Friends

class regexp::MatchState
 
bool operator== (const RegExp &a, const RegExp &b)
 
bool operator!= (const RegExp &a, const RegExp &b)
 

Detailed Description

A regular expression instance.

Constructor & Destructor Documentation

◆ RegExp() [1/2]

RegExp::RegExp ( std::string  pattern,
regexp::Flags  flags = regexp::Flags() 
)

Instantiates a new regular expression instance.

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

◆ RegExp() [2/2]

RegExp::RegExp ( const std::vector< std::string > &  patterns,
regexp::Flags  flags = regexp::Flags() 
)

Instantiates a new regular expression instance performing parallel set matching on multiple patterns. Set matching implicitly sets the Flags::no_sub (even if just one pattern is passed in).

Parameters
patternsregular expressions to compile jointly
flagscompilation flags for the regexp
Exceptions
<tt>PatternError</tt>if a pattern cannot be compiled

Member Function Documentation

◆ find()

std::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.

◆ 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: