From a78af39e732565456434ba82eadeb822aaed1774 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Fri, 6 Nov 2026 05:57:15 +0300 Subject: feat(sb): add string builder --- include/sb.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 include/sb.h (limited to 'include') diff --git a/include/sb.h b/include/sb.h new file mode 100644 index 0000000..1dbed9a --- /dev/null +++ b/include/sb.h @@ -0,0 +1,58 @@ +// sb.h --- String Builder -*- C -*- +// +// Copyright (c) 2026 Martin Michalec +// +// SPDX-License-Identifier: MIT +// +// This file is part of COSMOS Codebase. +// +// Commentary: +// +// MAYBE(cmmm): include as extension in da.h +// +// Code: + +#ifndef INCLUDED_COSMOS_SB_H +#define INCLUDED_COSMOS_SB_H + +#include "da.h" +#include "mv.h" + +struct sb { + struct da_hdr hdr; + char *arr; +}; + +/* */ char *sb_cstr (struct sb *); +struct ms sb_ms (struct sb); + +// specialized pushing +struct ms sb_push_mv (struct sb *, struct mv ); +struct ms sb_push_mv_arr (struct sb *, struct mv_arr); +struct ms sb_pad (struct sb *, int n, char ); + +#ifndef SB_NO_FEAT_STDIO + +// FORMAT_PRINTF (2, 3) +__attribute__ ((__format__ (__printf__, 2, 3))) +int sb_printf (struct sb *, const char *fmt, ... ); +int sb_vprintf (struct sb *, const char *fmt, va_list); + +#endif // SB_NO_FEAT_STDIO + +#ifndef SB_NO_FEAT_UNISTD + +struct ms sb_read_until_eof (struct sb *, int fd); + +#ifndef IOBUF_NO_FEAT_UNISTD +#include "iobuf.h" +struct ms sb_read_until (struct sb *, int fd, u8 del, struct iobuf *); +struct ms sb_read_until_any (struct sb *, int fd, struct mv set, struct iobuf *); +struct ms sb_read_until_seq (struct sb *, int fd, struct mv seq, struct iobuf *); +#endif // IOBUF_NO_FEAT_UNISTD + +#endif // SB_NO_FEAT_UNISTD + +#endif // INCLUDED_COSMOS_SB_H + +// sb.h ends here -- cgit v1.3.1