Orcania
Potluck with different functions for different purposes that can be shared among C programs
|
Functions | |
char * | str_replace (const char *source, const char *str_old, const char *str_new) |
char * | o_strdup (const char *source) |
char * | o_strndup (const char *source, size_t len) |
int | o_strcmp (const char *p1, const char *p2) |
int | o_strncmp (const char *p1, const char *p2, size_t n) |
char * | o_strcpy (char *p1, const char *p2) |
char * | o_strncpy (char *p1, const char *p2, size_t n) |
int | o_strcasecmp (const char *p1, const char *p2) |
int | o_strncasecmp (const char *p1, const char *p2, size_t n) |
char * | o_strstr (const char *haystack, const char *needle) |
char * | o_strnstr (const char *haystack, const char *needle, size_t len) |
char * | o_strcasestr (const char *haystack, const char *needle) |
char * | o_strchr (const char *haystack, int c) |
const char * | o_strnchr (const char *haystack, size_t len, char c) |
char * | o_strrchr (const char *haystack, int c) |
const char * | o_strrnchr (const char *haystack, size_t len, char c) |
int | o_strnullempty (const char *s) |
size_t | o_strlen (const char *s) |
const char * | trimwhitespace (char *str) |
char * | trimcharacter (char *str, char to_remove) |
char * | msprintf (const char *message,...) |
char * | mstrcatf (char *source, const char *message,...) |
These functions are used for string manipulation Types of functions available:
char * str_replace | ( | const char * | source, |
const char * | str_old, | ||
const char * | str_new | ||
) |
char * str_replace(const char * source, char * old, char * new) replace all occurences of old by new in the string source return a char * with the new value
source | the source string |
str_old | string to be replaced in source |
str_new | new string to replace |
Orcania library
Different functions for different purposes but that can be shared between other projects char * str_replace(const char * source, char * str_old, char * str_new) replace all occurences of str_old by str_new in the string source return a char * with the str_new value return NULL on error returned value must be free'd after use
char * o_strdup | ( | const char * | source | ) |
o_strdup a modified strdup function that don't crash when source is NULL, instead return NULL
source | the source string to duplicate |
o_strdup a modified strdup function that don't crash when source is NULL, instead return NULL Returned value must be free'd after use
char * o_strndup | ( | const char * | source, |
size_t | len | ||
) |
o_strndup a modified strndup function that don't crash when source is NULL, instead return NULL
source | the source string to duplicate |
len | the maximum length of the string source to duplicate |
o_strndup a modified strndup function that don't crash when source is NULL, instead return NULL Returned value must be free'd after use
int o_strcmp | ( | const char * | p1, |
const char * | p2 | ||
) |
o_strcmp a modified strcmp function that don't crash when p1 is NULL or p2 us NULL
p1 | the first string to compare |
p2 | the second string to compare |
o_strcmp a modified strcmp function that don't crash when p1 is NULL or p2 us NULL
int o_strncmp | ( | const char * | p1, |
const char * | p2, | ||
size_t | n | ||
) |
o_strncmp a modified strncmp function that don't crash when p1 is NULL or p2 us NULL
p1 | the first string to compare |
p2 | the second string to compare |
n | the maximum number of char to compare |
o_strncmp a modified strncmp function that don't crash when p1 is NULL or p2 us NULL
char * o_strcpy | ( | char * | p1, |
const char * | p2 | ||
) |
o_strcpy a modified strcpy function that don't crash when p1 is NULL or p2 us NULL
p1 | the string to copy p2 |
p2 | the source string to be copied |
o_strcpy a modified strcpy function that don't crash when p1 is NULL or p2 us NULL
char * o_strncpy | ( | char * | p1, |
const char * | p2, | ||
size_t | n | ||
) |
o_strncpy
p1 | the string to copy p2 |
p2 | the source string to be copied |
n | the maximum characters to copy from p2 to p1 |
o_strncpy a modified strncpy function that don't crash when p1 is NULL or p2 us NULL
int o_strcasecmp | ( | const char * | p1, |
const char * | p2 | ||
) |
o_strcasecmp a modified strcasecmp function that don't crash when p1 is NULL or p2 us NULL
p1 | the first string to compare |
p2 | the second string to compare |
o_strcasecmp a modified strcasecmp function that don't crash when p1 is NULL or p2 us NULL
int o_strncasecmp | ( | const char * | p1, |
const char * | p2, | ||
size_t | n | ||
) |
o_strncasecmp a modified strncasecmp function that don't crash when p1 is NULL or p2 us NULL
p1 | the first string to compare |
p2 | the second string to compare |
n | the maximum number of char to compare |
o_strncasecmp a modified strncasecmp function that don't crash when p1 is NULL or p2 us NULL
char * o_strstr | ( | const char * | haystack, |
const char * | needle | ||
) |
o_strstr a modified strstr function that don't crash when haystack is NULL or needle us NULL
haystack | the string to be looked for |
needle | the string to search in haystack |
o_strstr a modified strstr function that don't crash when haystack is NULL or needle us NULL
char * o_strnstr | ( | const char * | haystack, |
const char * | needle, | ||
size_t | len | ||
) |
o_strnstr a modified strnstr function that don't crash when haystack is NULL or needle us NULL
haystack | the string to be looked for |
needle | the string to search in haystack |
len | the maximum length to look for in haystack |
o_strnstr a modified strnstr function that don't crash when haystack is NULL or needle us NULL
char * o_strcasestr | ( | const char * | haystack, |
const char * | needle | ||
) |
o_strcasestr a modified strcasestr function that don't crash when haystack is NULL or needle us NULL
haystack | the string to be looked for |
needle | the string to search in haystack |
o_strcasestr a modified strcasestr function that don't crash when haystack is NULL or needle us NULL
char * o_strchr | ( | const char * | haystack, |
int | c | ||
) |
o_strchr a modified strchr function that don't crash when haystack is NULL
haystack | the string to be looked for |
c | the character to look for in haystack |
o_strchr a modified strchr function that don't crash when haystack is NULL
const char * o_strnchr | ( | const char * | haystack, |
size_t | len, | ||
char | c | ||
) |
o_strnchr a modified strnchr function that don't crash when haystack is NULL
haystack | the string to be looked for |
len | the maxmimum length of characters to look for in haystack |
c | the character to look for in haystack |
o_strnchr a modified strnchr function that don't crash when haystack is NULL
char * o_strrchr | ( | const char * | haystack, |
int | c | ||
) |
o_strrchr a modified strrchr function that don't crash when haystack is NULL
haystack | the string to be looked for |
c | the character to look for in haystack |
o_strrchr a modified strrchr function that don't crash when haystack is NULL
const char * o_strrnchr | ( | const char * | haystack, |
size_t | len, | ||
char | c | ||
) |
o_strrnchr a modified strrnchr function that don't crash when haystack is NULL
haystack | the string to be looked for |
len | the maxmimum length of characters to look for in haystack |
c | the character to look for in haystack |
o_strrnchr a modified strrnchr function that don't crash when haystack is NULL
int o_strnullempty | ( | const char * | s | ) |
o_strnullempty return true if s is NULL or empty string, false otherwise
size_t o_strlen | ( | const char * | s | ) |
o_strlen a modified version of strlen that don't crash when s is NULL
s | the string to calculate length |
o_strlen a modified version of strlen that don't crash when s is NULL
const char * trimwhitespace | ( | char * | str | ) |
Remove string of beginning and ending whitespaces the string str will be modified
str | the string to trim |
Remove string of beginning and ending whitespaces
char * trimcharacter | ( | char * | str, |
char | to_remove | ||
) |
Remove string of beginning and ending given character the string str will be modified
str | the string to trim |
Remove string of beginning and ending given character
char * msprintf | ( | const char * | message, |
... | |||
) |
char * msprintf(const char * message, ...) Implementation of sprintf that return a malloc'd char * with the string construction because life is too short to use 3 lines instead of 1 but don't forget to free the returned value after use! Disclaimer: When I made this function, I didn't know asprintf existed. If I did I surely wouldn't make msprintf although, msprintf has the advantage to work with o_malloc and o_free so it can use specific memory allocation functions
message | the message format to concat to source, printf format |
char * msprintf(const char * message, ...) Implementation of sprintf that return a malloc'd char * with the string construction because life is too short to use 3 lines instead of 1 but don't forget to free the returned value after use!
char * mstrcatf | ( | char * | source, |
const char * | message, | ||
... | |||
) |
char * mstrcatf((char * source, const char * message, ...) A combination of strcat and msprintf that will concat source and message formatted and return the combination as a new allocated char * and will o_free source but don't forget to free the returned value after use!
source | the source string to concat message, source will be free'd during the process |
message | the message format to concat to source, printf format |
char * mstrcatf((char * source, const char * message, ...) A combination of strcat and msprintf that will concat source and message formatted and return the combination as a new allocated char * and will o_free source but don't forget to free the returned value after use!