[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay bomb.sh/docs/tty
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940/* buffer.c — fixed-capacity byte buffer */
#include "buffer.h"#include "mem.h"#include "utf8.h"
void buf_put(Buffer *b, const char *s, int n) { if (b->length + n > b->capacity) return; memcpy(b->data + b->length, s, n); b->length += n;}
void buf_str(Buffer *b, const char *s) { buf_put(b, s, strlen(s)); }
void buf_num(Buffer *b, int n) { char tmp[12]; int i = 0; if (n < 0) { buf_put(b, "-", 1); n = -n; } if (n == 0) { buf_put(b, "0", 1); return; } while (n > 0) { tmp[i++] = '0' + (n % 10); n /= 10; } for (int j = i - 1; j >= 0; j--) buf_put(b, &tmp[j], 1);}
void buf_char(Buffer *b, uint32_t ch) { char u[8]; int n = utf8_encode(u, ch); buf_put(b, u, n);}