Mercurial > hg > th-libs
diff th_regex.h @ 640:9e1f9e1d1487
Aaand some more work. Still just a broken concept.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 24 Jan 2020 09:13:24 +0200 |
parents | 8c957ad9d4c3 |
children | b897995101b7 |
line wrap: on
line diff
--- a/th_regex.h Thu Jan 23 11:38:28 2020 +0200 +++ b/th_regex.h Fri Jan 24 09:13:24 2020 +0200 @@ -22,10 +22,26 @@ // // Definitions // + // Character type -typedef char th_regex_char; +typedef char th_regex_char_t; + + +// Structure containing the compiled regular expression +struct th_regex_t; +typedef struct th_regex_t th_regex_t; +// Linked list structure for returned match sequences +typedef struct +{ + th_llist_t node; + size_t start, len; +} th_regex_match_t; + + +// Flags for th_regex_match() +// (not actually used or supported yet :D) enum { TH_REF_CASEFOLD = 0x0001, @@ -33,59 +49,6 @@ }; -typedef struct -{ - int type; - th_regex_char start, end; - - size_t nchars; - th_regex_char *chars; -} th_regex_list_item; - - -typedef struct -{ - size_t nitems, itemssize; - th_regex_list_item *items; -} th_regex_list; - - -struct th_regex_ctx; - -typedef struct -{ - int mode, type; - ssize_t repeatMin, repeatMax; - - union - { - th_regex_char chr; - - struct - { - size_t nchars; - th_regex_char *chars; - } list; - - struct th_regex_ctx *expr; - } match; -} th_regex_node; - - -typedef struct th_regex_ctx -{ - size_t nnodes, nodessize; - th_regex_node *nodes; -} th_regex_ctx; - - -typedef struct -{ - th_llist_t node; - size_t start, len; -} th_regex_match_node; - - #ifdef TH_EXPERIMENTAL_REGEX_DEBUG enum { @@ -101,13 +64,14 @@ // // Functions // -int th_regex_compile(th_regex_ctx **pexpr, const th_regex_char *pattern); -void th_regex_free(th_regex_ctx *expr); +int th_regex_compile(th_regex_t **pexpr, const th_regex_char_t *pattern); +void th_regex_free(th_regex_t *expr); -int th_regex_match(const th_regex_ctx *expr, const th_regex_char *haystack, - size_t *pnmatches, th_regex_match_node **pmatches, const size_t maxmatches, +int th_regex_match(const th_regex_t *expr, const th_regex_char_t *haystack, + size_t *pnmatches, th_regex_match_t **pmatches, const size_t maxmatches, const int flags); -void th_regex_free_matches(th_regex_match_node *matches); + +void th_regex_free_matches(th_regex_match_t *matches); #ifdef __cplusplus