String manipulation functions. More...
Typedefs | |
typedef char * | xbt_string_t |
Classical alias to (char*). | |
Functions | |
int | asprintf (char **ptr, const char *fmt,...) _XBT_GNUC_PRINTF(2 |
print to allocated string (reimplemented when not provided by the system) | |
int int | vasprintf (char **ptr, const char *fmt, va_list ap) |
print to allocated string (reimplemented when not provided by the system) | |
char * | bvprintf (const char *fmt, va_list ap) |
print to allocated string | |
char * | bprintf (const char *fmt,...) _XBT_GNUC_PRINTF(1 |
print to allocated string | |
void | xbt_str_rtrim (char *s, const char *char_list) |
Strip whitespace (or other characters) from the end of a string. | |
void | xbt_str_ltrim (char *s, const char *char_list) |
Strip whitespace (or other characters) from the beginning of a string. | |
void | xbt_str_trim (char *s, const char *char_list) |
Strip whitespace (or other characters) from the end and the begining of a string. | |
xbt_dynar_t | xbt_str_split (const char *s, const char *sep) |
Splits a string into a dynar of strings. | |
xbt_dynar_t | xbt_str_split_quoted (const char *s) |
Splits a string into a dynar of strings, taking quotes into account. | |
xbt_dynar_t | xbt_str_split_str (const char *s, const char *sep) |
This functions splits a string after using another string as separator For example A!!B!!C splitted after !! will return the dynar {A,B,C}. | |
char * | xbt_str_join (xbt_dynar_t dynar, const char *sep) |
Join a set of strings as a single string. | |
void | xbt_str_subst (char *str, char from, char to, int amount) |
Substitutes a char for another in a string. | |
char * | xbt_str_varsubst (char *str, xbt_dict_t patterns) |
Replaces a set of variables by their values. | |
void | xbt_str_strip_spaces (char *) |
Replace double whitespaces (but no other characters) from the string. | |
char * | xbt_str_diff (char *a, char *b) |
Compute the unified diff of two strings. | |
char * | xbt_str_from_file (FILE *file) |
creates a new string containing what can be read on a fd |
String manipulation functions.
This module defines several string related functions. We redefine some quite classical functions on the platforms were they are not nativaly defined (such as getline() or asprintf()), while some other are a bit more exotic.
typedef char* xbt_string_t |
Classical alias to (char*).
This of almost no use, beside cosmetics and the GRAS parsing macro (see Automatic parsing of data descriptions).
int asprintf | ( | char ** | ptr, | |
const char * | fmt, | |||
... | ||||
) |
print to allocated string (reimplemented when not provided by the system)
The functions asprintf() and vasprintf() are analogues of sprintf() and vsprintf(), except that they allocate a string large enough to hold the output including the terminating null byte, and return a pointer to it via the first parameter. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed.
int int vasprintf | ( | char ** | ptr, | |
const char * | fmt, | |||
va_list | ap | |||
) |
print to allocated string (reimplemented when not provided by the system)
See asprintf()
char* bvprintf | ( | const char * | fmt, | |
va_list | ap | |||
) |
print to allocated string
Works just like vasprintf(), but returns a pointer to the newly created string, or aborts on error.
char* bprintf | ( | const char * | fmt, | |
... | ||||
) |
print to allocated string
Works just like asprintf(), but returns a pointer to the newly created string, or aborts on error.
void xbt_str_rtrim | ( | char * | s, | |
const char * | char_list | |||
) |
Strip whitespace (or other characters) from the end of a string.
Strips the whitespaces from the end of s. By default (when char_list=NULL), these characters get stripped:
s | The string to strip. Modified in place. | |
char_list | A string which contains the characters you want to strip. |
void xbt_str_ltrim | ( | char * | s, | |
const char * | char_list | |||
) |
Strip whitespace (or other characters) from the beginning of a string.
Strips the whitespaces from the begining of s. By default (when char_list=NULL), these characters get stripped:
s | The string to strip. Modified in place. | |
char_list | A string which contains the characters you want to strip. |
void xbt_str_trim | ( | char * | s, | |
const char * | char_list | |||
) |
Strip whitespace (or other characters) from the end and the begining of a string.
Strips the whitespaces from both the beginning and the end of s. By default (when char_list=NULL), these characters get stripped:
s | The string to strip. | |
char_list | A string which contains the characters you want to strip. |
xbt_dynar_t xbt_str_split | ( | const char * | s, | |
const char * | sep | |||
) |
Splits a string into a dynar of strings.
s,: | the string to split | |
sep,: | a string of all chars to consider as separator. |
By default (with sep=NULL), these characters are used as separator:
xbt_dynar_t xbt_str_split_quoted | ( | const char * | s | ) |
Splits a string into a dynar of strings, taking quotes into account.
It basically does the same argument separation than the shell, where white spaces can be escaped and where arguments are never splitted within a quote group. Several subsequent spaces are ignored (unless within quotes, of course).
xbt_dynar_t xbt_str_split_str | ( | const char * | s, | |
const char * | sep | |||
) |
This functions splits a string after using another string as separator For example A!!B!!C splitted after !! will return the dynar {A,B,C}.
void xbt_str_subst | ( | char * | str, | |
char | from, | |||
char | to, | |||
int | occurence | |||
) |
Substitutes a char for another in a string.
str | the string to modify | |
from | char to search | |
to | char to put instead | |
occurence | number of changes to do (=0 means all) |
char* xbt_str_varsubst | ( | char * | str, | |
xbt_dict_t | patterns | |||
) |
Replaces a set of variables by their values.
str | where to apply the change | |
patterns | what to change |
Check xbt_strbuff_varsubst() for more details, and remember that the string may be reallocated (moved) in the process.
void xbt_str_strip_spaces | ( | char * | s | ) |
Replace double whitespaces (but no other characters) from the string.
The function modifies the string so that each time that several spaces appear, they are replaced by a single space. It will only do so for spaces (ASCII 32, 0x20).
s | The string to strip. Modified in place. |
char* xbt_str_from_file | ( | FILE * | file | ) |
creates a new string containing what can be read on a fd
Back to the main Simgrid Documentation page |
Generated for SimGridAPI by
![]() |