Mercurial > hg > th-libs
changeset 167:7638fa9d191f
Add th_get_boolean() function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 18 Feb 2015 21:13:44 +0200 |
parents | 28fd04f43a95 |
children | a2cd862315c5 |
files | th_string.c th_string.h |
diffstat | 2 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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--)
--- 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);