junie-undo

This commit is contained in:
2025-11-29 11:55:55 -08:00
parent a574df2ab7
commit 0cfb06dff2
9 changed files with 388 additions and 57 deletions

35
abuf.c
View File

@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdint-gcc.h>
#include "abuf.h"
#include "core.h"
@@ -36,6 +37,16 @@ ab_init_cap(abuf *buf, const size_t cap)
}
void
ab_init_str(abuf *buf, const char *s)
{
size_t len = kstrnlen(s, SIZE_MAX);
ab_init_cap(buf, len);
ab_append(buf, s, len);
}
void
ab_resize(abuf *buf, size_t cap)
{
@@ -71,6 +82,18 @@ ab_append(abuf *buf, const char *s, size_t len)
}
void
ab_append_ab(abuf *buf, abuf *other)
{
assert(buf != NULL && other != NULL);
if (other->size == 0) {
return;
}
ab_append(buf, other->b, other->size);
}
void
ab_prependch(abuf *buf, const char c)
{
@@ -97,6 +120,18 @@ ab_prepend(abuf *buf, const char *s, const size_t len)
}
void
ab_prepend_ab(abuf *buf, abuf *other)
{
assert(buf != NULL && other != NULL);
if (other->size == 0) {
return;
}
ab_prepend(buf, other->b, other->size);
}
void
ab_free(abuf *buf)
{