diff options
| author | Tyge Lovset <[email protected]> | 2023-05-20 08:58:33 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-05-20 08:58:33 +0200 |
| commit | 56b0884044610861866a1a27fb64276411604986 (patch) | |
| tree | 241cdfa174d05f0a67becc83eb10ce69dea1b2ad | |
| parent | 6cd19a9ebdb5fb83f798c3d69d82e3ff08edaad4 (diff) | |
| download | STC-modified-56b0884044610861866a1a27fb64276411604986.tar.gz STC-modified-56b0884044610861866a1a27fb64276411604986.zip | |
Fixed two minor things.
| -rw-r--r-- | include/stc/cstr.h | 10 | ||||
| -rw-r--r-- | src/cregex.c | 8 |
2 files changed, 8 insertions, 10 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 694c02d0..244b0a91 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -364,13 +364,11 @@ STC_INLINE void cstr_pop(cstr* self) { STC_INLINE char* cstr_append(cstr* self, const char* str) { return cstr_append_n(self, str, c_strlen(str)); } -STC_INLINE void cstr_append_sv(cstr* self, csview sv) - { cstr_append_n(self, sv.str, sv.size); } +STC_INLINE char* cstr_append_sv(cstr* self, csview sv) + { return cstr_append_n(self, sv.str, sv.size); } -STC_INLINE char* cstr_append_s(cstr* self, cstr s) { - csview sv = cstr_sv(&s); - return cstr_append_n(self, sv.str, sv.size); -} +STC_INLINE char* cstr_append_s(cstr* self, cstr s) + { return cstr_append_sv(self, cstr_sv(&s)); } #define cstr_replace(...) c_MACRO_OVERLOAD(cstr_replace, __VA_ARGS__) #define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, INT32_MAX) diff --git a/src/cregex.c b/src/cregex.c index 5ba07550..730d35a4 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -1217,11 +1217,11 @@ _build_subst(const char* replace, int nmatch, const csview match[], g = arg - '0'; if (replace[1] >= '0' && replace[1] <= '9' && replace[2] == ';') { g = g*10 + (replace[1] - '0'); replace += 2; } - if (g < (int)nmatch) { + if (g < nmatch) { csview m = mfun && mfun(g, match[g], &mstr) ? cstr_sv(&mstr) : match[g]; if (len + m.size > cap) - dst = cstr_reserve(subst, cap += cap*3/2 + m.size); - for (int i = 0; i < (int)m.size; ++i) + dst = cstr_reserve(subst, cap += cap/2 + m.size); + for (int i = 0; i < m.size; ++i) dst[len++] = m.str[i]; } ++replace; @@ -1230,7 +1230,7 @@ _build_subst(const char* replace, int nmatch, const csview match[], } } if (len == cap) - dst = cstr_reserve(subst, cap = cap*3/2 + 4); + dst = cstr_reserve(subst, cap += cap/2 + 4); dst[len++] = *replace++; } cstr_drop(&mstr); |
