From 8e91ce67c5f134c2ad1d1b2102b12a25db0e91a1 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Thu, 25 Sep 2014 16:01:41 -0700 Subject: [PATCH] Allow beast::lexicalCast to parse 'true' & 'false' into a bool --- .../beast/module/core/text/LexicalCast.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/beast/beast/module/core/text/LexicalCast.h b/src/beast/beast/module/core/text/LexicalCast.h index 26649dc02..c83fdda40 100644 --- a/src/beast/beast/module/core/text/LexicalCast.h +++ b/src/beast/beast/module/core/text/LexicalCast.h @@ -178,6 +178,27 @@ struct LexicalCast { return parseSigned (out, std::begin(in), std::end(in)); } + + bool + operator () (bool& out, std::string in) const + { + // Convert the input to lowercase + std::transform(in.begin (), in.end (), in.begin (), ::tolower); + + if (in == "1" || in == "true") + { + out = true; + return true; + } + + if (in == "0" || in == "false") + { + out = false; + return true; + } + + return false; + } }; //------------------------------------------------------------------------------