Mercurial > hg > th-libs
diff th_regex.c @ 735:31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:14:39 +0200 |
parents | 29e44a58bc73 |
children | c17eadc60c3d |
line wrap: on
line diff
--- a/th_regex.c Wed Dec 07 11:58:54 2022 +0200 +++ b/th_regex.c Wed Dec 07 12:14:39 2022 +0200 @@ -219,32 +219,32 @@ } -static BOOL th_regex_find_next(const th_char_t *str, +static bool th_regex_find_next(const th_char_t *str, const size_t start, size_t *offs, const th_char_t delim) { for (*offs = start; str[*offs] != 0; (*offs)++) { if (str[*offs] == delim) - return TRUE; + return true; } - return FALSE; + return false; } -static BOOL th_regex_parse_ssize_t(const th_char_t *str, +static bool th_regex_parse_ssize_t(const th_char_t *str, ssize_t *value) { th_char_t ch; - BOOL neg; + bool neg; if (*str == '-') { str++; - neg = TRUE; + neg = true; } else - neg = FALSE; + neg = false; // Is the value negative? while ((ch = *str++)) @@ -255,13 +255,13 @@ *value += ch - '0'; } else - return FALSE; + return false; } if (neg) *value = -(*value); - return TRUE; + return true; } @@ -416,7 +416,7 @@ } -static int th_regex_parse_ctx_node_commit_strchr(th_regex_parse_ctx_t *ctx, const BOOL split) +static int th_regex_parse_ctx_node_commit_strchr(th_regex_parse_ctx_t *ctx, const bool split) { int res = THERR_OK;; @@ -486,7 +486,7 @@ case '?': case '*': case '+': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, TRUE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, true)) != THERR_OK) goto out; if ((res = th_regex_parse_ctx_get_prev_node(&ctx, &pnode)) != THERR_OK) @@ -526,7 +526,7 @@ break; case '{': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, TRUE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, true)) != THERR_OK) goto out; // {n} | {min,max} @@ -578,7 +578,7 @@ /* case '|': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Alt pattern .. how to handle these? @@ -586,7 +586,7 @@ */ case '(': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Start of subpattern @@ -595,7 +595,7 @@ break; case ')': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // End of subpattern @@ -608,7 +608,7 @@ break; case '^': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Start of line anchor @@ -620,7 +620,7 @@ break; case '$': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // End of line anchor @@ -632,7 +632,7 @@ break; case '[': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Start of char list @@ -660,7 +660,7 @@ break; case '.': - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Any single character matches @@ -687,14 +687,14 @@ if (ctx.bufPos < ctx.bufSize) ctx.buf[ctx.bufPos++] = ctx.pattern[ctx.offs]; else - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; break; } } // Commit last string/char if any - if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, FALSE)) != THERR_OK) + if ((res = th_regex_parse_ctx_node_commit_strchr(&ctx, false)) != THERR_OK) goto out; // Create root node @@ -841,7 +841,7 @@ } -static BOOL th_regex_match_list(const th_regex_list_t *list, const th_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++) @@ -853,21 +853,21 @@ for (size_t n = 0; n < item->nchars; n++) { if (item->chars[n] == cch) - return TRUE; + return true; } } else { if (cch >= item->start && cch <= item->end) - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL th_regex_match_expr( +static bool th_regex_match_expr( const th_char_t *haystack, size_t *offs, const th_regex_t *expr, @@ -877,7 +877,7 @@ ); -static BOOL th_regex_match_one( +static bool th_regex_match_one( const th_char_t *haystack, size_t *offs, const th_regex_node_t *node, @@ -886,7 +886,7 @@ ) { th_char_t cch; - BOOL res = FALSE; + bool res = false; switch (node->type) { @@ -897,7 +897,7 @@ case TH_RE_TYPE_LIST: case TH_RE_TYPE_LIST_REVERSE: if ((cch = haystack[*offs]) == 0) - res = FALSE; + res = false; else { res = th_regex_match_list(&node->match.list, cch); @@ -911,17 +911,17 @@ case TH_RE_TYPE_ANY_CHAR: if ((cch = haystack[*offs]) == 0) - res = FALSE; + res = false; else { - res = TRUE; + res = true; (*offs)++; } break; case TH_RE_TYPE_CHAR: if ((cch = haystack[*offs]) == 0) - res = FALSE; + res = false; else { res = (cch == node->match.chr); @@ -930,13 +930,13 @@ break; case TH_RE_TYPE_STR: - res = TRUE; + res = true; for (th_char_t *str = node->match.str; res && *str != 0; str++, (*offs)++) { if (haystack[*offs] != *str) - res = FALSE; + res = false; } break; } @@ -945,7 +945,7 @@ } -static BOOL th_regex_match_count( +static bool th_regex_match_count( const th_char_t *haystack, size_t *offs, const th_regex_t *expr, @@ -962,6 +962,7 @@ { // Attempt to match the repeated node once size_t poffs = toffs; + if (th_regex_match_one(haystack, &poffs, node, flags, level)) { // Matched, increase count of repeats @@ -1024,7 +1025,7 @@ } while (haystack[toffs] != 0); // Check results - BOOL res = count >= node->repeatMin || + bool res = count >= node->repeatMin || (node->repeatMax > 0 && count >= node->repeatMax); if (res) @@ -1041,7 +1042,7 @@ } -static BOOL th_regex_match_expr( +static bool th_regex_match_expr( const th_char_t *haystack, size_t *offs, const th_regex_t *expr, @@ -1050,7 +1051,7 @@ const int level ) { - BOOL res = TRUE; + bool res = true; size_t soffs = *offs; for (size_t nnode = startnode; res && nnode < expr->nnodes; nnode++)