basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to streq()

This commit is contained in:
Lennart Poettering
2020-05-04 10:11:19 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 2d4f8cf467
commit ddd6a22a0f
5 changed files with 60 additions and 19 deletions
+16 -2
View File
@@ -18,14 +18,28 @@
#include "process-util.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
int parse_boolean(const char *v) {
if (!v)
return -EINVAL;
if (streq(v, "1") || strcaseeq(v, "yes") || strcaseeq(v, "y") || strcaseeq(v, "true") || strcaseeq(v, "t") || strcaseeq(v, "on"))
if (STRCASE_IN_SET(v,
"1",
"yes",
"y",
"true",
"t",
"on"))
return 1;
else if (streq(v, "0") || strcaseeq(v, "no") || strcaseeq(v, "n") || strcaseeq(v, "false") || strcaseeq(v, "f") || strcaseeq(v, "off"))
if (STRCASE_IN_SET(v,
"0",
"no",
"n",
"false",
"f",
"off"))
return 0;
return -EINVAL;