libusual  0.1
Defines | Functions
usual/string.h File Reference

Theme include for strings. More...

Defines

#define strerror_r(a, b, c)
 Compat: Provide GNU-style API: const char *strerror_r(int e, char *dst, size_t dstlen)

Functions

bool parse_word_list (const char *s, str_cb cb_func, void *cb_arg)
 Parse comma-separated elements from string and launch callback for each of them.
size_t strlcpy (char *dst, const char *src, size_t n)
 Compat: Safely copy string to fixed-length buffer.
size_t strlcat (char *dst, const char *src, size_t n)
 Compat: Safely append string to fixed-length buffer.
void * memrchr (const void *s, int c, size_t n)
 Compat: find byte in reverse direction.
void * memmem (const void *s, size_t slen, const void *q, size_t qlen)
 Compat: find memory area.
void * mempbrk (const void *data, size_t dlen, const void *find, size_t flen)
 Return position to first byte that is in 'find'.
size_t memcspn (const void *data, size_t dlen, const void *reject, size_t rlen)
 Return number of bytes where none are in reject.
size_t memspn (const void *data, size_t dlen, const void *accept, size_t alen)
 Return number of bytes where all are in accept.
const char * basename (const char *path)
 Compat: Return pointer to last non-path element.
const char * dirname (const char *path)
 Compat: Return directory part of pathname.
void explicit_bzero (void *buf, size_t len)
 Definitely clear memory.
double strtod_dot (const char *s, char **tokend)
 strtod() that uses '.
ssize_t dtostr_dot (char *buf, size_t buflen, double val)
 Convert double to string with '.
long long strtonum (const char *s, long long minval, long long maxval, const char **errstr_p)
 Convert string to integer, check limits.
char * strsep (char **stringp, const char *delim)
 Return next token from string.

List of strings.

typedef bool(* str_cb )(void *arg, const char *s)
 Callback signature.
struct StrList * strlist_new (CxMem *ca)
 Allocate new string list.
void strlist_free (struct StrList *slist)
 Free string string.
bool strlist_empty (struct StrList *slist)
 Check if empty.
bool strlist_append (struct StrList *slist, const char *str)
 Append copy of string.
bool strlist_append_ref (struct StrList *slist, const char *str)
 Append reference, strlist now owns it.
bool strlist_foreach (const struct StrList *slist, str_cb cb_func, void *cb_arg)
 Call function on each element.
const char * strlist_pop (struct StrList *slist)
 Remove and return first element.

Detailed Description

Theme include for strings.


Define Documentation

#define strerror_r (   a,
  b,
 
)

Compat: Provide GNU-style API: const char *strerror_r(int e, char *dst, size_t dstlen)


Typedef Documentation

typedef bool(* str_cb)(void *arg, const char *s)

Callback signature.


Function Documentation

struct StrList* strlist_new ( CxMem ca) [read]

Allocate new string list.

void strlist_free ( struct StrList *  slist)

Free string string.

bool strlist_empty ( struct StrList *  slist)

Check if empty.

bool strlist_append ( struct StrList *  slist,
const char *  str 
)

Append copy of string.

bool strlist_append_ref ( struct StrList *  slist,
const char *  str 
)

Append reference, strlist now owns it.

bool strlist_foreach ( const struct StrList *  slist,
str_cb  cb_func,
void *  cb_arg 
)

Call function on each element.

const char* strlist_pop ( struct StrList *  slist)

Remove and return first element.

bool parse_word_list ( const char *  s,
str_cb  cb_func,
void *  cb_arg 
)

Parse comma-separated elements from string and launch callback for each of them.

size_t strlcpy ( char *  dst,
const char *  src,
size_t  n 
)

Compat: Safely copy string to fixed-length buffer.

size_t strlcat ( char *  dst,
const char *  src,
size_t  n 
)

Compat: Safely append string to fixed-length buffer.

void* memrchr ( const void *  s,
int  c,
size_t  n 
)

Compat: find byte in reverse direction.

void* memmem ( const void *  s,
size_t  slen,
const void *  q,
size_t  qlen 
)

Compat: find memory area.

void* mempbrk ( const void *  data,
size_t  dlen,
const void *  find,
size_t  flen 
)

Return position to first byte that is in 'find'.

size_t memcspn ( const void *  data,
size_t  dlen,
const void *  reject,
size_t  rlen 
)

Return number of bytes where none are in reject.

size_t memspn ( const void *  data,
size_t  dlen,
const void *  accept,
size_t  alen 
)

Return number of bytes where all are in accept.

const char* basename ( const char *  path)

Compat: Return pointer to last non-path element.

Never modifies path, returns either pointer inside path or static buffer.

const char* dirname ( const char *  path)

Compat: Return directory part of pathname.

Never modifies path, returns either pointer inside path or static buffer.

void explicit_bzero ( void *  buf,
size_t  len 
)

Definitely clear memory.

double strtod_dot ( const char *  s,
char **  tokend 
)

strtod() that uses '.

' as decimal separator

ssize_t dtostr_dot ( char *  buf,
size_t  buflen,
double  val 
)

Convert double to string with '.

' as decimal separator

long long strtonum ( const char *  s,
long long  minval,
long long  maxval,
const char **  errstr_p 
)

Convert string to integer, check limits.

Accepts only decimal numbers, no octal or hex. Allows leading whitespace, but not tailing.

On success, returns value that is minval <= res <= maxval. If errstr_p is given it stores NULL there. Keeps old errno value.

On error, returns 0, sets errno, and if errstr_p is given, stores error reason there.

char* strsep ( char **  stringp,
const char *  delim 
)

Return next token from string.

Tokens are separated by delim chars Modifies string in-place.