C Standard Library Extensions 1.2.4
|
Functions | |
cxint | cx_strcasecmp (const cxchar *s1, const cxchar *s2) |
Compare two strings ignoring the case of ASCII characters. More... | |
cxint | cx_strncasecmp (const cxchar *s1, const cxchar *s2, cxsize n) |
Compare the first n characters of two strings ignoring the case of ASCII characters. More... | |
cxint | cx_strempty (const cxchar *string, const cxchar *pattern) |
Test if a string represents an empty string. More... | |
cxchar * | cx_strlower (cxchar *s) |
Convert all uppercase characters in a string into lowercase characters. More... | |
cxchar * | cx_strupper (cxchar *s) |
Convert all lowercase characters in a string into uppercase characters. More... | |
cxchar * | cx_strtrim (cxchar *string) |
Remove leading whitespace characters from a string. More... | |
cxchar * | cx_strrtrim (cxchar *string) |
Remove trailing whitespace characters from a string. More... | |
cxchar * | cx_strstrip (cxchar *string) |
Remove leading and trailing whitespace characters from a string. More... | |
cxchar * | cx_strskip (const cxchar *string, int(*ctype)(int)) |
Locate the first character in a string that does not belong to a given character class. More... | |
cxchar * | cx_strdup (const cxchar *string) |
Duplicate a string. More... | |
cxchar * | cx_strndup (const cxchar *string, cxsize n) |
Duplicate the first n charactes of a string. More... | |
cxchar * | cx_strvdupf (const cxchar *format, va_list args) |
Create a string from a variable-length argument list under format control. More... | |
cxchar * | cx_stpcpy (cxchar *dest, const cxchar *src) |
Copy a string returning a pointer to its end. More... | |
void | cx_strfreev (cxchar **sarray) |
Deallocate a NULL terminated string array. More... | |
cxchar ** | cx_strsplit (const cxchar *string, const cxchar *delimiter, cxint max_tokens) |
Split a string into pieces at a given delimiter. More... | |
cxchar * | cx_strjoinv (const cxchar *separator, cxchar **sarray) |
Join strings from an array of strings. More... | |
The module implements various string-related utility functions suitable for creating, searching and modifying C strings.
cxchar * cx_stpcpy | ( | cxchar * | dest, |
const cxchar * | src | ||
) |
Copy a string returning a pointer to its end.
dest | Destination string. |
src | Source string. |
The function copies the string src, including its terminating '\0', to the string dest. The source and the destination string may not overlap and the destination buffer must be large enough to receive the copy.
cxint cx_strcasecmp | ( | const cxchar * | s1, |
const cxchar * | s2 | ||
) |
Compare two strings ignoring the case of ASCII characters.
s1 | First string. |
s2 | Second string. |
The function compares the two strings s1 and s2 as strcmp() does, but ignores the case of ASCII characters.
Referenced by cx_string_casecmp().
cxchar * cx_strdup | ( | const cxchar * | string | ) |
Duplicate a string.
string | String to be duplicated. |
Duplicates the input string string. The newly allocated copy returned to the caller can be deallocated using cx_free().
Referenced by cx_vasprintf().
cxint cx_strempty | ( | const cxchar * | string, |
const cxchar * | pattern | ||
) |
Test if a string represents an empty string.
string | String to be tested. |
pattern | String containing all allowed comment characters. |
The function skips all leading whitespace characters in the string string. Whitespace characters are recognized by isspace(). If the first character which is not a whitespace character is either '\0' or one out of the pattern string pattern, the string is considered as empty and the function returns 1.
If pattern is set to NULL
there is no checking for special characters that should be considered as whitespaces.
void cx_strfreev | ( | cxchar ** | sarray | ) |
Deallocate a NULL
terminated string array.
sarray | String array to deallocate |
The function deallocates the array of strings sarray and any string it possibly contains.
References cx_free().
cxchar * cx_strjoinv | ( | const cxchar * | separator, |
cxchar ** | sarray | ||
) |
Join strings from an array of strings.
separator | Optional separator string. |
sarray | Array of strings to join. |
NULL
in case of error.The function builds a single string from the strings referenced by sarray. The array of input strings sarray has to be NULL
terminated. Optionally, a separator string can be passed through separator which will then be inserted between two strings. If no separator should be inserted when joining, separator must be set to NULL
.
References cx_malloc().
cxchar * cx_strlower | ( | cxchar * | s | ) |
Convert all uppercase characters in a string into lowercase characters.
s | The string to convert. |
Walks through the given string and turns uppercase characters into lowercase characters using tolower().
cxint cx_strncasecmp | ( | const cxchar * | s1, |
const cxchar * | s2, | ||
cxsize | n | ||
) |
Compare the first n characters of two strings ignoring the case of ASCII characters.
s1 | First string. |
s2 | Second string. |
n | Number of characters to compare. |
The function compares the first n characters of the two strings s1 and s2 as strncmp() does, but ignores the case of ASCII characters.
Referenced by cx_string_ncasecmp().
cxchar * cx_strndup | ( | const cxchar * | string, |
cxsize | n | ||
) |
Duplicate the first n charactes of a string.
string | Source string |
n | Maximum number of characters to be duplicated. |
Duplicates the first n characters of the source string string, returning the copied characters in newly allocated string of the size n + 1. The returned string is always null terminated. If the length of string is less than n the returned string is padded with nulls. The newly allocated string can be deallocated using cx_free().
References cx_calloc().
cxchar * cx_strrtrim | ( | cxchar * | string | ) |
Remove trailing whitespace characters from a string.
string | String to be processed. |
NULL
.The function removes trailing whitespace characters, or from the string string. Whitespace characters are recognized by isspace().
cxchar * cx_strskip | ( | const cxchar * | string, |
int(*)(int) | ctype | ||
) |
Locate the first character in a string that does not belong to a given character class.
string | String to be processed. |
ctype | Character class test function. |
Searches the string string for the first occurence of a character which does not belong to a certain character class. The character class is represented through a function that returns a non zero value if a character belongs to that class and 0 otherwise. Such functions are the character classification routines like isspace() for instance. It is expected that the input string is properly terminated. In case the whole string consists of characters of the specified class the function will return the location of the terminating '\0'.
cxchar ** cx_strsplit | ( | const cxchar * | string, |
const cxchar * | delimiter, | ||
cxint | max_tokens | ||
) |
Split a string into pieces at a given delimiter.
string | The string to split. |
delimiter | String specifying the locations where to split. |
max_tokens | The maximum number of tokens the string is split into. |
NULL
terminated array of strings, or NULL
in case of an error.The function breaks up the string string into, at most, max_tokens pieces at the places indicated by delimiter. If max_tokens is reached, the remainder of the string is appended to the last token. If max_tokens is less than 1 the string string is split completely.
The delimiter string delimiter never shows up in any of the resulting strings, unless max_tokens is reached.
As a special case, the result of splitting the empty string "" is an empty vector, not a vector containing a single string.
The created result vector can be deallocated using cx_strfreev().
References cx_malloc(), cx_slist_new(), and cx_slist_push_front().
cxchar * cx_strstrip | ( | cxchar * | string | ) |
Remove leading and trailing whitespace characters from a string.
NULL
.string | String to be processed. |
The function removes leading and trailing whitespace characters from the string string. Whitespace characters are recognized by isspace().
cxchar * cx_strtrim | ( | cxchar * | string | ) |
Remove leading whitespace characters from a string.
string | String to be processed. |
NULL
.The function removes leading whitespace characters, or from the string string. Whitespace characters are recognized by isspace().
cxchar * cx_strupper | ( | cxchar * | s | ) |
Convert all lowercase characters in a string into uppercase characters.
s | The string to convert. |
Walks through the given string and turns lowercase characters into uppercase characters using toupper().
cxchar * cx_strvdupf | ( | const cxchar * | format, |
va_list | args | ||
) |
Create a string from a variable-length argument list under format control.
format | The format string. |
args | Variable-length arguments to be inserted into format. |
The function is similar to vsprintf() but calculates the size needed to store the formatted result string and allocates the memory. The newly allocated string can be deallocated using cx_free().
References cx_vasprintf().
Referenced by cx_print(), and cx_printerr().