basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to streq()
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
2d4f8cf467
commit
ddd6a22a0f
+16
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user