mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added overload for operator [] for char * (non-const version)
This commit is contained in:
@@ -77,7 +77,9 @@ namespace YAML
|
|||||||
|
|
||||||
// specific to maps
|
// specific to maps
|
||||||
const Node *FindValue(const char *key) const;
|
const Node *FindValue(const char *key) const;
|
||||||
|
const Node *FindValue(char *key) const;
|
||||||
const Node& operator [] (const char *key) const;
|
const Node& operator [] (const char *key) const;
|
||||||
|
const Node& operator [] (char *key) const;
|
||||||
|
|
||||||
// for tags
|
// for tags
|
||||||
const std::string& Tag() const { return m_tag; }
|
const std::string& Tag() const { return m_tag; }
|
||||||
|
@@ -68,10 +68,18 @@ namespace YAML
|
|||||||
inline const Node *Node::FindValue(const char *key) const {
|
inline const Node *Node::FindValue(const char *key) const {
|
||||||
return FindValue(std::string(key));
|
return FindValue(std::string(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Node *Node::FindValue(char *key) const {
|
||||||
|
return FindValue(std::string(key));
|
||||||
|
}
|
||||||
|
|
||||||
inline const Node& Node::operator [] (const char *key) const {
|
inline const Node& Node::operator [] (const char *key) const {
|
||||||
return GetValue(std::string(key));
|
return GetValue(std::string(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Node& Node::operator [] (char *key) const {
|
||||||
|
return GetValue(std::string(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
@@ -864,6 +864,22 @@ namespace Test
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NonConstKey()
|
||||||
|
{
|
||||||
|
std::string input = "{a: 1}";
|
||||||
|
std::stringstream stream(input);
|
||||||
|
YAML::Parser parser(stream);
|
||||||
|
YAML::Node doc;
|
||||||
|
parser.GetNextDocument(doc);
|
||||||
|
|
||||||
|
std::vector<char> key(2);
|
||||||
|
key[0] = 'a';
|
||||||
|
key[1] = '\0';
|
||||||
|
if(doc[&key[0]].to<int>() != 1)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -1142,6 +1158,7 @@ namespace Test
|
|||||||
RunParserTest(&Parser::ExplicitNonSpecificSequenceTag, "explicit, non-specific sequence tag", passed, total);
|
RunParserTest(&Parser::ExplicitNonSpecificSequenceTag, "explicit, non-specific sequence tag", passed, total);
|
||||||
RunParserTest(&Parser::Infinity, "infinity", passed, total);
|
RunParserTest(&Parser::Infinity, "infinity", passed, total);
|
||||||
RunParserTest(&Parser::NaN, "NaN", passed, total);
|
RunParserTest(&Parser::NaN, "NaN", passed, total);
|
||||||
|
RunParserTest(&Parser::NonConstKey, "non const key", passed, total);
|
||||||
|
|
||||||
RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed, total);
|
RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed, total);
|
||||||
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed, total);
|
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed, total);
|
||||||
|
Reference in New Issue
Block a user