NeoMutt  2024-04-16-36-g75b6fb
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
33struct Buffer;
34
35/* This is a non-standard option supported by Solaris 2.5.x
36 * which allows patterns of the form <...> */
37#ifndef REG_WORDS
38#define REG_WORDS 0
39#endif
40
49#define REG_COMP(preg, regex, cflags) regcomp(preg, regex, REG_WORDS | REG_EXTENDED | (cflags))
50
56static inline regoff_t mutt_regmatch_start(const regmatch_t *match)
57{
58 return match->rm_so;
59}
60
66static inline regoff_t mutt_regmatch_end(const regmatch_t *match)
67{
68 return match->rm_eo;
69}
70
76static inline size_t mutt_regmatch_len(const regmatch_t *match)
77{
78 return match->rm_eo - match->rm_so;
79}
80
84struct Regex
85{
86 char *pattern;
87 regex_t *regex;
88 bool pat_not;
89};
90
95{
96 struct Regex *regex;
98};
100
105{
106 struct Regex *regex;
107 size_t nmatch;
108 char *templ;
110};
111STAILQ_HEAD(ReplaceList, Replace);
112
113struct Regex *mutt_regex_compile(const char *str, uint16_t flags);
114struct Regex *mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err);
115void mutt_regex_free(struct Regex **ptr);
116
117int mutt_regexlist_add (struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err);
118void mutt_regexlist_free (struct RegexList *rl);
119bool mutt_regexlist_match (struct RegexList *rl, const char *str);
120struct RegexNode *mutt_regexlist_new (void);
121int mutt_regexlist_remove(struct RegexList *rl, const char *str);
122
123int mutt_replacelist_add (struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err);
124char * mutt_replacelist_apply (struct ReplaceList *rl, const char *str);
125void mutt_replacelist_free (struct ReplaceList *rl);
126bool mutt_replacelist_match (struct ReplaceList *rl, char *buf, size_t buflen, const char *str);
127struct Replace *mutt_replacelist_new (void);
128int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat);
129
130bool mutt_regex_match (const struct Regex *regex, const char *str);
131bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t num, regmatch_t matches[]);
132
133#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:76
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:66
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:56
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:95
STAILQ_ENTRY(RegexNode) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:96
Cached regular expression.
Definition: regex3.h:85
char * pattern
printable version
Definition: regex3.h:86
bool pat_not
do not match
Definition: regex3.h:88
regex_t * regex
compiled expression
Definition: regex3.h:87
List of regular expressions.
Definition: regex3.h:105
char * templ
Template to match.
Definition: regex3.h:108
size_t nmatch
Match the 'nth' occurrence (0 means the whole expression)
Definition: regex3.h:107
STAILQ_ENTRY(Replace) entries
Linked list.
struct Regex * regex
Regex containing a regular expression.
Definition: regex3.h:106