edbee - Qt Editor Library
Public Types | Public Member Functions | Static Public Member Functions | List of all members
edbee::RegExp Class Reference

A class for matching QStrings with the Oniguruma API We need this Regular Expression library to be able to support tmLanguages fully I tried to make this class as close as possible to the QRegExp library. More...

#include <regexp.h>

+ Collaboration diagram for edbee::RegExp:

Public Types

enum  Engine { EngineOniguruma = 1, EngineQRegExp = 2 }
 
enum  Syntax { SyntaxDefault, SyntaxFixedString }
 

Public Member Functions

 RegExp (const QString &pattern, bool caseSensitive=true, Syntax syntax=SyntaxDefault, Engine engine=EngineOniguruma)
 Constructs the regular expression matcher. More...
 
virtual ~RegExp ()
 destructs the regular expression object More...
 
bool isValid () const
 returns true if the supplied regular expression was valid More...
 
QString errorString () const
 returns the error message of the regular expression More...
 
QString pattern () const
 returns th supplied pattern More...
 
int indexIn (const QString &str, int offset=0)
 Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc. Returns the position of the first match, or -1 if there was no match. The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset. You might prefer to use QString::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace(). More...
 
int indexIn (const QChar *str, int offset, int length)
 Searchers for the regular expression in the given string. More...
 
int lastIndexIn (const QString &str, int offset=-1)
 Searcher for the last match of the regular expression in the given string. More...
 
int lastIndexIn (const QChar *str, int offset, int length)
 Searchers for the last match of the regular expression in the given string. More...
 
int pos (int nth=0) const
 Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match. For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation. More...
 
int len (int nth=0) const
 The length of nth element. More...
 
QString cap (int nth=0) const
 This method returns the given matched length. More...
 
int matchedLength ()
 matched length is equal to pos-0-length More...
 

Static Public Member Functions

static QString escape (const QString &str, Engine engine=EngineOniguruma)
 escapes a string with every regexp special character escaped we currently always use QRegExp::escape.. For the future we added an engine parameter which is currently ignored More...
 

Detailed Description

A class for matching QStrings with the Oniguruma API We need this Regular Expression library to be able to support tmLanguages fully I tried to make this class as close as possible to the QRegExp library.

Member Enumeration Documentation

◆ Engine

Enumerator
EngineOniguruma 
EngineQRegExp 

◆ Syntax

Enumerator
SyntaxDefault 
SyntaxFixedString 

The default syntax.

A plain fixed string

Constructor & Destructor Documentation

◆ RegExp()

edbee::RegExp::RegExp ( const QString &  pattern,
bool  caseSensitive = true,
Syntax  syntax = SyntaxDefault,
Engine  engine = EngineOniguruma 
)

Constructs the regular expression matcher.

Parameters
patternthe pattern of the regular expression
caseSensitiveshould the match be case sensitive
syntaxthe syntax of th given regular expression (SyntaxDefault(default) or SyntaxFixedString)
enginethe engine to use (EngineOniguruma(default) or EngineQRegExp)

◆ ~RegExp()

edbee::RegExp::~RegExp ( )
virtual

destructs the regular expression object

Member Function Documentation

◆ cap()

QString edbee::RegExp::cap ( int  nth = 0) const

This method returns the given matched length.

◆ errorString()

QString edbee::RegExp::errorString ( ) const

returns the error message of the regular expression

◆ escape()

QString edbee::RegExp::escape ( const QString &  str,
RegExp::Engine  engine = EngineOniguruma 
)
static

escapes a string with every regexp special character escaped we currently always use QRegExp::escape.. For the future we added an engine parameter which is currently ignored

◆ indexIn() [1/2]

int edbee::RegExp::indexIn ( const QString &  str,
int  offset = 0 
)

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc. Returns the position of the first match, or -1 if there was no match. The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset. You might prefer to use QString::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace().

◆ indexIn() [2/2]

int edbee::RegExp::indexIn ( const QChar *  str,
int  offset,
int  length 
)

Searchers for the regular expression in the given string.

Parameters
strthe string to search in
offsetthe offset to start searching
lengththe length of the supplied string
Returns
the found index of the regular expression

◆ isValid()

bool edbee::RegExp::isValid ( ) const

returns true if the supplied regular expression was valid

◆ lastIndexIn() [1/2]

int edbee::RegExp::lastIndexIn ( const QString &  str,
int  offset = -1 
)

Searcher for the last match of the regular expression in the given string.

Parameters
strthe string to search in
offsetthe offset to start searching
Returns
the found index of the regular expression

◆ lastIndexIn() [2/2]

int edbee::RegExp::lastIndexIn ( const QChar *  str,
int  offset,
int  length 
)

Searchers for the last match of the regular expression in the given string.

Parameters
strthe string to search in
offsetthe offset to start searching
lengththe length of the supplied string
Returns
the found index of the regular expression

◆ len()

int edbee::RegExp::len ( int  nth = 0) const

The length of nth element.

◆ matchedLength()

int edbee::RegExp::matchedLength ( )
inline

matched length is equal to pos-0-length

◆ pattern()

QString edbee::RegExp::pattern ( ) const

returns th supplied pattern

◆ pos()

int edbee::RegExp::pos ( int  nth = 0) const

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match. For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation.


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