mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
regexp: support NEWLINE and EXTENDED flags
Support the NEWLINE and EXTENDED flags for posix regexp; for PCRE, it supports only NEWLINE (as MULTILINE) and not fully compatibly. We'll likely need to bring our own regexp implementation (like git does) but for now this is a good bandaid.
This commit is contained in:
@@ -16,6 +16,8 @@ int git_regexp_compile(git_regexp *r, const char *pattern, int flags)
|
||||
|
||||
if (flags & GIT_REGEXP_ICASE)
|
||||
cflags |= PCRE_CASELESS;
|
||||
if (flags & GIT_REGEXP_NEWLINE)
|
||||
cflags |= PCRE_MULTILINE;
|
||||
|
||||
if ((*r = pcre_compile(pattern, cflags, &error, &erroffset, NULL)) == NULL) {
|
||||
git_error_set_str(GIT_ERROR_REGEX, error);
|
||||
@@ -102,6 +104,8 @@ int git_regexp_compile(git_regexp *r, const char *pattern, int flags)
|
||||
|
||||
if (flags & GIT_REGEXP_ICASE)
|
||||
cflags |= PCRE2_CASELESS;
|
||||
if (flags & GIT_REGEXP_NEWLINE)
|
||||
cflags |= PCRE2_MULTILINE;
|
||||
|
||||
if ((*r = pcre2_compile((const unsigned char *) pattern, PCRE2_ZERO_TERMINATED,
|
||||
cflags, &error, &erroff, NULL)) == NULL) {
|
||||
@@ -200,6 +204,10 @@ int git_regexp_compile(git_regexp *r, const char *pattern, int flags)
|
||||
|
||||
if (flags & GIT_REGEXP_ICASE)
|
||||
cflags |= REG_ICASE;
|
||||
if (flags & GIT_REGEXP_EXTENDED)
|
||||
cflags |= REG_EXTENDED;
|
||||
if (flags & GIT_REGEXP_NEWLINE)
|
||||
cflags |= REG_NEWLINE;
|
||||
|
||||
# if defined(GIT_REGEX_REGCOMP)
|
||||
if ((error = regcomp(r, pattern, cflags)) != 0)
|
||||
|
||||
@@ -30,7 +30,13 @@ typedef regex_t git_regexp;
|
||||
/** Options supported by @git_regexp_compile. */
|
||||
typedef enum {
|
||||
/** Enable case-insensitive matching */
|
||||
GIT_REGEXP_ICASE = (1 << 0)
|
||||
GIT_REGEXP_ICASE = (1 << 0),
|
||||
|
||||
/** Enable extended matching */
|
||||
GIT_REGEXP_EXTENDED = (1 << 1),
|
||||
|
||||
/** Newline matching */
|
||||
GIT_REGEXP_NEWLINE = (1 << 2)
|
||||
} git_regexp_flags_t;
|
||||
|
||||
/** Structure containing information about regular expression matching groups */
|
||||
|
||||
Reference in New Issue
Block a user