Make separator configurable for parsing integers

The separator was hardcoded to ':'. This will allow to reuse the
function to parse sizes as WIDTHxHEIGHT.
This commit is contained in:
Romain Vimont 2023-08-23 20:22:39 +02:00
parent bd3c94240d
commit 8b487bf52e

View File

@ -1211,9 +1211,9 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
}
static size_t
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
long max, const char *name) {
size_t count = sc_str_parse_integers(s, ':', max_items, out);
parse_integers_arg(const char *s, const char sep, size_t max_items, long *out,
long min, long max, const char *name) {
size_t count = sc_str_parse_integers(s, sep, max_items, out);
if (!count) {
LOGE("Could not parse %s: %s", name, s);
return 0;
@ -1369,7 +1369,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
static bool
parse_port_range(const char *s, struct sc_port_range *port_range) {
long values[2];
size_t count = parse_integers_arg(s, 2, values, 0, 0xFFFF, "port");
size_t count = parse_integers_arg(s, ':', 2, values, 0, 0xFFFF, "port");
if (!count) {
return false;
}