All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
The Regular Expression Engine

The regular expression engine. More...

Functions

void re_strlcpy (char *outstr, const char *instr, size_t outsz, regmatch_t rem)
 
size_t re_strlen (regmatch_t rem)
 
bool re_init (struct regeng *re_array)
 
bool re_parse (re_callback_t re_callback, struct regeng *re_array, char *str)
 
#define RE_MATCH(x)   (((x).rm_so != -1) && ((x).rm_eo != -1))
 
#define RE_INVALID_ID   0xffffffff
 
#define RE_REMATCH_MAX   32
 
#define RE_REGENG_VALID(x)
 
#define RE_REGENG_END   { .re_id = RE_INVALID_ID, .re_exp = NULL }
 
typedef void re_callback_t (uint32_t re_id, const char *str, regmatch_t *rematch, size_t rematch_max)
 

Detailed Description

The regular expression engine.

This module was written first by using regular POSIX-regex. Since there's no POSIX regex support in MinGW, it was necessary to use an external regex library – PCRE.

Note
This is the only module that heavily relies on 3rd party libraries.

Macro Definition Documentation

#define RE_INVALID_ID   0xffffffff

Marker for end of regeng

#define RE_MATCH (   x)    (((x).rm_so != -1) && ((x).rm_eo != -1))

This macro checks if a regmatch_t x was matched

Return values
trueIf x was matched
falseIf x was not matched
#define RE_REGENG_END   { .re_id = RE_INVALID_ID, .re_exp = NULL }

The last element of the regeng array must be this macro

#define RE_REGENG_VALID (   x)
Value:
(((x)->re_id != RE_INVALID_ID) && \
((x)->re_exp != NULL))

Check if the regeng is valid

#define RE_REMATCH_MAX   32

Maximum number of regmatch_t structures

Typedef Documentation

typedef void re_callback_t(uint32_t re_id, const char *str, regmatch_t *rematch, size_t rematch_max)

The regeng callback

Note
That rematch may contain fewer matches than rematch_max. RE_MATCH should be used to check if a regmatch_t element is valid or not.
Parameters
[in]re_idThis is the re_id from The Regular Expression Engine
[in]strThis is the full string that had a match
[in]rematchArray of matched parameters
[in]rematch_maxNumber of matches in rematch, maximum RE_REMATCH_MAX

Function Documentation

bool re_init ( struct regeng re_array)

Initialize the regular expression engine

Scan the regex array and compile the regular expressions in the re_exp field

Parameters
[in]re_arrayArray of regular expression structures
Returns
true on success, or false if any of the regular expressions failed to initialize.
bool re_parse ( re_callback_t  re_callback,
struct regeng re_array,
char *  str 
)

This is the main loop of the regular expression engine

Note
re_array must have been initialized with re_init() before calling this function
Parameters
[in]re_arrayInitialized regular expression array
[in]re_callbackCallback that will be called for processing any matches
[in]strString to match
Returns
Currently returns always true
void re_strlcpy ( char *  outstr,
const char *  instr,
size_t  outsz,
regmatch_t  rem 
)

Extract a sub-string that was matched by the regular expression in rem

Note
This function will properly truncate the string if the output string is too small and place a '\0' at the end without causing any overflows.
Parameters
[out]outstrSub-string pointer
[in]instrFull-string on which regex was performed
[in]outszMaximum size of the output sub-string
[in]remThe regex match structure
size_t re_strlen ( regmatch_t  rem)

Returns the length of the matched regex

Parameters
[in]remMatched regex
Returns
Number of characters that was matched in rem