2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#ifndef GIMBAL_STRING_BUFFER_H
24#define GIMBAL_STRING_BUFFER_H
26#include "../containers/gimbal_array_list.h"
32#define GBL_SELF_TYPE GblStringBuffer
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
70
71
72
73
89
90
91
92
115
116
117
118
137
138
139
140
148
149
150
151
161
162
163
164
172
173
174
175
201
202
203
204
218 const char* pReplacement,
225
226
227
228
246
247
248
249
259
260
261
262
278#define GblStringBuffer_construct(...)
280#define GblStringBuffer_construct_1(self)
281 GblStringBuffer_construct_2
(self, "")
282#define GblStringBuffer_construct_2(self, str)
283 GblStringBuffer_construct_3
(self, str, 0
)
284#define GblStringBuffer_construct_3(self, str, len)
285 GblStringBuffer_construct_4
(self, str, len, sizeof(GblStringBuffer))
286#define GblStringBuffer_construct_4(self, str, len, size)
287 GblStringBuffer_construct_5
(self, str, len, size, GBL_NULL)
288#define GblStringBuffer_construct_5(self, str, len, size, ctx)
289 ((GblStringBuffer_construct
(self, str, len, size, ctx)))
291#define GblStringBuffer_view(...)
292 GblStringBuffer_viewDefault_
(__VA_ARGS__)
293#define GblStringBuffer_viewDefault_(...)
294 GblStringBuffer_viewDefault__
(__VA_ARGS__, 0
, 0
)
295#define GblStringBuffer_viewDefault__(buffer, offset, length, ...)
296 ((GblStringBuffer_view
)(buffer, offset, length))
298#define GblStringBuffer_set(...)
299 GblStringBuffer_setDefault_
(__VA_ARGS__)
300#define GblStringBuffer_setDefault_(...)
301 GblStringBuffer_setDefault__
(__VA_ARGS__, 0
)
302#define GblStringBuffer_setDefault__(buffer, str, len, ...)
303 ((GblStringBuffer_set
)(buffer, str, len))
305#define GblStringBuffer_insert(...)
306 GblStringBuffer_insertDefault_
(__VA_ARGS__)
307#define GblStringBuffer_insertDefault_(...)
308 GblStringBuffer_insertDefault__
(__VA_ARGS__, 0
)
309#define GblStringBuffer_insertDefault__(buffer, offset, str, len, ...)
310 ((GblStringBuffer_insert
)(buffer, offset, str, len))
312#define GblStringBuffer_append(...)
313 GblStringBuffer_appendDefault_
(__VA_ARGS__)
314#define GblStringBuffer_appendDefault_(...)
315 GblStringBuffer_appendDefault__
(__VA_ARGS__, 0
)
316#define GblStringBuffer_appendDefault__(buffer, str, len, ...)
317 ((GblStringBuffer_append
)(buffer, str, len))
319#define GblStringBuffer_prepend(...)
320 GblStringBuffer_prependDefault_
(__VA_ARGS__)
321#define GblStringBuffer_prependDefault_(...)
322 GblStringBuffer_prependDefault__
(__VA_ARGS__, 0
)
323#define GblStringBuffer_prependDefault__(buffer, str, len, ...)
324 ((GblStringBuffer_prepend
)(buffer, str, len))
326#define GblStringBuffer_overwrite(...)
327 GblStringBuffer_overwriteDefault_
(__VA_ARGS__)
328#define GblStringBuffer_overwriteDefault_(...)
329 GblStringBuffer_overwriteDefault__
(__VA_ARGS__, 0
)
330#define GblStringBuffer_overwriteDefault__(buffer, offset, str, len, ...)
331 ((GblStringBuffer_overwrite
)(buffer, offset, str, len))
333#define GblStringBuffer_remove(...)
334 GblStringBuffer_removeDefault_
(__VA_ARGS__)
335#define GblStringBuffer_removeDefault_(...)
336 GblStringBuffer_removeDefault__
(__VA_ARGS__, 0
)
337#define GblStringBuffer_removeDefault__(buffer, str, len, ...)
338 ((GblStringBuffer_remove
)(buffer, str, len))
340#define GblStringBuffer_replace(...)
341 GblStringBuffer_replaceDefault_
(__VA_ARGS__)
342#define GblStringBuffer_replaceDefault_(...)
343 GblStringBuffer_replaceDefault__
(__VA_ARGS__, 0
, 0
, 0
)
344#define GblStringBuffer_replaceDefault__(buffer, substr, repl, count, substrLen, replLen, ...)
345 (GblStringBuffer_replace
(buffer, substr, repl, count, substrLen, replLen))
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uintptr_t GblQuark
Uniquely identifiable interned string type.
const char GblStringRef
Reference-counted, const char*-compatible string type.
Mutable string type optimized for building and writing.
size_t GblStringBuffer_remove(GblStringBuffer *pSelf, const char *pStr, size_t len)
Removes all instances of pStr (len is optional) from the given buffer, returning the number of entrie...
GBL_RESULT GblStringBuffer_appendPointer(GblStringBuffer *pSelf, const void *pPtr)
Adds the hexadecimal string representation of the pointer, pPtr, to the end of the given GblStringBuf...
GBL_RESULT GblStringBuffer_destruct(GblStringBuffer *pSelf)
Destructs the given GblStringBuffer structure, releasing any allocated resources and returning a resu...
size_t GblStringBuffer_stackBytes(const GblStringBuffer *pSelf)
Returns the number of bytes the given GblStringBuffer can store before falling back to the heap.
char * GblStringBuffer_data(GblStringBuffer *pSelf)
Returns a mutable pointer to the internal data buffer of the given GblStringBuffer.
const GblStringRef * GblStringBuffer_createRef(const GblStringBuffer *pSelf)
Creates and returns a new GblStringRef based on the contents of the given buffer (don't forget to unr...
const char * GblStringBuffer_set(GblStringBuffer *pSelf, const char *pStr, size_t len)
Assigns the value of the given GblStringBuffer to pStr, optionally taking its length,...
GBL_RESULT GblStringBuffer_appendPadding(GblStringBuffer *pSelf, char value, size_t count)
Adds count copies of value to the end of the given GblStringBuffer, returning a result code.
GBL_RESULT GblStringBuffer_resize(GblStringBuffer *pSelf, size_t size)
Sets the length of the given GblStringBuffer to size, regrowing if necessary, but not shrinking,...
GblBool GblStringBuffer_valid(const GblStringBuffer *pSelf)
Returns GBL_TRUE if the given GblStringBuffer holds a valid C string (with NULL terminator)
GBL_RESULT GblStringBuffer_appendUint(GblStringBuffer *pSelf, unsigned value)
Adds the stringified respresentation of the unsigned integer, value, to the end of the given GblStrin...
size_t GblStringBuffer_replace(GblStringBuffer *pSelf, const char *pSubstr, const char *pReplacement, size_t limit, size_t substrLen, size_t replLen)
Replaces limit instances (0 is infinite) of Substr with pReplacement, with both lenghts being optiona...
GblBool GblStringBuffer_blank(const GblStringBuffer *pSelf)
Returns GBL_TRUE if the given GblStringBuffer is empty or holds only spacing characters.
GBL_RESULT GblStringBuffer_acquire(GblStringBuffer *pSelf, char *pData, size_t capacity)
Transfers ownership of a given C string to the given buffer, assigning its value and updating its cap...
GBL_RESULT GblStringBuffer_trimStart(GblStringBuffer *pSelf, char value)
Removes any leading instances of value from the beginning of the given GblStringBuffer,...
GblContext * GblStringBuffer_context(const GblStringBuffer *pSelf)
Returns a pointer to the context the GblStringBuffer was created with.
GBL_RESULT GblStringBuffer_upper(GblStringBuffer *pSelf)
Changes the casing of every character within the GblStringBuffer to uppercase, returning a result cod...
GBL_RESULT GblStringBuffer_appendInt(GblStringBuffer *pSelf, int value)
Adds the stringified representation of the integer, value, to the end of the given GblStringBuffer,...
GblBool GblStringBuffer_empty(const GblStringBuffer *pSelf)
Returns GBL_TRUE if the given GblStringBuffer is empty, otherwise returns GBL_FALSE.
GBL_RESULT GblStringBuffer_appendFloat(GblStringBuffer *pSelf, float value)
Adds the stringified representation of the float, value, to the end of the given GblStringBuffer,...
GBL_RESULT GblStringBuffer_prepend(GblStringBuffer *pSelf, const char *pStr, size_t len)
Inserts pStr (with optional length, len) at the beginning of the given buffer, returning a result cod...
GBL_RESULT GblStringBuffer_chop(GblStringBuffer *pSelf)
Removes the last character from the given GblStringBuffer, returning a result code.
size_t GblStringBuffer_capacity(const GblStringBuffer *pSelf)
Returns the actual size of the internal data buffer held by the given GblStringBuffer.
GBL_RESULT GblStringBuffer_appendNil(GblStringBuffer *pSelf)
Adds the word "nil" to the end of the given GblStringBuffer, returning a result code.
GblStringView GblStringBuffer_view(const GblStringBuffer *pSelf, size_t offset, size_t len)
Creates a GblStringView containing either the whole buffer or a subsection of it.
GBL_RESULT GblStringBuffer_clear(GblStringBuffer *pSelf)
Clears the contents of the given GblStringBuffer, resetting it back to an empty state and returning a...
GBL_RESULT GblStringBuffer_shrinkToFit(GblStringBuffer *pSelf)
Shrinks the capacity of the given GblStringBuffer to match its length, if it doesn't already,...
const char * GblStringBuffer_cString(const GblStringBuffer *pSelf)
Returns a pointer to a constant NULL-terminated C string for the given GblStringBuffer.
GBL_RESULT GblStringBuffer_insert(GblStringBuffer *pSelf, size_t index, const char *pString, size_t length)
Inserts pString at the given index with optional length, returning a result code.
GblArrayList data
Internal storage buffer.
const char * GblStringBuffer_printf(GblStringBuffer *pSelf, const char *pFmt,...)
Assings the value of the formatted string to the given GblStringBuffer, similarly to C's sscanf()
const char * GblStringBuffer_vPrintf(GblStringBuffer *pSelf, const char *pFmt, va_list varArgs)
Equivalent to GblStringBuffer_printf(), except passing additional arguments via a va_list.
GBL_RESULT GblStringBuffer_overwrite(GblStringBuffer *pSelf, size_t index, const char *pString, size_t length)
Ovewrites a prtion of the string starting at index, with pString (length is optional),...
GBL_RESULT GblStringBuffer_grow(GblStringBuffer *pSelf, size_t delta)
Resizes the length of the given GblStringBuffer to be its current length + delta, returning a result ...
GBL_RESULT GblStringBuffer_setChar(const GblStringBuffer *pSelf, size_t index, char value)
Sets the character stored in the given buffer at index to value, returning an error upon failure.
GBL_RESULT GblStringBuffer_construct(GblStringBuffer *pSelf, const char *pString, size_t length, size_t structSize, GblContext *pCtx)
Constructs the given GblStringBuffer struct with any given initial values (or defaults),...
GblBool GblStringBuffer_stack(const GblStringBuffer *pSelf)
Returns GBL_TRUE if the given GblStringBuffer's internal buffer is on the stack and not heap.
GblQuark GblStringBuffer_tryQuark(const GblStringBuffer *pSelf)
Returns the GblQuark corresponding to the given GblStringBuffer only if it already exists.
GBL_RESULT GblStringBuffer_release(GblStringBuffer *pSelf, char **ppStrPtr, size_t *pCapacity)
Takes ownership of the given GblStringBuffer's internal buffer, also returning its capacity and a res...
GBL_RESULT GblStringBuffer_prependPadding(GblStringBuffer *pSelf, char value, size_t count)
Inserts count copies of value at the beginning of the given buffer, returning a result code.
GblQuark GblStringBuffer_quark(const GblStringBuffer *pSelf)
Converts the GblStringBuffer to a GblQuark, possibly interning it, and returning its GblQuark.
GBL_RESULT GblStringBuffer_reserve(GblStringBuffer *pSelf, size_t capacity)
Ensures that there is room for capacity characters within the given GblStringBuffer,...
char * GblStringBuffer_stackBuffer(const GblStringBuffer *pSelf)
Returns a mutable pointer to the extra stack storage region, if present.
GBL_RESULT GblStringBuffer_erase(GblStringBuffer *pSelf, size_t offset, size_t len)
Erases the portion of the string from offset to offset + len, resizing it, and returning a result cod...
GBL_RESULT GblStringBuffer_shrink(GblStringBuffer *pSelf, size_t delta)
Resizes the length of the given GblStringBuffer to be its current length - delta, returning a result ...
GBL_RESULT GblStringBuffer_reverse(GblStringBuffer *pSelf)
Reverses the order of the characters with the given GblStringBuffer, returninga result code.
GBL_RESULT GblStringBuffer_append(GblStringBuffer *pSelf, const char *pStr, size_t len)
Appends pStr (with optional length, len) to the given GblStringBuffer, returning a result code.
GBL_RESULT GblStringBuffer_appendPrintf(GblStringBuffer *pSelf, const char *pFmt,...)
Appends a printf()-style formatted string to the given GblStringBuffer, returning a result code.
GBL_RESULT GblStringBuffer_appendVPrintf(GblStringBuffer *pSelf, const char *pFmt, va_list varArgs)
Equivalent to GblStringBuffer_appendPrintf(), except additional arguments are provided as a va_list.
GBL_RESULT GblStringBuffer_trimEnd(GblStringBuffer *pSelf, char value)
Returns any trailing instances of value from the end of the given GblStringBuffer,...
GBL_RESULT GblStringBuffer_appendDouble(GblStringBuffer *pSelf, double value)
Adds the stringified representation of the double, value, to the end of the given GblStringBuffer,...
GBL_RESULT GblStringBuffer_appendBool(GblStringBuffer *pSelf, GblBool value)
Adds either "true" or "false" to the end of the given GblStringBuffer, depending on value,...
GBL_RESULT GblStringBuffer_lower(GblStringBuffer *pSelf)
Changes the casing of every character within the GblStringBuffer to lowercase, returning a result cod...
GBL_RESULT GblStringBuffer_chomp(GblStringBuffer *pSelf)
Removes any trailing newline characters (\r and \n) from the given GblStringBuffer,...
size_t GblStringBuffer_length(const GblStringBuffer *pSelf)
Returns the string length of the string held by the given GblStringBuffer.
const char * GblStringBuffer_intern(const GblStringBuffer *pSelf)
Returns a pointer to the interned string representation of the buffer, interning it if it hasn't been...
char GblStringBuffer_at(const GblStringBuffer *pSelf, size_t index)
Returns the character stored in the given buffer at index, throwing an error and returning '\0' if in...