-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple patterns #45
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ static int ismetachar(char c); | |
/* Public functions: */ | ||
int re_match(const char* pattern, const char* text, int* matchlength) | ||
{ | ||
#if defined(RE_ENABLE_MULTI_PATTERNS) && (RE_ENABLE_MULTI_PATTERNS == 1) | ||
re_t re_p; /* pointer to (to be created) copy of compiled regex */ | ||
int ret = -1; | ||
|
||
|
@@ -79,6 +80,9 @@ int re_match(const char* pattern, const char* text, int* matchlength) | |
free(re_p); | ||
|
||
return (ret); | ||
#else | ||
return re_matchp(re_compile(pattern), text, matchlength); | ||
#endif | ||
} | ||
|
||
int re_matchp(re_t pattern, const char* text, int* matchlength) | ||
|
@@ -120,7 +124,9 @@ re_t re_compile(const char* pattern) | |
static regex_t re_compiled[MAX_REGEXP_OBJECTS]; | ||
static unsigned char ccl_buf[MAX_CHAR_CLASS_LEN]; | ||
int ccl_bufidx = 1; | ||
#if defined(RE_ENABLE_MULTI_PATTERNS) && (RE_ENABLE_MULTI_PATTERNS == 1) | ||
re_t re_p; /* pointer to (to be created) copy of compiled regex in re_compiled */ | ||
#endif | ||
|
||
char c; /* current char in pattern */ | ||
int i = 0; /* index into pattern */ | ||
|
@@ -246,11 +252,16 @@ re_t re_compile(const char* pattern) | |
/* 'UNUSED' is a sentinel used to indicate end-of-pattern */ | ||
re_compiled[j].type = UNUSED; | ||
|
||
#if defined(RE_ENABLE_MULTI_PATTERNS) && (RE_ENABLE_MULTI_PATTERNS == 1) | ||
re_p = (re_t)calloc(1, sizeof(re_compiled)); | ||
memcpy(re_p, re_compiled, sizeof(re_compiled)); | ||
return (re_t)re_p; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes ,delete it. |
||
#else | ||
return (re_t)re_compiled; | ||
#endif | ||
} | ||
|
||
#if defined(RE_ENABLE_MULTI_PATTERNS) && (RE_ENABLE_MULTI_PATTERNS == 1) | ||
void re_freecompile(re_t pattern) | ||
{ | ||
if (pattern) | ||
|
@@ -259,6 +270,7 @@ void re_freecompile(re_t pattern) | |
pattern = NULL; | ||
} | ||
} | ||
#endif | ||
|
||
void re_print(regex_t* pattern) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ | |
#define RE_DOT_MATCHES_NEWLINE 1 | ||
#endif | ||
|
||
/* Define to Support for multiple patterns */ | ||
#ifndef RE_ENABLE_MULTI_PATTERNS | ||
#define RE_ENABLE_MULTI_PATTERNS 0 | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C"{ | ||
#endif | ||
|
@@ -53,10 +58,12 @@ re_t re_compile(const char* pattern); | |
int re_matchp(re_t pattern, const char* text, int* matchlenght); | ||
|
||
/* Free memory of the compiled pattern */ | ||
#if defined(RE_ENABLE_MULTI_PATTERNS) && (RE_ENABLE_MULTI_PATTERNS == 1) | ||
void re_freecompile(re_t pattern); | ||
#endif | ||
|
||
/* Find matches of the txt pattern inside text (will compile automatically first). */ | ||
int re_match(const char* pattern, const char* text, int* matchlenght); | ||
int re_match(const char *pattern, const char *text, int *matchlenght); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to avoid mixing functional and style changes in one commit. This change also breaks style consistency with the rest of the code, doesn't it? Patches should preserve existing code style even if it's not your favorite one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, fix it. |
||
|
||
|
||
#ifdef __cplusplus | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this part but in my understanding one don't have to check
defined(RE_ENABLE_MULTI_PATTERNS)
every time, just a single check inre.h
(#ifndef ... #define ... #endif
) seems to be enough and it's already there. At the same time I see that this construction is common for both this and other repos of the author, so your change is consistent with the other code. It's interesting what @kokke thinks about such checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emmmm , fix it