26#define STRB_EXT_STATE 1
46#ifndef STRB_REUSE_CONST
47#define STRB_REUSE_CONST 1
53#if defined(_MSC_VER) || \
54 (defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L)
55#define STRB_SIZE_HINT(X)
57#define STRB_SIZE_HINT(X) static restrict X
65#define STRB_MAX SIZE_MAX
74#define PRIstrbsize PRIu8
79#define STRB_MAX_SIZE UINT8_MAX
81#elif STRB_STATIC_ALLOC
97#define PRIstrbsize PRIu8
102#define STRB_MAX_SIZE (256 - 8)
109#define STRB_MAX SIZE_MAX
120#define PRIstrbsize PRIu16
125#define STRB_MAX_SIZE UINT16_MAX
131#define STRB_DFL_SIZE (256)
137#define STRB_MAX_INTERNAL_SIZE (256)
142#define STRB_GROW_FACTOR (2)
154#if !STRB_FREESTANDING
159static inline void optional_free(_Optional
void *x)
164#define free(x) optional_free(x)
166static inline _Optional
void *optional_malloc(
size_t n)
171#define malloc(n) optional_malloc(n)
173static inline _Optional
void *optional_realloc(_Optional
void *p,
size_t n)
175 return realloc((
void *)p, n);
178#define realloc(p, n) optional_realloc(p, n)
180static inline int optional_vsnprintf(_Optional
char *buffer,
size_t sz,
181 const char *format, va_list vlist)
183 return vsnprintf((
char *)buffer, sz, format, vlist);
186#define vsnprintf(buffer, sz, format, vlist) \
187 optional_vsnprintf(buffer, sz, format, vlist)
191#define NULL ((_Optional void *)0)
365#elif !STRB_FREESTANDING
439#if !STRB_FREESTANDING
632#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
633#define strb_ptr(sb) \
634 _Generic(sb, strb_t *: strb_ptr, const strb_t *: strb_cptr)(sb)
896#if !STRB_FREESTANDING
925int strb_vputf(
strb_t *restrict sb,
const char *restrict format, va_list args);
1054#define strb_wrote(sb) strb_restore(sb)
1130int strb_ncpy(
strb_t *restrict sb,
const char *restrict str,
size_t n);
1132#if !STRB_FREESTANDING
#define STRB_SIZE_HINT(X)
int strb_seek(strb_t *sb, size_t pos)
Set the editing position of a string buffer.
int strb_vprintf(strb_t *restrict sb, const char *restrict format, va_list args)
Print a generated string into a string buffer.
_Optional strb_t * strb_ndup(const char *str, size_t n)
Create a string buffer object with internal storage by duplicating a sequence of characters.
int strb_getmode(const strb_t *sb)
Get the editing mode of a string buffer.
_Optional strb_t * strb_vaprintf(const char *restrict format, va_list args)
Create a string buffer object with internal storage by parsing a format string.
int strb_printf(strb_t *restrict sb, const char *restrict format,...)
Print a generated string into a string buffer.
size_t strb_tell(strb_t const *sb)
Get the editing position of a string buffer.
void strb_delto(strb_t *sb, size_t pos)
Delete characters to a specified position in a string buffer.
_Optional strb_t * strb_alloc(size_t n)
Create a string buffer object with internal storage.
void strb_free(_Optional strb_t *sb)
Destroy a string buffer object.
_Optional strb_t * strb_dup(const char *str)
Create a string buffer object with internal storage by duplicating a string.
int strb_nputs(strb_t *restrict sb, const char *restrict str, size_t n)
Put a sequence of characters into a string buffer.
int strb_cpy(strb_t *restrict sb, const char *restrict str)
Copy a string into a string buffer.
_Optional const strb_t * strb_reuse_const(strbstate_t *restrict sbs, const char buf[STRB_SIZE_HINT(1)])
Create a string buffer object that wraps a constant string.
void strb_restore(strb_t *sb)
Restore a character that may have been overwritten by a preceding write.
size_t strb_len(strb_t const *sb)
Get the number of characters stored in a string buffer.
char * strb_ptr(strb_t *sb)
Get a pointer to the character array underlying a string buffer.
bool strb_error(strb_t const *sb)
Get the error indicator of a string buffer.
int strb_unputc(strb_t *sb)
Undo the last put character operation.
int strb_nputc(strb_t *sb, int c, size_t n)
Put a character into a string buffer multiple times.
const char * strb_cptr(strb_t const *sb)
int strb_putf(strb_t *restrict sb, const char *restrict format,...)
Put a generated string into a string buffer.
int strb_puts(strb_t *restrict sb, const char *restrict str)
Put a string into a string buffer.
void strb_clearerr(strb_t *sb)
Clear the error indicator of a string buffer.
void strb_split(strb_t *sb)
Split a string at the current position.
int strb_vputf(strb_t *restrict sb, const char *restrict format, va_list args)
Put a generated string into a string buffer.
_Optional char * strb_write(strb_t *sb, size_t n)
Prepare to write characters directly into a string buffer.
strb_t * strb_use(strbstate_t *restrict sbs, size_t size, char buf[STRB_SIZE_HINT(size)])
Create a string buffer object for managing an external character array.
int strb_putc(strb_t *sb, int c)
Put a character into a string buffer.
int strb_ncpy(strb_t *restrict sb, const char *restrict str, size_t n)
Copy a sequence of characters into a string buffer.
int strb_setmode(strb_t *sb, int mode)
Set the editing mode of a string buffer.
_Optional strb_t * strb_aprintf(const char *restrict format,...)
Create a string buffer object with internal storage by parsing a format string.
_Optional strb_t * strb_reuse(strbstate_t *restrict sbs, size_t size, char buf[STRB_SIZE_HINT(size)])
Create a string buffer object by reusing an external character array.