diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/alt/cstr.h | 12 | ||||
| -rw-r--r-- | include/stc/cstr.h | 6 | ||||
| -rw-r--r-- | include/stc/csview.h | 6 | ||||
| -rw-r--r-- | include/stc/forward.h | 2 |
4 files changed, 16 insertions, 10 deletions
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 51a4f521..536cd10e 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -26,7 +26,7 @@ */
#ifndef CSTR_H_INCLUDED
#define CSTR_H_INCLUDED
-#define CSTR_IS_SSO
+#define CSTR_USE_SSO
#include <stc/ccommon.h>
#include <stc/forward.h>
@@ -79,8 +79,8 @@ STC_API char* cstr_reserve(cstr* self, size_t cap); STC_API void cstr_shrink_to_fit(cstr* self);
STC_API void cstr_resize(cstr* self, size_t size, char value);
STC_API size_t cstr_find_n(cstr s, const char* needle, size_t pos, size_t nmax);
-STC_API void cstr_assign_n(cstr* self, const char* str, size_t n);
-STC_API void cstr_append_n(cstr* self, const char* str, size_t n);
+STC_API cstr* cstr_assign_n(cstr* self, const char* str, size_t n);
+STC_API cstr* cstr_append_n(cstr* self, const char* str, size_t n);
STC_API bool cstr_getdelim(cstr *self, int delim, FILE *fp);
STC_API void cstr_erase_n(cstr* self, size_t pos, size_t n);
STC_API cstr cstr_from_fmt(const char* fmt, ...);
@@ -348,7 +348,7 @@ STC_DEF size_t cstr_find_n(cstr s, const char* needle, const size_t pos, const s return res ? res - r.data : cstr_npos;
}
-STC_DEF void cstr_assign_n(cstr* self, const char* str, const size_t n) {
+STC_DEF cstr* cstr_assign_n(cstr* self, const char* str, const size_t n) {
cstr_rep_t r = cstr_rep(self);
if (n > r.cap) {
r.data = (char *)c_realloc(cstr_is_long(self) ? r.data : NULL, n + 1);
@@ -356,9 +356,10 @@ STC_DEF void cstr_assign_n(cstr* self, const char* str, const size_t n) { }
memmove(r.data, str, n);
_cstr_set_size(self, n);
+ return self;
}
-STC_DEF void cstr_append_n(cstr* self, const char* str, const size_t n) {
+STC_DEF cstr* cstr_append_n(cstr* self, const char* str, const size_t n) {
cstr_rep_t r = cstr_rep(self);
if (r.size + n > r.cap) {
const size_t off = (size_t)(str - r.data);
@@ -367,6 +368,7 @@ STC_DEF void cstr_append_n(cstr* self, const char* str, const size_t n) { }
memcpy(r.data + r.size, str, n);
_cstr_set_size(self, r.size + n);
+ return self;
}
STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 6a866825..5ffd09bf 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -20,6 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+
+#ifdef CSTR_USE_SSO
+#include "alt/cstr.h"
+#else
#ifndef CSTR_H_INCLUDED
#define CSTR_H_INCLUDED
@@ -368,4 +372,4 @@ cstr_find_n(cstr s, const char* needle, const size_t pos, const size_t nmax) { #endif
#endif
-#undef i_opt
+#endif
diff --git a/include/stc/csview.h b/include/stc/csview.h index 0d445623..c4b88f4d 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -94,9 +94,9 @@ STC_INLINE csview csview_from_s(const cstr* self) STC_INLINE cstr cstr_from_sv(csview sv)
{ return cstr_from_n(sv.str, sv.size); }
-STC_INLINE cstr cstr_from_replace_all_sv(csview sv, csview find, csview repl)
+/*STC_INLINE cstr cstr_from_replace_all_sv(csview sv, csview find, csview repl)
{ return cstr_from_replace_all(sv.str, sv.size, find.str, find.size,
- repl.str, repl.size); }
+ repl.str, repl.size); }*/
STC_INLINE csview cstr_to_sv(const cstr* self)
{ return c_make(csview){cstr_str(self), cstr_size(*self)}; }
STC_INLINE csview cstr_substr(const cstr* self, intptr_t pos, size_t n)
@@ -110,7 +110,7 @@ STC_INLINE cstr* cstr_append_sv(cstr* self, csview sv) STC_INLINE void cstr_insert_sv(cstr* self, size_t pos, csview sv)
{ cstr_replace_n(self, pos, 0, sv.str, sv.size); }
STC_INLINE void cstr_replace_sv(cstr* self, csview sub, csview with)
- { cstr_replace_n(self, sub.str - self->str, sub.size, with.str, with.size); }
+ { cstr_replace_n(self, sub.str - cstr_str(self), sub.size, with.str, with.size); }
STC_INLINE bool cstr_equals_sv(cstr s, csview sv)
{ return sv.size == cstr_size(s) && !memcmp(cstr_str(&s), sv.str, sv.size); }
STC_INLINE size_t cstr_find_sv(cstr s, csview needle)
diff --git a/include/stc/forward.h b/include/stc/forward.h index 3996416e..5dae64c6 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -44,7 +44,7 @@ typedef struct { char* data; size_t size, cap; } cstr_rep_t;
typedef char cstr_value;
-#ifdef CSTR_IS_SSO
+#ifdef CSTR_USE_SSO
typedef union {
struct { char data[sizeof(cstr_rep_t) - 1]; uint8_t last; } sso;
struct { char* data; size_t size, ncap; } lon;
|
