diff options
| author | Tyge Løvset <[email protected]> | 2022-07-22 15:05:25 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-07-22 15:05:25 +0200 |
| commit | 29d9d1d96d8a37f6d7e24dc170aa08a40f0f1559 (patch) | |
| tree | b239018af9c0dfa1b07edaf835663757dd4759ed /include | |
| parent | 28ee78e128c14fe309cb5f7cfc3f2172bf675ea7 (diff) | |
| download | STC-modified-29d9d1d96d8a37f6d7e24dc170aa08a40f0f1559.tar.gz STC-modified-29d9d1d96d8a37f6d7e24dc170aa08a40f0f1559.zip | |
FINAL cregex update for now: optimize/change callback mfun API. Also, cstr_printf() cannot take self as print argument.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cregex.h | 6 | ||||
| -rw-r--r-- | include/stc/cstr.h | 8 |
2 files changed, 6 insertions, 8 deletions
diff --git a/include/stc/cregex.h b/include/stc/cregex.h index f93a0c03..fff8ccb1 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -98,11 +98,11 @@ int cregex_match_p(const char* input, const char* pattern, /* replace regular expression */ cstr cregex_replace(const char* input, const cregex* re, const char* replace, - cstr (*mfun)(int i, csview match), unsigned count); + bool (*mfun)(int i, csview match, cstr* mstr), unsigned count); -/* replace + compile RE pattern and extra arguments */ +/* replace + compile RE pattern, and extra arguments */ cstr cregex_replace_pe(const char* input, const char* pattern, const char* replace, - cstr (*mfun)(int i, csview match), unsigned count, int cflags); + bool (*mfun)(int i, csview match, cstr* mstr), unsigned count, int cflags); static inline cstr cregex_replace_p(const char* input, const char* pattern, const char* replace) { return cregex_replace_pe(input, pattern, replace, NULL, 0, 0); } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 8395f127..6db5ef49 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -511,8 +511,7 @@ STC_DEF int cstr_vfmt(cstr* self, const char* fmt, va_list args) { va_list args2; va_copy(args2, args); const int n = vsnprintf(NULL, (size_t)0, fmt, args); - cstr_reserve(self, n); - vsprintf(cstr_data(self), fmt, args2); + vsprintf(cstr_reserve(self, n), fmt, args2); va_end(args2); _cstr_set_size(self, n); return n; @@ -532,13 +531,12 @@ STC_DEF cstr cstr_from_fmt(const char* fmt, ...) { return s; } +/* NB! self-data in args is UB */ STC_DEF int cstr_printf(cstr* self, const char* fmt, ...) { - cstr s = cstr_null; va_list args; va_start(args, fmt); - const int n = cstr_vfmt(&s, fmt, args); + const int n = cstr_vfmt(self, fmt, args); va_end(args); - cstr_drop(self); *self = s; return n; } |
