teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Classes | Public Member Functions | Static Public Attributes | List of all members
teditor::parser::NFA Struct Reference

Ken-Thompson NFA as described here: https://swtch.com/~rsc/regexp/regexp1.html but adjusted to work with teditor environment. More...

#include <nfa.h>

Public Member Functions

 NFA (const std::string &reg)
 ctor with adding a regex for the NFA More...
 
size_t find (const std::string &str, size_t start=0, size_t end=0)
 String match function. More...
 
size_t findAny (const std::string &str, size_t &matchStartPos, size_t start=0, size_t end=0)
 Tries for regex match starting from anywhere in the string. More...
 
 ~NFA ()
 
bool isMatch (bool lastStateRemaining=false) const
 checks if we have reached match state, indicating a regex match More...
 
bool areActiveStatesEmpty () const
 Tells if after the current step() whether there are any active states still remaining. So, this can be used to prematurely stop the regex search in the string. More...
 
const PointgetMatchPos () const
 After the search has finished, use this to know the latest position of the match of the regex in the input string. More...
 
bool step (char c, const Point &pos)
 Step through the NFA state using the current char. More...
 
void reset ()
 Reset all the variables used during regex search. This needs to be called once before beginning of every search. More...
 

Static Public Attributes

static const size_t NoMatch = std::string::npos
 

Detailed Description

Ken-Thompson NFA as described here: https://swtch.com/~rsc/regexp/regexp1.html but adjusted to work with teditor environment.

Note
the current design is not thread-safe! Meaning, the same NFA object cannot be used by multiple threads at the same. It will cause corruption of data

Constructor & Destructor Documentation

◆ NFA()

teditor::parser::NFA::NFA ( const std::string &  reg)

ctor with adding a regex for the NFA

Parameters
regregex

◆ ~NFA()

teditor::parser::NFA::~NFA ( )
inline

Member Function Documentation

◆ find()

size_t teditor::parser::NFA::find ( const std::string &  str,
size_t  start = 0,
size_t  end = 0 
)

String match function.

Parameters
strthe input string
startlocation from where to start searching
endlocation (minus 1) till where to search
Returns
the location of the longest match, else returns NFA::NoMatch

◆ findAny()

size_t teditor::parser::NFA::findAny ( const std::string &  str,
size_t &  matchStartPos,
size_t  start = 0,
size_t  end = 0 
)

Tries for regex match starting from anywhere in the string.

Parameters
strthe input string
matchStartPoswill contain the starting location of the longest match, if found, else, NFA::NoMatch
startlocation from where to start searching
endlocation (minus 1) till where to search
Returns
the location of the longest match, else returns NFA::NoMatch

Member Data Documentation

◆ NoMatch

const size_t teditor::parser::NFA::NoMatch = std::string::npos
static

represents case when regex didn't match anything


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