fmt: add string to bool function
MODIFY
include/re_fmt.h
include/re_fmt.h
@@ -105,6 +105,7 @@ uint8_t ch_hex(char ch);
/* String functions */
+int str_bool(bool *val, const char *str);
int str_hex(uint8_t *hex, size_t len, const char *str);
void str_ncpy(char *dst, const char *src, size_t n);
int str_dup(char **dst, const char *src);

MODIFY
src/fmt/str.c
src/fmt/str.c
@@ -140,3 +140,56 @@ size_t str_len(const char *s)
{
return s ? strlen(s) : 0;
}
+
+
+/**
+ * Convert various possible boolean strings to a bool
+ *
+ * @param val Pointer to bool for returned value
+ * @param str String to be converted
+ *
+ * @return int 0 if success, otherwise errorcode
+ */
+int str_bool(bool *val, const char *str)
+{
+ int err = 0;
+
+ if (!val || !str_isset(str))
+ return EINVAL;
+
+ if (!str_casecmp(str, "0")) {
+ *val = false;
+ }
+ else if (!str_casecmp(str, "1")) {
+ *val = true;
+ }
+ else if (!str_casecmp(str, "false")) {
+ *val = false;
+ }
+ else if (!str_casecmp(str, "true")) {
+ *val = true;
+ }
+ else if (!str_casecmp(str, "disable")) {
+ *val = false;
+ }
+ else if (!str_casecmp(str, "enable")) {
+ *val = true;
+ }
+ else if (!str_casecmp(str, "off")) {
+ *val = false;
+ }
+ else if (!str_casecmp(str, "on")) {
+ *val = true;
+ }
+ else if (!str_casecmp(str, "no")) {
+ *val = false;
+ }
+ else if (!str_casecmp(str, "yes")) {
+ *val = true;
+ }
+ else {
+ err = EINVAL;
+ }
+
+ return err;
+}

fmt: add string to bool function