42 s->str_end =
s->str_start;
44 memset(
s->str_start, 0, size);
50 if (
s->str_start )
lwfree(
s->str_start);
90 s->str_start[0] =
'\0';
91 s->str_end =
s->str_start;
100 if(
s->str_end ==
s->str_start )
103 return *(
s->str_end - 1);
126 size_t size = (
s->str_end -
s->str_start) + 1;
128 memcpy(
str,
s->str_start, size);
129 str[size - 1] =
'\0';
140 return (
s->str_end -
s->str_start);
170 int maxlen = (
s->capacity - (
s->str_end -
s->str_start));
177 len = vsnprintf(
s->str_end, maxlen,
fmt, ap2);
182 #if defined(__MINGW64_VERSION_MAJOR)
183 len = _vscprintf(
fmt, ap2);
194 maxlen = (
s->capacity - (
s->str_end -
s->str_start));
197 len = vsnprintf(
s->str_end, maxlen,
fmt, ap);
200 if ( len < 0 )
return len;
202 if ( len >= maxlen )
return -1;
234 char *ptr =
s->str_end;
238 while( ptr >
s->str_start )
241 if( (*ptr ==
' ') || (*ptr ==
'\t') )
248 dist =
s->str_end - ptr;
270 char *ptr =
s->str_end;
271 char *decimal_ptr = NULL;
274 if (
s->str_end -
s->str_start < 2)
278 while( ptr >
s->str_start )
286 if ( (*ptr >=
'0') && (*ptr <=
'9' ) )
299 while( ptr >= decimal_ptr )
309 if ( ptr ==
s->str_end )
320 dist =
s->str_end - ptr;
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.
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 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
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
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.