# HG changeset patch # User Matti Hamalainen # Date 1580104107 -7200 # Node ID c5aa9ada1051283d8d4da506a3afef363d4805c5 # Parent 284d5b789b7caeffea785f193609319ec6432bdf s/th_regex_char_t/th_char_t/g diff -r 284d5b789b7c -r c5aa9ada1051 tests.c --- a/tests.c Mon Jan 27 07:47:26 2020 +0200 +++ b/tests.c Mon Jan 27 07:48:27 2020 +0200 @@ -568,7 +568,7 @@ typedef struct { - th_regex_char_t *str; + th_char_t *str; size_t nmatches; int flags; } test_regex_def1; @@ -576,14 +576,14 @@ typedef struct { - th_regex_char_t *pattern; - th_regex_char_t *str; + th_char_t *pattern; + th_char_t *str; size_t nmatches; int flags; } test_regex_def2; -void test_regex_print_matches(const th_regex_char_t *str, const th_regex_match_t *matches) +void test_regex_print_matches(const th_char_t *str, const th_regex_match_t *matches) { for (const th_regex_match_t *mt = matches; mt != NULL; mt = (th_regex_match_t *) mt->node.next) @@ -598,7 +598,7 @@ } -void test_regex_list1(const test_regex_def1 *list, const th_regex_char_t *pattern) +void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) { th_regex_t *expr = NULL; int res; diff -r 284d5b789b7c -r c5aa9ada1051 th_regex.c --- a/th_regex.c Mon Jan 27 07:47:26 2020 +0200 +++ b/th_regex.c Mon Jan 27 07:48:27 2020 +0200 @@ -67,10 +67,10 @@ typedef struct { int type; - th_regex_char_t start, end; + th_char_t start, end; size_t nchars; - th_regex_char_t *chars; + th_char_t *chars; } th_regex_list_item_t; @@ -87,8 +87,8 @@ ssize_t repeatMin, repeatMax; struct { - th_regex_char_t chr; - th_regex_char_t *str; + th_char_t chr; + th_char_t *str; th_regex_list_t list; th_regex_t *expr; @@ -98,7 +98,7 @@ typedef struct { - const th_regex_char_t *pattern; + const th_char_t *pattern; size_t offs; th_regex_t *data; @@ -106,7 +106,7 @@ size_t nstack, stacksize; th_regex_t **stack; - th_regex_char_t *buf; + th_char_t *buf; size_t bufSize, bufPos; } th_regex_parse_ctx_t; @@ -128,20 +128,20 @@ } -static int th_regex_strndup(th_regex_char_t **pdst, - const th_regex_char_t *src, const size_t len) +static int th_regex_strndup(th_char_t **pdst, + const th_char_t *src, const size_t len) { if (pdst == NULL) return THERR_NULLPTR; - if (UINTPTR_MAX / sizeof(th_regex_char_t) < len + 1) + if (UINTPTR_MAX / sizeof(th_char_t) < len + 1) return THERR_BOUNDS; - if ((*pdst = (th_regex_char_t *) - th_malloc((len + 1) * sizeof(th_regex_char_t))) == NULL) + if ((*pdst = (th_char_t *) + th_malloc((len + 1) * sizeof(th_char_t))) == NULL) return THERR_MALLOC; - memcpy(*pdst, src, len * sizeof(th_regex_char_t)); + memcpy(*pdst, src, len * sizeof(th_char_t)); (*pdst)[len] = 0; return THERR_OK; @@ -219,9 +219,9 @@ } -static BOOL th_regex_find_next(const th_regex_char_t *str, +static BOOL th_regex_find_next(const th_char_t *str, const size_t start, size_t *offs, - const th_regex_char_t delim) + const th_char_t delim) { for (*offs = start; str[*offs] != 0; (*offs)++) { @@ -232,10 +232,10 @@ } -static BOOL th_regex_parse_ssize_t(const th_regex_char_t *str, +static BOOL th_regex_parse_ssize_t(const th_char_t *str, ssize_t *value) { - th_regex_char_t ch; + th_char_t ch; BOOL neg; if (*str == '-') @@ -302,10 +302,10 @@ } -static int th_regex_parse_list(const th_regex_char_t *str, +static int th_regex_parse_list(const th_char_t *str, const size_t slen, th_regex_list_t *list) { - th_regex_char_t *tmp = NULL; + th_char_t *tmp = NULL; th_regex_list_item_t item; int res; @@ -315,7 +315,7 @@ // Handle ranges like [A-Z] for (size_t offs = 0; offs < slen; offs++) { - th_regex_char_t + th_char_t *prev = (offs > 0) ? tmp + offs - 1 : NULL, *curr = tmp + offs, *next = (offs + 1 < slen) ? tmp + offs + 1 : NULL; @@ -357,14 +357,14 @@ for (size_t offs = 0; offs < slen; offs++) { - th_regex_char_t curr = tmp[offs]; + th_char_t curr = tmp[offs]; if (curr != 0) item.nchars++; } if (item.nchars > 0) { - if ((item.chars = th_malloc(sizeof(th_regex_char_t) * item.nchars)) == NULL) + if ((item.chars = th_malloc(sizeof(th_char_t) * item.nchars)) == NULL) { res = THERR_MALLOC; goto out; @@ -372,7 +372,7 @@ for (size_t offs = 0, n = 0; offs < slen; offs++) { - th_regex_char_t curr = tmp[offs]; + th_char_t curr = tmp[offs]; if (curr != 0) { item.chars[n] = curr; @@ -394,7 +394,7 @@ static int th_regex_parse_ctx_node_commit_strchr_do(th_regex_parse_ctx_t *ctx, - const th_regex_char_t *buf, const size_t bufLen) + const th_char_t *buf, const size_t bufLen) { th_regex_node_t node; th_regex_node_init(&node); @@ -449,12 +449,12 @@ * @param[in] pattern regular expression pattern string * @returns @c THERR_* return value indicating success or failure */ -int th_regex_compile(th_regex_t **pexpr, const th_regex_char_t *pattern) +int th_regex_compile(th_regex_t **pexpr, const th_char_t *pattern) { int res = THERR_OK; th_regex_parse_ctx_t ctx; th_regex_node_t node, *pnode; - th_regex_char_t *tmp = NULL; + th_char_t *tmp = NULL; size_t start; // Check pointers @@ -469,7 +469,7 @@ ctx.pattern = pattern; ctx.bufSize = 256; - if ((ctx.buf = th_malloc(ctx.bufSize * sizeof(th_regex_char_t))) == NULL) + if ((ctx.buf = th_malloc(ctx.bufSize * sizeof(th_char_t))) == NULL) { res = THERR_MALLOC; goto out; @@ -478,7 +478,7 @@ // Start parsing the pattern for (; ctx.pattern[ctx.offs] != 0; ctx.offs++) { - th_regex_char_t cch = ctx.pattern[ctx.offs]; + th_char_t cch = ctx.pattern[ctx.offs]; switch (cch) { @@ -828,7 +828,7 @@ } -static BOOL th_regex_match_list(const th_regex_list_t *list, const th_regex_char_t cch) +static BOOL th_regex_match_list(const th_regex_list_t *list, const th_char_t cch) { // Could be optimized, perhaps .. sort match.chars, binary search etc? for (size_t nitem = 0; nitem < list->nitems; nitem++) @@ -855,7 +855,7 @@ static BOOL th_regex_match_expr( - const th_regex_char_t *haystack, + const th_char_t *haystack, size_t *offs, const th_regex_t *expr, const size_t startnode, @@ -865,14 +865,14 @@ static BOOL th_regex_match_one( - const th_regex_char_t *haystack, + const th_char_t *haystack, size_t *offs, const th_regex_node_t *node, const int flags, const int level ) { - th_regex_char_t cch; + th_char_t cch; BOOL res = FALSE; switch (node->type) @@ -918,7 +918,7 @@ case TH_RE_TYPE_STR: res = TRUE; - for (th_regex_char_t *str = node->match.str; + for (th_char_t *str = node->match.str; res && *str != 0; str++, (*offs)++) { @@ -933,7 +933,7 @@ static BOOL th_regex_match_count( - const th_regex_char_t *haystack, + const th_char_t *haystack, size_t *offs, const th_regex_t *expr, const th_regex_node_t *node, @@ -997,7 +997,7 @@ static BOOL th_regex_match_expr( - const th_regex_char_t *haystack, + const th_char_t *haystack, size_t *offs, const th_regex_t *expr, const size_t startnode, @@ -1069,7 +1069,7 @@ * @param[in] maxmatches maximum number of matches until bailing out, or @c 0 if no limit * @param[in] flags additional flags, see @c TH_REF_* */ -int th_regex_match(const th_regex_t *expr, const th_regex_char_t *haystack, +int th_regex_match(const th_regex_t *expr, const th_char_t *haystack, size_t *pnmatches, th_regex_match_t **pmatches, const size_t maxmatches, const int flags) { diff -r 284d5b789b7c -r c5aa9ada1051 th_regex.h --- a/th_regex.h Mon Jan 27 07:47:26 2020 +0200 +++ b/th_regex.h Mon Jan 27 07:48:27 2020 +0200 @@ -23,12 +23,6 @@ // Definitions // -/** @brief th_regex_char_t - * Character type used by th_regex module. - */ -typedef char th_regex_char_t; - - /** @struct th_regex_t * Structure containing the tokenized / compiled regular expression. */ @@ -44,8 +38,8 @@ { th_llist_t node; ///< Internal linked list data - size_t start; ///< Start offset of the match sequence in @p haystack in @c th_regex_char_t units. - size_t len; ///< Length of the match sequence in @p haystack in @c th_regex_char_t units. + size_t start; ///< Start offset of the match sequence in @p haystack in @c th_char_t units. + size_t len; ///< Length of the match sequence in @p haystack in @c th_char_t units. } th_regex_match_t; @@ -66,11 +60,11 @@ // // Functions // -int th_regex_compile(th_regex_t **pexpr, const th_regex_char_t *pattern); +int th_regex_compile(th_regex_t **pexpr, const th_char_t *pattern); void th_regex_free(th_regex_t *expr); void th_regex_dump(th_ioctx *fh, const int level, const th_regex_t *expr); -int th_regex_match(const th_regex_t *expr, const th_regex_char_t *haystack, +int th_regex_match(const th_regex_t *expr, const th_char_t *haystack, size_t *pnmatches, th_regex_match_t **pmatches, const size_t maxmatches, const int flags);