Libecoli 0.11.1
Extensible COmmand LIne library
Loading...
Searching...
No Matches
String manipulation

Helpers for strings manipulation. More...

Functions

size_t ec_strcmp_count (const char *s1, const char *s2)
int ec_str_startswith (const char *s, const char *beginning)
bool ec_str_is_space (const char *s)
int ec_str_parse_llint (const char *str, unsigned int base, int64_t min, int64_t max, int64_t *val)
int ec_str_parse_ullint (const char *str, unsigned int base, uint64_t min, uint64_t max, uint64_t *val)
char * ec_str_quote (const char *str, char quote, bool force)
char * ec_str_wrap (const char *str, size_t max_cols, size_t start_off)

Detailed Description

Helpers for strings manipulation.

Function Documentation

◆ ec_strcmp_count()

size_t ec_strcmp_count ( const char * s1,
const char * s2 )

Count the number of identical characters at the beginning of two strings.

◆ ec_str_startswith()

int ec_str_startswith ( const char * s,
const char * beginning )

Return 1 if the string starts with the given prefix.

◆ ec_str_is_space()

bool ec_str_is_space ( const char * s)

Return true if the string contains only whitespace characters.

◆ ec_str_parse_llint()

int ec_str_parse_llint ( const char * str,
unsigned int base,
int64_t min,
int64_t max,
int64_t * val )

Parse a string for a signed integer.

Parameters
strThe string to parse.
baseThe base (0 means "guess").
minThe minimum allowed value.
maxThe maximum allowed value.
valThe pointer to the value to be set on success.
Returns
On success, return 0. Otherwise, return -1 and set errno.

◆ ec_str_parse_ullint()

int ec_str_parse_ullint ( const char * str,
unsigned int base,
uint64_t min,
uint64_t max,
uint64_t * val )

Parse a string for an unsigned integer.

Parameters
strThe string to parse.
baseThe base (0 means "guess").
minThe minimum allowed value.
maxThe maximum allowed value.
valThe pointer to the value to be set on success.
Returns
On success, return 0. Otherwise, return -1 and set errno.

◆ ec_str_quote()

char * ec_str_quote ( const char * str,
char quote,
bool force )

Quote a string, escaping nested quotes.

Parameters
strThe string to quote.
quoteThe quote character to use: usually " or ' but can be anything. If 0, select between " or ' automatically.
forceIf true, always add quotes, else add them only if the string contains spaces or quotes.
Returns
An allocated string, that must be freed by the caller using free().
Examples
parse-yaml/parse-yaml.c.

◆ ec_str_wrap()

char * ec_str_wrap ( const char * str,
size_t max_cols,
size_t start_off )

Wrap a text to a maximum number of columns.

Parameters
strThe input text.
max_colsThe maximum number of columns.
start_offThe number of already consumed columns on the first line, filled with padding in other lines.
Returns
An allocated string containing the wrapped text. It must be freed by the user using free().