bool Convert(const std::string& input, bool& b) { // we can't use iostream bool extraction operators as they don't // recognize all possible values in the table below (taken from // http://yaml.org/type/bool.html) static const struct { std::string truename, falsename; } names[] = { { "y", "n" }, { "yes", "no" }, { "true", "false" }, { "on", "off" }, }; if(!IsFlexibleCase(input)) return false; for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) { if(names[i].truename == tolower(input)) { b = true; return true; } if(names[i].falsename == tolower(input)) { b = false; return true; } } return false; }
bool convert<bool>::decode(const Node& node, bool& rhs) { if (!node.IsScalar()) return false; // we can't use iostream bool extraction operators as they don't // recognize all possible values in the table below (taken from // http://yaml.org/type/bool.html) static const struct { std::string truename, falsename; } names[] = {{"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"}, }; if (!IsFlexibleCase(node.Scalar())) return false; for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) { if (names[i].truename == tolower(node.Scalar())) { rhs = true; return true; } if (names[i].falsename == tolower(node.Scalar())) { rhs = false; return true; } } return false; }