crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Query::RegEx Class Reference

Implements a RegEx query using the PCRE2 library. More...

#include <RegEx.hpp>

Classes

class  Exception
 Class for JSONPath exceptions. More...
 

Construction

 RegEx (const std::string &expression, bool single, bool multi)
 Constructor setting a RegEx string and whether the query will return single and/or multiple results. More...
 

Getters

bool getBool (const std::string &text) const
 Gets a boolean result from performing the query on a parsed JSON document. More...
 
void getFirst (const std::string &text, std::string &resultTo) const
 Gets the first match from performing the query on a parsed JSON document. More...
 
void getAll (const std::string &text, std::vector< std::string > &resultTo) const
 Gets all matches from performing the query on a parsed JSON document. More...
 
bool valid () const noexcept
 Gets whether the query is valid. More...
 

Detailed Description

Implements a RegEx query using the PCRE2 library.

For more information about the PCRE2 library, see its website.

Constructor & Destructor Documentation

◆ RegEx()

crawlservpp::Query::RegEx::RegEx ( const std::string &  expression,
bool  single,
bool  multi 
)
inline

Constructor setting a RegEx string and whether the query will return single and/or multiple results.

Note
Cannot use string view, because the underlying API requires a null- terminated string.
Parameters
expressionConst reference to a string containing the RegEx query. Newlines at the end of the expression will be removed.
singleSet whether the query can return single results.
multiSet whether the query can return multiple results.
Exceptions
RegEx::Exceptionif the given expression is empty, no result type has been specified, or the compilation of the RegEx expression failed.

References crawlservpp::Query::pcre2ErrorBufferLength, crawlservpp::Wrapper::PCRE::set(), and crawlservpp::Wrapper::PCRE::valid().

Member Function Documentation

◆ getAll()

void crawlservpp::Query::RegEx::getAll ( const std::string &  text,
std::vector< std::string > &  resultTo 
) const
inline

Gets all matches from performing the query on a parsed JSON document.

Note
Cannot use string view, because the underlying API requires a null- terminated string.
Parameters
textConst reference to a string containing the text on which the query should be performed.
resultToReference to a vector to which the results will be written. The vector will be cleared even if an error occurs during execution of the query.
Exceptions
RegEx::Exceptionif no RegEx expression has been defined, an error occurs during execution of the query, or the output vector is unexpectedly too small to contain the result.

References crawlservpp::Query::bitmaskTopBit, crawlservpp::Query::bitmaskTopTwoBits, crawlservpp::Wrapper::PCREMatch::get(), crawlservpp::Wrapper::PCRE::getc(), crawlservpp::Query::pcre2ErrorBufferLength, and crawlservpp::Wrapper::PCRE::valid().

Referenced by crawlservpp::Main::Server::tick().

◆ getBool()

bool crawlservpp::Query::RegEx::getBool ( const std::string &  text) const
inline

Gets a boolean result from performing the query on a parsed JSON document.

Note
Cannot use string view, because the underlying API requires a null- terminated string.
Parameters
textConst reference to a string containing the text on which the query should be performed.
Returns
True, if there is at least one match after performing the query on the document. False otherwise.
Exceptions
RegEx::Exceptionif no RegEx expression has been defined, an error occurs during execution of the query, or the output vector is unexpectedly too small to contain the result.

References crawlservpp::Wrapper::PCREMatch::get(), crawlservpp::Wrapper::PCRE::getc(), crawlservpp::Query::pcre2ErrorBufferLength, and crawlservpp::Wrapper::PCRE::valid().

Referenced by crawlservpp::Main::Server::tick().

◆ getFirst()

void crawlservpp::Query::RegEx::getFirst ( const std::string &  text,
std::string &  resultTo 
) const
inline

Gets the first match from performing the query on a parsed JSON document.

Note
Cannot use string view, because the underlying API requires a null- terminated string.
Parameters
textConst reference to a string containing the text on which the query should be performed.
resultToReference to a string to which the result will be written. The string will be cleared even if an error occurs during execution of the query.
Exceptions
RegEx::Exceptionif no RegEx expression has been defined, an error occurs during execution of the query, or the output vector is unexpectedly too small to contain the result.

References crawlservpp::Wrapper::PCREMatch::get(), crawlservpp::Wrapper::PCRE::getc(), crawlservpp::Query::pcre2ErrorBufferLength, and crawlservpp::Wrapper::PCRE::valid().

Referenced by crawlservpp::Main::Server::tick().

◆ valid()

bool crawlservpp::Query::RegEx::valid ( ) const
inlinenoexcept

Gets whether the query is valid.

Returns
True, if the unerlying expression is valid. False otherwise.

References crawlservpp::Wrapper::PCRE::valid().


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