# HG changeset patch # User Matti Hamalainen # Date 1424286824 -7200 # Node ID 7638fa9d191f1994a28439d130a90b85de1ec1ee # Parent 28fd04f43a955e7377b326f51f2aea26f4c873fd Add th_get_boolean() function. diff -r 28fd04f43a95 -r 7638fa9d191f th_string.c --- a/th_string.c Wed Feb 18 13:28:29 2015 +0200 +++ b/th_string.c Wed Feb 18 21:13:44 2015 +0200 @@ -574,6 +574,28 @@ } +BOOL th_get_boolean(const char *str, BOOL *value) +{ + if (!th_strcasecmp(str, "yes") || + !th_strcasecmp(str, "true") || + !th_strcasecmp(str, "1")) + { + *value = TRUE; + return TRUE; + } + else + if (!th_strcasecmp(str, "no") || + !th_strcasecmp(str, "false") || + !th_strcasecmp(str, "0")) + { + *value = FALSE; + return TRUE; + } + else + return FALSE; +} + + static void th_pad(FILE *outFile, int count) { while (count--) diff -r 28fd04f43a95 -r 7638fa9d191f th_string.h --- a/th_string.h Wed Feb 18 13:28:29 2015 +0200 +++ b/th_string.h Wed Feb 18 21:13:44 2015 +0200 @@ -78,6 +78,7 @@ BOOL th_strcasematch(const char *, const char *); int th_get_hex_triplet(const char *); +BOOL th_get_boolean(const char *str, BOOL *value); void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width);