Spicy
Classes | Public Member Functions | List of all members
hilti::rt::regexp::MatchState Class Reference

#include <regexp.h>

Classes

class  Pimpl
 

Public Member Functions

 MatchState (const RegExp &re)
 
 MatchState (const MatchState &other)
 
 MatchState (MatchState &&) noexcept
 
MatchStateoperator= (const MatchState &other)
 
MatchStateoperator= (MatchState &&) noexcept
 
std::tuple< int32_t, stream::Viewadvance (const stream::View &data)
 
std::tuple< int32_t, int64_t > advance (const Bytes &data, bool is_final=false)
 
Captures captures (const Stream &data) const
 

Detailed Description

Match state for incremental regexp matching.

Constructor & Destructor Documentation

◆ MatchState()

regexp::MatchState::MatchState ( const RegExp re)

Creates a fresh instances ready to match data against a given regular expression. The expression will considered anchored to the beginning of any data.

Member Function Documentation

◆ advance() [1/2]

std::tuple< int32_t, stream::View > regexp::MatchState::advance ( const stream::View data)

Feeds the next chunk of data into the matcher.

Parameters
datachunk of data; if the underlying stream is frozen, this will be assumed to be the last chunk of data, and the result of any further calls to advance() will then trigger a MatchStateReuse exception
Returns
A tuple in which the integer is: (1) larger than zero if a match has been found; for sets compiled via compileSet the integer value then indicates the ID of the pattern that was found. (2) zero if no match was found and advancing further to more data is guaranteed to not change that fact. (3) smaller than 0 if no match was found so far but advancing further may change that. In either case, the returned view trims data to the part not consumed yet. Note that the latter could actually be more than what was previously returned in case matching needed to backtrack because of a match now determined to end earlier.

◆ advance() [2/2]

std::tuple< int32_t, int64_t > regexp::MatchState::advance ( const Bytes data,
bool  is_final = false 
)

Feeds the next chunk of data into the matcher.

Parameters
datachunk of data
is_finaltrue to signal the last chunk of data; the result of any further calls to advance() will then trigger a MatchStateReuse exception
Returns
A tuple in which the integer is: (1) larger than zero if a match has been found; for sets compiled via compileSet the integer value then indicates the ID of the pattern that was found. (2) zero if no match was found and advancing further to more data is guaranteed to not change that fact. (3) smaller than 0 if no match was found so far but advancing further may change that. In either case, the 2nd element in the tuple returns the number of bytes that were consumed from data by the matching. Note that the integer can be negative in case of a match that has now been determined to end before the current chunk. In that case, the caller needs to backtrack by the given number of bytes. Because this could be tricky to handle, it's usually better to use the other variant of advance(), returning a view, if possible.

◆ captures()

regexp::Captures regexp::MatchState::captures ( const Stream data) const

Returns extracted capture groups after successful matching. Element zero will contain the full match. For i>0, index i will contain the i'th capture group. If capture groups cannot be extracted (e.g., because the regexp was compiled without support for that, or when matching has not finished successfully), the return vector will be empty.


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