11#if __STDC_VERSION__ >= CSTR_DEFAULT_C_STD
19#define CSTR_FORCECAP_LIMIT 2
22#ifdef CSTR_RECOMMENDED
23# define CSTR_DYNAMIC_CAPACITY
24# define CSTR_ENABLE_GET_RETURN
25# define CSTR_ENABLE_GET_CONST_RETURN
71#ifdef CSTR_DEFINE_INTERNAL
334# ifdef CSTR_ENABLE_GET_RETURN
335# define CSTR_GET_RETURN(_cstr, _call, ...) ((_call(&_cstr, __VA_ARGS__)), _cstr)
337# define CSTR_GET_RETURN(_cstr, _call, ...)
340# ifdef CSTR_CONST_RETURN_USE_PTR_METHOD
341# define CSTR_CONST_RETURN_PTR_METHOD ->
343# define CSTR_CONST_RETURN_PTR_METHOD .
346# ifdef CSTR_ENABLE_GET_CONST_RETURN
347# define CSTR_GET_CONST_RETURN(_str, _call, ...) \
350 cstr_initCopy(&tmpS, _str CSTR_CONST_RETURN_PTR_METHOD data); \
351 _call(&tmpS, __VA_ARGS__); \
355# define CSTR_GET_CONST_RETURN(_str, _call, ...)
360# 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.
int cstr_replace(CSTR *_str, const char *_old, const char *_new)
Replace only the first occurrence of a substring.
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 ...