61 if (!str || (*str ==
'\0'))
82 if (!str || (*str ==
'\0'))
123 struct Regex *rx = *ptr;
143 if (!rl || !str || (*str ==
'\0'))
184 struct RegexNode *np = NULL, *tmp = NULL;
247 struct RegexNode *np = NULL, *tmp = NULL;
272 const char *templ,
struct Buffer *err)
274 if (!rl || !pat || (*pat ==
'\0') || !templ)
319 for (
const char *p =
templ; *p;)
352 buf_addstr(err,
_(
"Not enough subexpressions for template"));
371 if (!rl || !str || (*str ==
'\0'))
374 static regmatch_t *pmatch = NULL;
400 for (p = np->
templ; *p;)
417 long n = strtoul(p, &p, 10);
421 pmatch[n].rm_eo - pmatch[n].rm_so);
423 while (isdigit((
unsigned char) *p))
455 struct Replace *np = NULL, *tmp = NULL;
480 if (!rl || !buf || !str)
483 static regmatch_t *pmatch = NULL;
505 for (p = np->
templ; *p && (tlen < (buflen - 1));)
513 long n = strtol(p, &e, 10);
517 if ((e != p) && (n >= 0) && (n < np->
nmatch) && (pmatch[n].rm_so != -1))
521 for (
int idx = pmatch[n].rm_so;
522 (idx < pmatch[n].rm_eo) && (tlen < (buflen - 1)); idx++)
524 buf[tlen++] = str[idx];
572 struct Replace *np = NULL, *tmp = NULL;
598 size_t nmatch, regmatch_t matches[])
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Parse a number in a string.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
General purpose object for storing and parsing strings.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
#define mutt_debug(LEVEL,...)
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG2
Log at debug level 2.
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Multi-byte String manipulation functions.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Memory management wrappers.
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
struct Regex * mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
struct RegexNode * mutt_regexlist_new(void)
Create a new RegexList.
struct Regex * mutt_regex_compile(const char *str, uint16_t flags)
Create an Regex from a string.
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList 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.
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.
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
bool mutt_replacelist_match(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Does a string match a pattern?
char * mutt_replacelist_apply(struct ReplaceList *rl, const char *str)
Apply replacements to a buffer.
struct Replace * mutt_replacelist_new(void)
Create a new ReplaceList.
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.
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
void mutt_regex_free(struct Regex **ptr)
Free a Regex object.
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
A global pool of Buffers.
#define STAILQ_REMOVE(head, elm, type, field)
#define STAILQ_INIT(head)
#define STAILQ_FOREACH(var, head, field)
#define STAILQ_INSERT_TAIL(head, elm, field)
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Manage regular expressions.
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
String manipulation functions.
String manipulation buffer.
size_t dsize
Length of data.
char * data
Pointer to data.
List of regular expressions.
struct Regex * regex
Regex containing a regular expression.
Cached regular expression.
char * pattern
printable version
regex_t * regex
compiled expression
List of regular expressions.
char * templ
Template to match.
size_t nmatch
Match the 'nth' occurrence (0 means the whole expression)
struct Regex * regex
Regex containing a regular expression.
Constants for all the config types.
#define D_REGEX_ALLOW_NOT
Regex can begin with '!'.
#define D_REGEX_MATCH_CASE
Case-sensitive matching.