summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-05-06 05:44:41 +0200
committerTyge Lovset <[email protected]>2022-05-06 05:44:41 +0200
commitbf3a35e3cd8d1df9548aa0e57b58d7a0e5dfef14 (patch)
treed7fa178e449f64c0d91d3d4b97e20a5619fccab3 /include
parent85180f17da3ea3d1cebc30d42560fb12a997aabf (diff)
downloadSTC-modified-bf3a35e3cd8d1df9548aa0e57b58d7a0e5dfef14.tar.gz
STC-modified-bf3a35e3cd8d1df9548aa0e57b58d7a0e5dfef14.zip
Made cstr_buffer() func. public, and docs for cstr_sv() - convert to csview.
Diffstat (limited to 'include')
-rw-r--r--include/stc/alt/cstr.h4
-rw-r--r--include/stc/cstr.h22
-rw-r--r--include/stc/forward.h4
3 files changed, 15 insertions, 15 deletions
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h
index ec7f3bba..db9c0505 100644
--- a/include/stc/alt/cstr.h
+++ b/include/stc/alt/cstr.h
@@ -120,9 +120,9 @@ STC_INLINE bool cstr_contains(cstr s, const char* needle)
STC_INLINE bool cstr_getline(cstr *self, FILE *stream)
{ return cstr_getdelim(self, '\n', stream); }
-STC_INLINE cstr_rep_t cstr_rep(cstr* s) {
+STC_INLINE cstr_buf cstr_buffer(cstr* s) {
cstr_priv* p = _cstr_p(s);
- return c_make(cstr_rep_t){s->str, p->size, p->cap};
+ return c_make(cstr_buf){s->str, p->size, p->cap};
}
STC_INLINE cstr cstr_with_capacity(const size_t cap) {
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 20b50ee9..85c5061f 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -45,7 +45,7 @@
# pragma GCC diagnostic ignored "-Wstringop-overflow="
#endif
-enum { cstr_s_cap = sizeof(cstr_rep_t) - 1 };
+enum { cstr_s_cap = sizeof(cstr_buf) - 1 };
#define cstr_s_size(s) ((size_t)(cstr_s_cap - (s)->sml.last))
#define cstr_s_set_size(s, len) ((s)->sml.last = cstr_s_cap - (len), (s)->sml.data[len] = 0)
#define cstr_s_data(s) (s)->sml.data
@@ -89,10 +89,10 @@ STC_API int cstr_printf(cstr* self, const char* fmt, ...);
STC_API void cstr_replace_all(cstr* self, const char* find, const char* repl);
STC_API cstr cstr_from_replace_all_sv(csview sv, csview find, csview repl);
-STC_INLINE cstr_rep_t cstr_rep(cstr* s) {
+STC_INLINE cstr_buf cstr_buffer(cstr* s) {
return cstr_is_long(s)
- ? c_make(cstr_rep_t){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
- : c_make(cstr_rep_t){s->sml.data, cstr_s_size(s), cstr_s_cap};
+ ? c_make(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
+ : c_make(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap};
}
STC_INLINE csview cstr_sv(const cstr* s) {
return cstr_is_long(s) ? c_make(csview){s->lon.data, cstr_l_size(s)}
@@ -278,7 +278,7 @@ STC_INLINE uint64_t cstr_hash(const cstr *self) {
#if defined(i_implement)
STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t pos2) {
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
if (pos1 != pos2) {
const size_t newlen = r.size + pos2 - pos1;
if (newlen > r.cap)
@@ -301,7 +301,7 @@ STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) {
}
STC_DEF void cstr_shrink_to_fit(cstr* self) {
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
if (r.size == r.cap)
return;
if (r.size > cstr_s_cap) {
@@ -336,7 +336,7 @@ STC_DEF char* cstr_reserve(cstr* self, const size_t cap) {
}
STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) {
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
if (size > r.size) {
if (size > r.cap) r.data = cstr_reserve(self, size);
memset(r.data + r.size, value, size - r.size);
@@ -353,7 +353,7 @@ STC_DEF size_t cstr_find_n(cstr s, const char* needle, const size_t pos, const s
}
STC_DEF cstr* cstr_assign_n(cstr* self, const char* str, const size_t n) {
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
if (n > r.cap) {
r.data = (char *)c_realloc(cstr_is_long(self) ? r.data : NULL, n + 1);
cstr_l_set_cap(self, n);
@@ -364,7 +364,7 @@ STC_DEF cstr* cstr_assign_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);
+ cstr_buf r = cstr_buffer(self);
if (r.size + n > r.cap) {
const size_t off = (size_t)(str - r.data);
r.data = cstr_reserve(self, (r.size*3 >> 1) + n);
@@ -380,7 +380,7 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
if (c == EOF)
return false;
size_t pos = 0;
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
for (;;) {
if (c == delim || c == EOF) {
_cstr_set_size(self, pos);
@@ -426,7 +426,7 @@ cstr_from_replace_all_sv(csview sv, csview find, csview repl) {
}
STC_DEF void cstr_erase_n(cstr* self, const size_t pos, size_t n) {
- cstr_rep_t r = cstr_rep(self);
+ cstr_buf r = cstr_buffer(self);
if (n > r.size - pos) n = r.size - pos;
memmove(&r.data[pos], &r.data[pos + n], r.size - (pos + n));
_cstr_set_size(self, r.size - n);
diff --git a/include/stc/forward.h b/include/stc/forward.h
index 6af17c2b..9952416a 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -42,11 +42,11 @@
#define forward_cqueue(CX, VAL) _c_cdeq_types(CX, VAL)
#define forward_cvec(CX, VAL) _c_cvec_types(CX, VAL)
-typedef struct { char* data; size_t size, cap; } cstr_rep_t;
+typedef struct { char* data; size_t size, cap; } cstr_buf;
typedef char cstr_value;
#ifndef STC_OLD_CSTR
typedef union {
- struct { char data[sizeof(cstr_rep_t) - 1]; unsigned char last; } sml;
+ struct { char data[sizeof(cstr_buf) - 1]; unsigned char last; } sml;
struct { char* data; size_t size, ncap; } lon;
} cstr;
#else