diff options
| author | Tyge Løvset <[email protected]> | 2020-11-03 09:41:36 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-11-03 09:41:36 +0100 |
| commit | 96a572458d7ab43d19b060a867cf80c37b6473ec (patch) | |
| tree | 127a7cb11ae3051b70c27819944c0ebcc244747a | |
| parent | cc8fd2c9d8b5b8170a02ec33168d60bb92cd781d (diff) | |
| download | STC-modified-96a572458d7ab43d19b060a867cf80c37b6473ec.tar.gz STC-modified-96a572458d7ab43d19b060a867cf80c37b6473ec.zip | |
Small API change c_withbuffer() and doc fix.
| -rw-r--r-- | examples/bits.c | 5 | ||||
| -rw-r--r-- | stc/carray.h | 9 | ||||
| -rw-r--r-- | stc/cbitset.h | 10 | ||||
| -rw-r--r-- | stc/ccommon.h | 4 | ||||
| -rw-r--r-- | stc/cstr.h | 2 | ||||
| -rw-r--r-- | stc/cvec.h | 2 |
6 files changed, 16 insertions, 16 deletions
diff --git a/examples/bits.c b/examples/bits.c index 8bb187a6..8e1533cc 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -8,9 +8,8 @@ int main() { cbitset_reset(&set, 9);
cbitset_resize(&set, 43, false);
- cstr_t str = cbitset_to_str(set);
- c_print(1, " str: {}\n", str.str);
- cstr_del(&str);
+ c_withbuffer (str, char, set.size + 1)
+ c_print(1, " str: {}\n", cbitset_to_str(set, str, 0, -1));
c_print(1, "{:4}: ", set.size);
c_forrange (i, int, set.size)
diff --git a/stc/carray.h b/stc/carray.h index 5ff95513..c7b3fd36 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -30,18 +30,19 @@ Multi-dimensional generic array allocated as one block of heap-memory.
// demo:
#include <stc/carray.h>
+#include <stc/cfmt.h>
using_carray(f, float);
int main()
{
- carray3f a3 = carray3f_make(30, 20, 10, 0.f);
+ carray3f a3 = carray3f_init(30, 20, 10, 0.f);
*carray3f_at(a3, 5, 4, 3) = 10.2f; // a3[5][4][3]
carray2f a2 = carray3f_at1(a3, 5); // sub-array reference: a2 = a3[5]
- printf("%f\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f)
- printf("%f\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array.
+ c_printf(1, "{}\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f)
+ c_printf(1, "{}\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array.
carray2f_del(&a2); // does nothing, since it is a sub-array.
- carray3f_del(&a3); // also invalidates a2.
+ carray3f_del(&a3); // destroy a3, invalidates a2.
}
*/
diff --git a/stc/cbitset.h b/stc/cbitset.h index 28c1a9ef..946f9545 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -51,7 +51,7 @@ typedef struct cbitset { uint64_t* _arr; size_t size; } cbitset_t; STC_API cbitset_t cbitset_with_size(size_t size, bool value);
STC_API cbitset_t cbitset_from_str(const char* str);
-STC_API cstr_t cbitset_to_str(cbitset_t set);
+STC_API char* cbitset_to_str(cbitset_t set, char* str, size_t start, intptr_t stop);
STC_API cbitset_t cbitset_clone(cbitset_t other);
STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value);
STC_API size_t cbitset_count(cbitset_t set);
@@ -190,10 +190,10 @@ STC_DEF cbitset_t cbitset_from_str(const char* str) { for (size_t i=0; i<set.size; ++i) if (str[i] == '1') cbitset_set(&set, i);
return set;
}
-STC_DEF cstr_t cbitset_to_str(cbitset_t set) {
- cstr_t out = cstr_with_size(set.size, '0');
- for (size_t i=0; i<set.size; ++i) if (cbitset_test(set, i)) out.str[i] = '1';
- return out;
+STC_DEF char* cbitset_to_str(cbitset_t set, char* out, size_t start, intptr_t stop) {
+ size_t end = stop < 0 ? set.size : stop;
+ for (size_t i=start; i<end; ++i) out[i] = (cbitset_test(set, i)) ? '1' : '0';
+ out[end] = '\0'; return out;
}
STC_DEF cbitset_t cbitset_clone(cbitset_t other) {
size_t bytes = ((other.size + 63) >> 6) * 8;
diff --git a/stc/ccommon.h b/stc/ccommon.h index 5b35459b..75567256 100644 --- a/stc/ccommon.h +++ b/stc/ccommon.h @@ -103,8 +103,8 @@ #define c_break_with continue
#define c_withfile(f, open) for (FILE *f = open; f; fclose(f), f = NULL)
-#define c_withbuffer(type, b, n) c_withbuffer_x(type, b, n, 256)
-#define c_withbuffer_x(type, b, n, BYTES) \
+#define c_withbuffer(b, type, n) c_withbuffer_x(b, type, n, 256)
+#define c_withbuffer_x(b, type, n, BYTES) \
for (type __b[((BYTES) - 1) / sizeof(type) + 1], \
*b = (n) * sizeof *b > (BYTES) ? c_new_2(type, n) : __b; \
b; b != __b ? c_free(b) : (void)0, b = NULL)
@@ -331,7 +331,7 @@ STC_INLINE void _cstr_internal_move(cstr_t* self, size_t pos1, size_t pos2) { STC_DEF void
cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n) {
- c_withbuffer (char, xstr, n) {
+ c_withbuffer (xstr, char, n) {
memcpy(xstr, str, n);
_cstr_internal_move(self, pos + len, pos + n);
memcpy(&self->str[pos], xstr, n);
@@ -242,7 +242,7 @@ STC_DEF cvec_##X##_iter_t \
cvec_##X##_insert_range_p(cvec_##X* self, cvec_##X##_value_t* pos, const cvec_##X##_value_t* first, const cvec_##X##_value_t* finish) { \
size_t len = finish - first, idx = pos - self->data, size = cvec_size(*self); \
- c_withbuffer (cvec_##X##_value_t, buf, len) { \
+ c_withbuffer (buf, cvec_##X##_value_t, len) { \
for (size_t i=0; i<len; ++i, ++first) \
buf[i] = valueFromRaw(valueToRaw(first)); \
if (size + len > cvec_capacity(*self)) \
|
