Doxygen
Loading...
Searching...
No Matches
reg Namespace Reference

Namespace for the regular expression functions. More...

Classes

class  Ex
 Class representing a regular expression. More...
class  Iterator
 Class to iterate through matches. More...
class  Match
 Object representing the matching results. More...
class  PToken
 Class representing a token in the compiled regular expression token stream. More...
class  SubMatch
 Object representing the match results of a capture range. More...

Functions

static bool isspace (char c)
static bool isalpha (char c)
static bool isdigit (char c)
static bool isalnum (char c)
static std::string wildcard2regex (std::string_view pattern)
bool search (std::string_view str, Match &match, const Ex &re, size_t pos=0)
 Search in a given string str starting at position pos for a match against regular expression re.
bool search (std::string_view str, const Ex &re, size_t pos=0)
 Search in a given string str starting at position pos for a match against regular expression re.
bool match (std::string_view str, Match &match, const Ex &re)
 Matches a given string str for a match against regular expression re.
bool match (std::string_view str, const Ex &re)
 Matches a given string str for a match against regular expression re.
std::string replace (std::string_view str, const Ex &re, std::string_view replacement)
 Searching in a given input string for parts that match regular expression re and replaces those parts by string replacement.

Detailed Description

Namespace for the regular expression functions.

Function Documentation

◆ isalnum()

bool reg::isalnum ( char c)
inlinestatic

Definition at line 48 of file regex.cpp.

49{
50 return isalpha(c) || isdigit(c);
51}
static bool isalpha(char c)
Definition regex.cpp:38
static bool isdigit(char c)
Definition regex.cpp:43

References isalnum(), isalpha(), and isdigit().

Referenced by isalnum(), and reg::Ex::Private::matchAt().

◆ isalpha()

bool reg::isalpha ( char c)
inlinestatic

Definition at line 38 of file regex.cpp.

39{
40 return static_cast<unsigned char>(c)>=128 || (c>='a' && c<='z') || (c>='A' && c<='Z');
41}

References isalpha().

Referenced by isalnum(), isalpha(), and reg::Ex::Private::matchAt().

◆ isdigit()

bool reg::isdigit ( char c)
inlinestatic

Definition at line 43 of file regex.cpp.

44{
45 return c>='0' && c<='9';
46}

References isdigit().

Referenced by isalnum(), isdigit(), and reg::Ex::Private::matchAt().

◆ isspace()

bool reg::isspace ( char c)
inlinestatic

Definition at line 33 of file regex.cpp.

34{
35 return c==' ' || c=='\t' || c=='\n' || c=='\r';
36}

References isspace().

Referenced by isspace(), and reg::Ex::Private::matchAt().

◆ match() [1/2]

bool reg::match ( std::string_view str,
const Ex & re )

Matches a given string str for a match against regular expression re.

Returns true iff a match was found for the whole string.

Definition at line 863 of file regex.cpp.

864{
865 Match match;
866 return re.match(str,match,0) && match.position()==0 && match.length()==str.length();
867}
bool match(std::string_view str, Match &match, size_t pos=0) const
Check if a given string matches this regular expression.
Definition regex.cpp:805
Object representing the matching results.
Definition regex.h:154
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:858

References reg::Ex::match(), and match().

◆ match() [2/2]

bool reg::match ( std::string_view str,
Match & match,
const Ex & re )

Matches a given string str for a match against regular expression re.

Returns true iff a match was found for the whole string. Any capture groups are returned via the match object.

Definition at line 858 of file regex.cpp.

859{
860 return re.match(str,match,0) && match.position()==0 && match.length()==str.length();
861}

References reg::Ex::match(), and match().

Referenced by DocParser::checkArgumentName(), dateTimeFromString(), endBrief(), genericPatternMatch(), getFilterFromList(), DocParser::handleStyleArgument(), VhdlDocGen::isNumber(), match(), match(), replace(), search(), search(), setOutput(), and LayoutParser::startLayout().

◆ replace()

std::string reg::replace ( std::string_view str,
const Ex & re,
std::string_view replacement )

Searching in a given input string for parts that match regular expression re and replaces those parts by string replacement.

Definition at line 869 of file regex.cpp.

870{
871 std::string result;
872 Match match;
873 size_t p=0;
874 while (re.match(str,match,p))
875 {
876 size_t i=match.position();
877 size_t l=match.length();
878 if (i>p) result+=str.substr(p,i-p);
879 result+=replacement;
880 p=i+l;
881 }
882 if (p<str.length()) result+=str.substr(p);
883 return result;
884}

References reg::Ex::match(), match(), and replace().

Referenced by VhdlDocGen::addBaseClass(), VHDLOutlineParser::checkInlineCode(), FlowChart::printNode(), replace(), and replaceAnonymousScopes().

◆ search() [1/2]

bool reg::search ( std::string_view str,
const Ex & re,
size_t pos = 0 )

Search in a given string str starting at position pos for a match against regular expression re.

Returns true iff a match was found.

Definition at line 852 of file regex.cpp.

853{
854 Match match;
855 return re.match(str,match,pos);
856}

References reg::Ex::match(), match(), and search().

◆ search() [2/2]

bool reg::search ( std::string_view str,
Match & match,
const Ex & re,
size_t pos = 0 )

Search in a given string str starting at position pos for a match against regular expression re.

Returns true iff a match was found. Details of what part of the string has matched is returned via the match object.

An example to show how to match all identifiers in a string.

static reg::Ex re(R"(\a\w*)");
std::string = u8"void(Func是<B_C::Códe42>(42));";
while (reg::search(str,match,re,pos))
{
std::cout << match.str() << std::endl;
pos=match.position()+match.length();
}
Class representing a regular expression.
Definition regex.h:39
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:847

produces:

void
Func是
B_C
Códe42
See also
Ex::Ex() for details on the regular expression patterns.

Definition at line 847 of file regex.cpp.

848{
849 return re.match(str,match,pos);
850}

References reg::Ex::match(), match(), and search().

Referenced by CommentScanner::addDeprecatedDocs(), HtmlHelpIndex::addItem(), addValidAliasToMap(), addVariable(), addVariableToFile(), VHDLOutlineParser::checkInlineCode(), containsEnvVar(), MemberDefImpl::displayDefinition(), expandAliasRec(), Markdown::Private::extractTitleId(), findFunctionPtr(), findIndex(), FormulaManager::initFromRepository(), insertDimension(), isVarWithConstructor(), loadExtensions(), loadStylesheet(), matchExcludedSymbols(), MarkdownOutlineParser::parseInput(), runQHelpGenerator(), search(), search(), StyleData::setStyle(), simplifyTypeForTable(), splitKnRArg(), StyleData::StyleData(), DotAttributes::updateValue(), MemberDefImpl::writeDeclaration(), MemberDefImpl::writeDocumentation(), and MemberDefImpl::writeMemberDocSimple().

◆ wildcard2regex()

std::string reg::wildcard2regex ( std::string_view pattern)
static

Definition at line 748 of file regex.cpp.

749{
750 std::string result="^"; // match start of input
751 result.reserve(pattern.length());
752 for (size_t i=0;i<pattern.length();i++)
753 {
754 char c=pattern[i];
755 switch(c)
756 {
757 case '*':
758 result+=".*";
759 break; // '*' => '.*'
760 case '?':
761 result+='.';
762 break; // '?' => '.'
763 case '.':
764 case '+':
765 case '\\':
766 case '$':
767 case '^':
768 case '(':
769 case ')':
770 result+='\\'; result+=c; // escape
771 break;
772 case '[':
773 if (i<pattern.length()-1 && pattern[i+1]=='^') // don't escape ^ after [
774 {
775 result+="[^";
776 i++;
777 }
778 else
779 {
780 result+=c;
781 }
782 break;
783 default: // just copy
784 result+=c;
785 break;
786 }
787 }
788 result+='$'; // match end of input
789 return result;
790}

References wildcard2regex().

Referenced by reg::Ex::Ex(), and wildcard2regex().