include/Zycore/String.h(3)
π NAME π
include/Zycore/String.h β bestie, it's the Zycore string situation, and it's giving everything. π
So this is include/Zycore/String.h(3), from the Library Functions Manual. It's a header for a whole string type in Zycore, and we're breaking it down section by section. More parts are coming, so don't go anywhere. π
β¨ SYNOPSIS β¨
Okay first, the includes. You need all of these, no cap:
#include <Zycore/Allocator.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#include <Zycore/Vector.h>
π§Έ Classes
struct ZyanString_
struct ZyanStringView_
π Macros
These are the defines, exactly as they live:
#define ZYAN_STRING_MIN_CAPACITY 32
#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2
#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 4
#define ZYAN_STRING_HAS_FIXED_CAPACITY 0x01
#define ZYAN_STRING_INITIALIZER
#define ZYAN_STRING_TO_VIEW(string)
#define ZYAN_DEFINE_STRING_VIEW(string)
π¦ Typedefs
typedef ZyanU8 ZyanStringFlags
typedef struct ZyanString_ ZyanString
typedef struct ZyanStringView_ ZyanStringView
π Functions
Miss girl, this list is long, and every single one is here. Read it and weep (affectionately):
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit (ZyanString
*string, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringInitEx (ZyanString *string, ZyanUSize
capacity, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8
shrink_threshold)
ZYCORE_EXPORT ZyanStatus ZyanStringInitCustomBuffer (ZyanString *string,
char *buffer, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringDestroy (ZyanString *string)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate
(ZyanString *destination, const ZyanStringView *source, ZyanUSize
capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateEx (ZyanString *destination,
const ZyanStringView *source, ZyanUSize capacity, ZyanAllocator
*allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateCustomBuffer (ZyanString
*destination, const ZyanStringView *source, char *buffer, ZyanUSize
capacity)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringConcat (ZyanString
*destination, const ZyanStringView *s1, const ZyanStringView *s2,
ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringConcatEx (ZyanString *destination,
const ZyanStringView *s1, const ZyanStringView *s2, ZyanUSize
capacity, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8
shrink_threshold)
ZYCORE_EXPORT ZyanStatus ZyanStringConcatCustomBuffer (ZyanString
*destination, const ZyanStringView *s1, const ZyanStringView *s2,
char *buffer, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideView (ZyanStringView *view,
const ZyanStringView *source)
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideViewEx (ZyanStringView
*view, const ZyanStringView *source, ZyanUSize index, ZyanUSize
count)
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBuffer (ZyanStringView
*view, const char *string)
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBufferEx (ZyanStringView
*view, const char *buffer, ZyanUSize length)
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetSize (const ZyanStringView
*view, ZyanUSize *size)
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetData (const ZyanStringView
*view, const char **buffer)
ZYCORE_EXPORT ZyanStatus ZyanStringGetChar (const ZyanStringView
*string, ZyanUSize index, char *value)
ZYCORE_EXPORT ZyanStatus ZyanStringGetCharMutable (ZyanString *string,
ZyanUSize index, char **value)
ZYCORE_EXPORT ZyanStatus ZyanStringSetChar (ZyanString *string,
ZyanUSize index, char value)
ZYCORE_EXPORT ZyanStatus ZyanStringInsert (ZyanString *destination,
ZyanUSize index, const ZyanStringView *source)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertEx (ZyanString *destination,
ZyanUSize destination_index, const ZyanStringView *source, ZyanUSize
source_index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringAppend (ZyanString *destination,
const ZyanStringView *source)
ZYCORE_EXPORT ZyanStatus ZyanStringAppendEx (ZyanString *destination,
const ZyanStringView *source, ZyanUSize source_index, ZyanUSize
count)
ZYCORE_EXPORT ZyanStatus ZyanStringDelete (ZyanString *string, ZyanUSize
index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringTruncate (ZyanString *string,
ZyanUSize index)
ZYCORE_EXPORT ZyanStatus ZyanStringClear (ZyanString *string)
ZYCORE_EXPORT ZyanStatus ZyanStringLPos (const ZyanStringView *haystack,
const ZyanStringView *needle, ZyanISize *found_index)
ZYCORE_EXPORT ZyanStatus ZyanStringLPosEx (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringLPosI (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index)
ZYCORE_EXPORT ZyanStatus ZyanStringLPosIEx (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringRPos (const ZyanStringView *haystack,
const ZyanStringView *needle, ZyanISize *found_index)
ZYCORE_EXPORT ZyanStatus ZyanStringRPosEx (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringRPosI (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index)
ZYCORE_EXPORT ZyanStatus ZyanStringRPosIEx (const ZyanStringView
*haystack, const ZyanStringView *needle, ZyanISize *found_index,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringCompare (const ZyanStringView *s1,
const ZyanStringView *s2, ZyanI32 *result)
ZYCORE_EXPORT ZyanStatus ZyanStringCompareI (const ZyanStringView *s1,
const ZyanStringView *s2, ZyanI32 *result)
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCase (ZyanString *string)
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCaseEx (ZyanString *string,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCase (ZyanString *string)
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCaseEx (ZyanString *string,
ZyanUSize index, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanStringResize (ZyanString *string, ZyanUSize
size)
ZYCORE_EXPORT ZyanStatus ZyanStringReserve (ZyanString *string,
ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringShrinkToFit (ZyanString *string)
ZYCORE_EXPORT ZyanStatus ZyanStringGetCapacity (const ZyanString
*string, ZyanUSize *capacity)
ZYCORE_EXPORT ZyanStatus ZyanStringGetSize (const ZyanString *string,
ZyanUSize *size)
ZYCORE_EXPORT ZyanStatus ZyanStringGetData (const ZyanString *string,
const char **value)
π DETAILED DESCRIPTION π
It implements a string type. That's the whole vibe. A string type, but make it Zycore. π
π MACRO DEFINITION DOCUMENTATION π
#define ZYAN_DEFINE_STRING_VIEW( string)
Value β and bestie, this is exactly how it looks:
{ \
/* string */ \
{ \
/* flags */ 0, \
/* vector */ \
{ \
/* allocator */ ZYAN_NULL, \
/* growth_factor */ 1, \
/* shrink_threshold */ 0, \
/* size */ sizeof(string), \
/* capacity */ sizeof(string), \
/* element_size */ sizeof(char), \
/* destructor */ ZYAN_NULL, \
/* data */ (char*)(string) \
} \
} \
}
Defines a ZyanStringView struct that provides a view into a static C-style string. So it's like a little window you can peek through. πͺ
Parameters
- string β the C-style string. That's the one.
#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2
The default growth factor for all string instances. When it grows, it grows by this much. Periodt. β¨
#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 4
The default shrink threshold for all string instances. It's the "okay bestie, time to tighten up" number. π
#define ZYAN_STRING_HAS_FIXED_CAPACITY 0x01
The string uses a custom user-defined buffer with a fixed capacity. So it's not flexible β it is what it is, and what it is is fixed. π«Ά
#define ZYAN_STRING_INITIALIZER
Value:
{ \
/* flags */ 0, \
/* vector */ ZYAN_VECTOR_INITIALIZER \
}
Defines an uninitialized ZyanString instance. It's giving blank-slate energy. π¦
#define ZYAN_STRING_MIN_CAPACITY 32
The initial minimum capacity (number of characters) for all dynamically allocated string instances β and this is important β not including the terminating '\0'-character. So 32 chars plus the null terminator. Don't forget the null terminator, bestie, it will humble you. π
#define ZYAN_STRING_TO_VIEW( string)
Value:
(const ZyanStringView*)(string)
Casts a ZyanString pointer to a constant ZyanStringView pointer. Glow-up via cast, zero runtime overhead. π
π§ TYPEDEF DOCUMENTATION π§
typedef struct ZyanString_ ZyanString
Defines the ZyanString struct.
The ZyanString type is implemented as a size-prefixed string β which allows for a lot of performance optimizations. Nevertheless, null-termination is guaranteed at all times to provide maximum compatibility with default C-style strings (use ZyanStringGetData to access the C-style string).
All fields in this struct should be considered as "private". Any changes may lead to unexpected behavior. So like... don't touch. Respect the privacy, bestie. π
typedef ZyanU8 ZyanStringFlags
Defines the ZyanStringFlags data-type. It's literally just a ZyanU8, but make it named. π
typedef struct ZyanStringView_ ZyanStringView
Defines the ZyanStringView struct.
The ZyanStringView type provides a view inside a string (ZyanString instances, null-terminated C-style strings, or even not-null-terminated custom strings). A view is immutable by design and can't be directly converted to a C-style string.
Views might become invalid (e.g. pointing to invalid memory), if the underlying string gets destroyed or resized. So like... don't go holding onto a view after you've messed with the thing it's viewing. That's giving dangling pointer, and not in a cute way. π
The ZYAN_STRING_TO_VIEW macro can be used to cast a ZyanString to a ZyanStringView pointer without any runtime overhead. Casting a view to a normal string is not supported and will lead to unexpected behavior (use ZyanStringDuplicate to create a deep-copy instead). Deep-copy = the safe way. Don't skip steps. π
All fields in this struct should be considered as "private". Any changes may lead to unexpected behavior. Again β private. Hands off. π
π₯ FUNCTION DOCUMENTATION π₯
ZYCORE_EXPORT ZyanStatus ZyanStringAppend (ZyanString * destination, const ZyanStringView * source)
Appends the content of the source string to the end of the destination string. Like adding a little β¨moreβ¨ to the end of your sentence.
Parameters
- destination β the destination string.
- source β the source string.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringAppendEx (ZyanString * destination, const ZyanStringView * source, ZyanUSize source_index, ZyanUSize count)
Appends count characters of the source string to the end of the destination string. You pick where to start and how much to take. Choose wisely. π
Parameters
- destination β the destination string.
- source β the source string.
- source_index β the index of the first character to be appended from the source string.
- count β the number of chars to append from the source string.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringClear (ZyanString * string)
Erases the given string. Gone. Deleted. Not a trace. π«₯
Parameters
- string β a pointer to the
ZyanStringinstance.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringCompare (const ZyanStringView * s1, const ZyanStringView * s2, ZyanI32 * result)
Compares two strings.
Parameters
okay so here's what you're handing over π
s1β the first string πΈs2β the second string π«Άresultβ receives the comparison result.
and the values result can end up with, no cap:
result < 0β the first character that doesn't match has a lower value ins1than ins2result == 0β the contents of both strings are equal β¨result > 0β the first character that doesn't match has a greater value ins1than ins2
Returns
ZYAN_STATUS_TRUE if the strings are equal, ZYAN_STATUS_FALSE if they're not, or another zyan status code if an error occurred π
ZYCORE_EXPORT ZyanStatus ZyanStringCompareI (const ZyanStringView * s1, const ZyanStringView * s2, ZyanI32 * result)
Performs a case-insensitive comparison of two strings. she does not care about your capital letters, bestie π
Parameters
s1β the first strings2β the second string.resultβ receives the comparison result.
Values it can receive:
result < 0β the first character that does not match has a lower value ins1than ins2result == 0β the contents of both strings are equalresult > 0β the first character that does not match has a greater value ins1than ins2
Returns
ZYAN_STATUS_TRUE, if the strings are equal, ZYAN_STATUS_FALSE, if not, or another zyan status code, if an error occurred.
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringConcat (ZyanString * destination, const ZyanStringView * s1, const ZyanStringView * s2, ZyanUSize capacity)
Initializes a new ZyanString instance by concatenating two existing strings. it's giving β¨glow upβ¨, two strings becoming one.
heads up: this one is ZYAN_REQUIRES_LIBC, so she needs libc to do her thing π«Ά
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.- this function will fail, if the destination
ZyanStringinstance equals one of the source strings. no self-concat shenanigans
- this function will fail, if the destination
s1β a pointer to the first source string.s2β a pointer to the second source string.capacityβ the initial capacity (number of characters).- this value is automatically adjusted to the combined size of the source strings, if a smaller value was passed. she fixes your math for you π
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifs1ors2are views into the destination string ordestinationpoints to an already initializedZyanStringinstance. like, undefined undefined. don't do it fr fr.
The memory for the string is dynamically allocated by the default allocator using the default growth factor and the default shrink threshold.
The allocated buffer will be at least one character larger than the given capacity, to reserve space for the terminating '\0'.
Finalization with ZyanStringDestroy is required for all strings created by this function. don't forget, i'm watching π
ZYCORE_EXPORT ZyanStatus ZyanStringConcatCustomBuffer (ZyanString * destination, const ZyanStringView * s1, const ZyanStringView * s2, char * buffer, ZyanUSize capacity)
Initializes a new ZyanString instance by concatenating two existing strings and configures it to use a custom user defined buffer with a fixed size. you bring the storage, she brings the vibes π
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.- this function will fail, if the destination
ZyanStringinstance equals one of the source strings.
- this function will fail, if the destination
s1β a pointer to the first source string.s2β a pointer to the second source string.bufferβ a pointer to the buffer that is used as storage for the string.capacityβ the maximum capacity (number of characters) of the buffer.- this function will fail, if the capacity of the buffer is less or equal to the combined size of the source strings. so give her room okay
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifs1ors2are views into the destination string ordestinationpoints to an already initializedZyanStringinstance.
Finalization is not required for strings created by this function. so you can just... let her be π¦
ZYCORE_EXPORT ZyanStatus ZyanStringConcatEx (ZyanString * destination, const ZyanStringView * s1, const ZyanStringView * s2, ZyanUSize capacity, ZyanAllocator * allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
Initializes a new ZyanString instance by concatenating two existing strings and sets a custom allocator and memory allocation/deallocation parameters. main character energy, she gets to pick her own everything π
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.- this function will fail, if the destination
ZyanStringinstance equals one of the source strings.
- this function will fail, if the destination
s1β a pointer to the first source string.s2β a pointer to the second source string.capacityβ the initial capacity (number of characters).- this value is automatically adjusted to the combined size of the source strings, if a smaller value was passed.
allocatorβ a pointer to aZyanAllocatorinstance.growth_factorβ the growth factor.shrink_thresholdβ the shrink threshold.
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifs1ors2are views into the destination string ordestinationpoints to an already initializedZyanStringinstance.
A growth_factor of 1 disables overallocation and a shrink_threshold of 0 disables dynamic shrinking. pick your poison π
The allocated buffer will be at least one character larger than the given capacity, to reserve space for the terminating '\0'.
Finalization with ZyanStringDestroy is required for all strings created by this function.
ZYCORE_EXPORT ZyanStatus ZyanStringDelete (ZyanString * string, ZyanUSize index, ZyanUSize count)
Deletes characters from the given string, starting at index. and just like that, gone β¨
Parameters
stringβ a pointer to theZyanStringinstance.indexβ the index of the first character to delete.countβ the number of characters to delete.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringDestroy (ZyanString * string)
Destroys the given ZyanString instance. it's over bestie ππ (but like, in a memory-management way)
Parameters
stringβ a pointer to theZyanStringinstance.
Returns
A zyan status code.
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate (ZyanString * destination, const ZyanStringView * source, ZyanUSize capacity)
Initializes a new ZyanString instance by duplicating an existing string. twin where π«Ά
this one is ZYAN_REQUIRES_LIBC too, so libc is required
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.sourceβ a pointer to the source string.capacityβ the initial capacity (number of characters).- this value is automatically adjusted to the size of the source string, if a smaller value was passed.
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifsourceis a view into the destination string ordestinationpoints to an already initializedZyanStringinstance.
The memory for the string is dynamically allocated by the default allocator using the default growth factor and the default shrink threshold.
The allocated buffer will be at least one character larger than the given capacity, to reserve space for the terminating '\0'.
Finalization with ZyanStringDestroy is required for all strings created by this function.
ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateCustomBuffer (ZyanString * destination, const ZyanStringView * source, char * buffer, ZyanUSize capacity)
Initializes a new ZyanString instance by duplicating an existing string and configures it to use a custom user defined buffer with a fixed size. yes she'll use your buffer, she's not picky like that π
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.sourceβ a pointer to the source string.bufferβ a pointer to the buffer that is used as storage for the string.capacityβ the maximum capacity (number of characters) of the buffer, including the terminating'\0'.
This function will fail, if the capacity of the buffer is less or equal to the size of the source string. so yes the '\0' counts, that's the whole point π
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifsourceis a view into the destination string ordestinationpoints to an already initializedZyanStringinstance.
Finalization is not required for strings created by this function.
ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateEx (ZyanString * destination, const ZyanStringView * source, ZyanUSize capacity, ZyanAllocator * allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
Initializes a new ZyanString instance by duplicating an existing string and sets a custom allocator and memory allocation/deallocation parameters. custom everything, she said "i have a vision" π
Parameters
destinationβ a pointer to the (uninitialized) destinationZyanStringinstance.sourceβ a pointer to the source string.capacityβ the initial capacity (number of characters).- this value is automatically adjusted to the size of the source string, if a smaller value was passed.
allocatorβ a pointer to aZyanAllocatorinstance.growth_factorβ the growth factor.shrink_thresholdβ the shrink threshold.
Returns
A zyan status code.
β οΈ the behavior of this function is undefined, ifsourceis a view into the destination string ordestinationpoints to an already initializedZyanStringinstance.
A growth_factor of 1 disables overallocation and a shrink_threshold of 0 disables dynamic shrinking.
The allocated buffer will be at least one character larger than the given capacity, to reserve space for the terminating '\0'.
Finalization with ZyanStringDestroy is required for all strings created by this function.
ZYCORE_EXPORT ZyanStatus ZyanStringGetCapacity (const ZyanString * string, ZyanUSize * capacity)
Returns the current capacity of the string. she's telling you how much room she has πΈ
Parameters
stringβ a pointer to theZyanStringinstance.capacityβ receives the size of the string.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringGetChar (const ZyanStringView * string, ZyanUSize index, char * value)
Returns the character at the given index. just one lil guy π¦
Parameters
stringβ a pointer to theZyanStringViewinstance.indexβ the character index.valueβ receives the desired character of the string.
Returns
A zyan status code.
ZYCORE_EXPORT ZyanStatus ZyanStringGetCharMutable (ZyanString * string, ZyanUSize index, char ** value)
Returns a pointer to the character at the given index. a pointer, note the char ** β she wants you to be able to touch it π
stringβ a pointer to theZyanStringinstance πindexβ the character index πΈvalueβ this one receives a pointer to the character you wanted, sitting right there in the string β¨
Returns: a zyan status code π«Ά
ZYCORE_EXPORT ZyanStatus ZyanStringGetData (const ZyanString * string, const char ** value)
Hands you the C-style string of the given ZyanString instance β like, the actual char-pointer era version. no cap π
Parameters
stringβ a pointer to theZyanStringinstance πvalueβ receives a pointer to the C-style string π₯
Returns: a zyan status code β
ZYCORE_EXPORT ZyanStatus ZyanStringGetSize (const ZyanString * string, ZyanUSize * size)
Tells you the current size β that's the number of characters, and bestie, it does not count the terminating zero character. the '\0' is not invited to this count π
Parameters
stringβ a pointer to theZyanStringinstance πsizeβ receives the size (number of characters) of the string π
Returns: a zyan status code π
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit (ZyanString * string, ZyanUSize capacity)
Sets up the given ZyanString instance. brand new, sparkling, ready for content β¨
Parameters
stringβ a pointer to theZyanStringinstance πcapacityβ the initial capacity (number of characters) π
Returns: a zyan status code π«Ά
The memory for the string gets dynamically allocated by the default allocator, using the default growth factor and the default shrink threshold. defaults everywhere, it's giving low-effort slay π
The allocated buffer will be at least one character larger than the given capacity, so there's always room reserved for that terminating '\0'. she saves a seat πͺ
Finalization with ZyanStringDestroy is required for all strings created by this function. don't ghost her, ok? π
ZYCORE_EXPORT ZyanStatus ZyanStringInitCustomBuffer (ZyanString * string, char * buffer, ZyanUSize capacity)
Sets up the given ZyanString instance and tells it to use a custom user defined buffer with a fixed size. your buffer, your rules π
Parameters
stringβ a pointer to theZyanStringinstance πΈbufferβ a pointer to the buffer that is used as storage for the string π§Ίcapacityβ the maximum capacity (number of characters) of the buffer, including the terminating'\0'β οΈ yes bestie, this one counts the zero π«
Returns: a zyan status code β
Finalization is not required for strings created by this function. she's self-sufficient, main character energy π
ZYCORE_EXPORT ZyanStatus ZyanStringInitEx (ZyanString * string, ZyanUSize capacity, ZyanAllocator * allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
Sets up the given ZyanString instance and lets you set a custom allocator plus your own memory allocation/deallocation parameters. full DIY mode π§
Parameters
stringβ a pointer to theZyanStringinstance πcapacityβ the initial capacity (number of characters) πallocatorβ a pointer to aZyanAllocatorinstance πgrowth_factorβ the growth factor πshrink_thresholdβ the shrink threshold π
Returns: a zyan status code π
A growth factor of 1 disables overallocation, and a shrink threshold of 0 disables dynamic shrinking. noted π
The allocated buffer will be at least one character larger than the given capacity, to reserve space for the terminating '\0' π«Ά
Finalization with ZyanStringDestroy is required for all strings created by this function. again β do not forget her π
ZYCORE_EXPORT ZyanStatus ZyanStringInsert (ZyanString * destination, ZyanUSize index, const ZyanStringView * source)
Inserts the content of the source string into the destination string at the given index. sneaking text in at exactly the right spot, we love to see it β¨
Parameters
destinationβ the destination string π―indexβ the insert index πsourceβ the source string π¦
Returns: a zyan status code π¦
ZYCORE_EXPORT ZyanStatus ZyanStringInsertEx (ZyanString * destination, ZyanUSize destination_index, const ZyanStringView * source, ZyanUSize source_index, ZyanUSize count)
Inserts count characters of the source string into the destination string at the given index. it's the same vibe as ZyanStringInsert but now you get to pick which characters and how many π
Parameters
destinationβ the destination string π―destination_indexβ the insert index πsourceβ the source string π¦source_indexβ the index of the first character to be inserted from the source string πcountβ the number of chars to insert from the source string π’
Returns: a zyan status code πΈ
ZYCORE_EXPORT ZyanStatus ZyanStringLPos (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index)
Searches for the first occurrence of needle in the given haystack, starting from the left. classic needle-in-haystack detective work π
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occured β
The found_index is set to -1 if the needle was not found. not found = -1, always π€
ZYCORE_EXPORT ZyanStatus ZyanStringLPosEx (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index, ZyanUSize index, ZyanUSize count)
Searches for the first occurrence of needle in the given haystack, starting from the left. same hunt, but now you control the range πΊοΈ
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―indexβ the start index π©countβ the maximum number of characters to iterate, beginning from the start index π’
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occured β¨
The found_index is set to -1 if the needle was not found π
ZYCORE_EXPORT ZyanStatus ZyanStringLPosI (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index)
Does a case-insensitive search for the first occurrence of needle in the given haystack, starting from the left. "BESTIE" and "bestie" are the same girl, periodt π
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occured π«Ά
The found_index is set to -1 if the needle was not found πΈ
ZYCORE_EXPORT ZyanStatus ZyanStringLPosIEx (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index, ZyanUSize index, ZyanUSize count)
Does a case-insensitive search for the first occurrence of needle in the given haystack, starting from the left. case-insensitive and range-limited, she does it all π
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―indexβ the start index π©countβ the maximum number of characters to iterate, beginning from the start index π’
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occurred β
The found_index is set to -1 if the needle was not found π
ZYCORE_EXPORT ZyanStatus ZyanStringReserve (ZyanString * string, ZyanUSize capacity)
Changes the capacity of the given ZyanString instance. glow-up for the buffer allocation π
Parameters
stringβ a pointer to theZyanStringinstance πcapacityβ the new minimum capacity of the string π
Returns: a zyan status code π¦
This function will fail if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance. she said no changes, and she meant it π
ZYCORE_EXPORT ZyanStatus ZyanStringResize (ZyanString * string, ZyanUSize size)
Resizes the given ZyanString instance. growing or shrinking, whatever the era calls for β¨
Parameters
stringβ a pointer to theZyanStringinstance πsizeβ the new size of the string π
Returns: a zyan status code π
This function will fail if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance. immutability check said nope π
ZYCORE_EXPORT ZyanStatus ZyanStringRPos (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index)
Searches for the first occurrence of needle in the given haystack, starting from the right. she's walking backwards through the text, iconic π
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occurred β
The found_index is set to -1 if the needle was not found π€
ZYCORE_EXPORT ZyanStatus ZyanStringRPosEx (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index, ZyanUSize index, ZyanUSize count)
Searches for the first occurrence of needle in the given haystack, starting from the right. right-to-left but make it bounded πΊοΈ
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―indexβ the start index π©countβ the maximum number of characters to iterate, beginning from the start index π’
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occurred β¨
The found_index is set to -1 if the needle was not found π
ZYCORE_EXPORT ZyanStatus ZyanStringRPosI (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index)
Does a case-insensitive search for the first occurrence of needle in the given haystack, starting from the right. right side, no case sensitivity, all vibes π¦
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occurred π
The found_index is set to -1 if the needle was not found πΈ
ZYCORE_EXPORT ZyanStatus ZyanStringRPosIEx (const ZyanStringView * haystack, const ZyanStringView * needle, ZyanISize * found_index, ZyanUSize index, ZyanUSize count)
Does a case-insensitive search for the first occurrence of needle in the given haystack, starting from the right. the final boss of search functions, and she ate π₯
Parameters
haystackβ the string to search in πΎneedleβ the sub-string to search for πͺ‘found_indexβ a pointer to a variable that receives the index of the first occurrence ofneedleπ―indexβ the start index π©countβ the maximum number of characters to iterate, beginning from the start index π’
Returns: ZYAN_STATUS_TRUE if the needle was found, ZYAN_STATUS_FALSE if not, or another zyan status code if an error occurred β
The found_index is set to -1 if the needle was not found π
ZyanStringSetChar β¨
ZYCORE_EXPORT ZyanStatus ZyanStringSetChar (ZyanString * string, ZyanUSize index, char value)
okay so this one is literally assigning a new value to the character at the given index. it's giving single-character glow-up π
Parameters
stringβ a pointer to theZyanStringinstance.indexβ the character index.valueβ the character to assign.
Returns
- A zyan status code. slay.
ZyanStringShrinkToFit π
ZYCORE_EXPORT ZyanStatus ZyanStringShrinkToFit (ZyanString * string)
Shrinks the capacity of the given string to match it's size. yes bestie, it's giving "snatched to the exact fit" π
Parameters
stringβ a pointer to theZyanStringinstance.
Returns
- A zyan status code.
β οΈ This function will fail, if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance.
ZyanStringToLowerCase πΈ
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCase (ZyanString * string)
Converts the given string to lowercase letters. lowercase era activated. β¨
Parameters
stringβ a pointer to theZyanStringinstance.
Returns
- A zyan status code.
β οΈ This function will fail, if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance.
ZyanStringToLowerCaseEx π
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCaseEx (ZyanString * string, ZyanUSize index, ZyanUSize count)
Converts count characters of the given string to lowercase letters.
Parameters
stringβ a pointer to theZyanStringinstance.indexβ the start index.countβ the number of characters to convert, beginning from the start index.
Returns
- A zyan status code.
β οΈ This function will fail, if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance.
ZyanStringToUpperCase π
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCase (ZyanString * string)
Converts the given string to uppercase letters. uppercase main character energy. π
Parameters
stringβ a pointer to theZyanStringinstance.
Returns
- A zyan status code.
β οΈ This function will fail, if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance.
ZyanStringToUpperCaseEx π¦
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCaseEx (ZyanString * string, ZyanUSize index, ZyanUSize count)
Converts count characters of the given string to uppercase letters.
Parameters
stringβ a pointer to theZyanStringinstance.indexβ the start index.countβ the number of characters to convert, beginning from the start index.
Returns
- A zyan status code.
β οΈ This function will fail, if theZYAN_STRING_IS_IMMUTABLEflag is set for the specifiedZyanStringinstance.
ZyanStringTruncate βοΈ
ZYCORE_EXPORT ZyanStatus ZyanStringTruncate (ZyanString * string, ZyanUSize index)
Deletes all remaining characters from the given string, starting at index. it's giving "cut the chat, we're done here" π
Parameters
stringβ a pointer to theZyanStringinstance.indexβ the index of the first character to delete.
Returns
- A zyan status code.
ZyanStringViewGetData πΎ
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetData (const ZyanStringView * view, const char ** buffer)
Returns the C-style string of the given ZyanString instance.
β οΈ Warning: The string is not guaranteed to be null terminated!
Parameters
viewβ a pointer to theZyanStringViewinstance.bufferβ receives a pointer to the C-style string.
Returns
- A zyan status code.
ZyanStringViewGetSize π
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetSize (const ZyanStringView * view, ZyanUSize * size)
Returns the size (number of characters) of the view.
Parameters
viewβ a pointer to theZyanStringViewinstance.sizeβ receives the size (number of characters) of the view.
Returns
- A zyan status code.
ZyanStringViewInsideBuffer π«Ά
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBuffer (ZyanStringView * view, const char * string)
Returns a view inside a null-terminated C-style string.
Parameters
viewβ a pointer to theZyanStringViewinstance.stringβ the C-style string.
Returns
- A zyan status code.
ZyanStringViewInsideBufferEx β¨
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBufferEx (ZyanStringView * view, const char * buffer, ZyanUSize length)
Returns a view inside a character buffer with custom length.
Parameters
viewβ a pointer to theZyanStringViewinstance.bufferβ a pointer to the buffer containing the string characters.lengthβ the length of the string (number of characters).
Returns
- A zyan status code.
ZyanStringViewInsideView π
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideView (ZyanStringView * view, const ZyanStringView * source)
Returns a view inside an existing view/string.
Parameters
viewβ a pointer to theZyanStringViewinstance.sourceβ a pointer to the source string.
Returns
- A zyan status code.
π‘ TheZYAN_STRING_TO_VEWmacro can be used to pass anyZyanStringinstance as value for the source string.
ZyanStringViewInsideViewEx π§
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideViewEx (ZyanStringView * view, const ZyanStringView * source, ZyanUSize index, ZyanUSize count)
Returns a view inside an existing view/string starting from the given index.
Parameters
viewβ a pointer to theZyanStringViewinstance.sourceβ a pointer to the source string.indexβ the start index.countβ the number of characters.
Returns
- A zyan status code.
π‘ TheZYAN_STRING_TO_VEWmacro can be used to pass anyZyanStringinstance as value for the source string.
Author π
Generated automatically by Doxygen for Zycore from the source code.
That's the whole page, bestie! Zycore, Version 1.5.2.0, from include/Zycore/String.h(3) β periodt. π
β¨
π¦ where this page comes from
- ubuntu resolute: libzycore-doc 1.5.2-1build1 Β· MIT
- ubuntu stonking: libzycore-doc 1.5.2-1build1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms