2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#ifndef GIMBAL_STRING_VIEW_H
24#define GIMBAL_STRING_VIEW_H
26#include "../core/gimbal_ctx.h"
27#include "../algorithms/gimbal_hash.h"
28#include "../preprocessor/gimbal_compiler.h"
29#include "../preprocessor/gimbal_macro_composition.h"
38#define GBL_STRV(...) GblStringView_fromString
(__VA_ARGS__)
42#define GBL_STRING_VIEW_CSTR_ALLOCA(view) GblStringView_toCString(view, (char*)GBL_ALLOCA(view.length + 1
), view.length + 1
)
44#define GBL_SELF_TYPE GblStringView
49
50
51
52
53
54
55
56
62#elif defined(GBL_32BIT)
68
69
70
71
81
82
83
84
96
97
98
99
111
112
113
114
126
127
128
129
165
166
167
168
190
191
192
193
227#define GblStringView_fromString(...)
228 GblStringView_fromStringDefault_
(__VA_ARGS__)
229#define GblStringView_fromStringDefault_(...)
230 GblStringView_fromStringDefault__
(__VA_ARGS__, 0
)
231#define GblStringView_fromStringDefault__(string, length, ...)
232 (GblStringView_fromString
)(string, length)
234#define GblStringView_compare(...)
235 GblStringView_compareDefault_
(__VA_ARGS__)
236#define GblStringView_compareDefault_(...)
237 GblStringView_compareDefault__
(__VA_ARGS__, 0
)
238#define GblStringView_compareDefault__(view, string, length, ...)
239 (GblStringView_compare
)(view, string, length)
241#define GblStringView_compareIgnoreCase(...)
242 GblStringView_compareIgnoreCaseDefault_
(__VA_ARGS__)
243#define GblStringView_compareIgnoreCaseDefault_(...)
244 GblStringView_compareIgnoreCaseDefault__
(__VA_ARGS__, 0
)
245#define GblStringView_compareIgnoreCaseDefault__(view, string, length, ...)
246 (GblStringView_compareIgnoreCase
)(view, string, length)
248#define GblStringView_equals(...)
249 GblStringView_equalsDefault_
(__VA_ARGS__)
250#define GblStringView_equalsDefault_(...)
251 GblStringView_equalsDefault__
(__VA_ARGS__, 0
)
252#define GblStringView_equalsDefault__(view, string, length, ...)
253 (GblStringView_equals
)(view, string, length)
255#define GblStringView_equalsIgnoreCase(...)
256 GblStringView_equalsIgnoreCaseDefault_
(__VA_ARGS__)
257#define GblStringView_equalsIgnoreCaseDefault_(...)
258 GblStringView_equalsIgnoreCaseDefault__
(__VA_ARGS__, 0
)
259#define GblStringView_equalsIgnoreCaseDefault__(view, string, length, ...)
260 (GblStringView_equalsIgnoreCase
)(view, string, length)
262#define GblStringView_contains(...)
263 GblStringView_containsDefault_
(__VA_ARGS__)
264#define GblStringView_containsDefault_(...)
265 GblStringView_containsDefault__
(__VA_ARGS__, 0
)
266#define GblStringView_containsDefault__(view, string, length, ...)
267 (GblStringView_contains
)(view, string, length)
269#define GblStringView_containsIgnoreCase(...)
270 GblStringView_containsIgnoreCaseDefault_
(__VA_ARGS__)
271#define GblStringView_containsIgnoreCaseDefault_(...)
272 GblStringView_containsIgnoreCaseDefault__
(__VA_ARGS__, 0
)
273#define GblStringView_containsIgnoreCaseDefault__(view, string, length, ...)
274 (GblStringView_containsIgnoreCase
)(view, string, length)
276#define GblStringView_count(...)
277 GblStringView_countDefault_
(__VA_ARGS__)
278#define GblStringView_countDefault_(...)
279 GblStringView_countDefault__
(__VA_ARGS__, 0
)
280#define GblStringView_countDefault__(view, string, length, ...)
281 (GblStringView_count
)(view, string, length)
283#define GblStringView_startsWith(...)
284 GblStringView_startsWithDefault_
(__VA_ARGS__)
285#define GblStringView_startsWithDefault_(...)
286 GblStringView_startsWithDefault__
(__VA_ARGS__, 0
)
287#define GblStringView_startsWithDefault__(view, string, length, ...)
288 (GblStringView_startsWith
)(view, string, length)
290#define GblStringView_startsWithIgnoreCase(...)
291 GblStringView_startsWithIgnoreCaseDefault_
(__VA_ARGS__)
292#define GblStringView_startsWithIgnoreCaseDefault_(...)
293 GblStringView_startsWithIgnoreCaseDefault__
(__VA_ARGS__, 0
)
294#define GblStringView_startsWithIgnoreCaseDefault__(view, string, length, ...)
295 (GblStringView_startsWithIgnoreCase
)(view, string, length)
297#define GblStringView_endsWith(...)
298 GblStringView_endsWithDefault_
(__VA_ARGS__)
299#define GblStringView_endsWithDefault_(...)
300 GblStringView_endsWithDefault__
(__VA_ARGS__, 0
)
301#define GblStringView_endsWithDefault__(view, string, length, ...)
302 (GblStringView_endsWith
)(view, string, length)
304#define GblStringView_endsWithIgnoreCase(...)
305 GblStringView_endsWithIgnoreCaseDefault_
(__VA_ARGS__)
306#define GblStringView_endsWithIgnoreCaseDefault_(...)
307 GblStringView_endsWithIgnoreCaseDefault__
(__VA_ARGS__, 0
)
308#define GblStringView_endsWithIgnoreCaseDefault__(view, string, length, ...)
309 (GblStringView_endsWithIgnoreCase
)(view, string, length)
311#define GblStringView_find(...)
312 GblStringView_findDefault_
(__VA_ARGS__)
313#define GblStringView_findDefault_(...)
314 GblStringView_findDefault__
(__VA_ARGS__, 0
, 0
)
315#define GblStringView_findDefault__(view, string, length, offset, ...)
316 (GblStringView_find
)(view, string, length, offset)
318#define GblStringView_findIgnoreCase(...)
319 GblStringView_findIgnoreCaseDefault_
(__VA_ARGS__)
320#define GblStringView_findIgnoreCaseDefault_(...)
321 GblStringView_findIgnoreCaseDefault__
(__VA_ARGS__, 0
, 0
)
322#define GblStringView_findIgnoreCaseDefault__(view, string, length, offset, ...)
323 (GblStringView_findIgnoreCase
)(view, string, length, offset)
325#define GblStringView_rfind(...)
327#define GblStringView_rfind_2(view, str)
328 GblStringView_rfind_3
(view, str, 0
)
329#define GblStringView_rfind_3(view, str, len)
331#define GblStringView_rfind_4(view, str, len, offset)
332 (GblStringView_rfind
)(view, str, len, offset)
334#define GblStringView_rfindIgnoreCase(...)
336#define GblStringView_rfindIgnoreCase_2(view, str)
337 GblStringView_rfindIgnoreCase_3
(view, str, 0
)
338#define GblStringView_rfindIgnoreCase_3(view, str, len)
340#define GblStringView_rfindIgnoreCase_4(view, str, len, offset)
341 (GblStringView_rfindIgnoreCase
)(view, str, len, offset)
343#define GblStringView_findFirstOf(...)
344 GblStringView_findFirstOfDefault_
(__VA_ARGS__)
345#define GblStringView_findFirstOfDefault_(...)
346 GblStringView_findFirstOfDefault__
(__VA_ARGS__, 0
, 0
)
347#define GblStringView_findFirstOfDefault__(view, string, length, offset, ...)
348 (GblStringView_findFirstOf
)(view, string, length, offset)
350#define GblStringView_findFirstNotOf(...)
351 GblStringView_findFirstNotOfDefault_
(__VA_ARGS__)
352#define GblStringView_findFirstNotOfDefault_(...)
353 GblStringView_findFirstNotOfDefault__
(__VA_ARGS__, 0
, 0
)
354#define GblStringView_findFirstNotOfDefault__(view, string, length, offset, ...)
355 (GblStringView_findFirstNotOf
)(view, string, length, offset)
357#define GblStringView_findLastOf(...)
359#define GblStringView_findLastOf_2(view, str)
360 GblStringView_findLastOf_3
(view, str, 0
)
361#define GblStringView_findLastOf_3(view, str, len)
363#define GblStringView_findLastOf_4(view, str, len, offset)
364 (GblStringView_findLastOf
)(view, str, len, offset)
366#define GblStringView_findLastNotOf(...)
368#define GblStringView_findLastNotOf_2(view, str)
369 GblStringView_findLastNotOf_3
(view, str, 0
)
370#define GblStringView_findLastNotOf_3(view, str, len)
372#define GblStringView_findLastNotOf_4(view, str, len, offset)
373 (GblStringView_findLastNotOf
)(view, str, len, offset)
375#define GblStringView_toBool(...)
376 GblStringView_toBoolDefault_
(__VA_ARGS__)
377#define GblStringView_toBoolDefault_(...)
378 GblStringView_toBoolDefault__
(__VA_ARGS__, NULL
)
379#define GblStringView_toBoolDefault__(self, success, ...)
380 ((GblStringView_toBool
)(self, success))
382#define GblStringView_toChar(...)
383 GblStringView_toCharDefault_
(__VA_ARGS__)
384#define GblStringView_toCharDefault_(...)
385 GblStringView_toCharDefault__
(__VA_ARGS__, NULL
)
386#define GblStringView_toCharDefault__(self, success, ...)
387 ((GblStringView_toChar
)(self, success))
389#define GblStringView_toUint8(...)
390 GblStringView_toUint8Default_
(__VA_ARGS__)
391#define GblStringView_toUint8Default_(...)
392 GblStringView_toUint8Default__
(__VA_ARGS__, NULL
)
393#define GblStringView_toUint8Default__(self, success, ...)
394 ((GblStringView_toUint8
)(self, success))
396#define GblStringView_toUint16(...)
397 GblStringView_toUint16Default_
(__VA_ARGS__)
398#define GblStringView_toUint16Default_(...)
399 GblStringView_toUint16Default__
(__VA_ARGS__, NULL
)
400#define GblStringView_toUint16Default__(self, success, ...)
401 ((GblStringView_toUint16
)(self, success))
403#define GblStringView_toInt16(...)
404 GblStringView_toInt16Default_
(__VA_ARGS__)
405#define GblStringView_toInt16Default_(...)
406 GblStringView_toInt16Default__
(__VA_ARGS__, NULL
)
407#define GblStringView_toInt16Default__(self, success, ...)
408 ((GblStringView_toInt16
)(self, success))
410#define GblStringView_toUint32(...)
411 GblStringView_toUint32Default_
(__VA_ARGS__)
412#define GblStringView_toUint32Default_(...)
413 GblStringView_toUint32Default__
(__VA_ARGS__, NULL
)
414#define GblStringView_toUint32Default__(self, success, ...)
415 ((GblStringView_toUint32
)(self, success))
417#define GblStringView_toInt32(...)
418 GblStringView_toInt32Default_
(__VA_ARGS__)
419#define GblStringView_toInt32Default_(...)
420 GblStringView_toInt32Default__
(__VA_ARGS__, NULL
)
421#define GblStringView_toInt32Default__(self, success, ...)
422 ((GblStringView_toInt32
)(self, success))
424#define GblStringView_toUint64(...)
425 GblStringView_toUint64Default_
(__VA_ARGS__)
426#define GblStringView_toUint64Default_(...)
427 GblStringView_toUint64Default__
(__VA_ARGS__, NULL
)
428#define GblStringView_toUint64Default__(self, success, ...)
429 ((GblStringView_toUint64
)(self, success))
431#define GblStringView_toInt64(...)
432 GblStringView_toInt64Default_
(__VA_ARGS__)
433#define GblStringView_toInt64Default_(...)
434 GblStringView_toInt64Default__
(__VA_ARGS__, NULL
)
435#define GblStringView_toInt64Default__(self, success, ...)
436 ((GblStringView_toInt64
)(self, success))
438#define GblStringView_toFloat(...)
439 GblStringView_toFloatDefault_
(__VA_ARGS__)
440#define GblStringView_toFloatDefault_(...)
441 GblStringView_toFloatDefault__
(__VA_ARGS__, NULL
)
442#define GblStringView_toFloatDefault__(self, success, ...)
443 ((GblStringView_toFloat
)(self, success))
445#define GblStringView_toDouble(...)
446 GblStringView_toDoubleDefault_
(__VA_ARGS__)
447#define GblStringView_toDoubleDefault_(...)
448 GblStringView_toDoubleDefault__
(__VA_ARGS__, NULL
)
449#define GblStringView_toDoubleDefault__(self, success, ...)
450 ((GblStringView_toDouble
)(self, success))
452#define GblStringView_toPointer(...)
453 GblStringView_toPointerDefault_
(__VA_ARGS__)
454#define GblStringView_toPointerDefault_(...)
455 GblStringView_toPointerDefault__
(__VA_ARGS__, NULL
)
456#define GblStringView_toPointerDefault__(self, success, ...)
457 ((GblStringView_toPointer
)(self, success))
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
#define GBL_STRING_VIEW_NPOS
Constant value used to signify the last position or an invalid position in a GblStringView.
#define GBL_STRING_VIEW_CSTR_ALLOCA(view)
Convenience macro for creating a NULL-terminated C string from a GblStringView on the stack,...
uint32_t GblHash
Type representing a calculated numeric hash across the codebase.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uintptr_t GblQuark
Uniquely identifiable interned string type.
Immutable substring type.
size_t GblStringView_findIgnoreCase(GblStringView self, const char *pStr, size_t len, size_t offset)
Returns the starting index of the first occurrence of pStr appearing as a substring within the given ...
int32_t GblStringView_toInt32(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to an int32_t value, optionally returning whether the conversion suc...
char GblStringView_at(GblStringView self, size_t index)
Returns the character within the given view at index, raising an error if it is out-of-range.
GblBool GblStringView_endsWithIgnoreCase(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView ends with the substring given by pString (ignoring casing...
GblStringView GblStringView_fromString(const char *pString, size_t length)
Constructs a GblStringView from a(n optionally sized) character array.
GblBool GblStringView_toNil(GblStringView self)
Converts the given GblStringView to NIL (returns GBL_TRUE if it's empty or matches "nil")
GblBool GblStringView_blank(GblStringView self)
Returns GBL_TRUE if the given GblStringView contains only whitespace characters (spaces,...
GBL_RESULT GblStringView_copy(GblStringView self, void *pDst, size_t offset, size_t bytes)
Copies an arbitrary substring within teh view into the external buffer, pDst of size bytes starting a...
size_t GblStringView_rfindIgnoreCase(GblStringView self, const char *pStr, size_t len, size_t offset)
Returns the starting index of the last occurrence of pStr appearing as a substring within the given G...
GblQuark GblStringView_tryQuark(GblStringView self)
Attempts to return the GblQuark corresponding to the given GblStringView, retruning GBL_QUARK_INVALID...
void * GblStringView_toPointer(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a pointer value, optionally returning whether the conversion succ...
GblStringView GblStringView_fromQuark(GblQuark quark)
Constructs a GblStringView from an existing GblQuark, or creating an empty view if it's invalid.
GblBool GblStringView_toBool(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a boolean value, optionally returning whether the conversion succ...
GblBool GblStringView_containsIgnoreCase(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView contains the substring, pString, (ignoring case) otherwis...
int GblStringView_compare(GblStringView self, const char *pString, size_t len)
Lexicographically compares the given view to pString, returning a positive or negative for inequality...
GblQuark GblStringView_quark(GblStringView self)
Creates and returns a GblQuark interned string representation from the given GblStringView.
int16_t GblStringView_toInt16(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to an int16_t value, optionally returning whether the conversion suc...
size_t GblStringView_rfind(GblStringView self, const char *pStr, size_t len, size_t offset)
Returns the starting index of the last occurrence of pStr appearing as a substring within the given G...
int64_t GblStringView_toInt64(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to an int64_t value, optionally returning whether the conversion suc...
GblBool GblStringView_endsWith(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView ends with the substring given by pString,...
float GblStringView_toFloat(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a float value, optionally returning whether the conversion succee...
GblBool GblStringView_empty(GblStringView self)
Returns GBL_TRUE if the given GblStringView is empty, otherwise returning GBL_FALSE.
size_t nullTerminated
Reserved bit for maintaining whether the string is NULL terminated or not.
GblHash GblStringView_hash(GblStringView self)
Returns the GblHash for the given GblStringView, using the default libGimbal hashing algorithm.
uint32_t GblStringView_toUint32(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a uint32_t value, optionally returning whether the conversion suc...
size_t GblStringView_countIgnoreCase(GblStringView self, const char *pString, size_t len)
Returns the number of times the substring, pString, appears within the given GblStringView,...
GblBool GblStringView_contains(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView contains the substring, pString, otherwise returning GBL_...
GblBool GblStringView_startsWithIgnoreCase(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView starts with the substring given by pString (ignoring casi...
GblBool GblStringView_equals(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given string view equals pString or returns GBL_FALSE otherwise.
GblStringView GblStringView_substr(GblStringView self, size_t offset, size_t length)
Retruns a new GblStringView as a subview of the given GblStringView, starting at offset of size lengt...
const char * GblStringView_intern(GblStringView self)
Interns (creates a GblQuark) from the given GblStringView, returning its C string representation.
char * GblStringView_toCString(GblStringView self, char *pDest, size_t destSize)
Converts the given GblStringView to a NULL-terminated C string, copying it to the pDest buffer of des...
GblStringView GblStringView_chomp(GblStringView self)
Returns a new GblStringView which has any terminating newline characters (linux + windows) chopped of...
char * GblStringView_strdup(GblStringView self)
Duplicates the given GblStringView as a heap-allocated NULL-terminated C string and returns it....
double GblStringView_toDouble(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a double value, optionally returning whether the conversion succe...
const char * pData
Start address of the string being viewed.
GblStringView GblStringView_removeSuffix(GblStringView self, size_t length)
Returns a new GblStringView which has the last length characters chopped off, raising an error upon f...
size_t GblStringView_findLastNotOf(GblStringView self, const char *pChars, size_t len, size_t offset)
Returns the index of the last occurrence of a character NOT provided within pChars,...
GblStringView GblStringView_fromEmpty(void)
Constructs an empty GblStringView (same as zero initializing one)
size_t GblStringView_find(GblStringView self, const char *pStr, size_t len, size_t offset)
Returns the starting index of the first occurrence of pStr appearing as a substring within the given ...
uint8_t GblStringView_toUint8(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a uint8_t value, optionally returning whether the conversion succ...
size_t GblStringView_findFirstNotOf(GblStringView self, const char *pChars, size_t len, size_t offset)
Returns the index of the first occurrence of a character NOT provided within pChars,...
int GblStringView_compareIgnoreCase(GblStringView self, const char *pString, size_t len)
Lexicographically compares the given view to pString, ignoring case, returning a positive or negative...
size_t GblStringView_count(GblStringView self, const char *pString, size_t len)
Returns the number of times the substring, pString, appears within the given GblStringView.
char GblStringView_last(GblStringView self)
Returns the last character within the given view, raising an error if the view is empty.
int GblStringView_scanf(GblStringView self, const char *pFmt,...)
Calls libC's sscanf() using the given GblStringView as the source buffer.
uint16_t GblStringView_toUint16(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a uint16_t value, optionally returning whether the conversion suc...
GblStringView GblStringView_removePrefix(GblStringView self, size_t length)
! Returns a new GblStringView which has had the first length characters chopped off,...
char GblStringView_toChar(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a char value, optionally returning whether the conversion succeed...
GblBool GblStringView_equalsIgnoreCase(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given string view equals pString (ignoring casing on both operands) or return...
GblBool GblStringView_startsWith(GblStringView self, const char *pString, size_t len)
Returns GBL_TRUE if the given GblStringView starts with the substring given by pString,...
uint64_t GblStringView_toUint64(GblStringView self, GblBool *pSuccess)
Converts the given GblStringView to a uint64_t value, optionally returning whether the conversion suc...
size_t GblStringView_findLastOf(GblStringView self, const char *pChars, size_t len, size_t offset)
Returns the index of the last occurrence of one of the characters provided within pChars,...
size_t length
Length (bytes) of the substring being viewed.
size_t GblStringView_findFirstOf(GblStringView self, const char *pChars, size_t len, size_t offset)
Returns the index of the first occurrence of one of the characters provided within pChars,...
int GblStringView_scanfVa(GblStringView self, const char *pFmt, va_list *pVarArgs)
Calls libC's vsscanf() using the given GblStringView as the source buffer.
char GblStringView_first(GblStringView self)
Returns the first character within the given view, raising an error if the view is empty.