summaryrefslogtreecommitdiff
path: root/ds.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-22 16:38:32 -0500
committerpommicket <pommicket@gmail.com>2022-12-22 16:38:32 -0500
commit23e138019964662b4e847770eeda2bb5d3130f7a (patch)
treec92d36b878d26594cab5a35110dff6ad546d6a3d /ds.c
parent6bb4da5fab94d2ed3d093b996674fd1cc28eda2f (diff)
better write_string
Diffstat (limited to 'ds.c')
-rw-r--r--ds.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ds.c b/ds.c
index ef4a1b4..eb235d6 100644
--- a/ds.c
+++ b/ds.c
@@ -297,7 +297,6 @@ void str_builder_append(StrBuilder *builder, const char *s) {
size_t prev_len = prev_size - 1; // null terminator
// note: this zeroes the newly created elements, so we have a new null terminator
arr_set_len(builder->str, prev_size + s_len);
- // -1 for null terminator
memcpy(builder->str + prev_len, s, s_len);
}
@@ -331,3 +330,16 @@ u32 str_builder_len(StrBuilder *builder) {
return arr_len(builder->str) - 1;
}
+char *str_builder_get_ptr(StrBuilder *builder, size_t index) {
+ assert(index <= str_builder_len(builder));
+ return &builder->str[index];
+}
+
+void str_builder_shrink(StrBuilder *builder, size_t new_len) {
+ if (new_len > str_builder_len(builder)) {
+ assert(0);
+ return;
+ }
+ arr_set_len(builder->str, new_len + 1);
+}
+