1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * @defgroup string String
9 * @brief Helpers for strings manipulation.
19 /* count the number of identical chars at the beginning of 2 strings */
20 size_t ec_strcmp_count(const char *s1, const char *s2);
22 /* return 1 if 's' starts with 'beginning' */
23 int ec_str_startswith(const char *s, const char *beginning);
25 /* like asprintf, but use libecoli allocator */
26 int ec_asprintf(char **buf, const char *fmt, ...);
28 /* like vasprintf, but use libecoli allocator */
29 int ec_vasprintf(char **buf, const char *fmt, va_list ap);
31 /* return true if string is only composed of spaces (' ', '\n', ...) */
32 bool ec_str_is_space(const char *s);
35 * Parse a string for a signed integer.
38 * The string to parse.
40 * The base (0 means "guess").
42 * The minimum allowed value.
44 * The maximum allowed value.
46 * The pointer to the value to be set on success.
48 * On success, return 0. Else, return -1 and set errno.
50 int ec_str_parse_llint(const char *str, unsigned int base, int64_t min,
51 int64_t max, int64_t *val);
54 * Parse a string for an unsigned integer.
57 * The string to parse.
59 * The base (0 means "guess").
61 * The minimum allowed value.
63 * The maximum allowed value.
65 * The pointer to the value to be set on success.
67 * On success, return 0. Else, return -1 and set errno.
69 int ec_str_parse_ullint(const char *str, unsigned int base, uint64_t min,
70 uint64_t max, uint64_t *val);