diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-29 19:04:52 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-30 13:32:46 -0500 |
commit | f85a69aed58d44ea9a2ec1788c82646b4ae01acc (patch) | |
tree | dbf3ef7526971422e12ee8d02f1db945bb7eb8a5 | |
parent | 0abd5e70389a9d67cde3b571676dce0903c3f64f (diff) | |
download | libgit2-f85a69aed58d44ea9a2ec1788c82646b4ae01acc.tar.gz |
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.
-rw-r--r-- | src/regexp.c | 8 | ||||
-rw-r--r-- | src/regexp.h | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/regexp.c b/src/regexp.c index 29ae8f9e4..62035a96c 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -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) diff --git a/src/regexp.h b/src/regexp.h index d914a807a..61824bf5c 100644 --- a/src/regexp.h +++ b/src/regexp.h @@ -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 */ |