57 if (!str || (*str ==
'\0'))
78 if (!str || (*str ==
'\0'))
119 struct Regex *rx = *ptr;
139 if (!rl || !str || (*str ==
'\0'))
180 struct RegexNode *np = NULL, *tmp = NULL;
243 struct RegexNode *np = NULL, *tmp = NULL;
268 const char *templ,
struct Buffer *err)
270 if (!rl || !pat || (*pat ==
'\0') || !templ)
316 for (
const char *p =
templ; *p;)
349 buf_addstr(err,
_(
"Not enough subexpressions for template"));
373 static regmatch_t *pmatch = NULL;
375 static char twinbuf[2][1024];
378 size_t cpysize, tlen;
379 char *src = NULL, *dst = NULL;
381 if (buf && (buflen != 0))
384 if (!rl || !str || (*str ==
'\0') || (buf && (buflen == 0)))
387 twinbuf[0][0] =
'\0';
388 twinbuf[1][0] =
'\0';
389 src = twinbuf[switcher];
408 dst = twinbuf[switcher];
415 for (p = np->
templ; *p && (tlen < (
sizeof(*twinbuf) - 1));)
423 cpysize =
MIN(pmatch[0].rm_so, (
sizeof(*twinbuf) - 1) - tlen);
424 strncpy(&dst[tlen], src, cpysize);
430 cpysize =
MIN(strlen(src) - pmatch[0].rm_eo, (
sizeof(*twinbuf) - 1) - tlen);
431 strncpy(&dst[tlen], &src[pmatch[0].rm_eo], cpysize);
436 long n = strtoul(p, &p, 10);
439 while (isdigit((
unsigned char) *p))
441 for (
int i = pmatch[n].rm_so;
442 (i < pmatch[n].rm_eo) && (tlen < (
sizeof(*twinbuf) - 1)); i++)
444 dst[tlen++] = src[i];
477 struct Replace *np = NULL, *tmp = NULL;
502 if (!rl || !buf || !str)
505 static regmatch_t *pmatch = NULL;
527 for (p = np->
templ; *p && (tlen < (buflen - 1));)
535 long n = strtol(p, &e, 10);
539 if ((e != p) && (n >= 0) && (n < np->
nmatch) && (pmatch[n].rm_so != -1))
543 for (
int idx = pmatch[n].rm_so;
544 (idx < pmatch[n].rm_eo) && (tlen < (buflen - 1)); idx++)
546 buf[tlen++] = str[idx];
594 struct Replace *np = NULL, *tmp = NULL;
620 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(struct Buffer *buf, const char *s)
Add a string to a Buffer.
General purpose object for storing and parsing strings.
#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.
char * mutt_replacelist_apply(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Apply replacements to a buffer.
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?
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.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
#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 DT_REGEX_ALLOW_NOT
Regex can begin with '!'.
#define DT_REGEX_MATCH_CASE
Case-sensitive matching.
#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.