44 s->str_end =
s->str_start;
46 memset(
s->str_start, 0, size);
52 if (
s->str_start )
lwfree(
s->str_start);
92 s->str_start[0] =
'\0';
93 s->str_end =
s->str_start;
103 size_t current_size = (
s->str_end -
s->str_start);
104 size_t capacity =
s->capacity;
105 size_t required_size = current_size + size_to_add;
107 while (capacity < required_size)
110 if ( capacity >
s->capacity )
113 s->capacity = capacity;
114 s->str_end =
s->str_start + current_size;
124 if(
s->str_end ==
s->str_start )
127 return *(
s->str_end - 1);
136 int alen = strlen(a);
137 int alen0 = alen + 1;
139 memcpy(
s->str_end, a, alen0);
162 size_t size = (
s->str_end -
s->str_start) + 1;
164 memcpy(str,
s->str_start, size);
165 str[size - 1] =
'\0';
176 return (
s->str_end -
s->str_start);
206 int maxlen = (
s->capacity - (
s->str_end -
s->str_start));
213 len = vsnprintf(
s->str_end, maxlen,
fmt, ap2);
218 #if defined(__MINGW64_VERSION_MAJOR)
219 len = _vscprintf(
fmt, ap2);
230 maxlen = (
s->capacity - (
s->str_end -
s->str_start));
233 len = vsnprintf(
s->str_end, maxlen,
fmt, ap);
236 if ( len < 0 )
return len;
238 if ( len >= maxlen )
return -1;
270 char *ptr =
s->str_end;
274 while( ptr >
s->str_start )
277 if( (*ptr ==
' ') || (*ptr ==
'\t') )
284 dist =
s->str_end - ptr;
306 char *ptr =
s->str_end;
307 char *decimal_ptr = NULL;
310 if (
s->str_end -
s->str_start < 2)
314 while( ptr >
s->str_start )
322 if ( (*ptr >=
'0') && (*ptr <=
'9' ) )
335 while( ptr >= decimal_ptr )
345 if ( ptr ==
s->str_end )
356 dist =
s->str_end - ptr;
void * lwrealloc(void *mem, size_t size)
void * lwalloc(size_t size)
stringbuffer_t * stringbuffer_create_with_size(size_t size)
Allocate a new stringbuffer_t.
void stringbuffer_release(stringbuffer_t *s)
void stringbuffer_clear(stringbuffer_t *s)
Reset the stringbuffer_t.
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
char stringbuffer_lastchar(stringbuffer_t *s)
Return the last character in the buffer.
void stringbuffer_set(stringbuffer_t *s, const char *str)
Clear the stringbuffer_t and re-start it with the specified string.
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.
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
static void stringbuffer_init_with_size(stringbuffer_t *s, size_t size)
int stringbuffer_getlength(stringbuffer_t *s)
Returns the length of the current string, not including the null terminator (same behavior as strlen(...
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
void stringbuffer_init(stringbuffer_t *s)
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string.
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.
static int stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
Appends a formatted string to the current string buffer, using the format and argument list provided.
void stringbuffer_copy(stringbuffer_t *dst, stringbuffer_t *src)
Copy the contents of src into dst.
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
int stringbuffer_trim_trailing_white(stringbuffer_t *s)
Trims whitespace off the end of the stringbuffer.
#define STRINGBUFFER_STARTSIZE