diff options
| author | Tyge Løvset <[email protected]> | 2021-12-13 13:53:22 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-12-13 13:53:22 +0100 |
| commit | 17280f8177736c35b34e41556a307ca51e68d1e2 (patch) | |
| tree | 96b0b7dfeede1dc0a6c6f36ec60f18e2ff3bd68a /include/stc/cbits.h | |
| parent | c7a26eb5b5fef1c2706d5875a0603d352926487e (diff) | |
| download | STC-modified-17280f8177736c35b34e41556a307ca51e68d1e2.tar.gz STC-modified-17280f8177736c35b34e41556a307ca51e68d1e2.zip | |
Renamed constructor *cstr_lit()* to `cstr_new(lit)`.
Renamed *cstr_assign_fmt()* to `cstr_printf()`.
Renamed cbits_from_str() to cbits_from().
Diffstat (limited to 'include/stc/cbits.h')
| -rw-r--r-- | include/stc/cbits.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 2843f7d0..1816f41a 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -61,9 +61,9 @@ struct cbits { size_t size;
} typedef cbits;
+STC_API cbits cbits_from_n(const char* str, size_t n);
STC_API cbits cbits_with_size(size_t size, bool value);
STC_API cbits cbits_with_values(size_t size, uint64_t pattern);
-STC_API cbits cbits_from_str(const char* str);
STC_API char* cbits_to_str(cbits set, char* str, size_t start, intptr_t stop);
STC_API cbits cbits_clone(cbits other);
STC_API void cbits_resize(cbits* self, size_t size, bool value);
@@ -73,10 +73,14 @@ STC_API bool cbits_subset_of(cbits set, cbits other); STC_API bool cbits_disjoint(cbits set, cbits other);
STC_INLINE cbits cbits_init() { return c_make(cbits){NULL, 0}; }
+STC_INLINE cbits cbits_from(const char* s) { return cbits_from_n(s, strlen(s)); }
STC_INLINE void cbits_clear(cbits* self) { self->size = 0; }
STC_INLINE void cbits_del(cbits* self) { c_free(self->data64); }
STC_INLINE size_t cbits_size(cbits set) { return set.size; }
+#define cbits_new(literal) \
+ cbits_from_n(literal, sizeof c_make(c_strlit){literal} - 1)
+
STC_INLINE cbits* cbits_take(cbits* self, cbits other) {
if (self->data64 != other.data64) {cbits_del(self); *self = other;}
return self;
@@ -190,9 +194,8 @@ STC_DEF cbits cbits_with_values(size_t size, uint64_t pattern) { cbits_set_values(&set, pattern);
return set;
}
-STC_DEF cbits cbits_from_str(const char* str) {
- const char* p = str; while (*p) ++p;
- cbits set = cbits_with_size(p - str, false);
+STC_DEF cbits cbits_from_n(const char* str, size_t n) {
+ cbits set = cbits_with_size(n, false);
for (size_t i=0; i<set.size; ++i) if (str[i] == '1') cbits_set(&set, i);
return set;
}
|
