From ad466f86cc0497f6a5ba0e2540e399c32c0b96ba Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 25 Jun 2017 11:28:29 +0200 Subject: [PATCH] strutil: Assume bool is true when no value is specified Adjust the string to boolean conversion for an edge case. Accept empty text (either NULL or empty strings) to mean true instead of false. This behaviour is more useful from the user's point of view, when the option's name alone will enable a feature, and an explicit "option=yes" specification is not strictly necessary. All calling applications in mainline already implemented this semantics. --- src/strutil.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/strutil.c b/src/strutil.c index 72378d4a..38270893 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -555,8 +555,13 @@ SR_API uint64_t sr_parse_timestring(const char *timestring) /** @since 0.1.0 */ SR_API gboolean sr_parse_boolstring(const char *boolstr) { - if (!boolstr) - return FALSE; + /* + * Complete absence of an input spec is assumed to mean TRUE, + * as in command line option strings like this: + * ...:samplerate=100k:header:numchannels=4:... + */ + if (!boolstr || !*boolstr) + return TRUE; if (!g_ascii_strncasecmp(boolstr, "true", 4) || !g_ascii_strncasecmp(boolstr, "yes", 3) ||