diff options
| author | tylov <[email protected]> | 2023-08-13 23:15:45 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-08-13 23:15:45 +0200 |
| commit | 25dc58db206714dc02c1ae0548f6ba7dd3519d29 (patch) | |
| tree | dcf65b08300d82c4d6752284d5c0a5a00507f07f /src | |
| parent | 8bb2f5618e4cefe668a663936354cf53191f2129 (diff) | |
| download | STC-modified-25dc58db206714dc02c1ae0548f6ba7dd3519d29.tar.gz STC-modified-25dc58db206714dc02c1ae0548f6ba7dd3519d29.zip | |
API CHANGES:
Changed csview: becomes a null-terminated string view.
Added csubview: a null-terminated string view/span, like previous csview.
Note that csview works like a csubview, so not much compability issues should arise.
However, some functions have changed from _sv suffix to _ss.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cregex.c | 28 | ||||
| -rw-r--r-- | src/libstc.c | 2 | ||||
| -rw-r--r-- | src/singleupdate.sh | 2 | ||||
| -rw-r--r-- | src/utf8code.c | 2 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/cregex.c b/src/cregex.c index 975a5104..c045b9f3 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -100,7 +100,7 @@ typedef struct _Reprog /* * Sub expression matches */ -typedef csview _Resub; +typedef csubstr _Resub; /* * substitution list @@ -1215,8 +1215,8 @@ _regexec(const _Reprog *progp, /* program to run */ static void -_build_subst(const char* replace, int nmatch, const csview match[], - bool (*mfun)(int, csview, cstr*), cstr* subst) { +_build_subst(const char* replace, int nmatch, const csubstr match[], + bool (*mfun)(int, csubstr, 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 csview match[], if (replace[1] >= '0' && replace[1] <= '9' && replace[2] == ';') { g = g*10 + (replace[1] - '0'); replace += 2; } if (g < nmatch) { - csview m = mfun && mfun(g, match[g], &mstr) ? cstr_sv(&mstr) : match[g]; + csubstr m = mfun && mfun(g, match[g], &mstr) ? cstr_ss(&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, csview match[], int mflags) { +cregex_find_4(const cregex* re, const char* input, csubstr 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, csview match[], int mflags) { int cregex_find_pattern_4(const char* pattern, const char* input, - csview match[], int cmflags) { + csubstr 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_sv_6(const cregex* re, csview input, const char* replace, int count, - bool (*mfun)(int, csview, cstr*), int rflags) { +cregex_replace_ss_6(const cregex* re, csubstr input, const char* replace, int count, + bool (*mfun)(int, csubstr, cstr*), int rflags) { cstr out = cstr_init(); cstr subst = cstr_init(); - csview match[CREG_MAX_CAPTURES]; + csubstr match[CREG_MAX_CAPTURES]; int nmatch = cregex_captures(re) + 1; if (!count) count = INT32_MAX; bool copy = !(rflags & CREG_STRIP); - while (count-- && cregex_find_sv(re, input, match) == CREG_OK) { + while (count-- && cregex_find_ss(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_sv_6(const cregex* re, csview input, const char* replace, int cou input.str = match[0].str + match[0].size; input.size -= mpos + match[0].size; } - if (copy) cstr_append_sv(&out, input); + if (copy) cstr_append_ss(&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, csview, cstr*), int crflags) { + bool (*mfun)(int, csubstr, cstr*), int crflags) { cregex re = cregex_init(); if (cregex_compile(&re, pattern, crflags) != CREG_OK) assert(0); - csview sv = {input, c_strlen(input)}; - cstr out = cregex_replace_sv(&re, sv, replace, count, mfun, crflags); + csubstr ss = c_ss(input, c_strlen(input)); + cstr out = cregex_replace_ss(&re, ss, replace, count, mfun, crflags); cregex_drop(&re); return out; } diff --git a/src/libstc.c b/src/libstc.c index 462c97c4..b0d27350 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/csview.h"
+#include "../include/stc/csubstr.h"
#define i_implement
#include "../include/stc/crand.h"
#if __STDC_VERSION__ >= 201112L
diff --git a/src/singleupdate.sh b/src/singleupdate.sh index e706dd97..be99d4a7 100644 --- a/src/singleupdate.sh +++ b/src/singleupdate.sh @@ -17,12 +17,12 @@ python singleheader.py $d/include/stc/cqueue.h $d/../stcsingle/stc/cqueue.h python singleheader.py $d/include/stc/crand.h $d/../stcsingle/stc/crand.h python singleheader.py $d/include/stc/cregex.h $d/../stcsingle/stc/cregex.h python singleheader.py $d/include/stc/cset.h $d/../stcsingle/stc/cset.h - python singleheader.py $d/include/stc/csmap.h $d/../stcsingle/stc/csmap.h 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/cvec.h $d/../stcsingle/stc/cvec.h python singleheader.py $d/include/stc/extend.h $d/../stcsingle/stc/extend.h diff --git a/src/utf8code.c b/src/utf8code.c index 4abf10ea..ddc4cb97 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_sv(const csview s1, const csview s2) { +int utf8_icmp_ss(const csubstr s1, const csubstr s2) { utf8_decode_t d1 = {.state=0}, d2 = {.state=0}; intptr_t j1 = 0, j2 = 0; while ((j1 < s1.size) & (j2 < s2.size)) { |
