PixelLightAPI  .
Public Types | Public Member Functions | Static Public Member Functions
PLCore::RegEx Class Reference

Regular expression class (PCRE syntax) More...

#include <RegEx.h>

List of all members.

Public Types

enum  EFlags {
  MatchCaseSensitive = 1, MatchGreedy = 2, EncodingASCII = 4, EncodingUTF8 = 8,
  Multiline = 16, DotAll = 32
}
 Matching and encoding flags. More...

Public Member Functions

 RegEx ()
 Constructor.
 RegEx (const String &sExpression, uint32 nFlags=MatchCaseSensitive|MatchGreedy)
 Constructor.
 RegEx (const RegEx &cRegEx)
 Copy constructor.
PLCORE_API ~RegEx ()
 Destructor.
RegExoperator= (const RegEx &cRegEx)
 Assignment operator.
String GetExpression () const
 Get regular expression.
PLCORE_API void SetExpression (const String &sExpression, uint32 nFlags=MatchCaseSensitive|MatchGreedy)
 Set regular expression.
bool IsValid () const
 Check if the regular expression is valid.
uint32 GetFlags () const
 Get mode and encoding flags.
bool IsCaseSensitive () const
 Is the expression case sensitive?
bool IsGreedy () const
 Is the expression greedy?
bool IsASCII () const
 Is ASCII encoding used?
bool IsUTF8 () const
 Is UTF8 encoding used?
PLCORE_API void Study ()
 Analyze the regular expression and store additional internal information.
PLCORE_API bool Match (const String &sSubject, uint32 nPosition=0)
 Check if a string matches the given regular expression.
int GetPosition () const
 Get current byte position in the subject string.
const Array< String > & GetResults () const
 Get the results of the last check.
String GetResult (uint32 nIndex) const
 Get a matching group from the last check.
const Map< String, String > & GetNameResults () const
 Get the results of the last check by name.
String GetNameResult (const String &sName) const
 Get a matching group from the last check by name.
void ClearResults ()
 Clear all results.

Static Public Member Functions

static PLCORE_API String WildcardToRegEx (const String &sWildcard)
 Converts a given wildcard into a regular expression.

Detailed Description

Regular expression class (PCRE syntax)

Remarks:
Internally the PCRE library (http://www.pcre.org) is used - this here is only a wrapper interface. This class supports ASCII and UTF8 encoding. You can force a certain encoding by setting special flags like 'EncodingASCII' for forced ASCII encoding. If no such encoding flags are set by the user, the internal string format of the given regular expression is used as encoding.

Member Enumeration Documentation

Matching and encoding flags.

Enumerator:
MatchCaseSensitive 

Match is case sensitive

MatchGreedy 

Match is greedy

EncodingASCII 

ASCII encoding, 1 byte per character (American Standard Code for Information Interchange, 0-128 defined, above undefined)

EncodingUTF8 

UTF8 encoding (8-bit Unicode Transformation Format) with 1 to 6 bytes to encode one Unicode character

Multiline 

PCRE-documentation says: "The "start of line" and "end of line" constructs match immediately following or immediately before internal newlines in the subject string, respectively, as well as at the very start and end"

DotAll 

PCRE-documentation says: "A dot metacharacter in the pattern matches a character of any value, including one that indicates a newline"


Constructor & Destructor Documentation

PLCore::RegEx::RegEx ( ) [inline]
PLCore::RegEx::RegEx ( const String sExpression,
uint32  nFlags = MatchCaseSensitive | MatchGreedy 
) [inline]

Constructor.

Parameters:
[in]sExpressionRegular expression
[in]nFlagsProcessing mode and encoding (combination of EFlags values)
PLCore::RegEx::RegEx ( const RegEx cRegEx) [inline]

Copy constructor.

Parameters:
[in]cRegExRegEx to copy
PLCORE_API PLCore::RegEx::~RegEx ( )

Destructor.


Member Function Documentation

static PLCORE_API String PLCore::RegEx::WildcardToRegEx ( const String sWildcard) [static]

Converts a given wildcard into a regular expression.

Parameters:
[in]sWildcardString with wildcard to convert (for example "BeerNumber*")
Returns:
The converted regular expression (for example "^BeerNumber.*$")
RegEx & PLCore::RegEx::operator= ( const RegEx cRegEx) [inline]

Assignment operator.

Parameters:
[in]cRegExRegEx to copy
Returns:
Reference to this instance

Get regular expression.

Returns:
Regular expression
PLCORE_API void PLCore::RegEx::SetExpression ( const String sExpression,
uint32  nFlags = MatchCaseSensitive|MatchGreedy 
)

Set regular expression.

Parameters:
[in]sExpressionRegular expression
[in]nFlagsProcessing mode and encoding (combination of EFlags values)
bool PLCore::RegEx::IsValid ( ) const [inline]

Check if the regular expression is valid.

Returns:
Regular expression
uint32 PLCore::RegEx::GetFlags ( ) const [inline]

Get mode and encoding flags.

Returns:
Mode and encoding flags (combination of EFlags values)
bool PLCore::RegEx::IsCaseSensitive ( ) const [inline]

Is the expression case sensitive?

Returns:
'true', if the expression is treated case sensitive, else 'false'
bool PLCore::RegEx::IsGreedy ( ) const [inline]

Is the expression greedy?

Returns:
'true', if the matching is greedy, else 'false'
bool PLCore::RegEx::IsASCII ( ) const [inline]

Is ASCII encoding used?

Returns:
'true', if ASCII encoding, else 'false'
bool PLCore::RegEx::IsUTF8 ( ) const [inline]

Is UTF8 encoding used?

Returns:
'true', if UTF8 encoding, else 'false'
PLCORE_API void PLCore::RegEx::Study ( )

Analyze the regular expression and store additional internal information.

Remarks:
This function analyses and stores additional internal information about the regular expression, which is later used to speed up processing. So you should call this e.g. for rather complicated expressions and/or expressions that are used many times.
PLCORE_API bool PLCore::RegEx::Match ( const String sSubject,
uint32  nPosition = 0 
)

Check if a string matches the given regular expression.

Parameters:
[in]sSubjectString to test
[in]nPositionStart byte position in the string, for instance a value received by 'GetPosition()'
Remarks:
'sSubject' is internally automatically converted into the internal string format this regular expression is using. You can for instance use 'IsASCII()' to check whether or not ASCII is used.
Returns:
'true' if the string matches, else 'false'
int PLCore::RegEx::GetPosition ( ) const [inline]

Get current byte position in the subject string.

Returns:
New byte position in the subject string after the last match
const Array< String > & PLCore::RegEx::GetResults ( ) const [inline]

Get the results of the last check.

Returns:
List containing all matching groups
String PLCore::RegEx::GetResult ( uint32  nIndex) const [inline]

Get a matching group from the last check.

Parameters:
[in]nIndexWhich group shall be returned?
Returns:
The matching substring or ""
const Map< String, String > & PLCore::RegEx::GetNameResults ( ) const [inline]

Get the results of the last check by name.

Returns:
Map containing all matching groups as pairs of name->substring
String PLCore::RegEx::GetNameResult ( const String sName) const [inline]

Get a matching group from the last check by name.

Parameters:
[in]sNameWhich group shall be returned?
Returns:
The matching substring or ""
void PLCore::RegEx::ClearResults ( ) [inline]

Clear all results.


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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:15
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported