diff options
| author | Tyge Løvset <[email protected]> | 2022-12-14 10:35:13 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-14 10:35:13 +0100 |
| commit | 992812341a98c889297db8df0f8a34f1c59d07bb (patch) | |
| tree | adf301c5b1e43fda286b990b3a451cc5cecf5ac1 | |
| parent | 0db528ed0062920e9bd5b2c7fcdc7506bd41abad (diff) | |
| download | STC-modified-992812341a98c889297db8df0f8a34f1c59d07bb.tar.gz STC-modified-992812341a98c889297db8df0f8a34f1c59d07bb.zip | |
cregex: renamed enums to all uppercase and prefixed CREG_
| -rw-r--r-- | docs/cregex_api.md | 62 | ||||
| -rw-r--r-- | examples/regex1.c | 2 | ||||
| -rw-r--r-- | examples/regex2.c | 2 | ||||
| -rw-r--r-- | examples/regex_match.c | 4 | ||||
| -rw-r--r-- | examples/regex_replace.c | 8 | ||||
| -rw-r--r-- | examples/splitstr.c | 2 | ||||
| -rw-r--r-- | include/stc/cregex.h | 68 | ||||
| -rw-r--r-- | src/cregex.c | 66 | ||||
| -rw-r--r-- | tests/cregex_test.c | 8 |
9 files changed, 111 insertions, 111 deletions
diff --git a/docs/cregex_api.md b/docs/cregex_api.md index 865e569e..1c0f346a 100644 --- a/docs/cregex_api.md +++ b/docs/cregex_api.md @@ -12,26 +12,26 @@ The API is simple and includes powerful string pattern matches and replace funct ```c enum { // compile-flags - cre_c_dotall = 1<<0, // dot matches newline too - cre_c_caseless = 1<<1, // ignore case + CREG_C_DOTALL = 1<<0, // dot matches newline too + CREG_C_ICASE = 1<<1, // ignore case // match-flags - cre_m_fullmatch = 1<<2, // like start-, end-of-line anchors were in pattern: "^ ... $" - cre_m_next = 1<<3, // use end of previous match[0] as start of input - cre_m_startend = 1<<4, // use match[0] as start+end of input + CREG_M_FULLMATCH = 1<<2, // like start-, end-of-line anchors were in pattern: "^ ... $" + CREG_M_NEXT = 1<<3, // use end of previous match[0] as start of input + CREG_M_STARTEND = 1<<4, // use match[0] as start+end of input // replace-flags - cre_r_strip = 1<<5, // only keep the replaced matches, strip the rest + CREG_R_STRIP = 1<<5, // only keep the replaced matches, strip the rest }; cregex cregex_init(void); cregex cregex_from(const char* pattern, int cflags); - // return cre_success, or negative error code on failure. + // return CREG_SUCCESS, or negative error code on failure. int cregex_compile(cregex *self, const char* pattern, int cflags); // num. of capture groups in regex. 0 if RE is invalid. First group is the full match. int cregex_captures(const cregex* self); - // return cre_success, cre_nomatch, or cre_matcherror. + // return CREG_SUCCESS, CREG_NOMATCH, or CREG_MATCHERROR. int cregex_find(const cregex* re, const char* input, csview match[], int mflags); int cregex_find_sv(const cregex* re, csview input, csview match[]); int cregex_find_pattern(const char* pattern, const char* input, csview match[], int cmflags); @@ -50,35 +50,35 @@ void cregex_drop(cregex* self); // destroy ``` ### Error codes -- cre_success = 0 -- cre_nomatch = -1 -- cre_matcherror = -2 -- cre_outofmemory = -3 -- cre_unmatchedleftparenthesis = -4 -- cre_unmatchedrightparenthesis = -5 -- cre_toomanysubexpressions = -6 -- cre_toomanycharacterclasses = -7 -- cre_malformedcharacterclass = -8 -- cre_missingoperand = -9 -- cre_unknownoperator = -10 -- cre_operandstackoverflow = -11 -- cre_operatorstackoverflow = -12 -- cre_operatorstackunderflow = -13 +- CREG_SUCCESS = 0 +- CREG_NOMATCH = -1 +- CREG_MATCHERROR = -2 +- CREG_OUTOFMEMORY = -3 +- CREG_UNMATCHEDLEFTPARENTHESIS = -4 +- CREG_UNMATCHEDRIGHTPARENTHESIS = -5 +- CREG_TOOMANYSUBEXPRESSIONS = -6 +- CREG_TOOMANYCHARACTERCLASSES = -7 +- CREG_MALFORMEDCHARACTERCLASS = -8 +- CREG_MISSINGOPERAND = -9 +- CREG_UNKNOWNOPERATOR = -10 +- CREG_OPERANDSTACKOVERFLOW = -11 +- CREG_OPERATORSTACKOVERFLOW = -12 +- CREG_OPERATORSTACKUNDERFLOW = -13 ### Limits -- cre_MAXCLASSES -- cre_MAXCAPTURES +- CREG_MAX_CLASSES +- CREG_MAX_CAPTURES ## Usage ### Compiling a regular expression ```c cregex re1 = cregex_init(); -int result = cregex_compile(&re1, "[0-9]+", cre_default); +int result = cregex_compile(&re1, "[0-9]+", CREG_DEFAULT); if (result < 0) return result; const char* url = "(https?://|ftp://|www\\.)([0-9A-Za-z@:%_+~#=-]+\\.)+([a-z][a-z][a-z]?)(/[/0-9A-Za-z\\.@:%_+~#=\\?&-]*)?"; -cregex re2 = cregex_from(url, cre_default); +cregex re2 = cregex_from(url, CREG_DEFAULT); if (re2.error) return re2.error; ... cregex_drop(&re2); @@ -96,11 +96,11 @@ int main() { const char* input = "start date is 2023-03-01, and end date is 2025-12-31."; const char* pattern = "\\b(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)\\b"; - cregex re = cregex_from(pattern, cre_default); + cregex re = cregex_from(pattern, CREG_DEFAULT); // Lets find the first date in the string: csview match[4]; // full-match, year, month, date. - if (cregex_find(&re, input, match, cre_default) == cre_success) + if (cregex_find(&re, input, match, CREG_DEFAULT) == CREG_SUCCESS) printf("Found date: %.*s\n", c_ARGsv(match[0])); else printf("Could not find any date\n"); @@ -116,7 +116,7 @@ int main() { ``` For a single match you may use the all-in-one function: ```c -if (cregex_find_pattern(pattern, input, match, cre_default)) +if (cregex_find_pattern(pattern, input, match, CREG_DEFAULT)) printf("Found date: %.*s\n", c_ARGsv(match[0])); ``` @@ -128,7 +128,7 @@ In order to use a callback function in the replace call, see `examples/regex_rep To iterate multiple matches in an input string, you may use ```c csview match[5] = {0}; -while (cregex_find(&re, input, match, cre_m_next) == cre_success) +while (cregex_find(&re, input, match, CREG_M_NEXT) == CREG_SUCCESS) c_forrange (k, cregex_captures(&re)) printf("submatch %lld: %.*s\n", k, c_ARGsv(match[k])); ``` @@ -189,7 +189,7 @@ c_formatch (it, &re, input) | [[:xdigit:]] [[:word:]] | Match ASCII character class | * | | [[:^***class***:]] | Match character not in the ASCII class | * | | $***n*** | *n*-th substitution backreference to capture group. ***n*** in 0-9. $0 is the entire match. | * | -| $***nn***; | As above, but can handle ***nn*** < cre_MAXCAPTURES. | * | +| $***nn***; | As above, but can handle ***nn*** < CREG_MAX_CAPTURES. | * | ## Limitations diff --git a/examples/regex1.c b/examples/regex1.c index 47cce4cf..7a22220d 100644 --- a/examples/regex1.c +++ b/examples/regex1.c @@ -10,7 +10,7 @@ int main(int argc, char* argv[]) c_auto (cstr, input) c_auto (cregex, float_expr) { - int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$", cre_default); + int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$", CREG_DEFAULT); // Until "q" is given, ask for another number if (res > 0) while (true) { diff --git a/examples/regex2.c b/examples/regex2.c index 8c4df420..4f60cfc4 100644 --- a/examples/regex2.c +++ b/examples/regex2.c @@ -16,7 +16,7 @@ int main() c_auto (cregex, re) c_forrange (i, c_arraylen(s)) { - int res = cregex_compile(&re, s[i].pattern, cre_default); + int res = cregex_compile(&re, s[i].pattern, CREG_DEFAULT); if (res < 0) { printf("error in regex pattern: %d\n", res); continue; diff --git a/examples/regex_match.c b/examples/regex_match.c index fd4315ad..376b002e 100644 --- a/examples/regex_match.c +++ b/examples/regex_match.c @@ -17,7 +17,7 @@ int main() c_auto (cstr, nums) { const char* pattern = "[+-]?([0-9]*\\.)?\\d+([Ee][+-]?\\d+)?"; - int res = cregex_compile(&re, pattern, cre_default); + int res = cregex_compile(&re, pattern, CREG_DEFAULT); printf("%d: %s\n", res, pattern); // extract and convert all numbers in str to floats @@ -28,7 +28,7 @@ int main() printf(" %g\n", *i.ref); // extracts the numbers only to a comma separated string. - nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, cre_r_strip); + nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, CREG_R_STRIP); printf("\n%s\n", cstr_str(&nums)); } } diff --git a/examples/regex_replace.c b/examples/regex_replace.c index 808ac086..e296dfd8 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -26,15 +26,15 @@ int main() printf("fixed: %s\n", cstr_str(&str)); /* US date format, and add 10 years to dates: */ - cstr_take(&str, cregex_replace_pattern_n(pattern, input, "$1/$3/$2", 0, add_10_years, cre_default)); + cstr_take(&str, cregex_replace_pattern_n(pattern, input, "$1/$3/$2", 0, add_10_years, CREG_DEFAULT)); printf("us+10: %s\n", cstr_str(&str)); /* Wrap first date inside []: */ - cstr_take(&str, cregex_replace_pattern_n(pattern, input, "[$0]", 1, NULL, cre_default)); + cstr_take(&str, cregex_replace_pattern_n(pattern, input, "[$0]", 1, NULL, CREG_DEFAULT)); printf("brack: %s\n", cstr_str(&str)); /* Shows how to compile RE separately */ - c_with (cregex re = cregex_from(pattern, cre_default), cregex_drop(&re)) { + c_with (cregex re = cregex_from(pattern, CREG_DEFAULT), cregex_drop(&re)) { if (cregex_captures(&re) == 0) continue; /* break c_with */ /* European date format. */ @@ -42,7 +42,7 @@ int main() printf("euros: %s\n", cstr_str(&str)); /* Strip out everything but the matches */ - cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, cre_r_strip)); + cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, CREG_R_STRIP)); printf("strip: %s\n", cstr_str(&str)); } diff --git a/examples/splitstr.c b/examples/splitstr.c index a7b386f3..39db1a54 100644 --- a/examples/splitstr.c +++ b/examples/splitstr.c @@ -13,7 +13,7 @@ int main() puts("\nSplit with c_formatch (regex):"); - c_with (cregex re = cregex_from("[^ ]+", cre_default), cregex_drop(&re)) + c_with (cregex re = cregex_from("[^ ]+", CREG_DEFAULT), cregex_drop(&re)) c_formatch (i, &re, " Hello World C99! ") printf("'%.*s'\n", c_ARGsv(i.match[0])); } diff --git a/include/stc/cregex.h b/include/stc/cregex.h index 57157b47..7798b5a7 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -34,39 +34,39 @@ THE SOFTWARE. #include <string.h> #include "forward.h" // csview -typedef enum { - cre_success = 0, - cre_nomatch = -1, - cre_matcherror = -2, - cre_outofmemory = -3, - cre_unmatchedleftparenthesis = -4, - cre_unmatchedrightparenthesis = -5, - cre_toomanysubexpressions = -6, - cre_toomanycharacterclasses = -7, - cre_malformedcharacterclass = -8, - cre_missingoperand = -9, - cre_unknownoperator = -10, - cre_operandstackoverflow = -11, - cre_operatorstackoverflow = -12, - cre_operatorstackunderflow = -13, -} cregex_result; - enum { - cre_default = 0, + CREG_DEFAULT = 0, /* compile-flags */ - cre_c_dotall = 1<<0, /* dot matches newline too */ - cre_c_caseless = 1<<1, /* ignore case */ + CREG_C_DOTALL = 1<<0, /* dot matches newline too */ + CREG_C_ICASE = 1<<1, /* ignore case */ /* match-flags */ - cre_m_fullmatch = 1<<2, /* like start-, end-of-line anchors were in pattern: "^ ... $" */ - cre_m_next = 1<<3, /* use end of previous match[0] as start of input */ - cre_m_startend = 1<<4, /* use match[0] as start+end of input */ + CREG_M_FULLMATCH = 1<<2, /* like start-, end-of-line anchors were in pattern: "^ ... $" */ + CREG_M_NEXT = 1<<3, /* use end of previous match[0] as start of input */ + CREG_M_STARTEND = 1<<4, /* use match[0] as start+end of input */ /* replace-flags */ - cre_r_strip = 1<<5, /* only keep the matched strings, strip rest */ + CREG_R_STRIP = 1<<5, /* only keep the matched strings, strip rest */ /* limits */ - cre_MAXCLASSES = 16, - cre_MAXCAPTURES = 32, + CREG_MAX_CLASSES = 16, + CREG_MAX_CAPTURES = 32, }; +typedef enum { + CREG_SUCCESS = 0, + CREG_NOMATCH = -1, + CREG_MATCHERROR = -2, + CREG_OUTOFMEMORY = -3, + CREG_UNMATCHEDLEFTPARENTHESIS = -4, + CREG_UNMATCHEDRIGHTPARENTHESIS = -5, + CREG_TOOMANYSUBEXPRESSIONS = -6, + CREG_TOOMANYCHARACTERCLASSES = -7, + CREG_MALFORMEDCHARACTERCLASS = -8, + CREG_MISSINGOPERAND = -9, + CREG_UNKNOWNOPERATOR = -10, + CREG_OPERANDSTACKOVERFLOW = -11, + CREG_OPERATORSTACKOVERFLOW = -12, + CREG_OPERATORSTACKUNDERFLOW = -13, +} cregex_result; + typedef struct { struct _Reprog* prog; int error; @@ -75,12 +75,12 @@ typedef struct { typedef struct { const cregex* re; const char* input; - csview match[cre_MAXCAPTURES]; + csview match[CREG_MAX_CAPTURES]; } cregex_iter; #define c_formatch(it, Re, Input) \ for (cregex_iter it = {Re, Input}; \ - cregex_find(it.re, it.input, it.match, cre_m_next) == cre_success;) + cregex_find(it.re, it.input, it.match, CREG_M_NEXT) == CREG_SUCCESS;) static inline cregex cregex_init(void) { @@ -88,7 +88,7 @@ cregex cregex_init(void) { return re; } -/* return cre_success, or negative error code on failure. */ +/* return CREG_SUCCESS, or negative error code on failure. */ int cregex_compile(cregex *self, const char* pattern, int cflags); static inline @@ -101,14 +101,14 @@ cregex cregex_from(const char* pattern, int cflags) { /* number of capture groups in a regex pattern, 0 if regex is invalid */ unsigned cregex_captures(const cregex* self); -/* return cre_success, cre_nomatch or cre_matcherror. */ +/* return CREG_SUCCESS, CREG_NOMATCH or CREG_MATCHERROR. */ int cregex_find(const cregex* re, const char* input, csview match[], int mflags); static inline int cregex_find_sv(const cregex* re, csview input, csview match[]) { csview *mp = NULL; if (match) { match[0] = input; mp = match; } - return cregex_find(re, input.str, mp, cre_m_startend); + return cregex_find(re, input.str, mp, CREG_M_STARTEND); } /* match + compile RE pattern */ @@ -117,7 +117,7 @@ int cregex_find_pattern(const char* pattern, const char* input, static inline bool cregex_is_match(const cregex* re, const char* input) - { return cregex_find(re, input, NULL, cre_default) == cre_success; } + { return cregex_find(re, input, NULL, CREG_DEFAULT) == CREG_SUCCESS; } /* replace regular expression */ cstr cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned count, @@ -126,7 +126,7 @@ cstr cregex_replace_sv(const cregex* re, csview input, const char* replace, unsi static inline cstr cregex_replace(const cregex* re, const char* input, const char* replace) { csview sv = {input, strlen(input)}; - return cregex_replace_sv(re, sv, replace, 0, NULL, cre_default); + return cregex_replace_sv(re, sv, replace, 0, NULL, CREG_DEFAULT); } /* replace + compile RE pattern, and extra arguments */ @@ -134,7 +134,7 @@ cstr cregex_replace_pattern_n(const char* pattern, const char* input, const char bool (*mfun)(int i, csview match, cstr* mstr), int crflags); static inline cstr cregex_replace_pattern(const char* pattern, const char* input, const char* replace) - { return cregex_replace_pattern_n(pattern, input, replace, 0, NULL, cre_default); } + { return cregex_replace_pattern_n(pattern, input, replace, 0, NULL, CREG_DEFAULT); } /* destroy regex */ void cregex_drop(cregex* self); diff --git a/src/cregex.c b/src/cregex.c index 41c3aaf8..71b1ee87 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -33,9 +33,9 @@ THE SOFTWARE. typedef uint32_t _Rune; /* Utf8 code point */ typedef int32_t _Token; /* max character classes per program */ -#define _NCLASS cre_MAXCLASSES +#define _NCLASS CREG_MAX_CLASSES /* max subexpressions */ -#define _NSUBEXP cre_MAXCAPTURES +#define _NSUBEXP CREG_MAX_CAPTURES /* max rune ranges per character class */ #define _NCCRUNE (_NSUBEXP * 2) @@ -382,10 +382,10 @@ static void _operator(_Parser *par, _Token t) { if (t==RE_RBRA && --par->nbra<0) - _rcerror(par, cre_unmatchedrightparenthesis); + _rcerror(par, CREG_UNMATCHEDRIGHTPARENTHESIS); if (t==RE_LBRA) { if (++par->cursubid >= _NSUBEXP) - _rcerror(par, cre_toomanysubexpressions); + _rcerror(par, CREG_TOOMANYSUBEXPRESSIONS); par->nbra++; if (par->lastwasand) _operator(par, RE_CAT); @@ -402,7 +402,7 @@ static void _pushand(_Parser *par, _Reinst *f, _Reinst *l) { if (par->andp >= &par->andstack[_NSTACK]) - _rcerror(par, cre_operandstackoverflow); + _rcerror(par, CREG_OPERANDSTACKOVERFLOW); par->andp->first = f; par->andp->last = l; par->andp++; @@ -412,7 +412,7 @@ static void _pushator(_Parser *par, _Token t) { if (par->atorp >= &par->atorstack[_NSTACK]) - _rcerror(par, cre_operatorstackoverflow); + _rcerror(par, CREG_OPERATORSTACKOVERFLOW); *par->atorp++ = t; *par->subidp++ = par->cursubid; } @@ -423,7 +423,7 @@ _popand(_Parser *par, _Token op) _Reinst *inst; if (par->andp <= &par->andstack[0]) { - _rcerror(par, cre_missingoperand); + _rcerror(par, CREG_MISSINGOPERAND); inst = _newinst(par, RE_NOP); _pushand(par, inst, inst); } @@ -434,7 +434,7 @@ static _Token _popator(_Parser *par) { if (par->atorp <= &par->atorstack[0]) - _rcerror(par, cre_operatorstackunderflow); + _rcerror(par, CREG_OPERATORSTACKUNDERFLOW); --par->subidp; return *--par->atorp; } @@ -448,7 +448,7 @@ _evaluntil(_Parser *par, _Token pri) while (pri==RE_RBRA || par->atorp[-1]>=pri) { switch (_popator(par)) { default: - _rcerror(par, cre_unknownoperator); + _rcerror(par, CREG_UNKNOWNOPERATOR); break; case RE_LBRA: /* must have been RE_RBRA */ op1 = _popand(par, '('); @@ -559,7 +559,7 @@ static _Reclass* _newclass(_Parser *par) { if (par->nclass >= _NCLASS) - _rcerror(par, cre_toomanycharacterclasses); + _rcerror(par, CREG_TOOMANYCHARACTERCLASSES); return &(par->classp[par->nclass++]); } @@ -592,7 +592,7 @@ _nextc(_Parser *par, _Rune *rp) *rp = 0; sscanf(++par->exprp, "%x", rp); while (*par->exprp) if (*(par->exprp++) == '}') break; if (par->exprp[-1] != '}') - _rcerror(par, cre_unmatchedrightparenthesis); + _rcerror(par, CREG_UNMATCHEDRIGHTPARENTHESIS); return 2; case 'p': case 'P': { /* https://www.regular-expressions.info/unicode.html */ static struct { const char* c; int n, r; } cls[] = { @@ -615,7 +615,7 @@ _nextc(_Parser *par, _Rune *rp) break; } if (*rp < RE_OPERATOR) { - _rcerror(par, cre_unknownoperator); + _rcerror(par, CREG_UNKNOWNOPERATOR); *rp = 0; } break; @@ -671,7 +671,7 @@ _lex(_Parser *par) case '-': enable = 0; break; case 's': par->dot_type = RE_ANY + enable; break; case 'i': par->rune_type = RE_RUNE + enable; break; - default: _rcerror(par, cre_unknownoperator); return 0; + default: _rcerror(par, CREG_UNKNOWNOPERATOR); return 0; } } return RE_LBRA; @@ -710,7 +710,7 @@ _bldcclass(_Parser *par) /* parse class into a set of spans */ for (; ep < &r[_NCCRUNE]; quoted = _nextc(par, &rune)) { if (rune == 0) { - _rcerror(par, cre_malformedcharacterclass); + _rcerror(par, CREG_MALFORMEDCHARACTERCLASS); return 0; } if (!quoted) { @@ -720,7 +720,7 @@ _bldcclass(_Parser *par) if (ep != r && *par->exprp != ']') { quoted = _nextc(par, &rune); if (rune == 0) { - _rcerror(par, cre_malformedcharacterclass); + _rcerror(par, CREG_MALFORMEDCHARACTERCLASS); return 0; } ep[-1] = par->rune_type == RE_IRUNE ? utf8_casefold(rune) : rune; @@ -797,12 +797,12 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) const size_t instcap = 5 + 6*strlen(s); _Reprog* pp = (_Reprog *)c_realloc(progp, sizeof(_Reprog) + instcap*sizeof(_Reinst)); if (pp == NULL) { - par->error = cre_outofmemory; + par->error = CREG_OUTOFMEMORY; c_free(progp); return NULL; } - pp->flags.icase = (cflags & cre_c_caseless) != 0; - pp->flags.dotall = (cflags & cre_c_dotall) != 0; + pp->flags.icase = (cflags & CREG_C_ICASE) != 0; + pp->flags.dotall = (cflags & CREG_C_DOTALL) != 0; par->freep = pp->firstinst; par->classp = pp->cclass; par->error = 0; @@ -844,7 +844,7 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) dumpstack(par); #endif if (par->nbra) - _rcerror(par, cre_unmatchedleftparenthesis); + _rcerror(par, CREG_UNMATCHEDLEFTPARENTHESIS); --par->andp; /* points to first and only _operand */ pp->startinst = par->andp->first; #ifdef DEBUG @@ -927,7 +927,7 @@ _runematch(_Rune s, _Rune r) static int _regexec1(const _Reprog *progp, /* program to run */ const char *bol, /* string to run machine on */ - _Resub *mp, /* subexpression elements */ + _Resub *mp, /* subexpression elements */ unsigned ms, /* number of elements at mp */ _Reljunk *j, int mflags @@ -1057,7 +1057,7 @@ _regexec1(const _Reprog *progp, /* program to run */ /* efficiency: advance and re-evaluate */ continue; case RE_END: /* Match! */ - match = !(mflags & cre_m_fullmatch) || + match = !(mflags & CREG_M_FULLMATCH) || ((s == j->eol || r == 0 || r == '\n') && (tlp->se.m[0].str == bol || tlp->se.m[0].str[-1] == '\n')); tlp->se.m[0].size = (size_t)(s - tlp->se.m[0].str); @@ -1082,7 +1082,7 @@ _regexec1(const _Reprog *progp, /* program to run */ static int _regexec2(const _Reprog *progp, /* program to run */ const char *bol, /* string to run machine on */ - _Resub *mp, /* subexpression elements */ + _Resub *mp, /* subexpression elements */ unsigned ms, /* number of elements at mp */ _Reljunk *j, int mflags @@ -1124,9 +1124,9 @@ _regexec(const _Reprog *progp, /* program to run */ j.eol = NULL; if (mp && mp[0].size) { - if (mflags & cre_m_startend) + if (mflags & CREG_M_STARTEND) j.starts = mp[0].str, j.eol = mp[0].str + mp[0].size; - else if (mflags & cre_m_next) + else if (mflags & CREG_M_NEXT) j.starts = mp[0].str + mp[0].size; } @@ -1213,9 +1213,9 @@ cregex_find(const cregex* re, const char* input, csview match[], int mflags) { int res = _regexec(re->prog, input, cregex_captures(re), match, mflags); switch (res) { - case 1: return cre_success; - case 0: return cre_nomatch; - default: return cre_matcherror; + case 1: return CREG_SUCCESS; + case 0: return CREG_NOMATCH; + default: return CREG_MATCHERROR; } } @@ -1224,7 +1224,7 @@ cregex_find_pattern(const char* pattern, const char* input, csview match[], int cmflags) { cregex re = cregex_init(); int res = cregex_compile(&re, pattern, cmflags); - if (res != cre_success) return res; + if (res != CREG_SUCCESS) return res; res = cregex_find(&re, input, match, cmflags); cregex_drop(&re); return res; @@ -1235,12 +1235,12 @@ cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned bool (*mfun)(int, csview, cstr*), int rflags) { cstr out = cstr_null; cstr subst = cstr_null; - csview match[cre_MAXCAPTURES]; + csview match[CREG_MAX_CAPTURES]; unsigned nmatch = cregex_captures(re); if (!count) count = ~0U; - bool copy = !(rflags & cre_r_strip); + bool copy = !(rflags & CREG_R_STRIP); - while (count-- && cregex_find_sv(re, input, match) == cre_success) { + while (count-- && cregex_find_sv(re, input, match) == CREG_SUCCESS) { _build_subst(replace, nmatch, match, mfun, &subst); const size_t mpos = (size_t)(match[0].str - input.str); if (copy & (mpos > 0)) cstr_append_n(&out, input.str, mpos); @@ -1257,7 +1257,7 @@ cstr cregex_replace_pattern_n(const char* pattern, const char* input, const char* replace, unsigned count, bool (*mfun)(int, csview, cstr*), int crflags) { cregex re = cregex_init(); - if (cregex_compile(&re, pattern, crflags) != cre_success) + if (cregex_compile(&re, pattern, crflags) != CREG_SUCCESS) assert(0); csview sv = {input, strlen(input)}; cstr out = cregex_replace_sv(&re, sv, replace, count, mfun, crflags); @@ -1269,4 +1269,4 @@ void cregex_drop(cregex* self) { c_free(self->prog); } -#endif
\ No newline at end of file +#endif diff --git a/tests/cregex_test.c b/tests/cregex_test.c index 7cd87e89..3125600f 100644 --- a/tests/cregex_test.c +++ b/tests/cregex_test.c @@ -196,13 +196,13 @@ START_TEST(search_all) csview m = {0}; int res; - res = cregex_find("ab,ab,ab", &m, cre_m_next); + res = cregex_find("ab,ab,ab", &m, CREG_M_NEXT); EXPECT_TRUE(res==1 && M_START(re, m) == 0); - res = cregex_find("ab,ab,ab", &m, cre_m_next); + res = cregex_find("ab,ab,ab", &m, CREG_M_NEXT); EXPECT_TRUE(res==1 && M_START(re, m) == 3); - res = cregex_find("ab,ab,ab", &m, cre_m_next); + res = cregex_find("ab,ab,ab", &m, CREG_M_NEXT); EXPECT_TRUE(res==1 && M_START(re, m) == 6); - res = cregex_find("ab,ab,ab", &m, cre_m_next); + res = cregex_find("ab,ab,ab", &m, CREG_M_NEXT); EXPECT_NE(res, 1); } } |
