summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-08-14 16:46:24 +0200
committerTyge Løvset <[email protected]>2023-08-14 16:46:24 +0200
commit78d8668e6d527070568a405408ed906e51055bf4 (patch)
tree60f963a36826acce264c7ecd0af3eb80502a4335 /src
parent2b6b4785c5c26bc47d800c1a7c7a48784df2d57b (diff)
downloadSTC-modified-78d8668e6d527070568a405408ed906e51055bf4.tar.gz
STC-modified-78d8668e6d527070568a405408ed906e51055bf4.zip
Reverted csubstr => csview. Sorry about that!
Added crawstr to become the null-terminated string view.
Diffstat (limited to 'src')
-rw-r--r--src/cregex.c28
-rw-r--r--src/libstc.c2
-rw-r--r--src/singleupdate.sh2
-rw-r--r--src/utf8code.c2
4 files changed, 17 insertions, 17 deletions
diff --git a/src/cregex.c b/src/cregex.c
index c045b9f3..e6da66b2 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -100,7 +100,7 @@ typedef struct _Reprog
/*
* Sub expression matches
*/
-typedef csubstr _Resub;
+typedef csview _Resub;
/*
* substitution list
@@ -1215,8 +1215,8 @@ _regexec(const _Reprog *progp, /* program to run */
static void
-_build_subst(const char* replace, int nmatch, const csubstr match[],
- bool (*mfun)(int, csubstr, cstr*), cstr* subst) {
+_build_subst(const char* replace, int nmatch, const csview match[],
+ bool (*mfun)(int, csview, cstr*), cstr* subst) {
cstr_buf buf = cstr_buffer(subst);
intptr_t len = 0, cap = buf.cap;
char* dst = buf.data;
@@ -1233,7 +1233,7 @@ _build_subst(const char* replace, int nmatch, const csubstr match[],
if (replace[1] >= '0' && replace[1] <= '9' && replace[2] == ';')
{ g = g*10 + (replace[1] - '0'); replace += 2; }
if (g < nmatch) {
- csubstr m = mfun && mfun(g, match[g], &mstr) ? cstr_ss(&mstr) : match[g];
+ csview m = mfun && mfun(g, match[g], &mstr) ? cstr_sv(&mstr) : match[g];
if (len + m.size > cap)
dst = cstr_reserve(subst, cap += cap/2 + m.size);
for (int i = 0; i < m.size; ++i)
@@ -1270,7 +1270,7 @@ cregex_captures(const cregex* self) {
}
int
-cregex_find_4(const cregex* re, const char* input, csubstr match[], int mflags) {
+cregex_find_4(const cregex* re, const char* input, csview match[], int mflags) {
int res = _regexec(re->prog, input, cregex_captures(re) + 1, match, mflags);
switch (res) {
case 1: return CREG_OK;
@@ -1281,7 +1281,7 @@ cregex_find_4(const cregex* re, const char* input, csubstr match[], int mflags)
int
cregex_find_pattern_4(const char* pattern, const char* input,
- csubstr match[], int cmflags) {
+ csview match[], int cmflags) {
cregex re = cregex_init();
int res = cregex_compile(&re, pattern, cmflags);
if (res != CREG_OK) return res;
@@ -1291,16 +1291,16 @@ cregex_find_pattern_4(const char* pattern, const char* input,
}
cstr
-cregex_replace_ss_6(const cregex* re, csubstr input, const char* replace, int count,
- bool (*mfun)(int, csubstr, cstr*), int rflags) {
+cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int count,
+ bool (*mfun)(int, csview, cstr*), int rflags) {
cstr out = cstr_init();
cstr subst = cstr_init();
- csubstr match[CREG_MAX_CAPTURES];
+ csview match[CREG_MAX_CAPTURES];
int nmatch = cregex_captures(re) + 1;
if (!count) count = INT32_MAX;
bool copy = !(rflags & CREG_STRIP);
- while (count-- && cregex_find_ss(re, input, match) == CREG_OK) {
+ while (count-- && cregex_find_sv(re, input, match) == CREG_OK) {
_build_subst(replace, nmatch, match, mfun, &subst);
const intptr_t mpos = (match[0].str - input.str);
if (copy & (mpos > 0)) cstr_append_n(&out, input.str, mpos);
@@ -1308,19 +1308,19 @@ cregex_replace_ss_6(const cregex* re, csubstr input, const char* replace, int co
input.str = match[0].str + match[0].size;
input.size -= mpos + match[0].size;
}
- if (copy) cstr_append_ss(&out, input);
+ if (copy) cstr_append_sv(&out, input);
cstr_drop(&subst);
return out;
}
cstr
cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, int count,
- bool (*mfun)(int, csubstr, cstr*), int crflags) {
+ bool (*mfun)(int, csview, cstr*), int crflags) {
cregex re = cregex_init();
if (cregex_compile(&re, pattern, crflags) != CREG_OK)
assert(0);
- csubstr ss = c_ss(input, c_strlen(input));
- cstr out = cregex_replace_ss(&re, ss, replace, count, mfun, crflags);
+ csview sv = c_sv(input, c_strlen(input));
+ cstr out = cregex_replace_sv(&re, sv, replace, count, mfun, crflags);
cregex_drop(&re);
return out;
}
diff --git a/src/libstc.c b/src/libstc.c
index b0d27350..462c97c4 100644
--- a/src/libstc.c
+++ b/src/libstc.c
@@ -1,7 +1,7 @@
#define i_import
#include "../include/stc/cregex.h" /* cstr. utf8, and cregex */
#define i_implement
-#include "../include/stc/csubstr.h"
+#include "../include/stc/csview.h"
#define i_implement
#include "../include/stc/crand.h"
#if __STDC_VERSION__ >= 201112L
diff --git a/src/singleupdate.sh b/src/singleupdate.sh
index be99d4a7..8c2bba45 100644
--- a/src/singleupdate.sh
+++ b/src/singleupdate.sh
@@ -22,8 +22,8 @@ python singleheader.py $d/include/stc/cspan.h $d/../stcsingle/stc/cspan.h
python singleheader.py $d/include/stc/csset.h $d/../stcsingle/stc/csset.h
python singleheader.py $d/include/stc/cstack.h $d/../stcsingle/stc/cstack.h
python singleheader.py $d/include/stc/cstr.h $d/../stcsingle/stc/cstr.h
-python singleheader.py $d/include/stc/csubstr.h $d/../stcsingle/stc/csubstr.h
python singleheader.py $d/include/stc/csview.h $d/../stcsingle/stc/csview.h
+python singleheader.py $d/include/stc/crawstr.h $d/../stcsingle/stc/crawstr.h
python singleheader.py $d/include/stc/cvec.h $d/../stcsingle/stc/cvec.h
python singleheader.py $d/include/stc/extend.h $d/../stcsingle/stc/extend.h
python singleheader.py $d/include/stc/forward.h $d/../stcsingle/stc/forward.h
diff --git a/src/utf8code.c b/src/utf8code.c
index ddc4cb97..4abf10ea 100644
--- a/src/utf8code.c
+++ b/src/utf8code.c
@@ -101,7 +101,7 @@ uint32_t utf8_toupper(uint32_t c) {
return c;
}
-int utf8_icmp_ss(const csubstr s1, const csubstr s2) {
+int utf8_icmp_sv(const csview s1, const csview s2) {
utf8_decode_t d1 = {.state=0}, d2 = {.state=0};
intptr_t j1 = 0, j2 = 0;
while ((j1 < s1.size) & (j2 < s2.size)) {