32#ifndef ZYCORE_STRING_H
33#define ZYCORE_STRING_H
52#define ZYAN_STRING_MIN_CAPACITY 32
57#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2
62#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 4
80#define ZYAN_STRING_HAS_FIXED_CAPACITY 0x01
155#define ZYAN_STRING_INITIALIZER \
158 ZYAN_VECTOR_INITIALIZER \
168#define ZYAN_STRING_TO_VIEW(string) (const ZyanStringView*)(string)
175#define ZYAN_DEFINE_STRING_VIEW(string) \
struct ZyanAllocator_ ZyanAllocator
Defines the ZyanAllocator struct.
#define ZYAN_REQUIRES_LIBC
Marks functions that require libc (cannot be used with ZYAN_NO_LIBC).
Definition Defines.h:468
#define ZYCORE_EXPORT
Symbol is exported in shared library builds.
Definition Defines.h:330
Status code definitions and check macros.
ZyanU32 ZyanStatus
Defines the ZyanStatus data type.
Definition Status.h:48
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.
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideView(ZyanStringView *view, const ZyanStringView *source)
Returns a view inside an existing view/string.
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCase(ZyanString *string)
Converts the given string to uppercase letters.
ZYCORE_EXPORT ZyanStatus ZyanStringInitCustomBuffer(ZyanString *string, char *buffer, ZyanUSize capacity)
Initializes the given ZyanString instance and configures it to use a custom user defined buffer with ...
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 a...
ZYCORE_EXPORT ZyanStatus ZyanStringGetData(const ZyanString *string, const char **value)
Returns the C-style string of the given ZyanString instance.
ZYCORE_EXPORT ZyanStatus ZyanStringRPosI(const ZyanStringView *haystack, const ZyanStringView *needle, ZyanISize *found_index)
Performs a case-insensitive search for the first occurrence of needle in the given haystack starting ...
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 allocat...
ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCaseEx(ZyanString *string, ZyanUSize index, ZyanUSize count)
Converts count characters of the given string to uppercase letters.
struct ZyanStringView_ ZyanStringView
Defines the ZyanStringView struct.
ZYCORE_EXPORT ZyanStatus ZyanStringDestroy(ZyanString *string)
Destroys the given ZyanString instance.
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCase(ZyanString *string)
Converts the given string to lowercase letters.
ZYCORE_EXPORT ZyanStatus ZyanStringCompareI(const ZyanStringView *s1, const ZyanStringView *s2, ZyanI32 *result)
Performs a case-insensitive comparison of two strings.
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit(ZyanString *string, ZyanUSize capacity)
Initializes the given ZyanString instance.
ZYCORE_EXPORT ZyanStatus ZyanStringRPosIEx(const ZyanStringView *haystack, const ZyanStringView *needle, ZyanISize *found_index, ZyanUSize index, ZyanUSize count)
Performs a case-insensitive search for the first occurrence of needle in the given haystack starting ...
ZYCORE_EXPORT ZyanStatus ZyanStringInsertEx(ZyanString *destination, ZyanUSize destination_index, const ZyanStringView *source, ZyanUSize source_index, ZyanUSize count)
Inserts count characters of the source string in the destination string at the given index.
ZYCORE_EXPORT ZyanStatus ZyanStringReserve(ZyanString *string, ZyanUSize capacity)
Changes the capacity of the given ZyanString instance.
struct ZyanString_ ZyanString
Defines the ZyanString struct.
ZYCORE_EXPORT ZyanStatus ZyanStringGetCapacity(const ZyanString *string, ZyanUSize *capacity)
Returns the current capacity of the string.
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBuffer(ZyanStringView *view, const char *string)
Returns a view inside a null-terminated C-style string.
ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBufferEx(ZyanStringView *view, const char *buffer, ZyanUSize length)
Returns a view inside a character buffer with custom length.
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.
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.
ZYCORE_EXPORT ZyanStatus ZyanStringGetChar(const ZyanStringView *string, ZyanUSize index, char *value)
Returns the character at the given index.
ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCaseEx(ZyanString *string, ZyanUSize index, ZyanUSize count)
Converts count characters of the given string to lowercase letters.
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 ...
ZYCORE_EXPORT ZyanStatus ZyanStringCompare(const ZyanStringView *s1, const ZyanStringView *s2, ZyanI32 *result)
Compares two strings.
ZYCORE_EXPORT ZyanStatus ZyanStringClear(ZyanString *string)
Erases the given string.
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.
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetData(const ZyanStringView *view, const char **buffer)
Returns the C-style string of the given ZyanString instance.
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.
ZYCORE_EXPORT ZyanStatus ZyanStringResize(ZyanString *string, ZyanUSize size)
Resizes the given ZyanString instance.
ZYCORE_EXPORT ZyanStatus ZyanStringViewGetSize(const ZyanStringView *view, ZyanUSize *size)
Returns the size (number of characters) of the view.
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 cu...
ZYCORE_EXPORT ZyanStatus ZyanStringLPosI(const ZyanStringView *haystack, const ZyanStringView *needle, ZyanISize *found_index)
Performs a case-insensitive search for the first occurrence of needle in the given haystack starting ...
ZYCORE_EXPORT ZyanStatus ZyanStringGetCharMutable(ZyanString *string, ZyanUSize index, char **value)
Returns a pointer to the character at the given index.
ZYCORE_EXPORT ZyanStatus ZyanStringLPosIEx(const ZyanStringView *haystack, const ZyanStringView *needle, ZyanISize *found_index, ZyanUSize index, ZyanUSize count)
Performs a case-insensitive search for the first occurrence of needle in the given haystack starting ...
ZYCORE_EXPORT ZyanStatus ZyanStringGetSize(const ZyanString *string, ZyanUSize *size)
Returns the current size (number of characters) of the string (excluding the terminating zero charact...
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.
ZyanU8 ZyanStringFlags
Defines the ZyanStringFlags data-type.
Definition String.h:75
ZYCORE_EXPORT ZyanStatus ZyanStringInsert(ZyanString *destination, ZyanUSize index, const ZyanStringView *source)
Inserts the content of the source string in the destination string at the given index.
ZYCORE_EXPORT ZyanStatus ZyanStringSetChar(ZyanString *string, ZyanUSize index, char value)
Assigns a new value to the character at the given index.
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate(ZyanString *destination, const ZyanStringView *source, ZyanUSize capacity)
Initializes a new ZyanString instance by duplicating an existing string.
ZYCORE_EXPORT ZyanStatus ZyanStringShrinkToFit(ZyanString *string)
Shrinks the capacity of the given string to match it's size.
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.
ZYCORE_EXPORT ZyanStatus ZyanStringInitEx(ZyanString *string, ZyanUSize capacity, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
Initializes the given ZyanString instance and sets a custom allocator and memory allocation/deallocat...
ZYCORE_EXPORT ZyanStatus ZyanStringTruncate(ZyanString *string, ZyanUSize index)
Deletes all remaining characters from the given string, starting at index.
ZYCORE_EXPORT ZyanStatus ZyanStringDelete(ZyanString *string, ZyanUSize index, ZyanUSize count)
Deletes characters from the given string, starting at index.
ZYCORE_EXPORT ZyanStatus ZyanStringAppend(ZyanString *destination, const ZyanStringView *source)
Appends the content of the source string to the end of the destination string.
Includes and defines some default data types.
ptrdiff_t ZyanISize
Definition Types.h:225
size_t ZyanUSize
Definition Types.h:224
int32_t ZyanI32
Definition Types.h:222
uint8_t ZyanU8
Definition Types.h:216
Implements the vector container class.
struct ZyanVector_ ZyanVector
Defines the ZyanVector struct.
Defines the ZyanStringView struct.
Definition String.h:132
ZyanString string
The string data.
Definition String.h:139
Defines the ZyanString struct.
Definition String.h:98
ZyanVector vector
The vector that contains the actual string.
Definition String.h:106
ZyanStringFlags flags
String flags.
Definition String.h:102