40#define PCRE2_CODE_UNIT_WIDTH 8
48static bool pcre2_has_unicode(
void)
50 static uint32_t checked = -1;
53 pcre2_config(PCRE2_CONFIG_UNICODE, &checked);
76 pcre2_match_data *mdata;
83#define PREX_MONTH "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
84#define PREX_MONTH_LAX \
85 "(Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)"
86#define PREX_DOW "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)"
87#define PREX_DOW_NOCASE \
88 "([Mm][Oo][Nn]|[Tt][Uu][Ee]|[Ww][Ee][Dd]|[Tt][Hh][Uu]|[Ff][Rr][Ii]|[Ss][Aa][Tt]|[Ss][Uu][Nn])"
89#define PREX_TIME "([[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2})"
90#define PREX_YEAR "([[:digit:]]{4})"
109#define UNR_PCTENC_SUBDEL "][\\p{L}\\p{N}._~%!$&'()*+,;="
111#define UNR_PCTENC_SUBDEL "][[:alnum:]._~%!$&'()*+,;="
114 "^([[:alpha:]][-+.[:alnum:]]+):"
126 "(\\[[[:xdigit:]:.]+\\])"
140#undef UNR_PCTENC_SUBDEL
145#define QUERY_PART "^&="
153 "([^][()<>@,;:\\\"/?. =]+)"
163 "^\\#H ([[:alnum:]_\\.-]+) ([[:alnum:]]{4}( [[:alnum:]]{4}){7})[ \t]*$"
170#define C "(\\(.*\\))?"
171#define CFWS FWS C FWS
174 "(([[:alpha:]]+)" CFWS ", *)?"
175 CFWS "([[:digit:]]{1,2}) "
177 CFWS "([[:digit:]]{2,4}) "
178 CFWS "([[:digit:]]{1,2})"
179 ":" CFWS "([[:digit:]]{1,2})"
181 "(:" CFWS "([[:digit:]]{1,2}))?"
184 "([+-][[:digit:]]{4})|"
194 "( ([[:digit:]])|([[:digit:]]{2}))"
198 " ([+-][[:digit:]]{4})"
209 " ( ([[:digit:]])|([[:digit:]]{2}))"
222 "( at [^[:space:]]+)?"
243 "([+][[:digit:]]{4} )"
254 "^([[:alpha:]]+): (.*)$"
259 "^(.*)(tags:)([[:alnum:],]*) ?(.*)$"
270 uint32_t opt = pcre2_has_unicode() ? PCRE2_UTF : 0;
273 h->
re = pcre2_compile((PCRE2_SPTR8) h->
str, PCRE2_ZERO_TERMINATED, opt,
276 h->mdata = pcre2_match_data_create_from_pattern(h->
re, NULL);
278 pcre2_pattern_info(h->
re, PCRE2_INFO_CAPTURECOUNT, &ccount);
279 ASSERT(((ccount + 1) == h->
nmatches) &&
"Number of matches do not match (...)");
283 const int rc = regcomp(h->
re, h->
str, REG_EXTENDED);
284 ASSERT(rc == 0 &&
"Fix your RE");
305 size_t len = strlen(
str);
306 int rc = pcre2_match(h->
re, (PCRE2_SPTR8)
str, len, 0, 0, h->mdata, NULL);
309 PCRE2_UCHAR errmsg[1024];
310 pcre2_get_error_message(rc, errmsg,
sizeof(errmsg));
314 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(h->mdata);
318 h->
matches[i].rm_so = ovector[i * 2];
319 h->
matches[i].rm_eo = ovector[i * 2 + 1];
331 "Regular expression and matches enum are out of sync");
345 pcre2_match_data_free(h->mdata);
346 pcre2_code_free(h->
re);
#define mutt_debug(LEVEL,...)
@ LL_DEBUG2
Log at debug level 2.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Memory management wrappers.
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
static struct PrexStorage * prex(enum Prex which)
Compile on demand and get data for a predefined regex.
void mutt_prex_cleanup(void)
Cleanup heap memory allocated by compiled regexes.
#define UNR_PCTENC_SUBDEL
Manage precompiled / predefined regular expressions.
@ PREX_MBOX_FROM_LAX_MATCH_MAX
@ PREX_ACCOUNT_CMD_MATCH_MAX
@ PREX_IMAP_DATE_MATCH_MAX
@ PREX_MBOX_FROM_MATCH_MAX
@ PREX_RFC2047_ENCODED_WORD_MATCH_MAX
@ PREX_URL_QUERY_KEY_VAL_MATCH_MAX
Prex
Predefined list of regular expressions.
@ PREX_GNUTLS_CERT_HOST_HASH
[#H foo.com A76D 954B EB79 1F49 5B3A 0A0E 0681 65B1]
@ PREX_MBOX_FROM_LAX
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
@ PREX_URL
[imaps://user:pass@example.com/INBOX?foo=bar]
@ PREX_MBOX_FROM
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
@ PREX_ACCOUNT_CMD
key: value
@ PREX_ALIAS_TAGS
tags:a,b,c
@ PREX_IMAP_DATE
[16-MAR-2020 15:09:35 -0700]
@ PREX_RFC5322_DATE_LAX
[Mon, (Comment) 16 Mar 2020 15:09:35 -0700]
@ PREX_URL_QUERY_KEY_VAL
https://example.com/?[q=foo]
@ PREX_RFC2047_ENCODED_WORD
[=?utf-8?Q?=E8=81=AA=E6=98=8E=E7=9A=84?=]
@ PREX_RFC5322_DATE_LAX_MATCH_MAX
@ PREX_GNUTLS_CERT_HOST_HASH_MATCH_MAX
@ PREX_ALIAS_TAGS_MATCH_MAX
A predefined / precompiled regex.
const char * str
Regex string.
enum Prex which
Regex type, e.g. PREX_URL.
size_t nmatches
Number of regex matches.
regex_t * re
Compiled regex.
regmatch_t * matches
Resulting matches.