reglibcpp  2.0.0
A C++ implementation of models for regular languages
Classes | Functions | Variables
reg Namespace Reference

Where this library lives. More...

Classes

class  dfa
 Represents deterministic finite automata. More...
 
class  expression
 Represents formal regular expressions. More...
 
class  fabuilder
 Constructs NFAs step by step. More...
 
class  gnfa
 Represents generalized nondeterministic finite automata. More...
 
class  nfa
 Represents nondeterministic finite automata with ε-moves. More...
 
struct  state_not_found
 Signals that a state was mentioned that isn't part of the FA. More...
 
struct  symbol_not_found
 Signals that an input symbol was used that the FA doesn't recognize. More...
 

Functions

u32string findShortestWord_ (dfa const &d)
 Searches the shortest UTF-32-encoded word accepted by a given DFA. More...
 
string findShortestWord (dfa const &d)
 Searches the shortest UTF-8-encoded word accepted by a given DFA. More...
 
u32string findShortestWord_ (nfa const &n)
 Searches the shortest UTF-32-encoded word accepted by a given NFA. More...
 
string findShortestWord (nfa const &n)
 Same as above for a UTF-8-encoded word. More...
 
template<class C , class T >
size_t index_of (C const &container, T const &element)
 Basically Java's List interface's indexOf, but as a non-member function and returning the container's size upon failure. More...
 

Variables

std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > converter
 Converts between UTF-8-encoded and UTF-32-encoded strings. More...
 

Detailed Description

Where this library lives.

Function Documentation

◆ findShortestWord() [1/2]

std::string reg::findShortestWord ( dfa const &  d)

Searches the shortest UTF-8-encoded word accepted by a given DFA.

This calls findShortestWord_() and converts the result to UTF-8. If you don't want that overhead and can handle UTF-32-encoded strings, use that function.

Parameters
dthe DFA
Returns
the shortest word leading to one of the DFA's accept states
Exceptions
std::logic_errorif the DFA doesn't accept any words

Definition at line 483 of file dfa.cpp.

◆ findShortestWord() [2/2]

std::string reg::findShortestWord ( nfa const &  n)

Same as above for a UTF-8-encoded word.

Definition at line 706 of file nfa.cpp.

◆ findShortestWord_() [1/2]

std::u32string reg::findShortestWord_ ( dfa const &  d)

Searches the shortest UTF-32-encoded word accepted by a given DFA.

Parameters
dthe DFA
Returns
the shortest word leading to one of the DFA's accept states
Exceptions
std::logic_errorif the DFA doesn't accept any words

Definition at line 447 of file dfa.cpp.

◆ findShortestWord_() [2/2]

std::u32string reg::findShortestWord_ ( nfa const &  n)

Searches the shortest UTF-32-encoded word accepted by a given NFA.

Parameters
nthe NFA
Returns
the shortest word leading to one of the NFA's accept states
Exceptions
std::logic_errorif the NFA doesn't accept any words

Definition at line 674 of file nfa.cpp.

◆ index_of()

template<class C , class T >
size_t reg::index_of ( C const &  container,
T const &  element 
)

Basically Java's List interface's indexOf, but as a non-member function and returning the container's size upon failure.

Parameters
containerthe container to search through
elementthe element to find the index of
Returns
the first i with container.begin()[i]==element or container.size() if none is found

Definition at line 43 of file utils.h.

Variable Documentation

◆ converter

std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> reg::converter
inline

Converts between UTF-8-encoded and UTF-32-encoded strings.

Definition at line 52 of file utils.h.