From 252c20d0688a84d59227c9934ade5085dd63d291 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Wed, 19 Mar 2025 13:56:24 +0800 Subject: [PATCH] Add parse bool --- str_util.cpp | 9 +++++++++ str_util.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/str_util.cpp b/str_util.cpp index ede0d9c..dc10528 100644 --- a/str_util.cpp +++ b/str_util.cpp @@ -131,3 +131,12 @@ std::string str_util::str_join(std::list input, std::string pattern } return output; } + +bool str_util::parse_bool(std::string input) { + input = tolower(input); + if (input == "true" || input == "yes" || input == "on" || input == "1") { + return true; + } else { + return false; + } +} diff --git a/str_util.h b/str_util.h index b798767..ba67887 100644 --- a/str_util.h +++ b/str_util.h @@ -79,5 +79,11 @@ namespace str_util { * @return Result */ std::string str_join(std::list input, std::string pattern); + /** + * @brief Parse a string to a boolean + * @param input Input string + * @return Result + */ + bool parse_bool(std::string input); } #endif