Manage regular expressions. More...
#include "config.h"
#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
#include "queue.h"
#include <stddef.h>
Go to the source code of this file.
Data Structures | |
struct | Regex |
Cached regular expression. More... | |
struct | RegexNode |
List of regular expressions. More... | |
struct | Replace |
List of regular expressions. More... | |
Macros | |
#define | REG_WORDS 0 |
#define | REG_COMP(preg, regex, cflags) regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags)) |
Compile a regular expression. | |
Functions | |
static regoff_t | mutt_regmatch_start (const regmatch_t *match) |
Return the start of a match. | |
static regoff_t | mutt_regmatch_end (const regmatch_t *match) |
Return the end of a match. | |
static size_t | mutt_regmatch_len (const regmatch_t *match) |
Return the length of a match. | |
STAILQ_HEAD (RegexList, RegexNode) | |
STAILQ_HEAD (ReplaceList, Replace) | |
struct Regex * | mutt_regex_compile (const char *str, uint16_t flags) |
Create an Regex from a string. | |
struct Regex * | mutt_regex_new (const char *str, uint32_t flags, struct Buffer *err) |
Create an Regex from a string. | |
void | mutt_regex_free (struct Regex **ptr) |
Free a Regex object. | |
int | mutt_regexlist_add (struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err) |
Compile a regex string and add it to a list. | |
void | mutt_regexlist_free (struct RegexList *rl) |
Free a RegexList object. | |
bool | mutt_regexlist_match (struct RegexList *rl, const char *str) |
Does a string match any Regex in the list? | |
struct RegexNode * | mutt_regexlist_new (void) |
Create a new RegexList. | |
int | mutt_regexlist_remove (struct RegexList *rl, const char *str) |
Remove a Regex from a list. | |
int | mutt_replacelist_add (struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err) |
Add a pattern and a template to a list. | |
char * | mutt_replacelist_apply (struct ReplaceList *rl, const char *str) |
Apply replacements to a buffer. | |
void | mutt_replacelist_free (struct ReplaceList *rl) |
Free a ReplaceList object. | |
bool | mutt_replacelist_match (struct ReplaceList *rl, char *buf, size_t buflen, const char *str) |
Does a string match a pattern? | |
struct Replace * | mutt_replacelist_new (void) |
Create a new ReplaceList. | |
int | mutt_replacelist_remove (struct ReplaceList *rl, const char *pat) |
Remove a pattern from a list. | |
bool | mutt_regex_match (const struct Regex *regex, const char *str) |
Shorthand to mutt_regex_capture() | |
bool | mutt_regex_capture (const struct Regex *regex, const char *str, size_t num, regmatch_t matches[]) |
Match a regex against a string, with provided options. | |
Manage regular expressions.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file regex3.h.
#define REG_COMP | ( | preg, | |
regex, | |||
cflags | |||
) | regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags)) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
STAILQ_HEAD | ( | RegexList | , |
RegexNode | |||
) |
STAILQ_HEAD | ( | ReplaceList | , |
Replace | |||
) |
struct Regex * mutt_regex_compile | ( | const char * | str, |
uint16_t | flags | ||
) |
Create an Regex from a string.
str | Regular expression |
flags | Type flags, e.g. REG_ICASE |
ptr | New Regex object |
NULL | Error |
Definition at line 59 of file regex.c.
Create an Regex from a string.
str | Regular expression |
flags | Type flags, e.g. D_REGEX_MATCH_CASE |
err | Buffer for error messages |
ptr | New Regex object |
NULL | Error |
Definition at line 80 of file regex.c.
void mutt_regex_free | ( | struct Regex ** | ptr | ) |
int mutt_regexlist_add | ( | struct RegexList * | rl, |
const char * | str, | ||
uint16_t | flags, | ||
struct Buffer * | err | ||
) |
Compile a regex string and add it to a list.
rl | RegexList to add to |
str | String to compile into a regex |
flags | Flags, e.g. REG_ICASE |
err | Buffer for error messages |
0 | Success, Regex compiled and added to the list |
-1 | Error, see message in 'err' |
Definition at line 140 of file regex.c.
void mutt_regexlist_free | ( | struct RegexList * | rl | ) |
Free a RegexList object.
rl | RegexList to free |
Definition at line 179 of file regex.c.
bool mutt_regexlist_match | ( | struct RegexList * | rl, |
const char * | str | ||
) |
Does a string match any Regex in the list?
rl | RegexList to match against |
str | String to compare |
true | String matches one of the Regexes in the list |
Definition at line 200 of file regex.c.
struct RegexNode * mutt_regexlist_new | ( | void | ) |
int mutt_regexlist_remove | ( | struct RegexList * | rl, |
const char * | str | ||
) |
Remove a Regex from a list.
rl | RegexList to alter |
str | Pattern to remove from the list |
0 | Success, pattern was found and removed from the list |
-1 | Error, pattern wasn't found |
If the pattern is "*", then all the Regexes are removed.
Definition at line 235 of file regex.c.
int mutt_replacelist_add | ( | struct ReplaceList * | rl, |
const char * | pat, | ||
const char * | templ, | ||
struct Buffer * | err | ||
) |
Add a pattern and a template to a list.
rl | ReplaceList to add to |
pat | Pattern to compile into a regex |
templ | Template string to associate with the pattern |
err | Buffer for error messages |
0 | Success, pattern added to the ReplaceList |
-1 | Error, see message in 'err' |
Definition at line 271 of file regex.c.
char * mutt_replacelist_apply | ( | struct ReplaceList * | rl, |
const char * | str | ||
) |
Apply replacements to a buffer.
rl | ReplaceList to apply |
str | String to manipulate |
ptr | New string with replacements |
Definition at line 369 of file regex.c.
void mutt_replacelist_free | ( | struct ReplaceList * | rl | ) |
Free a ReplaceList object.
rl | ReplaceList to free |
Definition at line 450 of file regex.c.
bool mutt_replacelist_match | ( | struct ReplaceList * | rl, |
char * | buf, | ||
size_t | buflen, | ||
const char * | str | ||
) |
Does a string match a pattern?
true | String matches a patterh in the ReplaceList |
Match a string against the patterns defined by the 'spam' command and output the expanded format into buf
when there is a match. If buflen<=0, the match is performed but the format is not expanded and no assumptions are made about the value of buf
so it may be NULL.
Definition at line 478 of file regex.c.
struct Replace * mutt_replacelist_new | ( | void | ) |
int mutt_replacelist_remove | ( | struct ReplaceList * | rl, |
const char * | pat | ||
) |
Remove a pattern from a list.
rl | ReplaceList to modify |
pat | Pattern to remove |
num | Matching patterns removed |
Definition at line 566 of file regex.c.
bool mutt_regex_match | ( | const struct Regex * | regex, |
const char * | str | ||
) |
Shorthand to mutt_regex_capture()
regex | Regex which is desired to match against |
str | String to search with given regex |
true | str matches |
false | str does not match |
Definition at line 614 of file regex.c.
bool mutt_regex_capture | ( | const struct Regex * | regex, |
const char * | str, | ||
size_t | nmatch, | ||
regmatch_t | matches[] | ||
) |
Match a regex against a string, with provided options.
regex | Regex to execute |
str | String to apply regex on |
nmatch | Length of matches |
matches | regmatch_t to hold match indices |
true | str matches |
false | str does not match |
Definition at line 597 of file regex.c.