2018-02-08 20:47:31 +08:00
|
|
|
#ifndef STRUTIL_H
|
|
|
|
#define STRUTIL_H
|
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
// like strncpy, except:
|
|
|
|
// - it copies at most n-1 chars
|
|
|
|
// - the dest string is nul-terminated
|
|
|
|
// - it does not write useless bytes if strlen(src) < n
|
|
|
|
// - it returns the number of chars actually written (max n-1) if src has
|
|
|
|
// been copied completely, or n if src has been truncated
|
|
|
|
size_t xstrncpy(char *dest, const char *src, size_t n);
|
|
|
|
|
|
|
|
// join tokens by sep into dst
|
|
|
|
// returns the number of chars actually written (max n-1) if no trucation
|
|
|
|
// occurred, or n if truncated
|
2017-12-14 18:38:44 +08:00
|
|
|
size_t xstrjoin(char *dst, const char *const tokens[], char sep, size_t n);
|
2018-02-08 20:47:31 +08:00
|
|
|
|
2018-10-05 02:47:53 +08:00
|
|
|
// quote a string
|
|
|
|
// returns the new allocated string, to be freed by the caller
|
|
|
|
char *strquote(const char *src);
|
|
|
|
|
2019-02-10 19:53:03 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
// convert a UTF-8 string to a wchar_t string
|
|
|
|
// returns the new allocated string, to be freed by the caller
|
|
|
|
wchar_t *utf8_to_wide_char(const char *utf8);
|
|
|
|
#endif
|
|
|
|
|
2018-02-08 20:47:31 +08:00
|
|
|
#endif
|