libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_string_view.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblStringView structure and related functions
3 * \ingroup strings
4 *
5 * This file contains the GblStringView structure and related
6 * API. A GblStringView is an immutable slice of a string,
7 * containing simply a pointer to the string and its size.
8 * When doing non-mutating operations on strings, such as
9 * searching, this is the preferred string type for the job
10 * with the most detailed API.
11 *
12 * \note
13 * GblStringView also reserves one bit of its length field to
14 * store whether it's NULL-terminated or not. This allows for
15 * more efficient conversions between string_view types and
16 * NULL-terminated C strings, as a copy can be ellided when
17 * the view is already of a NULL-terminated C string.
18 *
19 * \author 2023 Falco Girgis
20 * \copyright MIT License
21 */
22
23#ifndef GIMBAL_STRING_VIEW_H
24#define GIMBAL_STRING_VIEW_H
25
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"
30#include "gimbal_quark.h"
31#include <ctype.h>
32#include <stdint.h>
33#include <limits.h>
34
35//! Constant value used to signify the last position or an invalid position in a GblStringView
36#define GBL_STRING_VIEW_NPOS GBL_NPOS
37//! Convenience shorthand macro for creating a GblStringView from an existing string or substring
38#define GBL_STRV(/*const char* pString, size_t len=0*/...) GblStringView_fromString(__VA_ARGS__)
39//! Convenience macro for converting a GblStringView to a C string, elliding creation of a temporary when the view is already NULL terminated
40#define GBL_STRING_VIEW_CSTR(view) ((view).nullTerminated? (view).pData : GBL_STRING_VIEW_CSTR_ALLOCA((view)))
41//! Convenience macro for creating a NULL-terminated C string from a GblStringView on the stack, using alloca()
42#define GBL_STRING_VIEW_CSTR_ALLOCA(view) GblStringView_toCString(view, (char*)GBL_ALLOCA(view.length + 1), view.length + 1)
43
44#define GBL_SELF_TYPE GblStringView
45
47
48/*! \brief Immutable substring type
49 * \ingroup strings
50 *
51 * Represents an externally owned slice or "view"
52 * into a region of a string, storing its start
53 * address and length. NULL termination is not
54 * required, so a string view cannot be assumed
55 * to be a well-formed standalone C string.
56 */
57typedef struct GblStringView {
58 const char* pData; //!< Start address of the string being viewed
59 size_t nullTerminated : 1; //!< Reserved bit for maintaining whether the string is NULL terminated or not
60#ifdef GBL_64BIT
61 size_t length : 63; //!< Length (bytes) of the substring being viewed
62#elif defined(GBL_32BIT)
63 size_t length : 31;
64#endif
65} GblStringView;
66
67/*! \name Construction
68 * \brief Methods for constructing a new view
69 * \relatesalso GblStringView
70 * @{
71 */
72//! Constructs an empty GblStringView (same as zero initializing one)
74//! Constructs a GblStringView from a(n optionally sized) character array
75GBL_EXPORT GblStringView GblStringView_fromString (const char* pString, size_t length/*=0*/) GBL_NOEXCEPT;
76//! Constructs a GblStringView from an existing GblQuark, or creating an empty view if it's invalid
78//! @}
79
80/*! \name Comparisons
81 * \brief Methods providing string view comparison operators
82 * \relatesalso GblStringView
83 * @{
84 */
85//! Lexicographically compares the given view to \p pString, returning a positive or negative for inequality or 0 if equal
86GBL_EXPORT int GblStringView_compare (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
87//! Lexicographically compares the given view to \p pString, ignoring case, returning a positive or negative for inequality or 0 if equal
88GBL_EXPORT int GblStringView_compareIgnoreCase (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
89//! Returns GBL_TRUE if the given string view equals \p pString or returns GBL_FALSE otherwise
90GBL_EXPORT GblBool GblStringView_equals (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
91//! Returns GBL_TRUE if the given string view equals \p pString (ignoring casing on both operands) or returns GBL_FALSE otherwise
93//! @}
94
95/*! \name Reading
96 * \brief Methods for retrieving characters and substrings
97 * \relatesalso GblStringView
98 * @{
99 */
100//! Returns the character within the given view at \p index, raising an error if it is out-of-range
102//! Returns the first character within the given view, raising an error if the view is empty
104//! Returns the last character within the given view, raising an error if the view is empty
106//! Copies an arbitrary substring within teh view into the external buffer, \p pDst of size \p bytes starting at \p offset
107GBL_EXPORT GBL_RESULT GblStringView_copy (GBL_VSELF, void* pDst, size_t offset, size_t bytes) GBL_NOEXCEPT;
108//! @}
109
110/*! \name Trimming
111 * \brief Methods for creating substrings
112 * \relatesalso GblStringView
113 * @{
114 */
115///! Returns a new GblStringView which has had the first \p length characters chopped off, raising an error upon failure
117//! Returns a new GblStringView which has the last \p length characters chopped off, raising an error upon failure
119//! Returns a new GblStringView which has any terminating newline characters (linux + windows) chopped off
121//! Retruns a new GblStringView as a subview of the given GblStringView, starting at \p offset of size \p length
122GBL_EXPORT GblStringView GblStringView_substr (GBL_VSELF, size_t offset, size_t length) GBL_NOEXCEPT;
123//! @}
124
125/*! \name Searching
126 * \brief Methods for finding, counting, and matching
127 * \relatesalso GblStringView
128 * @{
129 */
130//! Returns GBL_TRUE if the given GblStringView contains the substring, \p pString, otherwise returning GBL_FALSE if not found
131GBL_EXPORT GblBool GblStringView_contains (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
132//! Returns GBL_TRUE if the given GblStringView contains the substring, \p pString, (ignoring case) otherwise returning GBL_FALSE if not found
134//! Returns the number of times the substring, \p pString, appears within the given GblStringView
135GBL_EXPORT size_t GblStringView_count (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
136//! Returns the number of times the substring, \p pString, appears within the given GblStringView, ignoring casing
137GBL_EXPORT size_t GblStringView_countIgnoreCase (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
138//! Returns the starting index of the first occurrence of \p pStr appearing as a substring within the given GblStringView after \p offset
139GBL_EXPORT size_t GblStringView_find (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
140//! Returns the starting index of the first occurrence of \p pStr appearing as a substring within the given GblStringView after \p offset (ignoring casing)
141GBL_EXPORT size_t GblStringView_findIgnoreCase (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
142//! Returns the starting index of the last occurrence of \p pStr appearing as a substring within the given GblStringView before \p offset
143GBL_EXPORT size_t GblStringView_rfind (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
144//! Returns the starting index of the last occurrence of \p pStr appearing as a substring within the given GblStringView before \p offset (ignoring case)
145GBL_EXPORT size_t GblStringView_rfindIgnoreCase (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
146//! Returns GBL_TRUE if the given GblStringView starts with the substring given by \p pString, otherwise returning GBL_FALSE
147GBL_EXPORT GblBool GblStringView_startsWith (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
148//! Returns GBL_TRUE if the given GblStringView starts with the substring given by \p pString (ignoring casing), otherwise returning GBL_FALSE
150//! Returns GBL_TRUE if the given GblStringView ends with the substring given by \p pString, otherwise returning GBL_FALSE
151GBL_EXPORT GblBool GblStringView_endsWith (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
152//! Returns GBL_TRUE if the given GblStringView ends with the substring given by \p pString (ignoring casing), otherwise returning GBL_FALSE
154//! Returns the index of the first occurrence of one of the characters provided within \p pChars, starting at \p offset
155GBL_EXPORT size_t GblStringView_findFirstOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
156//! Returns the index of the last occurrence of one of the characters provided within \p pChars, ending at \p offset
157GBL_EXPORT size_t GblStringView_findLastOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
158//! Returns the index of the first occurrence of a character NOT provided within \p pChars, starting at \p offset
159GBL_EXPORT size_t GblStringView_findFirstNotOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
160//! Returns the index of the last occurrence of a character NOT provided within \p pChars, ending at \p offset
161GBL_EXPORT size_t GblStringView_findLastNotOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
162//! @}
163
164/*! \name Utilities
165 * \brief Methods providing miscellaneous functionality
166 * \relatesalso GblStringView
167 * @{
168 */
169//! Returns GBL_TRUE if the given GblStringView is empty, otherwise returning GBL_FALSE
171//! Returns GBL_TRUE if the given GblStringView contains only whitespace characters (spaces, tabs, newlines)
173//! Returns the GblHash for the given GblStringView, using the default libGimbal hashing algorithm
175//! Creates and returns a GblQuark interned string representation from the given GblStringView
177//! Attempts to return the GblQuark corresponding to the given GblStringView, retruning GBL_QUARK_INVALID if there isn't one
179//! Interns (creates a GblQuark) from the given GblStringView, returning its C string representation
181//! Duplicates the given GblStringView as a heap-allocated NULL-terminated C string and returns it. Don't forget to free it!
183//! Calls libC's `sscanf()` using the given GblStringView as the source buffer
185//! Calls libC's `vsscanf()` using the given GblStringView as the source buffer
186GBL_EXPORT int GblStringView_scanfVa (GBL_VSELF, const char* pFmt, va_list* pVarArgs) GBL_NOEXCEPT;
187//! @}
188
189/*! \name Converting
190 * \brief Methods providing conversion operators from string views
191 * \relatesalso GblStringView
192 * @{
193 */
194//! Converts the given GblStringView to a NULL-terminated C string, copying it to the \p pDest buffer of \p destSize capacity
195GBL_EXPORT char* GblStringView_toCString (GBL_VSELF, char* pDest, size_t destSize) GBL_NOEXCEPT;
196//! Converts the given GblStringView to NIL (returns GBL_TRUE if it's empty or matches "nil")
198//! Converts the given GblStringView to a boolean value, optionally returning whether the conversion succeeded or not
200//! Converts the given GblStringView to a char value, optionally returning whether the conversion succeeded or not
202//! Converts the given GblStringView to a uint8_t value, optionally returning whether the conversion succeeded or not
204//! Converts the given GblStringView to a uint16_t value, optionally returning whether the conversion succeeded or not
206//! Converts the given GblStringView to an int16_t value, optionally returning whether the conversion succeeded or not
208//! Converts the given GblStringView to a uint32_t value, optionally returning whether the conversion succeeded or not
210//! Converts the given GblStringView to an int32_t value, optionally returning whether the conversion succeeded or not
212//! Converts the given GblStringView to a uint64_t value, optionally returning whether the conversion succeeded or not
214//! Converts the given GblStringView to an int64_t value, optionally returning whether the conversion succeeded or not
216//! Converts the given GblStringView to a float value, optionally returning whether the conversion succeeded or not
218//! Converts the given GblStringView to a double value, optionally returning whether the conversion succeeded or not
220//! Converts the given GblStringView to a pointer value, optionally returning whether the conversion succeeded or not
222//! @}
223
225
226//! \cond
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)
233
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)
240
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)
247
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)
254
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)
261
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)
268
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)
275
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)
282
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)
289
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)
296
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)
303
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)
310
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)
317
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)
324
325#define GblStringView_rfind(...)
326 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_rfind, __VA_ARGS__)
327#define GblStringView_rfind_2(view, str)
328 GblStringView_rfind_3(view, str, 0)
329#define GblStringView_rfind_3(view, str, len)
330 GblStringView_rfind_4(view, str, len, GBL_STRING_VIEW_NPOS)
331#define GblStringView_rfind_4(view, str, len, offset)
332 (GblStringView_rfind)(view, str, len, offset)
333
334#define GblStringView_rfindIgnoreCase(...)
335 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_rfindIgnoreCase, __VA_ARGS__)
336#define GblStringView_rfindIgnoreCase_2(view, str)
337 GblStringView_rfindIgnoreCase_3(view, str, 0)
338#define GblStringView_rfindIgnoreCase_3(view, str, len)
339 GblStringView_rfindIgnoreCase_4(view, str, len, GBL_STRING_VIEW_NPOS)
340#define GblStringView_rfindIgnoreCase_4(view, str, len, offset)
341 (GblStringView_rfindIgnoreCase)(view, str, len, offset)
342
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)
349
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)
356
357#define GblStringView_findLastOf(...)
358 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_findLastOf, __VA_ARGS__)
359#define GblStringView_findLastOf_2(view, str)
360 GblStringView_findLastOf_3(view, str, 0)
361#define GblStringView_findLastOf_3(view, str, len)
362 GblStringView_findLastOf_4(view, str, len, GBL_STRING_VIEW_NPOS)
363#define GblStringView_findLastOf_4(view, str, len, offset)
364 (GblStringView_findLastOf)(view, str, len, offset)
365
366#define GblStringView_findLastNotOf(...)
367 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_findLastNotOf, __VA_ARGS__)
368#define GblStringView_findLastNotOf_2(view, str)
369 GblStringView_findLastNotOf_3(view, str, 0)
370#define GblStringView_findLastNotOf_3(view, str, len)
371 GblStringView_findLastNotOf_4(view, str, len, GBL_STRING_VIEW_NPOS)
372#define GblStringView_findLastNotOf_4(view, str, len, offset)
373 (GblStringView_findLastNotOf)(view, str, len, offset)
374
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))
381
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))
388
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))
395
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))
402
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))
409
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))
416
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))
423
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))
430
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))
437
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))
444
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))
451
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))
458//! \endcond
459
460#undef GBL_SELF_TYPE
461
462#endif // GIMBAL_STRING_VIEW_H
#define GBL_NOEXCEPT
#define GBL_ALLOCA
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_VSELF
#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)
#define GBL_NPOS
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.