The regular expression engine.
More...
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.
#define RE_INVALID_ID 0xffffffff |
#define RE_MATCH |
( |
|
x) | |
(((x).rm_so != -1) && ((x).rm_eo != -1)) |
This macro checks if a regmatch_t x
was matched
- Return values
-
true | If x was matched |
false | If x was not matched |
The last element of the regeng array must be this macro
#define RE_REGENG_VALID |
( |
|
x) | |
|
Value:Check if the regeng is valid
#define RE_REMATCH_MAX 32 |
Maximum number of regmatch_t structures
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_id | This is the re_id from The Regular Expression Engine |
[in] | str | This is the full string that had a match |
[in] | rematch | Array of matched parameters |
[in] | rematch_max | Number of matches in rematch , maximum RE_REMATCH_MAX |
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_array | Array of regular expression structures |
- Returns
- true on success, or false if any of the regular expressions failed to initialize.
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_array | Initialized regular expression array |
[in] | re_callback | Callback that will be called for processing any matches |
[in] | str | String 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] | outstr | Sub-string pointer |
[in] | instr | Full-string on which regex was performed |
[in] | outsz | Maximum size of the output sub-string |
[in] | rem | The regex match structure |
size_t re_strlen |
( |
regmatch_t |
rem) | |
|
Returns the length of the matched regex
- Parameters
-
- Returns
- Number of characters that was matched in
rem