CSTR v1.0.0-build
Simple yet powerful string manipulation in C
|
Go to the source code of this file.
Classes | |
struct | CSTR |
Custom dynamic string type. More... |
Functions | |
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_CAPACITY is NOT defined. | |
int | cstr_add (CSTR *_str, const char *_suffix) |
Append a suffix to the end of a CSTR. | |
const char * | cstr_bool (const bool _bool) |
Return "true" or "false" based on a boolean value. | |
int | cstr_clear (CSTR *_str) |
Clear a CSTR to an empty string without freeing memory. | |
bool | cstr_comp (const CSTR _s1, const CSTR _s2) |
Compare two CSTR instances for equality. | |
int | cstr_destroy (CSTR *_str) |
Destroy and clean up a CSTR and its allocated objects. | |
bool | cstr_empty (const CSTR *_str) |
Get if the string is empty Return true if: .len smaller or equal to 0 .data is empty ("") .initialized is false _str is NULL If none of the requirements are met, means that it's not empty, hence, return false. | |
bool | cstr_endsWith (const CSTR _str, const char *_suffix) |
Check if a CSTR ends with the given suffix. | |
int | cstr_erase (CSTR *_str, int _pos, size_t _len) |
Erase a portion of the string. | |
size_t | cstr_find (const CSTR *_str, const char *_find) |
Find 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_fromDouble (CSTR *_str, double _val) |
Create a numeric string from a double. | |
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_fromInt (CSTR *_str, int _val) |
Create a numeric string from an integer. | |
int | cstr_fromLong (CSTR *_str, long _val) |
Create a numeric string from a long. | |
CSTR | cstr_init (void) |
Initialize a new empty CSTR. | |
int | cstr_initCopy (CSTR *_dest, const char *_src) |
Initialize a CSTR with a copy of an original C-string. | |
int | cstr_insert (CSTR *_str, const char *_data, size_t _pos) |
Insert a string at a specific position in a CSTR. | |
int | cstr_lower (CSTR *_str) |
Convert all characters in a CSTR to lowercase. | |
int | cstr_replace (CSTR *_str, const char *_old, const char *_new) |
Replace only the first occurrence of a substring. | |
int | cstr_replaceAll (CSTR *_str, const char *_old, const char *_new) |
Replace all occurrences of a substring. | |
int | cstr_reverse (CSTR *_str) |
Reverse the content of a CSTR in place. | |
int | cstr_set (CSTR *_str, const char *_data) |
Set the content of a CSTR to a new C-string in .data | |
int | cstr_shrink (CSTR *_str, const size_t _len) |
Clear the content of a CSTR and optionally shrink capacity. | |
bool | cstr_startsWith (CSTR _str, const char *_prefix) |
Check if a CSTR begins with the given prefix. | |
int | cstr_substr (CSTR *_str, size_t _start, size_t _len) |
Extract a substring in place from a CSTR. | |
int | cstr_upper (CSTR *_str) |
Convert all characters in a CSTR to uppercase. |
|
static |
Internal helper to format and set the string content.
Uses a printf-style format string and variadic arguments to overwrite the content of a CSTR. The function computes the required buffer size, reallocates if needed (unless forceCap is active), formats the string, and updates length/capacity.
_str | Pointer to the CSTR to modify. |
_fmt | printf-style format string. |
... | Variadic arguments corresponding to the format. |
int __cstr_updateCap | ( | CSTR * | _str | ) |
Update the capacity automatically IMPORTANT: This function won't do anything if macro CSTR_DYNAMIC_CAPACITY is NOT defined.
int cstr_add | ( | CSTR * | _str, |
const char * | _suffix ) |
const char * cstr_bool | ( | const bool | _bool | ) |
Return "true" or "false" based on a boolean value.
_bool | Boolean value |
int cstr_clear | ( | CSTR * | _str | ) |
int cstr_destroy | ( | CSTR * | _str | ) |
bool cstr_empty | ( | const CSTR * | _str | ) |
Get if the string is empty Return true if: .len smaller or equal to 0 .data is empty ("") .initialized is false _str is NULL If none of the requirements are met, means that it's not empty, hence, return false.
bool cstr_endsWith | ( | const CSTR | _str, |
const char * | _suffix ) |
int cstr_erase | ( | CSTR * | _str, |
int | _pos, | ||
size_t | _len ) |
Erase a portion of the string.
_str | Pointer to the CSTR |
_pos | Starting position |
_len | Number of characters to remove |
size_t cstr_find | ( | const CSTR * | _str, |
const char * | _find ) |
Find the first occurrence of a substring.
_str | Pointer to the CSTR to search |
_find | Substring to locate |
size_t cstr_findFrom | ( | const CSTR * | _str, |
const char * | _find, | ||
size_t | pos ) |
Find a substring starting from a specific index.
_str | Pointer to the CSTR to search |
_find | Substring to locate |
pos | Starting index |
int cstr_fromDouble | ( | CSTR * | _str, |
double | _val ) |
Create a numeric string from a double.
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_fromInt | ( | CSTR * | _str, |
int | _val ) |
Create a numeric string from an integer.
int cstr_fromLong | ( | CSTR * | _str, |
long | _val ) |
Create a numeric string from a long.
CSTR cstr_init | ( | void | ) |
int cstr_initCopy | ( | CSTR * | _dest, |
const char * | _src ) |
int cstr_insert | ( | CSTR * | _str, |
const char * | _data, | ||
size_t | _pos ) |
int cstr_lower | ( | CSTR * | _str | ) |
int cstr_replace | ( | CSTR * | _str, |
const char * | _old, | ||
const char * | _new ) |
Replace only the first occurrence of a substring.
_str | Pointer to the CSTR |
_old | Substring to locate |
_new | Replacement string |
int cstr_replaceAll | ( | CSTR * | _str, |
const char * | _old, | ||
const char * | _new ) |
Replace all occurrences of a substring.
_str | Pointer to the CSTR |
_old | Substring to locate |
_new | Replacement string |
int cstr_reverse | ( | CSTR * | _str | ) |
int cstr_set | ( | CSTR * | _str, |
const char * | _data ) |
int cstr_shrink | ( | CSTR * | _str, |
const size_t | _len ) |
bool cstr_startsWith | ( | CSTR | _str, |
const char * | _prefix ) |
int cstr_substr | ( | CSTR * | _str, |
size_t | _start, | ||
size_t | _len ) |