diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/utils.c | 26 | ||||
-rw-r--r-- | src/common/utils.h | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c index 563d8ab..7065047 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -9,6 +9,7 @@ #define BC_STRING_CHUNK_SIZE 128 #include <string.h> +#include <strings.h> #include <stdarg.h> #include <stdbool.h> #include <stdlib.h> @@ -302,6 +303,31 @@ bc_str_find(const char *str, char c) } +bool +bc_str_to_bool(const char *str) +{ + if (str == NULL) + return false; + + if (0 == strcmp(str, "1")) + return true; + + if (0 == strcasecmp(str, "y")) + return true; + + if (0 == strcasecmp(str, "yes")) + return true; + + if (0 == strcasecmp(str, "true")) + return true; + + if (0 == strcasecmp(str, "on")) + return true; + + return false; +} + + void bc_strv_free(char **strv) { diff --git a/src/common/utils.h b/src/common/utils.h index 0f05c96..101a4b3 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -50,6 +50,7 @@ char* bc_str_strip(char *str); char** bc_str_split(const char *str, char c, size_t max_pieces); char* bc_str_replace(const char *str, const char search, const char *replace); char* bc_str_find(const char *str, char c); +bool bc_str_to_bool(const char *str); void bc_strv_free(char **strv); char* bc_strv_join(char **strv, const char *separator); size_t bc_strv_length(char **strv); |