aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-03-10 15:08:10 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-03-10 15:08:10 +0200
commit791d6bc10ec81d08324807211d968d7e37110f0b (patch)
treeb38d150964199381d7e443975d375ba2a858f864
parentd78cf57211f24aeebc5e2f30927e2410bf068983 (diff)
Remove Bob the String-Builder
Seeing as dynarr.h already exists, there is no real use for Bob the String-Builder. It was *a bit* nice because of the generic u8strpush() macro, but it should be very easy to implement yourself, and you only really ever need 1 or 2 specific functions that are a few lines of code each.
-rw-r--r--README1
-rw-r--r--include/bob.h39
-rw-r--r--lib/bob/u8strfit.c9
-rw-r--r--lib/bob/u8strfree.c9
-rw-r--r--lib/bob/u8strgrow.c39
-rw-r--r--lib/bob/u8strinit.c16
-rw-r--r--lib/bob/u8strpushr.c11
-rw-r--r--lib/bob/u8strpushstr.c9
-rw-r--r--lib/bob/u8strpushu8.c14
9 files changed, 0 insertions, 147 deletions
diff --git a/README b/README
index 307f63a..a7b0c65 100644
--- a/README
+++ b/README
@@ -11,7 +11,6 @@ library. It is a C23 library with no plans to support older standards.
The headers as of now are:
• alloc.h — memory allocation functions
• bitset.h — bitset implementation
- • bob.h — bob the string-builder
• dynarr.h — dynamic array implementation
• errors.h — err.h-inspired diagnostics functions
• macros.h — miscellaneous utility macros (MIN/MAX/lengthof/etc.)
diff --git a/include/bob.h b/include/bob.h
deleted file mode 100644
index 699aa5e..0000000
--- a/include/bob.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef MLIB_BOB_H
-#define MLIB_BOB_H
-
-#include <stddef.h>
-
-#include "__charN_t.h"
-#include "__rune.h"
-#include "__u8view.h"
-
-struct u8str {
- char8_t *p;
- size_t len, cap;
-};
-
-struct u8str *u8strinit(struct u8str *, size_t);
-struct u8str *u8strgrow(struct u8str *, size_t);
-struct u8str *u8strfit(struct u8str *);
-void u8strfree(struct u8str);
-
-struct u8str *u8strpushr(struct u8str *, rune);
-struct u8str *u8strpushstr(struct u8str *, const char *);
-struct u8str *u8strpushu8(struct u8str *, struct u8view);
-
-[[gnu::always_inline]]
-static inline struct u8view
-u8strtou8(struct u8str s)
-{
- return (struct u8view){.p = s.p, .len = s.len};
-}
-
-#define u8strpush(sb, x) \
- _Generic((x), \
- char: u8strpushr, \
- int: u8strpushr, \
- rune: u8strpushr, \
- char *: u8strpushstr, \
- struct u8view: u8strpushu8)((sb), (x))
-
-#endif /* !MLIB_BOB_H */
diff --git a/lib/bob/u8strfit.c b/lib/bob/u8strfit.c
deleted file mode 100644
index 332a5d7..0000000
--- a/lib/bob/u8strfit.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <stdlib.h>
-
-#include "bob.h"
-
-struct u8str *
-u8strfit(struct u8str *b)
-{
- return (b->p = realloc(b->p, b->len)) ? b : nullptr;
-}
diff --git a/lib/bob/u8strfree.c b/lib/bob/u8strfree.c
deleted file mode 100644
index 7e25ca8..0000000
--- a/lib/bob/u8strfree.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <stdlib.h>
-
-#include "bob.h"
-
-void
-u8strfree(struct u8str b)
-{
- free(b.p);
-}
diff --git a/lib/bob/u8strgrow.c b/lib/bob/u8strgrow.c
deleted file mode 100644
index f1f86d3..0000000
--- a/lib/bob/u8strgrow.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <stdlib.h>
-
-#include "bob.h"
-
-static size_t nextpow2(size_t);
-
-struct u8str *
-u8strgrow(struct u8str *b, size_t n)
-{
- if (n > b->cap) {
- b->cap = nextpow2(n);
- if (!(b->p = realloc(b->p, b->cap)))
- return nullptr;
- }
- return b;
-}
-
-size_t
-nextpow2(size_t x)
-{
-#if defined(__has_builtin) && __has_builtin(__builtin_clzl)
- x = x <= 1 ? 1 : 1 << (64 - __builtin_clzl(x - 1));
-#else
- if (x) {
- x--;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- if (sizeof(size_t) >= 4)
- x |= x >> 16;
- if (sizeof(size_t) >= 8)
- x |= x >> 32;
- }
- x++;
-#endif
-
- return x;
-}
diff --git a/lib/bob/u8strinit.c b/lib/bob/u8strinit.c
deleted file mode 100644
index 60423c1..0000000
--- a/lib/bob/u8strinit.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdlib.h>
-
-#include "bob.h"
-
-struct u8str *
-u8strinit(struct u8str *b, size_t n)
-{
- if (n) {
- if (!(b->p = malloc(n)))
- return nullptr;
- } else
- b->p = nullptr;
- b->len = 0;
- b->cap = n;
- return b;
-}
diff --git a/lib/bob/u8strpushr.c b/lib/bob/u8strpushr.c
deleted file mode 100644
index 6fe5fd9..0000000
--- a/lib/bob/u8strpushr.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "bob.h"
-#include "mbstring.h"
-
-struct u8str *
-u8strpushr(struct u8str *b, rune ch)
-{
- if (!u8strgrow(b, b->len + rtou8(nullptr, ch, 0)))
- return nullptr;
- b->len += rtou8(b->p + b->len, ch, b->cap - b->len);
- return b;
-}
diff --git a/lib/bob/u8strpushstr.c b/lib/bob/u8strpushstr.c
deleted file mode 100644
index 64b123d..0000000
--- a/lib/bob/u8strpushstr.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-
-#include "bob.h"
-
-struct u8str *
-u8strpushstr(struct u8str *b, const char *s)
-{
- return u8strpushu8(b, (struct u8view){.p = s, .len = strlen(s)});
-}
diff --git a/lib/bob/u8strpushu8.c b/lib/bob/u8strpushu8.c
deleted file mode 100644
index 8358e01..0000000
--- a/lib/bob/u8strpushu8.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <string.h>
-
-#include "bob.h"
-#include "mbstring.h"
-
-struct u8str *
-u8strpushu8(struct u8str *b, struct u8view v)
-{
- if (!u8strgrow(b, b->len + v.len))
- return nullptr;
- memcpy(b->p + b->len, v.p, v.len);
- b->len += v.len;
- return b;
-}