NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
regex3.h
Go to the documentation of this file.
1
24#ifndef MUTT_MUTT_REGEX3_H
25#define MUTT_MUTT_REGEX3_H
26
27#include "config.h"
28#include <regex.h>
29#include <stdbool.h>
30#include <stdint.h>
31#include "queue.h"
32#include <stddef.h>
33
34struct Buffer;
35
36/* This is a non-standard option supported by Solaris 2.5.x
37 * which allows patterns of the form <...> */
38#ifndef REG_WORDS
39#define REG_WORDS 0
40#endif
41
50#define REG_COMP(preg, regex, cflags) regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags))
51
57static inline regoff_t mutt_regmatch_start(const regmatch_t *match)
58{
59 return match->rm_so;
60}
61
67static inline regoff_t mutt_regmatch_end(const regmatch_t *match)
68{
69 return match->rm_eo;
70}
71
77static inline size_t mutt_regmatch_len(const regmatch_t *match)
78{
79 return match->rm_eo - match->rm_so;
80}
81
85struct Regex
86{
87 char *pattern;
88 regex_t *regex;
89 bool pat_not;
90};
91
96{
97 struct Regex *regex;
99};
101
106{
107 struct Regex *regex;
108 size_t nmatch;
109 char *templ;
111};
112STAILQ_HEAD(ReplaceList, Replace);
113
114struct Regex *mutt_regex_compile(const char *str, uint16_t flags);
115struct Regex *mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err);
116void mutt_regex_free(struct Regex **ptr);
117
118int mutt_regexlist_add (struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err);
119void mutt_regexlist_free (struct RegexList *rl);
120bool mutt_regexlist_match (struct RegexList *rl, const char *str);
121struct RegexNode *mutt_regexlist_new (void);
122int mutt_regexlist_remove(struct RegexList *rl, const char *str);
123
124int mutt_replacelist_add (struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err);
125char * mutt_replacelist_apply (struct ReplaceList *rl, const char *str);
126void mutt_replacelist_free (struct ReplaceList *rl);
127bool mutt_replacelist_match (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
128struct Replace *mutt_replacelist_new (void);
129int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat);
130
131bool mutt_regex_match (const struct Regex *regex, const char *str);
132bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t num, regmatch_t matches[]);
133
134#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:566
struct Regex * mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:80
struct RegexNode * mutt_regexlist_new(void)
Create a new RegexList.
Definition: regex.c:221
struct Regex * mutt_regex_compile(const char *str, uint16_t flags)
Create an Regex from a string.
Definition: regex.c:59
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:179
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:140
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:450
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:235
bool mutt_replacelist_match(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Does a string match a pattern?
Definition: regex.c:478
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
Definition: regex3.h:77
char * mutt_replacelist_apply(struct ReplaceList *rl, const char *str)
Apply replacements to a buffer.
Definition: regex.c:369
struct Replace * mutt_replacelist_new(void)
Create a new ReplaceList.
Definition: regex.c:555
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:271
static regoff_t mutt_regmatch_end(const regmatch_t *match)
Return the end of a match.
Definition: regex3.h:67
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:200
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:597
void mutt_regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:118
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:57
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:614
String manipulation buffer.
Definition: buffer.h:36
List of regular expressions.
Definition: regex3.h:96
STAILQ_ENTRY(RegexNode) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:97
Cached regular expression.
Definition: regex3.h:86
char * pattern
printable version
Definition: regex3.h:87
bool pat_not
do not match
Definition: regex3.h:89
regex_t * regex
compiled expression
Definition: regex3.h:88
List of regular expressions.
Definition: regex3.h:106
char * templ
Template to match.
Definition: regex3.h:109
size_t nmatch
Match the 'nth' occurrence (0 means the whole expression)
Definition: regex3.h:108
STAILQ_ENTRY(Replace) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:107