summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-19 00:05:36 +0100
committerTyge Løvset <[email protected]>2022-12-19 00:05:36 +0100
commit26a75a218a115a10cee82534be568a606c83dbb2 (patch)
treec57014058ddcec7fd146b37f8721b7b942968e7d /src
parentfacc87d98d46b05bcd4e3d3c278b7dd2dfff3ab8 (diff)
downloadSTC-modified-26a75a218a115a10cee82534be568a606c83dbb2.tar.gz
STC-modified-26a75a218a115a10cee82534be568a606c83dbb2.zip
Some cleanup in cregex.
Diffstat (limited to 'src')
-rw-r--r--src/cregex.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/cregex.c b/src/cregex.c
index 213663e0..acbf53fa 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -861,22 +861,14 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags)
/* Force TOK_END */
_operand(par, TOK_END);
_evaluntil(par, TOK_START);
-#ifdef DEBUG
- dumpstack(par);
-#endif
+
if (par->nbra)
_rcerror(par, CREG_UNMATCHEDLEFTPARENTHESIS);
--par->andp; /* points to first and only _operand */
pp->startinst = par->andp->first;
-#ifdef DEBUG
- dump(pp);
-#endif
+
pp = _optimize(par, pp);
pp->nsubids = (unsigned)par->cursubid;
-#ifdef DEBUG
- print("start: %d\n", par->andp->first-pp->firstinst);
- dump(pp);
-#endif
out:
if (par->error) {
c_free(pp);
@@ -1236,7 +1228,7 @@ 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 CREG_SUCCESS;
+ case 1: return CREG_OK;
case 0: return CREG_NOMATCH;
default: return CREG_MATCHERROR;
}
@@ -1247,7 +1239,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 != CREG_SUCCESS) return res;
+ if (res != CREG_OK) return res;
res = cregex_find(&re, input, match, cmflags);
cregex_drop(&re);
return res;
@@ -1263,7 +1255,7 @@ cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned
if (!count) count = ~0U;
bool copy = !(rflags & CREG_R_STRIP);
- while (count-- && cregex_find_sv(re, input, match) == CREG_SUCCESS) {
+ while (count-- && cregex_find_sv(re, input, match) == CREG_OK) {
_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);
@@ -1280,7 +1272,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) != CREG_SUCCESS)
+ if (cregex_compile(&re, pattern, crflags) != CREG_OK)
assert(0);
csview sv = {input, strlen(input)};
cstr out = cregex_replace_sv(&re, sv, replace, count, mfun, crflags);