Skip to main content

The reg Namespace Reference

Namespace for the regular expression functions. More...

Definition

namespace reg { ... }

Classes Index

classEx

Class representing a regular expression. More...

classIterator

Class to iterate through matches. More...

classMatch

Object representing the matching results. More...

classPToken

Class representing a token in the compiled regular expression token stream. More...

classSubMatch

Object representing the match results of a capture range. More...

Functions Index

static boolisspace (char c)
static boolisalpha (char c)
static boolisdigit (char c)
static boolisalnum (char c)
static std::stringwildcard2regex (std::string_view pattern)
boolsearch (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. More...

boolsearch (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. More...

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

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

boolmatch (std::string_view str, const Ex &re)

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

std::stringreplace (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. More...

Description

Namespace for the regular expression functions.

Functions

isalnum()

bool reg::isalnum (char c)
inline static

Definition at line 48 of file regex.cpp.

48static inline bool isalnum(char c)
49{
50 return isalpha(c) || isdigit(c);
51}

References isalpha and isdigit.

Referenced by reg::Ex::Private::matchAt.

isalpha()

bool reg::isalpha (char c)
inline static

Definition at line 38 of file regex.cpp.

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

Referenced by isalnum and reg::Ex::Private::matchAt.

isdigit()

bool reg::isdigit (char c)
inline static

Definition at line 43 of file regex.cpp.

43static inline bool isdigit(char c)
44{
45 return c>='0' && c<='9';
46}

Referenced by isalnum and reg::Ex::Private::matchAt.

isspace()

bool reg::isspace (char c)
inline static

Definition at line 33 of file regex.cpp.

33static inline bool isspace(char c)
34{
35 return c==' ' || c=='\t' || c=='\n' || c=='\r';
36}

Referenced by reg::Ex::Private::matchAt.

match()

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 759 of file regex.cpp.

759bool match(std::string_view str,Match &match,const Ex &re)
760{
761 return re.match(str,match,0) && match.position()==0 && match.length()==str.length();
762}

References reg::Ex::match and match.

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

match()

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 764 of file regex.cpp.

764bool match(std::string_view str,const Ex &re)
765{
767 return re.match(str,match,0) && match.position()==0 && match.length()==str.length();
768}

References reg::Ex::match and match.

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 770 of file regex.cpp.

770std::string replace(std::string_view str,const Ex &re,std::string_view replacement)
771{
772 std::string result;
774 size_t p=0;
775 while (re.match(str,match,p))
776 {
777 size_t i=match.position();
778 size_t l=match.length();
779 if (i>p) result+=str.substr(p,i-p);
780 result+=replacement;
781 p=i+l;
782 }
783 if (p<str.length()) result+=str.substr(p);
784 return result;
785}

References reg::Ex::match and match.

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

search()

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();
 }

produces:

 void
 Func是
 B_C
 Códe42
See Also

Ex::Ex() for details on the regular expression patterns.

Definition at line 748 of file regex.cpp.

748bool search(std::string_view str,Match &match,const Ex &re,size_t pos)
749{
750 return re.match(str,match,pos);
751}

References reg::Ex::match and match.

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

search()

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 753 of file regex.cpp.

753bool search(std::string_view str,const Ex &re,size_t pos)
754{
756 return re.match(str,match,pos);
757}

References reg::Ex::match and match.

wildcard2regex()

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

Definition at line 649 of file regex.cpp.

649static std::string wildcard2regex(std::string_view pattern)
650{
651 std::string result="^"; // match start of input
652 result.reserve(pattern.length());
653 for (size_t i=0;i<pattern.length();i++)
654 {
655 char c=pattern[i];
656 switch(c)
657 {
658 case '*':
659 result+=".*";
660 break; // '*' => '.*'
661 case '?':
662 result+='.';
663 break; // '?' => '.'
664 case '.':
665 case '+':
666 case '\\':
667 case '$':
668 case '^':
669 case '(':
670 case ')':
671 result+='\\'; result+=c; // escape
672 break;
673 case '[':
674 if (i<pattern.length()-1 && pattern[i+1]=='^') // don't escape ^ after [
675 {
676 result+="[^";
677 i++;
678 }
679 else
680 {
681 result+=c;
682 }
683 break;
684 default: // just copy
685 result+=c;
686 break;
687 }
688 }
689 result+='$'; // match end of input
690 return result;
691}

Referenced by reg::Ex::Ex.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.