libGimbal 0.2.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_macro_utils.h"
29#include "gimbal_quark.h"
30#include <ctype.h>
31#include <stdint.h>
32#include <limits.h>
33
34//! Constant value used to signify the last position or an invalid position in a GblStringView
35#define GBL_STRING_VIEW_NPOS GBL_NPOS
36//! Convenience shorthand macro for creating a GblStringView from an existing string or substring
37#define GBL_STRV(/*const char* pString, size_t len=0*/...) GblStringView_fromString(__VA_ARGS__)
38//! Convenience macro for converting a GblStringView to a C string, elliding creation of a temporary when the view is already NULL terminated
39#define GBL_STRV_CSTR(view) ((view).nullTerminated? (view).pData : GBL_STRV_CSTR_ALLOCA((view)))
40//! Convenience macro for creating a NULL-terminated C string from a GblStringView on the stack, using alloca()
41#define GBL_STRV_CSTR_ALLOCA(view) GblStringView_toCString(view, (char*)GBL_ALLOCA(view.length + 1), view.length + 1)
42
43#define GBL_SELF_TYPE GblStringView
44
46
47/*! \brief Immutable substring type
48 * \ingroup strings
49 *
50 * Represents an externally owned slice or "view"
51 * into a region of a string, storing its start
52 * address and length. NULL termination is not
53 * required, so a string view cannot be assumed
54 * to be a well-formed standalone C string.
55 */
56typedef struct GblStringView {
57 const char* pData; //!< Start address of the string being viewed
59 size_t nullTerminated : 1, //!< Whether the string is NULL-terminated or not
60 size_t length : sizeof(size_t) * 8 - 1 //!< Length of the string in bytes
61 )
62} GblStringView;
63
64/*! \name Construction
65 * \brief Methods for constructing a new view
66 * \relatesalso GblStringView
67 * @{
68 */
69//! Constructs an empty GblStringView (same as zero initializing one)
71//! Constructs a GblStringView from a(n optionally sized) character array
72GBL_EXPORT GblStringView GblStringView_fromString (const char* pString, size_t length/*=0*/) GBL_NOEXCEPT;
73//! Constructs a GblStringView from an existing GblQuark, or creating an empty view if it's invalid
75//! @}
76
77/*! \name Comparisons
78 * \brief Methods providing string view comparison operators
79 * \relatesalso GblStringView
80 * @{
81 */
82//! Lexicographically compares the given view to \p pString, returning a positive or negative for inequality or 0 if equal
83GBL_EXPORT int GblStringView_compare (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
84//! Lexicographically compares the given view to \p pString, ignoring case, returning a positive or negative for inequality or 0 if equal
85GBL_EXPORT int GblStringView_compareIgnoreCase (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
86//! Returns GBL_TRUE if the given string view equals \p pString or returns GBL_FALSE otherwise
87GBL_EXPORT GblBool GblStringView_equals (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
88//! Returns GBL_TRUE if the given string view equals \p pString (ignoring casing on both operands) or returns GBL_FALSE otherwise
90//! @}
91
92/*! \name Reading
93 * \brief Methods for retrieving characters and substrings
94 * \relatesalso GblStringView
95 * @{
96 */
97//! Returns the character within the given view at \p index, raising an error if it is out-of-range
99//! Returns the first character within the given view, raising an error if the view is empty
101//! Returns the last character within the given view, raising an error if the view is empty
103//! Copies an arbitrary substring within teh view into the external buffer, \p pDst of size \p bytes starting at \p offset
104GBL_EXPORT GBL_RESULT GblStringView_copy (GBL_VSELF, void* pDst, size_t offset, size_t bytes) GBL_NOEXCEPT;
105//! @}
106
107/*! \name Trimming
108 * \brief Methods for creating substrings
109 * \relatesalso GblStringView
110 * @{
111 */
112///! Returns a new GblStringView which has had the first \p length characters chopped off, raising an error upon failure
114//! Returns a new GblStringView which has the last \p length characters chopped off, raising an error upon failure
116//! Returns a new GblStringView which has any terminating newline characters (linux + windows) chopped off
118//! Retruns a new GblStringView as a subview of the given GblStringView, starting at \p offset of size \p length
119GBL_EXPORT GblStringView GblStringView_substr (GBL_VSELF, size_t offset, size_t length) GBL_NOEXCEPT;
120//! @}
121
122/*! \name Searching
123 * \brief Methods for finding, counting, and matching
124 * \relatesalso GblStringView
125 * @{
126 */
127//! Returns GBL_TRUE if the given GblStringView contains the substring, \p pString, otherwise returning GBL_FALSE if not found
128GBL_EXPORT GblBool GblStringView_contains (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
129//! Returns GBL_TRUE if the given GblStringView contains the substring, \p pString, (ignoring case) otherwise returning GBL_FALSE if not found
131//! Returns the number of times the substring, \p pString, appears within the given GblStringView
132GBL_EXPORT size_t GblStringView_count (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
133//! Returns the number of times the substring, \p pString, appears within the given GblStringView, ignoring casing
134GBL_EXPORT size_t GblStringView_countIgnoreCase (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
135//! Returns the starting index of the first occurrence of \p pStr appearing as a substring within the given GblStringView after \p offset
136GBL_EXPORT size_t GblStringView_find (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
137//! Returns the starting index of the first occurrence of \p pStr appearing as a substring within the given GblStringView after \p offset (ignoring casing)
138GBL_EXPORT size_t GblStringView_findIgnoreCase (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
139//! Returns the starting index of the last occurrence of \p pStr appearing as a substring within the given GblStringView before \p offset
140GBL_EXPORT size_t GblStringView_rfind (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
141//! Returns the starting index of the last occurrence of \p pStr appearing as a substring within the given GblStringView before \p offset (ignoring case)
142GBL_EXPORT size_t GblStringView_rfindIgnoreCase (GBL_VSELF, const char* pStr, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
143//! Returns GBL_TRUE if the given GblStringView starts with the substring given by \p pString, otherwise returning GBL_FALSE
144GBL_EXPORT GblBool GblStringView_startsWith (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
145//! Returns GBL_TRUE if the given GblStringView starts with the substring given by \p pString (ignoring casing), otherwise returning GBL_FALSE
147//! Returns GBL_TRUE if the given GblStringView ends with the substring given by \p pString, otherwise returning GBL_FALSE
148GBL_EXPORT GblBool GblStringView_endsWith (GBL_VSELF, const char* pString, size_t len/*=0*/) GBL_NOEXCEPT;
149//! Returns GBL_TRUE if the given GblStringView ends with the substring given by \p pString (ignoring casing), otherwise returning GBL_FALSE
151//! Returns the index of the first occurrence of one of the characters provided within \p pChars, starting at \p offset
152GBL_EXPORT size_t GblStringView_findFirstOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
153//! Returns the index of the last occurrence of one of the characters provided within \p pChars, ending at \p offset
154GBL_EXPORT size_t GblStringView_findLastOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
155//! Returns the index of the first occurrence of a character NOT provided within \p pChars, starting at \p offset
156GBL_EXPORT size_t GblStringView_findFirstNotOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=0*/) GBL_NOEXCEPT;
157//! Returns the index of the last occurrence of a character NOT provided within \p pChars, ending at \p offset
158GBL_EXPORT size_t GblStringView_findLastNotOf (GBL_VSELF, const char* pChars, size_t len/*=0*/, size_t offset/*=GBL_NPOS*/) GBL_NOEXCEPT;
159//! @}
160
161/*! \name Utilities
162 * \brief Methods providing miscellaneous functionality
163 * \relatesalso GblStringView
164 * @{
165 */
166//! Returns GBL_TRUE if the given GblStringView is empty, otherwise returning GBL_FALSE
168//! Returns GBL_TRUE if the given GblStringView contains only whitespace characters (spaces, tabs, newlines)
170//! Returns the GblHash for the given GblStringView, using the default libGimbal hashing algorithm
172//! Creates and returns a GblQuark interned string representation from the given GblStringView
174//! Attempts to return the GblQuark corresponding to the given GblStringView, retruning GBL_QUARK_INVALID if there isn't one
176//! Interns (creates a GblQuark) from the given GblStringView, returning its C string representation
178//! Duplicates the given GblStringView as a heap-allocated NULL-terminated C string and returns it. Don't forget to free it!
180//! Calls libC's `sscanf()` using the given GblStringView as the source buffer
182//! Calls libC's `vsscanf()` using the given GblStringView as the source buffer
183GBL_EXPORT int GblStringView_scanfVa (GBL_VSELF, const char* pFmt, va_list* pVarArgs) GBL_NOEXCEPT;
184//! @}
185
186/*! \name Converting
187 * \brief Methods providing conversion operators from string views
188 * \relatesalso GblStringView
189 * @{
190 */
191//! Converts the given GblStringView to a NULL-terminated C string, copying it to the \p pDest buffer of \p destSize capacity
192GBL_EXPORT char* GblStringView_toCString (GBL_VSELF, char* pDest, size_t destSize) GBL_NOEXCEPT;
193//! Converts the given GblStringView to NIL (returns GBL_TRUE if it's empty or matches "nil")
195//! Converts the given GblStringView to a boolean value, optionally returning whether the conversion succeeded or not
197//! Converts the given GblStringView to a char value, optionally returning whether the conversion succeeded or not
199//! Converts the given GblStringView to a uint8_t value, optionally returning whether the conversion succeeded or not
201//! Converts the given GblStringView to a uint16_t value, optionally returning whether the conversion succeeded or not
203//! Converts the given GblStringView to an int16_t value, optionally returning whether the conversion succeeded or not
205//! Converts the given GblStringView to a uint32_t value, optionally returning whether the conversion succeeded or not
207//! Converts the given GblStringView to an int32_t value, optionally returning whether the conversion succeeded or not
209//! Converts the given GblStringView to a uint64_t value, optionally returning whether the conversion succeeded or not
211//! Converts the given GblStringView to an int64_t value, optionally returning whether the conversion succeeded or not
213//! Converts the given GblStringView to a float value, optionally returning whether the conversion succeeded or not
215//! Converts the given GblStringView to a double value, optionally returning whether the conversion succeeded or not
217//! Converts the given GblStringView to a pointer value, optionally returning whether the conversion succeeded or not
219//! @}
220
222
223//! \cond
224#define GblStringView_fromString(...)
225 GblStringView_fromStringDefault_(__VA_ARGS__)
226#define GblStringView_fromStringDefault_(...)
227 GblStringView_fromStringDefault__(__VA_ARGS__, 0)
228#define GblStringView_fromStringDefault__(string, length, ...)
229 (GblStringView_fromString)(string, length)
230
231#define GblStringView_compare(...)
232 GblStringView_compareDefault_(__VA_ARGS__)
233#define GblStringView_compareDefault_(...)
234 GblStringView_compareDefault__(__VA_ARGS__, 0)
235#define GblStringView_compareDefault__(view, string, length, ...)
236 (GblStringView_compare)(view, string, length)
237
238#define GblStringView_compareIgnoreCase(...)
239 GblStringView_compareIgnoreCaseDefault_(__VA_ARGS__)
240#define GblStringView_compareIgnoreCaseDefault_(...)
241 GblStringView_compareIgnoreCaseDefault__(__VA_ARGS__, 0)
242#define GblStringView_compareIgnoreCaseDefault__(view, string, length, ...)
243 (GblStringView_compareIgnoreCase)(view, string, length)
244
245#define GblStringView_equals(...)
246 GblStringView_equalsDefault_(__VA_ARGS__)
247#define GblStringView_equalsDefault_(...)
248 GblStringView_equalsDefault__(__VA_ARGS__, 0)
249#define GblStringView_equalsDefault__(view, string, length, ...)
250 (GblStringView_equals)(view, string, length)
251
252#define GblStringView_equalsIgnoreCase(...)
253 GblStringView_equalsIgnoreCaseDefault_(__VA_ARGS__)
254#define GblStringView_equalsIgnoreCaseDefault_(...)
255 GblStringView_equalsIgnoreCaseDefault__(__VA_ARGS__, 0)
256#define GblStringView_equalsIgnoreCaseDefault__(view, string, length, ...)
257 (GblStringView_equalsIgnoreCase)(view, string, length)
258
259#define GblStringView_contains(...)
260 GblStringView_containsDefault_(__VA_ARGS__)
261#define GblStringView_containsDefault_(...)
262 GblStringView_containsDefault__(__VA_ARGS__, 0)
263#define GblStringView_containsDefault__(view, string, length, ...)
264 (GblStringView_contains)(view, string, length)
265
266#define GblStringView_containsIgnoreCase(...)
267 GblStringView_containsIgnoreCaseDefault_(__VA_ARGS__)
268#define GblStringView_containsIgnoreCaseDefault_(...)
269 GblStringView_containsIgnoreCaseDefault__(__VA_ARGS__, 0)
270#define GblStringView_containsIgnoreCaseDefault__(view, string, length, ...)
271 (GblStringView_containsIgnoreCase)(view, string, length)
272
273#define GblStringView_count(...)
274 GblStringView_countDefault_(__VA_ARGS__)
275#define GblStringView_countDefault_(...)
276 GblStringView_countDefault__(__VA_ARGS__, 0)
277#define GblStringView_countDefault__(view, string, length, ...)
278 (GblStringView_count)(view, string, length)
279
280#define GblStringView_startsWith(...)
281 GblStringView_startsWithDefault_(__VA_ARGS__)
282#define GblStringView_startsWithDefault_(...)
283 GblStringView_startsWithDefault__(__VA_ARGS__, 0)
284#define GblStringView_startsWithDefault__(view, string, length, ...)
285 (GblStringView_startsWith)(view, string, length)
286
287#define GblStringView_startsWithIgnoreCase(...)
288 GblStringView_startsWithIgnoreCaseDefault_(__VA_ARGS__)
289#define GblStringView_startsWithIgnoreCaseDefault_(...)
290 GblStringView_startsWithIgnoreCaseDefault__(__VA_ARGS__, 0)
291#define GblStringView_startsWithIgnoreCaseDefault__(view, string, length, ...)
292 (GblStringView_startsWithIgnoreCase)(view, string, length)
293
294#define GblStringView_endsWith(...)
295 GblStringView_endsWithDefault_(__VA_ARGS__)
296#define GblStringView_endsWithDefault_(...)
297 GblStringView_endsWithDefault__(__VA_ARGS__, 0)
298#define GblStringView_endsWithDefault__(view, string, length, ...)
299 (GblStringView_endsWith)(view, string, length)
300
301#define GblStringView_endsWithIgnoreCase(...)
302 GblStringView_endsWithIgnoreCaseDefault_(__VA_ARGS__)
303#define GblStringView_endsWithIgnoreCaseDefault_(...)
304 GblStringView_endsWithIgnoreCaseDefault__(__VA_ARGS__, 0)
305#define GblStringView_endsWithIgnoreCaseDefault__(view, string, length, ...)
306 (GblStringView_endsWithIgnoreCase)(view, string, length)
307
308#define GblStringView_find(...)
309 GblStringView_findDefault_(__VA_ARGS__)
310#define GblStringView_findDefault_(...)
311 GblStringView_findDefault__(__VA_ARGS__, 0, 0)
312#define GblStringView_findDefault__(view, string, length, offset, ...)
313 (GblStringView_find)(view, string, length, offset)
314
315#define GblStringView_findIgnoreCase(...)
316 GblStringView_findIgnoreCaseDefault_(__VA_ARGS__)
317#define GblStringView_findIgnoreCaseDefault_(...)
318 GblStringView_findIgnoreCaseDefault__(__VA_ARGS__, 0, 0)
319#define GblStringView_findIgnoreCaseDefault__(view, string, length, offset, ...)
320 (GblStringView_findIgnoreCase)(view, string, length, offset)
321
322#define GblStringView_rfind(...)
323 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_rfind, __VA_ARGS__)
324#define GblStringView_rfind_2(view, str)
325 GblStringView_rfind_3(view, str, 0)
326#define GblStringView_rfind_3(view, str, len)
327 GblStringView_rfind_4(view, str, len, GBL_STRING_VIEW_NPOS)
328#define GblStringView_rfind_4(view, str, len, offset)
329 (GblStringView_rfind)(view, str, len, offset)
330
331#define GblStringView_rfindIgnoreCase(...)
332 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_rfindIgnoreCase, __VA_ARGS__)
333#define GblStringView_rfindIgnoreCase_2(view, str)
334 GblStringView_rfindIgnoreCase_3(view, str, 0)
335#define GblStringView_rfindIgnoreCase_3(view, str, len)
336 GblStringView_rfindIgnoreCase_4(view, str, len, GBL_STRING_VIEW_NPOS)
337#define GblStringView_rfindIgnoreCase_4(view, str, len, offset)
338 (GblStringView_rfindIgnoreCase)(view, str, len, offset)
339
340#define GblStringView_findFirstOf(...)
341 GblStringView_findFirstOfDefault_(__VA_ARGS__)
342#define GblStringView_findFirstOfDefault_(...)
343 GblStringView_findFirstOfDefault__(__VA_ARGS__, 0, 0)
344#define GblStringView_findFirstOfDefault__(view, string, length, offset, ...)
345 (GblStringView_findFirstOf)(view, string, length, offset)
346
347#define GblStringView_findFirstNotOf(...)
348 GblStringView_findFirstNotOfDefault_(__VA_ARGS__)
349#define GblStringView_findFirstNotOfDefault_(...)
350 GblStringView_findFirstNotOfDefault__(__VA_ARGS__, 0, 0)
351#define GblStringView_findFirstNotOfDefault__(view, string, length, offset, ...)
352 (GblStringView_findFirstNotOf)(view, string, length, offset)
353
354#define GblStringView_findLastOf(...)
355 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_findLastOf, __VA_ARGS__)
356#define GblStringView_findLastOf_2(view, str)
357 GblStringView_findLastOf_3(view, str, 0)
358#define GblStringView_findLastOf_3(view, str, len)
359 GblStringView_findLastOf_4(view, str, len, GBL_STRING_VIEW_NPOS)
360#define GblStringView_findLastOf_4(view, str, len, offset)
361 (GblStringView_findLastOf)(view, str, len, offset)
362
363#define GblStringView_findLastNotOf(...)
364 GBL_VA_OVERLOAD_CALL_ARGC(GblStringView_findLastNotOf, __VA_ARGS__)
365#define GblStringView_findLastNotOf_2(view, str)
366 GblStringView_findLastNotOf_3(view, str, 0)
367#define GblStringView_findLastNotOf_3(view, str, len)
368 GblStringView_findLastNotOf_4(view, str, len, GBL_STRING_VIEW_NPOS)
369#define GblStringView_findLastNotOf_4(view, str, len, offset)
370 (GblStringView_findLastNotOf)(view, str, len, offset)
371
372#define GblStringView_toBool(...)
373 GblStringView_toBoolDefault_(__VA_ARGS__)
374#define GblStringView_toBoolDefault_(...)
375 GblStringView_toBoolDefault__(__VA_ARGS__, NULL)
376#define GblStringView_toBoolDefault__(self, success, ...)
377 ((GblStringView_toBool)(self, success))
378
379#define GblStringView_toChar(...)
380 GblStringView_toCharDefault_(__VA_ARGS__)
381#define GblStringView_toCharDefault_(...)
382 GblStringView_toCharDefault__(__VA_ARGS__, NULL)
383#define GblStringView_toCharDefault__(self, success, ...)
384 ((GblStringView_toChar)(self, success))
385
386#define GblStringView_toUint8(...)
387 GblStringView_toUint8Default_(__VA_ARGS__)
388#define GblStringView_toUint8Default_(...)
389 GblStringView_toUint8Default__(__VA_ARGS__, NULL)
390#define GblStringView_toUint8Default__(self, success, ...)
391 ((GblStringView_toUint8)(self, success))
392
393#define GblStringView_toUint16(...)
394 GblStringView_toUint16Default_(__VA_ARGS__)
395#define GblStringView_toUint16Default_(...)
396 GblStringView_toUint16Default__(__VA_ARGS__, NULL)
397#define GblStringView_toUint16Default__(self, success, ...)
398 ((GblStringView_toUint16)(self, success))
399
400#define GblStringView_toInt16(...)
401 GblStringView_toInt16Default_(__VA_ARGS__)
402#define GblStringView_toInt16Default_(...)
403 GblStringView_toInt16Default__(__VA_ARGS__, NULL)
404#define GblStringView_toInt16Default__(self, success, ...)
405 ((GblStringView_toInt16)(self, success))
406
407#define GblStringView_toUint32(...)
408 GblStringView_toUint32Default_(__VA_ARGS__)
409#define GblStringView_toUint32Default_(...)
410 GblStringView_toUint32Default__(__VA_ARGS__, NULL)
411#define GblStringView_toUint32Default__(self, success, ...)
412 ((GblStringView_toUint32)(self, success))
413
414#define GblStringView_toInt32(...)
415 GblStringView_toInt32Default_(__VA_ARGS__)
416#define GblStringView_toInt32Default_(...)
417 GblStringView_toInt32Default__(__VA_ARGS__, NULL)
418#define GblStringView_toInt32Default__(self, success, ...)
419 ((GblStringView_toInt32)(self, success))
420
421#define GblStringView_toUint64(...)
422 GblStringView_toUint64Default_(__VA_ARGS__)
423#define GblStringView_toUint64Default_(...)
424 GblStringView_toUint64Default__(__VA_ARGS__, NULL)
425#define GblStringView_toUint64Default__(self, success, ...)
426 ((GblStringView_toUint64)(self, success))
427
428#define GblStringView_toInt64(...)
429 GblStringView_toInt64Default_(__VA_ARGS__)
430#define GblStringView_toInt64Default_(...)
431 GblStringView_toInt64Default__(__VA_ARGS__, NULL)
432#define GblStringView_toInt64Default__(self, success, ...)
433 ((GblStringView_toInt64)(self, success))
434
435#define GblStringView_toFloat(...)
436 GblStringView_toFloatDefault_(__VA_ARGS__)
437#define GblStringView_toFloatDefault_(...)
438 GblStringView_toFloatDefault__(__VA_ARGS__, NULL)
439#define GblStringView_toFloatDefault__(self, success, ...)
440 ((GblStringView_toFloat)(self, success))
441
442#define GblStringView_toDouble(...)
443 GblStringView_toDoubleDefault_(__VA_ARGS__)
444#define GblStringView_toDoubleDefault_(...)
445 GblStringView_toDoubleDefault__(__VA_ARGS__, NULL)
446#define GblStringView_toDoubleDefault__(self, success, ...)
447 ((GblStringView_toDouble)(self, success))
448
449#define GblStringView_toPointer(...)
450 GblStringView_toPointerDefault_(__VA_ARGS__)
451#define GblStringView_toPointerDefault_(...)
452 GblStringView_toPointerDefault__(__VA_ARGS__, NULL)
453#define GblStringView_toPointerDefault__(self, success, ...)
454 ((GblStringView_toPointer)(self, success))
455//! \endcond
456
457#undef GBL_SELF_TYPE
458
459#endif // GIMBAL_STRING_VIEW_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_VSELF
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
#define GBL_BIT_FIELDS(...)
Used to declare an endian-independent group of bitfields.
#define GBL_ALLOCA
#define GBL_STRING_VIEW_NPOS
Constant value used to signify the last position or an invalid position in a GblStringView.
#define GBL_STRV_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.
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 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.