Skip to content

allow user to provide regex object storage #58

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@

/* Definitions: */

#ifndef MAX_REGEXP_OBJECTS
#define MAX_REGEXP_OBJECTS 30 /* Max number of regex symbols in expression. */
#endif

#ifndef MAX_CHAR_CLASS_LEN
#define MAX_CHAR_CLASS_LEN 40 /* Max length of character-class buffer in. */
#endif


enum { UNUSED, DOT, BEGIN, END, QUESTIONMARK, STAR, PLUS, CHAR, CHAR_CLASS, INV_CHAR_CLASS, DIGIT, NOT_DIGIT, ALPHA, NOT_ALPHA, WHITESPACE, NOT_WHITESPACE, /* BRANCH */ };

typedef struct regex_t
{
unsigned char type; /* CHAR, STAR, etc. */
union
{
unsigned char ch; /* the character itself */
unsigned char* ccl; /* OR a pointer to characters in class */
} u;
} regex_t;



Expand Down Expand Up @@ -111,8 +107,13 @@ re_t re_compile(const char* pattern)
/* The sizes of the two static arrays below substantiates the static RAM usage of this module.
MAX_REGEXP_OBJECTS is the max number of symbols in the expression.
MAX_CHAR_CLASS_LEN determines the size of buffer for chars in all char-classes in the expression. */
static regex_t re_compiled[MAX_REGEXP_OBJECTS];
static unsigned char ccl_buf[MAX_CHAR_CLASS_LEN];
static regex_t static_objects[MAX_REGEXP_OBJECTS];
static unsigned char static_ccl_buf[MAX_CHAR_CLASS_LEN];
return re_compile_to(pattern, static_objects, static_ccl_buf);
}

re_t re_compile_to(const char* pattern, regex_t *re_compiled, unsigned char *ccl_buf)
{
int ccl_bufidx = 1;

char c; /* current char in pattern */
Expand Down
13 changes: 12 additions & 1 deletion re.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,25 @@ extern "C"{
#endif


typedef struct regex_t
{
unsigned char type; /* CHAR, STAR, etc. */
union
{
unsigned char ch; /* the character itself */
unsigned char* ccl; /* OR a pointer to characters in class */
} u;
} regex_t;

/* Typedef'd pointer to get abstract datatype. */
typedef struct regex_t* re_t;


/* Compile regex string pattern to a regex_t-array. */
/* Compile regex string pattern to a static regex_t-array. */
re_t re_compile(const char* pattern);

/* Compile regex string pattern to the given regex_t-array. */
re_t re_compile_to(const char* pattern, re_t objects, unsigned char *ccl_buf);

/* Find matches of the compiled pattern inside text. */
int re_matchp(re_t pattern, const char* text, int* matchlength);
Expand Down