api documentation for ec_parse
[protos/libecoli.git] / include / ecoli_string.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 /**
6  * @defgroup string String
7  * @{
8  *
9  * @brief Helpers for strings manipulation.
10  */
11
12 #ifndef ECOLI_STRING_
13 #define ECOLI_STRING_
14
15 #include <stddef.h>
16 #include <stdbool.h>
17 #include <stdint.h>
18
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);
21
22 /* return 1 if 's' starts with 'beginning' */
23 int ec_str_startswith(const char *s, const char *beginning);
24
25 /* like asprintf, but use libecoli allocator */
26 int ec_asprintf(char **buf, const char *fmt, ...);
27
28 /* like vasprintf, but use libecoli allocator */
29 int ec_vasprintf(char **buf, const char *fmt, va_list ap);
30
31 /* return true if string is only composed of spaces (' ', '\n', ...) */
32 bool ec_str_is_space(const char *s);
33
34 /**
35  * Parse a string for a signed integer.
36  *
37  * @param str
38  *   The string to parse.
39  * @param base
40  *   The base (0 means "guess").
41  * @param min
42  *   The minimum allowed value.
43  * @param max
44  *   The maximum allowed value.
45  * @param val
46  *   The pointer to the value to be set on success.
47  * @return
48  *   On success, return 0. Else, return -1 and set errno.
49  */
50 int ec_str_parse_llint(const char *str, unsigned int base, int64_t min,
51                 int64_t max, int64_t *val);
52
53 /**
54  * Parse a string for an unsigned integer.
55  *
56  * @param str
57  *   The string to parse.
58  * @param base
59  *   The base (0 means "guess").
60  * @param min
61  *   The minimum allowed value.
62  * @param max
63  *   The maximum allowed value.
64  * @param val
65  *   The pointer to the value to be set on success.
66  * @return
67  *   On success, return 0. Else, return -1 and set errno.
68  */
69 int ec_str_parse_ullint(const char *str, unsigned int base, uint64_t min,
70                         uint64_t max, uint64_t *val);
71 #endif