summaryrefslogtreecommitdiff
path: root/userland/libc/include/tb
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-11 17:22:00 +0200
committerAnton Kling <anton@kling.gg>2024-04-11 17:23:39 +0200
commitca082f686fd2dc7ee6f0284421f6212d6d4acee8 (patch)
tree493b1047661174816f0d1d300952e40e2846b24b /userland/libc/include/tb
parente25a47fcc4db09ab9b845a691297da67243e6049 (diff)
bug fixes
Diffstat (limited to 'userland/libc/include/tb')
-rw-r--r--userland/libc/include/tb/sb.h23
-rw-r--r--userland/libc/include/tb/sv.h32
2 files changed, 55 insertions, 0 deletions
diff --git a/userland/libc/include/tb/sb.h b/userland/libc/include/tb/sb.h
new file mode 100644
index 0000000..5675985
--- /dev/null
+++ b/userland/libc/include/tb/sb.h
@@ -0,0 +1,23 @@
+#ifndef SB_H
+#define SB_H
+#include "sv.h"
+#include <stddef.h>
+
+struct sb {
+ char *string;
+ size_t length;
+ size_t capacity;
+};
+
+struct sv;
+
+void sb_init(struct sb *ctx);
+void sb_free(struct sb *ctx);
+void sb_reset(struct sb *ctx);
+int sb_isempty(const struct sb *ctx);
+void sb_append_char(struct sb *ctx, char c);
+int sb_delete_right(struct sb *ctx, int n);
+void sb_append(struct sb *ctx, const char *s);
+void sb_append_sv(struct sb *ctx, struct sv sv);
+void sb_prepend_sv(struct sb *ctx, struct sv sv);
+#endif
diff --git a/userland/libc/include/tb/sv.h b/userland/libc/include/tb/sv.h
new file mode 100644
index 0000000..6e81b0b
--- /dev/null
+++ b/userland/libc/include/tb/sv.h
@@ -0,0 +1,32 @@
+#ifndef SV_H
+#define SV_H
+#include "sb.h"
+#include <stddef.h>
+
+#define SB_TO_SV(_sb) \
+ (struct sv) { \
+ .s = (_sb).string, .length = (_sb).length \
+ }
+
+#define C_TO_SV(_c_string) \
+ ((struct sv){.length = strlen(_c_string), .s = (_c_string)})
+
+struct sv {
+ const char *s;
+ size_t length;
+};
+
+char *SV_TO_C(struct sv s);
+struct sv sv_split_delim(const struct sv input, struct sv *rest, char delim);
+struct sv sv_end_split_delim(const struct sv input, struct sv *rest,
+ char delim);
+struct sv sv_split_space(const struct sv input, struct sv *rest);
+int sv_isempty(struct sv s);
+char sv_peek(struct sv s);
+int sv_eq(struct sv a, struct sv b);
+int sv_partial_eq(struct sv a, struct sv b);
+struct sv sv_trim_left(struct sv s, size_t n);
+struct sv sv_clone(struct sv s);
+struct sv sv_clone_from_c(const char *s);
+char *sv_copy_to_c(struct sv s, char *out, size_t buffer_length);
+#endif