edelib
2.1.0
|
#include <edelib/Regex.h>
Public Types | |
typedef list< RegexMatch > | MatchVec |
Public Member Functions | |
Regex () | |
~Regex () | |
bool | compile (const char *pattern, int m=0) |
operator bool (void) const | |
int | match (const char *str, int match_mode, int start, int len, MatchVec *matches) |
int | match (const char *str, int match_mode=0, MatchVec *matches=0) |
int | split (const char *str, list< String > &ls, int match_mode=0) |
const char * | strerror (void) const |
Regex class.
Regex is pattern matching (aka. regular expression) class used to search certain substrings inside line or text. This class use Perl compatible expressions thanks to PCRE backend.
Before doing some matching, you must compile pattern first buy using compile() member.
Matching is done via match() member. It will return the number of matched substrings and (if given) set RegexMatch list with offsets. If fails, -1 will be returned. Here is the sample: that explains it:
Here, match() will return 2 and MatchVec list will have (5,4) and (5,2) values (where the first value is offset and the second substring length). This explains one important property inherited from PCRE: when grouped patterns are involved and they are found in string, MatchVec first element will be full matched string and substrings will follow.
typedef list<RegexMatch> MatchVec |
Shortcut for the list of RegexMatch
Regex | ( | ) |
Empty constructor
~Regex | ( | ) |
Clears all internal data
bool compile | ( | const char * | pattern, |
int | m = 0 |
||
) |
Compile pattern for matching. This must be called before match/search functions.
pattern | is matching pattern |
m | is RegexMode type |
int match | ( | const char * | str, |
int | match_mode, | ||
int | start, | ||
int | len, | ||
MatchVec * | matches | ||
) |
Search compiled pattern in str and return number of grouped matches. If pattern wasn't found or some error occured during search, returned value (depending on error) will be less than 0 (see PCRE documentation about returned values).
str | is target string where compiled pattern is searched |
match_mode | is OR-ed RegexMatchMode value |
start | is starting position on string |
len | is desired length where matching will occur; if given -1, full length will be searched |
matches | is list of matching objects |
|
inline |
The same as above match(), but matching will start from the beginning and full string length will be used
operator bool | ( | void | ) | const |
Split given str and put each of splitted items in list.
str | is data to be splitted |
ls | is list where to put data |
match_mode | is OR-ed RegexMatchMode value |
const char* strerror | ( | void | ) | const |
Return error in string form. Returned value points to static data and must not be modified or cleared