RegularExpressionInterface Class Reference

#include <stringregularexpression.h>

Detailed Description

Class to operate with regular expressions. This class is not a complete regular expression parser. It supports only a subset of regular expressions. Supported functions are:

Public Types

using FindRecvType = Tuple< Int, String >
 

Public Member Functions

MAXON_METHOD Result< void > InitExpression (const String &regularExpression)
 
MAXON_METHOD Result< void > InitSimpleExpression (const String &simpleExpression)
 
MAXON_METHOD Result< BoolFind (const String &text, REGPARSEMODE mode, Bool onlyFirst, Int *resPos, String *resPattern)
 
MAXON_METHOD Result< BoolFindNext (const String &text, Int *resPos, String *resPattern)
 
MAXON_METHOD Result< BoolFindAll (const String &text, REGPARSEMODE mode, const ValueReceiver< const FindRecvType & > &recv, Bool onlyFirst=false) const
 

Static Public Member Functions

static MAXON_METHOD RegularExpressionInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (RegularExpressionInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.regularexpression")
 

Member Typedef Documentation

◆ FindRecvType

See FindAll, ValueReceiver element type.

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( RegularExpressionInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.regularexpression"   
)
private

◆ Alloc()

Parameters
[in]allocLocationSource location.

◆ InitExpression()

MAXON_METHOD Result<void> InitExpression ( const String regularExpression)

Initializes the regular expression parser with a complex expression.

Parameters
[in]regularExpressionA pattern string which allows the following placeholders:
  • * ... Zero or more of previous character.
  • + ... One or more of previous character.
  • . ... Any single character.
  • # ... Any single digit.
  • | ... Or condition.
  • [] ... One of the characters in the braces. E.g. [a-zA-Z] a-z or A-Z. [abc] a, b or c.
  • () ... A group of conditions. E.g. "(A|B)+" matches "ABAABB" but not "ACCCA".
Returns
OK on success.

◆ InitSimpleExpression()

MAXON_METHOD Result<void> InitSimpleExpression ( const String simpleExpression)

Initializes the regular expression parser with a simple expression. It can be used to find simple strings like: "net.maxon.unittest.*" to find all unit tests.

Parameters
[in]simpleExpressionA pattern string which allows the following placeholders:
  • * ... Zero or more of any character.
  • # ... One or more number characters (0...9). E.g. to check an ip4 address you can use the simple pattern "#.#.#.#" which matches "192.168.2.1".
  • ? ... Any single character.
  • | ... Or condition.
Returns
OK on success.

◆ Find()

MAXON_METHOD Result<Bool> Find ( const String text,
REGPARSEMODE  mode,
Bool  onlyFirst,
Int resPos,
String resPattern 
)

Finds the first occurrence of the expression in the given text.

Parameters
[in]textThe text to search through.
[in]modeSearch mode for the find operation.
See also
REGPARSEMODE.
Parameters
[in]onlyFirstSet to true if the search should return after the first finding. This speeds up search because otherwise the call will collect all further patterns.
[out]resPosReturns the position of the matching pattern.
[out]resPatternReturns the string of the matching pattern.
Returns
True if the function call found any match.

◆ FindNext()

MAXON_METHOD Result<Bool> FindNext ( const String text,
Int resPos,
String resPattern 
)

Finds the occurrence of the expression in the given text after calling Find.

Parameters
[in]textThe text to search through.
[out]resPosReturns the position of the matching pattern.
[out]resPatternReturns the string of the matching pattern.
Returns
True if the function call found another match.

◆ FindAll()

MAXON_METHOD Result<Bool> FindAll ( const String text,
REGPARSEMODE  mode,
const ValueReceiver< const FindRecvType & > &  recv,
Bool  onlyFirst = false 
) const

Finds the first occurrence of the expression in the given text. THREADSAFE. No search result is stored internally. One can call InitExpression only once, cache the RegularExpressionInterface instance and call FindAll on this instance from any thread. Other find methods (Find, FindNext) are not thread safe. This make much faster code since the InitExpression call is the most expensive part.

Parameters
[in]textThe text to search through.
[in]modeSearch mode for the find operation.
See also
REGPARSEMODE.
Parameters
[out]recvValueReceiver called each time a pattern match is found.
[in]onlyFirstSet to true if the search should return after the first finding. This speeds up search because otherwise the call will collect all further patterns.
Returns
Result of the ValueReceiver. False if receiver was not called. Error if there was unexpected issue.