diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
commit | ce05175372a9ddca1a225db0765ace1127a39293 (patch) | |
tree | 5988b4d4f6b402e4953945886fc90aae11203df6 /sys/base/string/make.c | |
parent | b375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff) |
chore: simplified organizational structurelaptop
Diffstat (limited to 'sys/base/string/make.c')
-rw-r--r-- | sys/base/string/make.c | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/sys/base/string/make.c b/sys/base/string/make.c deleted file mode 100644 index eb71543..0000000 --- a/sys/base/string/make.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "internal.h" - -// new returns a new dynamic string object, initialized from the given c string. -// len defines the length of the c substring that we will copy into our buffer. -// the backing buffer will have capacity cap. -string -str·makecap(const byte *s, vlong len, vlong cap) -{ - struct Hdr* h; - - h = malloc(sizeof(*h) + cap + 1); - if (s == nil) memset(h, 0, sizeof(*h)); - - if (h == nil) return nil; // Allocation failed. - - h->len = (s == nil) ? 0 : len; - h->cap = cap; - - if (cap < h->len) goto cleanup; - - if (s != nil && cap > 0) { - memcpy(h->buf, s, h->len); - memset(h->buf + h->len, '\0', h->cap - h->len + 1); - } - - return h->buf; - -cleanup: - free(h); - panicf("Attempted to create a string with less capacity than length"); - return nil; -} - -// new returns a new dynamic string object, initialized from the given c string. -// the backing buffer capacity is equivalent to the string length. -string -str·makelen(const byte *s, vlong len) -{ - vlong sl = (!s) ? 0 : strlen(s); - if (sl < len) panicf("attempted to take a bigger substring than string length"); - - vlong cap = (len == 0) ? 1 : len; - return str·makecap(s, len, cap); -} - -// new returns a new dynamic string object, initialized from the given c string. -// the backing buffer capacity is equivalent to the string length. -string -str·make(const byte *s) -{ - vlong len = (!s) ? 0 : strlen(s); - return str·makelen(s, len); -} |