NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
regex3.h
Go to the documentation of this file.
1 
23 #ifndef MUTT_LIB_REGEX_H
24 #define MUTT_LIB_REGEX_H
25 
26 #include <stddef.h>
27 #include <regex.h>
28 #include <stdbool.h>
29 #include "queue.h"
30 
31 struct Buffer;
32 
33 /* ... DT_REGEX */
34 #define DT_REGEX_MATCH_CASE (1 << 6)
35 #define DT_REGEX_ALLOW_NOT (1 << 7)
36 #define DT_REGEX_NOSUB (1 << 8)
37 
38 /* This is a non-standard option supported by Solaris 2.5.x
39  * which allows patterns of the form <...> */
40 #ifndef REG_WORDS
41 #define REG_WORDS 0
42 #endif
43 
52 #define REG_COMP(preg, regex, cflags) regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags))
53 
57 struct Regex
58 {
59  char *pattern;
60  regex_t *regex;
61  bool pat_not;
62 };
63 
67 struct RegexNode
68 {
69  struct Regex *regex;
70  STAILQ_ENTRY(RegexNode) entries;
71 };
72 STAILQ_HEAD(RegexList, RegexNode);
73 
77 struct Replace
78 {
79  struct Regex *regex;
80  size_t nmatch;
81  char *templ;
82  STAILQ_ENTRY(Replace) entries;
83 };
84 STAILQ_HEAD(ReplaceList, Replace);
85 
86 struct Regex *mutt_regex_compile(const char *str, int flags);
87 struct Regex *mutt_regex_new(const char *str, int flags, struct Buffer *err);
88 void mutt_regex_free(struct Regex **r);
89 
90 int mutt_regexlist_add (struct RegexList *rl, const char *str, int flags, struct Buffer *err);
91 void mutt_regexlist_free (struct RegexList *rl);
92 bool mutt_regexlist_match (struct RegexList *rl, const char *str);
93 struct RegexNode *mutt_regexlist_new (void);
94 int mutt_regexlist_remove(struct RegexList *rl, const char *str);
95 
96 int mutt_replacelist_add (struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err);
97 char * mutt_replacelist_apply (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
98 void mutt_replacelist_free (struct ReplaceList *rl);
99 bool mutt_replacelist_match (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
100 struct Replace *mutt_replacelist_new (void);
101 int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat);
102 
103 bool mutt_regex_match (const struct Regex *regex, const char *str);
104 bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t num, regmatch_t matches[]);
105 
106 #endif /* MUTT_LIB_REGEX_H */
char * templ
Template to match.
Definition: regex3.h:81
bool mutt_replacelist_match(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Does a string match a pattern?
Definition: regex.c:475
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:447
struct Replace * mutt_replacelist_new(void)
Create a new ReplaceList.
Definition: regex.c:553
void mutt_regex_free(struct Regex **r)
Free a Regex object.
Definition: regex.c:111
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:170
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.
Definition: regex.c:262
regex_t * regex
compiled expression
Definition: regex3.h:60
String manipulation buffer.
Definition: buffer.h:33
bool pat_not
do not match
Definition: regex3.h:61
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
struct RegexNode * mutt_regexlist_new(void)
Create a new RegexList.
Definition: regex.c:212
#define STAILQ_ENTRY(type)
Definition: queue.h:325
List of regular expressions.
Definition: regex3.h:77
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:191
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:564
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:79
STAILQ_HEAD(RegexList, RegexNode)
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:610
struct Regex * mutt_regex_new(const char *str, int flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:74
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
Definition: regex.c:594
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:69
List of regular expressions.
Definition: regex3.h:67
struct Regex * mutt_regex_compile(const char *str, int flags)
Create an Regex from a string.
Definition: regex.c:53
Cached regular expression.
Definition: regex3.h:57
char * mutt_replacelist_apply(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Apply replacements to a buffer.
Definition: regex.c:352
char * pattern
printable version
Definition: regex3.h:59
size_t nmatch
Match the &#39;nth&#39; occurrence (0 means the whole expression)
Definition: regex3.h:80