11#if __STDC_VERSION__ >= CSTR_DEFAULT_C_STD
14# undef CSTR_sys_strdup
17#if defined(CSTR_OS_WIN32)
19# define CSTR_sys_strdup _strdup
21# ifdef _POSIX_C_SOURCE
22# undef _POSIX_C_SOURCE
24# define _POSIX_C_SOURCE 200809L
26# define CSTR_sys_strdup strdup
35#define CSTR_FORCECAP_LIMIT 2
38#ifdef CSTR_RECOMMENDED
39# define CSTR_DYNAMIC_CAPACITY
40# define CSTR_ENABLE_GET_RETURN
41# define CSTR_ENABLE_GET_CONST_RETURN
87#ifdef CSTR_DEFINE_INTERNAL
381# ifdef CSTR_ENABLE_GET_RETURN
382# define CSTR_GET_RETURN(_cstr, _call, ...) ((_call(&_cstr, __VA_ARGS__)), _cstr)
384# define CSTR_GET_RETURN(_cstr, _call, ...)
387# ifdef CSTR_CONST_RETURN_USE_PTR_METHOD
388# define CSTR_CONST_RETURN_PTR_METHOD ->
390# define CSTR_CONST_RETURN_PTR_METHOD .
393# ifdef CSTR_ENABLE_GET_CONST_RETURN
394# define CSTR_GET_CONST_RETURN(_str, _call, ...) \
397 cstr_initCopy(&tmpS, _str CSTR_CONST_RETURN_PTR_METHOD data); \
398 _call(&tmpS, __VA_ARGS__); \
402# define CSTR_GET_CONST_RETURN(_str, _call, ...)
407# error "Must use C11 as the minimum standard"
int cstr_insert(CSTR *_str, const char *_data, size_t _pos)
Insert a string at a specific position in a CSTR.
int cstr_reverse(CSTR *_str)
Reverse the content of a CSTR in place.
bool cstr_comp(const CSTR _s1, const CSTR _s2)
Compare two CSTR instances for equality.
int cstr_lower(CSTR *_str)
Convert all characters in a CSTR to lowercase.
int cstr_replaceAll(CSTR *_str, const char *_old, const char *_new)
Replace all occurrences of a substring.
int cstr_fromFloat(CSTR *_str, float _val)
Create a numeric string from a float.
int cstr_fromHex(CSTR *_str, unsigned int _val)
Create a hexadecimal string from an unsigned integer.
int cstr_shrink(CSTR *_str, const size_t _len)
Clear the content of a CSTR and optionally shrink capacity.
int cstr_destroy(CSTR *_str)
Destroy and clean up a CSTR and its allocated objects.
int cstr_substr(CSTR *_str, size_t _start, size_t _len)
Extract a substring in place from a CSTR.
int cstr_fromInt(CSTR *_str, int _val)
Create a numeric string from an integer.
int cstr_set(CSTR *_str, const char *_data)
Set the content of a CSTR to a new C-string in .data.
bool cstr_startsWith(CSTR _str, const char *_prefix)
Check if a CSTR begins with the given prefix.
int cstr_fromDouble(CSTR *_str, double _val)
Create a numeric string from a double.
int cstr_erase(CSTR *_str, int _pos, size_t _len)
Erase a portion of the string.
int cstr_add(CSTR *_str, const char *_suffix)
Append a suffix to the end of a CSTR.
int cstr_initCopy(CSTR *_dest, const char *_src)
Initialize a CSTR with a copy of an original C-string.
int cstr_upper(CSTR *_str)
Convert all characters in a CSTR to uppercase.
static int __cstr_setFormat(CSTR *_str, const char *_fmt,...)
Internal helper to format and set the string content.
int __cstr_updateCap(CSTR *_str)
Update the capacity automatically IMPORTANT: This function won't do anything if macro CSTR_DYNAMIC_CA...
bool cstr_empty(const CSTR *_str)
Get if the string is empty Return true if: .len smaller or equal to 0 .data is empty ("") ....
int cstr_fromLong(CSTR *_str, long _val)
Create a numeric string from a long.
size_t cstr_find(const CSTR *_str, const char *_find)
Find the first occurrence of a substring.
CSTR cstr_init(void)
Initialize a new empty CSTR.
const char * cstr_bool(const bool _bool)
Return "true" or "false" based on a boolean value.
size_t cstr_countChar(const CSTR *_str, const char ch)
Count occurrences of a single character within a CSTR.
int cstr_replace(CSTR *_str, const char *_old, const char *_new)
Replace only the first occurrence of a substring.
size_t cstr_count(const CSTR *_str, const char *ch)
Count occurrences of a substring within a CSTR.
size_t cstr_findFrom(const CSTR *_str, const char *_find, size_t pos)
Find a substring starting from a specific index.
int cstr_clear(CSTR *_str)
Clear a CSTR to an empty string without freeing memory.
bool cstr_endsWith(const CSTR _str, const char *_suffix)
Check if a CSTR ends with the given suffix.
Custom dynamic string type.
bool initialized
Tracks whether this CSTR has been initialized.
size_t len
Current string length (not counting the NULL terminator).
size_t cap
Total allocated capacity (including NULL terminator).
char * data
Pointer to the character buffer Always NULL terminated if properly managed through the API.
bool forceCap
If true, capacity is fixed and operations that exceed it return an error instead of reallocating the ...