NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
regex3.h
Go to the documentation of this file.
1
23#ifndef MUTT_MUTT_REGEX3_H
24#define MUTT_MUTT_REGEX3_H
25
26#include "config.h"
27#include <regex.h>
28#include <stdbool.h>
29#include <stdint.h>
30#include "queue.h"
31
32struct Buffer;
33
34/* ... DT_REGEX */
35#define DT_REGEX_MATCH_CASE (1 << 6)
36#define DT_REGEX_ALLOW_NOT (1 << 7)
37#define DT_REGEX_NOSUB (1 << 8)
38
39/* This is a non-standard option supported by Solaris 2.5.x
40 * which allows patterns of the form <...> */
41#ifndef REG_WORDS
42#define REG_WORDS 0
43#endif
44
53#define REG_COMP(preg, regex, cflags) regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags))
54
60static inline regoff_t mutt_regmatch_start(const regmatch_t *match)
61{
62 return match->rm_so;
63}
64
70static inline regoff_t mutt_regmatch_end(const regmatch_t *match)
71{
72 return match->rm_eo;
73}
74
80static inline size_t mutt_regmatch_len(const regmatch_t *match)
81{
82 return match->rm_eo - match->rm_so;
83}
84
88struct Regex
89{
90 char *pattern;
91 regex_t *regex;
92 bool pat_not;
93};
94
99{
100 struct Regex *regex;
102};
104
109{
110 struct Regex *regex;
111 size_t nmatch;
112 char *templ;
114};
115STAILQ_HEAD(ReplaceList, Replace);
116
117struct Regex *mutt_regex_compile(const char *str, uint16_t flags);
118struct Regex *mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err);
119void mutt_regex_free(struct Regex **ptr);
120
121int mutt_regexlist_add (struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err);
122void mutt_regexlist_free (struct RegexList *rl);
123bool mutt_regexlist_match (struct RegexList *rl, const char *str);
124struct RegexNode *mutt_regexlist_new (void);
125int mutt_regexlist_remove(struct RegexList *rl, const char *str);
126
127int mutt_replacelist_add (struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err);
128char * mutt_replacelist_apply (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
129void mutt_replacelist_free (struct ReplaceList *rl);
130bool mutt_replacelist_match (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
131struct Replace *mutt_replacelist_new (void);
132int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat);
133
134bool mutt_regex_match (const struct Regex *regex, const char *str);
135bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t num, regmatch_t matches[]);
136
137#endif /* MUTT_MUTT_REGEX3_H */
#define STAILQ_HEAD(name, type)
Definition: queue.h:312
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:588
struct Regex * mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:76
struct RegexNode * mutt_regexlist_new(void)
Create a new RegexList.
Definition: regex.c:217
char * mutt_replacelist_apply(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Apply replacements to a buffer.
Definition: regex.c:371
struct Regex * mutt_regex_compile(const char *str, uint16_t flags)
Create an Regex from a string.
Definition: regex.c:55
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:175
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.
Definition: regex.c:136
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:472
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:231
bool mutt_replacelist_match(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Does a string match a pattern?
Definition: regex.c:500
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
Definition: regex3.h:80
struct Replace * mutt_replacelist_new(void)
Create a new ReplaceList.
Definition: regex.c:577
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:267
static regoff_t mutt_regmatch_end(const regmatch_t *match)
Return the end of a match.
Definition: regex3.h:70
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:196
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:619
void mutt_regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:114
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:60
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:636
String manipulation buffer.
Definition: buffer.h:34
List of regular expressions.
Definition: regex3.h:99
STAILQ_ENTRY(RegexNode) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:100
Cached regular expression.
Definition: regex3.h:89
char * pattern
printable version
Definition: regex3.h:90
bool pat_not
do not match
Definition: regex3.h:92
regex_t * regex
compiled expression
Definition: regex3.h:91
List of regular expressions.
Definition: regex3.h:109
char * templ
Template to match.
Definition: regex3.h:112
size_t nmatch
Match the 'nth' occurrence (0 means the whole expression)
Definition: regex3.h:111
STAILQ_ENTRY(Replace) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:110