27 #ifndef _STRINGBUFFER_H
28 #define _STRINGBUFFER_H 1
37 #define STRINGBUFFER_STARTSIZE 128
73 size_t current_size = (
s->str_end -
s->str_start);
74 size_t capacity =
s->capacity;
75 size_t required_size = current_size + size_to_add;
77 while (capacity < required_size)
80 if (capacity >
s->capacity)
83 s->capacity = capacity;
84 s->str_end =
s->str_start + current_size;
97 memcpy(
s->str_end, a, alen0);
107 int alen = strlen(a);
void * lwrealloc(void *mem, size_t size)
#define OUT_MAX_BYTES_DOUBLE
int lwprint_double(double d, int maxdd, char *buf)
int stringbuffer_getlength(stringbuffer_t *sb)
Returns the length of the current string, not including the null terminator (same behavior as strlen(...
static void stringbuffer_append_double(stringbuffer_t *s, double d, int precision)
stringbuffer_t * stringbuffer_create_with_size(size_t size)
Allocate a new stringbuffer_t.
void stringbuffer_release(stringbuffer_t *s)
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
static void stringbuffer_append_char(stringbuffer_t *s, char c)
static void stringbuffer_append_len(stringbuffer_t *s, const char *a, size_t alen)
Append the specified string to the stringbuffer_t using known length.
int stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
lwvarlena_t * stringbuffer_getvarlenacopy(stringbuffer_t *s)
char stringbuffer_lastchar(stringbuffer_t *s)
Return the last character in the buffer.
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
const char * stringbuffer_getstring(stringbuffer_t *sb)
Returns a reference to the internal string being managed by the stringbuffer.
void stringbuffer_destroy(stringbuffer_t *sb)
Free the stringbuffer_t and all memory managed within it.
void stringbuffer_init(stringbuffer_t *s)
static void stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
If necessary, expand the stringbuffer_t internal buffer to accommodate the specified additional size.
void stringbuffer_copy(stringbuffer_t *sb, stringbuffer_t *src)
Copy the contents of src into dst.
lwvarlena_t * stringbuffer_getvarlena(stringbuffer_t *s)
void stringbuffer_set(stringbuffer_t *sb, const char *s)
Clear the stringbuffer_t and re-start it with the specified string.
char * stringbuffer_getstringcopy(stringbuffer_t *sb)
Returns a newly allocated string large enough to contain the current state of the string.
void stringbuffer_clear(stringbuffer_t *sb)
Reset the stringbuffer_t.
void stringbuffer_init_varlena(stringbuffer_t *s)
int stringbuffer_trim_trailing_white(stringbuffer_t *s)
Trims whitespace off the end of the stringbuffer.