summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-06-11 09:30:44 +0200
committerTyge Lovset <[email protected]>2022-06-11 09:30:44 +0200
commit69e930f36ab18999009d064f08e2a0b4f10733b3 (patch)
treee326a5a12bc94257143d48cc237bf05d15c26a7b /src
parentd5f213e6186264461295a91ba80f17ecabc09455 (diff)
downloadSTC-modified-69e930f36ab18999009d064f08e2a0b4f10733b3.tar.gz
STC-modified-69e930f36ab18999009d064f08e2a0b4f10733b3.zip
Improving cregex, and minors, e.g. cstr_foldcase=>cstr_casefold.
Diffstat (limited to 'src')
-rw-r--r--src/cregex.c18
-rw-r--r--src/utf8code.c9
2 files changed, 10 insertions, 17 deletions
diff --git a/src/cregex.c b/src/cregex.c
index 575f995c..69fc6cbb 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -210,10 +210,10 @@ static const char*
utfruneicase(const char *s, Rune c)
{
Rune r;
- c = utf8_tolower(c);
+ c = utf8_casefold(c);
for (;;) {
int n = chartorune(&r, s);
- if (utf8_tolower(r) == c) return s;
+ if (utf8_casefold(r) == c) return s;
if ((r == 0) | (n == 0)) return NULL;
s += n;
}
@@ -793,17 +793,17 @@ bldcclass(Parser *par)
}
static Reprog*
-regcomp1(Parser *par, const char *s, int cflags)
+regcomp1(Reprog *progp, Parser *par, const char *s, int cflags)
{
Token token;
Reprog *volatile pp;
/* get memory for the program. estimated max usage */
const int instcap = 5 + 6*strlen(s);
- pp = (Reprog *)malloc(sizeof(Reprog) + instcap*sizeof(Reinst));
+ pp = (Reprog *)realloc(progp, sizeof(Reprog) + instcap*sizeof(Reinst));
if (pp == NULL) {
+ pp = progp;
rcerror(par, creg_outofmemory);
- return NULL;
}
pp->flags.caseless = (cflags & creg_caseless) != 0;
pp->flags.dotall = (cflags & creg_dotall) != 0;
@@ -918,7 +918,7 @@ runematch(Rune s, Rune r, bool icase)
case UTF_XD: inv = 1;
case UTF_xd: return inv ^ utf8_isxdigit(r);
}
- return icase ? utf8_tolower(s) == utf8_tolower(r) : s == r;
+ return icase ? utf8_casefold(s) == utf8_casefold(r) : s == r;
}
/*
@@ -1033,8 +1033,8 @@ regexec1(const Reprog *progp, /* program to run */
case NWBOUND:
ok = true;
case WBOUND: /* fallthrough */
- if (ok ^ (s == bol || s == j->eol || ((utf8_isalnum(s[-1]) || s[-1] == '_')
- ^ (utf8_isalnum(s[ 0]) || s[ 0] == '_'))))
+ if (ok ^ (s == bol || s == j->eol || ((utf8_isalnum(utf8_peek(s, -1)) || s[-1] == '_')
+ ^ (utf8_isalnum(utf8_peek(s, 0)) || s[0] == '_'))))
continue;
break;
case NCCLASS:
@@ -1205,7 +1205,7 @@ void cregex_replace(
int cregex_compile(cregex *rx, const char* pattern, int cflags) {
Parser par;
- rx->prog = regcomp1(&par, pattern, cflags);
+ rx->prog = regcomp1(rx->prog, &par, pattern, cflags);
if (rx->prog)
return 1 + rx->prog->nsubids;
return par.errors;
diff --git a/src/utf8code.c b/src/utf8code.c
index f64ede70..dff10409 100644
--- a/src/utf8code.c
+++ b/src/utf8code.c
@@ -56,13 +56,6 @@ uint32_t utf8_peek(const char* s, int pos) {
return d.codep;
}
-bool utf8_valid(const char* s) {
- utf8_decode_t d = {.state=0};
- while (*s)
- utf8_decode(&d, (uint8_t)*s++);
- return d.state == 0;
-}
-
bool utf8_valid_n(const char* s, size_t nbytes) {
utf8_decode_t d = {.state=0};
while ((nbytes-- != 0) & (*s != 0))
@@ -216,7 +209,7 @@ cstr cstr_toupper(const cstr* self) {
return cstr_tocase(self, fn_toupper);
}
-void cstr_foldcase(cstr* self) {
+void cstr_casefold(cstr* self) {
cstr_take(self, cstr_tocase(self, fn_tofold));
}