Commit: f90875dbc58183c6c7c8d32cd1d208649da493cd
Parent: 0550c9f4ee71ad0d9bf421d3d5d8fe7c1240c197
Author: Randy Palamar
Date: Tue, 9 Jun 2026 09:39:19 -0600
util: stream helper for utf32 codepoints
Diffstat:
| M | util.c | | | 18 | +++++++++++++----- |
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/util.c b/util.c
@@ -330,11 +330,12 @@ stream_alloc(Arena *a, i32 cap)
return result;
}
-function s8
-stream_to_s8(Stream *s)
+#define stream_to_s8(s) s8_from_str8(stream_to_str8(s))
+function str8
+stream_to_str8(Stream *s)
{
- s8 result = s8("");
- if (!s->errors) result = (s8){.len = s->widx, .data = s->data};
+ str8 result = str8("");
+ if (!s->errors) result = (str8){.length = s->widx, .data = s->data};
return result;
}
@@ -359,11 +360,18 @@ stream_append(Stream *s, void *data, iz count)
{
s->errors |= (s->cap - s->widx) < count;
if (!s->errors) {
- mem_copy(s->data + s->widx, data, (uz)count);
+ memory_copy(s->data + s->widx, data, (uz)count);
s->widx += (i32)count;
}
}
+function void
+stream_append_codepoint(Stream *s, u32 codepoint)
+{
+ u8 buffer[4];
+ stream_append(s, buffer, utf8_encode(buffer, codepoint));
+}
+
// TODO(rnp): replace with handwritten version
#include <stdarg.h>
#include <stdio.h>