Merge pull request #1 from toep/u8_parse_fix

Fixed parsing of u8 (unsigned char)
This commit is contained in:
Thomas Pedersen 2020-01-17 09:12:19 -08:00 committed by GitHub
commit 0e0788d764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -68,6 +68,21 @@ struct convert<std::string> {
}
};
template <>
struct convert<unsigned char> {
static Node encode(const unsigned char& rhs) { Node n; n = rhs; return n; }
static bool decode(const Node& node, unsigned char& rhs) {
if (node.Type() != NodeType::Scalar) {
return false;
}
int t = stoi(node.Scalar());
if(t < 0 || t > 255) return false;
rhs = (unsigned char)t;
return true;
}
};
// C-strings can only be encoded
template <>
struct convert<const char*> {
@ -146,7 +161,7 @@ YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(signed char);
YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char);
//YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float);
YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double);

View File

@ -116,6 +116,7 @@ struct as_if<std::string, S> {
}
};
template <typename T>
struct as_if<T, void> {
explicit as_if(const Node& node_) : node(node_) {}