diff --git a/include/node.h b/include/node.h index f970f4f..ebfcdd9 100644 --- a/include/node.h +++ b/include/node.h @@ -40,6 +40,7 @@ namespace YAML bool Read(float& f) const; bool Read(double& d) const; bool Read(char& c) const; + bool Read(bool& b) const; // so you can specialize for other values template diff --git a/src/content.h b/src/content.h index 9561a4b..33e0d7d 100644 --- a/src/content.h +++ b/src/content.h @@ -43,6 +43,7 @@ namespace YAML virtual bool Read(float& f) const { return false; } virtual bool Read(double& d) const { return false; } virtual bool Read(char& c) const { return false; } + virtual bool Read(bool& b) const { return false; } // ordering virtual int Compare(Content *pContent) { return 0; } diff --git a/src/node.cpp b/src/node.cpp index df79ad4..48b81ec 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -293,6 +293,14 @@ namespace YAML return m_pContent->Read(c); } + bool Node::Read(bool& b) const + { + if(!m_pContent) + return false; + + return m_pContent->Read(b); + } + std::ostream& operator << (std::ostream& out, const Node& node) { node.Write(out, 0, false, false); diff --git a/src/scalar.cpp b/src/scalar.cpp index 00985cb..03dfa4b 100644 --- a/src/scalar.cpp +++ b/src/scalar.cpp @@ -5,6 +5,7 @@ #include "exceptions.h" #include "node.h" #include +#include namespace YAML { @@ -86,6 +87,81 @@ namespace YAML return !data.fail(); } + namespace + { + // we're not gonna mess with the mess that is all the isupper/etc. functions + bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; } + bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; } + char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; } + + std::string tolower(const std::string& str) + { + std::string s(str); + std::transform(s.begin(), s.end(), s.begin(), ToLower); + return s; + } + + template + bool IsEntirely(const std::string& str, T func) + { + for(unsigned i=0;iCompare(this); diff --git a/src/scalar.h b/src/scalar.h index 3dab558..4ccf932 100644 --- a/src/scalar.h +++ b/src/scalar.h @@ -24,6 +24,7 @@ namespace YAML virtual bool Read(float& f) const; virtual bool Read(double& d) const; virtual bool Read(char& c) const; + virtual bool Read(bool& b) const; // ordering virtual int Compare(Content *pContent); diff --git a/yaml-reader.vcproj b/yaml-reader.vcproj index 0d7cdda..f2522d1 100644 --- a/yaml-reader.vcproj +++ b/yaml-reader.vcproj @@ -58,6 +58,7 @@ /> #include -#ifdef _MSC_VER -#ifdef _DEBUG -#pragma comment(lib, "yamlcppd.lib") -#else -#pragma comment(lib, "yamlcpp.lib") -#endif // _DEBUG -#endif // _MSC_VER - void run() { std::ifstream fin("tests/test.yaml"); try { YAML::Parser parser(fin); - parser.PrintTokens(std::cout); + YAML::Node doc; + parser.GetNextDocument(doc); + for(unsigned i=0;i> value; + std::cout << (value ? "true" : "false") << "\n"; + } } catch(YAML::Exception&) { std::cout << "Error parsing the yaml!\n"; } diff --git a/yaml-reader/tests/test.yaml b/yaml-reader/tests/test.yaml index 6938c5c..34499d1 100644 --- a/yaml-reader/tests/test.yaml +++ b/yaml-reader/tests/test.yaml @@ -1 +1,7 @@ -bad YAML: [ \ No newline at end of file +- true +- n +- Off +- YES +- on +- FALSE +- FaLse