SimGrid  3.18
Versatile Simulation of Distributed Systems

Detailed Description

String manipulation functions.

This module defines several string related functions. Looking at the diversity of string manipulation functions that are provided, you can see that several SimGrid core developers actually like Perl.

Macros

#define XBT_DJB2_HASH_FUNCTION
 

Functions

char * bvprintf (const char *fmt, va_list ap)
 print to allocated string More...
 
char * bprintf (const char *fmt,...) XBT_ATTRIB_PRINTF(1
 print to allocated string More...
 
xbt_dynar_t xbt_str_split (const char *s, const char *sep)
 Splits a string into a dynar of strings. More...
 
xbt_dynar_t xbt_str_split_quoted (const char *s)
 Splits a string into a dynar of strings, taking quotes into account. More...
 
xbt_dynar_t xbt_str_split_quoted_in_place (char *s)
 Just like xbt_str_split_quoted (Splits a string into a dynar of strings), but without memory allocation. More...
 
char * xbt_str_join_array (const char *const *strs, const char *sep)
 Join a set of strings as a single string. More...
 
long int xbt_str_parse_int (const char *str, const char *error_msg)
 Parse an integer out of a string, or raise an error. More...
 
double xbt_str_parse_double (const char *str, const char *error_msg)
 Parse a double out of a string, or raise an error. More...
 
static unsigned int xbt_str_hash_ext (const char *str, int str_len)
 Returns the hash code of a string. More...
 
static unsigned int xbt_str_hash (const char *str)
 Returns the hash code of a string. More...
 
std::string simgrid::xbt::string_printf (const char *fmt,...)
 Create a C++ string from a C-style format. More...
 
std::string simgrid::xbt::string_vprintf (const char *fmt, va_list ap)
 Create a C++ string from a C-style format. More...
 

Macro Definition Documentation

◆ XBT_DJB2_HASH_FUNCTION

#define XBT_DJB2_HASH_FUNCTION

Function Documentation

◆ bvprintf()

char* bvprintf ( const char *  fmt,
va_list  ap 
)

print to allocated string

Similar to vasprintf(), but returns a pointer to the newly created string (or aborts on error).

◆ bprintf()

char* bprintf ( const char *  fmt,
  ... 
)

print to allocated string

Similar to asprintf(), but returns a pointer to the newly created string (or aborts on error).

Examples:
examples/s4u/energy-link/s4u-energy-link.cpp.

◆ xbt_str_split()

xbt_dynar_t xbt_str_split ( const char *  s,
const char *  sep 
)

Splits a string into a dynar of strings.

Parameters
sthe string to split
sepa string of all chars to consider as separator.

By default (with sep=nullptr), these characters are used as separator:

  • " " (ASCII 32 (0x20)) space.
  • "\t" (ASCII 9 (0x09)) tab.
  • "\n" (ASCII 10 (0x0A)) line feed.
  • "\r" (ASCII 13 (0x0D)) carriage return.
  • "\0" (ASCII 0 (0x00)) nullptr.
  • "\x0B" (ASCII 11 (0x0B)) vertical tab.

◆ xbt_str_split_quoted()

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 split within a quote group. Several subsequent spaces are ignored (unless within quotes, of course). You may want to trim the input string, if you want to avoid empty entries

◆ xbt_str_split_quoted_in_place()

xbt_dynar_t xbt_str_split_quoted_in_place ( char *  s)

Just like xbt_str_split_quoted (Splits a string into a dynar of strings), but without memory allocation.

The string passed as argument must be writable (not const) The elements of the dynar are just parts of the string passed as argument. So if you don't store that argument elsewhere, you should free it in addition to freeing the dynar. This can be done by simply freeing the first argument of the dynar: free(xbt_dynar_get_ptr(dynar,0));

Actually this function puts a bunch of \0 in the memory area you passed as argument to separate the elements, and pushes the address of each chunk in the resulting dynar. Yes, that's uneven. Yes, that's gory. But that's efficient.

◆ xbt_str_join_array()

char* xbt_str_join_array ( const char *const *  strs,
const char *  sep 
)

Join a set of strings as a single string.

The parameter must be a nullptr-terminated array of chars, just like xbt_dynar_to_array() produces

Examples:
examples/s4u/replay-comm/s4u-replay-comm.cpp, and examples/s4u/replay-storage/s4u-replay-storage.cpp.

◆ xbt_str_parse_int()

long int xbt_str_parse_int ( const char *  str,
const char *  error_msg 
)

Parse an integer out of a string, or raise an error.

The str is passed as argument to your error_msg, as follows:

THROWF(arg_error, 0, error_msg, str); 
Examples:
examples/msg/app-masterworker/app-masterworker.c, examples/msg/network-ns3/network-ns3.c, examples/msg/trace-categories/trace-categories.c, examples/msg/trace-masterworker/trace-masterworker.c, and examples/s4u/dht-chord/s4u-dht-chord.cpp.

◆ xbt_str_parse_double()

double xbt_str_parse_double ( const char *  str,
const char *  error_msg 
)

Parse a double out of a string, or raise an error.

The str is passed as argument to your error_msg, as follows:

THROWF(arg_error, 0, error_msg, str); 
Examples:
examples/msg/app-masterworker/app-masterworker.c, examples/msg/network-ns3/network-ns3.c, and examples/msg/trace-masterworker/trace-masterworker.c.

◆ xbt_str_hash_ext()

static unsigned int xbt_str_hash_ext ( const char *  str,
int  str_len 
)
inlinestatic

Returns the hash code of a string.

◆ xbt_str_hash()

static unsigned int xbt_str_hash ( const char *  str)
inlinestatic

Returns the hash code of a string.

◆ string_printf()

std::string simgrid::xbt::string_printf ( const char *  fmt,
  ... 
)

Create a C++ string from a C-style format.

◆ string_vprintf()

std::string simgrid::xbt::string_vprintf ( const char *  fmt,
va_list  ap 
)

Create a C++ string from a C-style format.