Add util function to parse a list of integers

This will help parsing arguments like '1234:5678' into a list of
integers.
This commit is contained in:
Romain Vimont
2019-12-09 14:32:59 +01:00
parent ca0031cbde
commit 2a3a9d4ea9
3 changed files with 84 additions and 0 deletions

View File

@@ -31,6 +31,11 @@ strquote(const char *src);
bool
parse_integer(const char *s, long *out);
// parse s as integers separated by sep (for example '1234:2000')
// returns the number of integers on success, 0 on failure
size_t
parse_integers(const char *s, const char sep, size_t max_items, long *out);
// parse s as an integer into value
// like parse_integer(), but accept 'k'/'K' (x1000) and 'm'/'M' (x1000000) as
// suffix