From 78dfb6bcf5bd2e1d0cd537337fe78784d0b61508 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/beast/module/core/text/LexicalCast.h b/beast/module/core/text/LexicalCast.h index 26649dc02..c83fdda40 100644 --- a/beast/module/core/text/LexicalCast.h +++ b/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; + } }; //------------------------------------------------------------------------------