diff --git a/src/content.h b/src/content.h index 33e0d7d..f689cd6 100644 --- a/src/content.h +++ b/src/content.h @@ -25,31 +25,31 @@ namespace YAML virtual void Parse(Scanner *pScanner, const ParserState& state) = 0; virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) = 0; - virtual bool GetBegin(std::vector ::const_iterator& it) const { return false; } - virtual bool GetBegin(std::map ::const_iterator& it) const { return false; } - virtual bool GetEnd(std::vector ::const_iterator& it) const { return false; } - virtual bool GetEnd(std::map ::const_iterator& it) const { return false; } - virtual Node *GetNode(unsigned i) const { return 0; } + virtual bool GetBegin(std::vector ::const_iterator&) const { return false; } + virtual bool GetBegin(std::map ::const_iterator&) const { return false; } + virtual bool GetEnd(std::vector ::const_iterator&) const { return false; } + virtual bool GetEnd(std::map ::const_iterator&) const { return false; } + virtual Node *GetNode(unsigned) const { return 0; } virtual unsigned GetSize() const { return 0; } virtual bool IsScalar() const { return false; } virtual bool IsMap() const { return false; } virtual bool IsSequence() const { return false; } // extraction - virtual bool Read(std::string& s) const { return false; } - virtual bool Read(int& i) const { return false; } - virtual bool Read(unsigned& u) const { return false; } - virtual bool Read(long& l) const { return false; } - 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; } + virtual bool Read(std::string&) const { return false; } + virtual bool Read(int&) const { return false; } + virtual bool Read(unsigned&) const { return false; } + virtual bool Read(long&) const { return false; } + virtual bool Read(float&) const { return false; } + virtual bool Read(double&) const { return false; } + virtual bool Read(char&) const { return false; } + virtual bool Read(bool&) const { return false; } // ordering - virtual int Compare(Content *pContent) { return 0; } - virtual int Compare(Scalar *pScalar) { return 0; } - virtual int Compare(Sequence *pSeq) { return 0; } - virtual int Compare(Map *pMap) { return 0; } + virtual int Compare(Content *) { return 0; } + virtual int Compare(Scalar *) { return 0; } + virtual int Compare(Sequence *) { return 0; } + virtual int Compare(Map *) { return 0; } protected: }; diff --git a/src/map.h b/src/map.h index 0f7c3bf..be722f4 100644 --- a/src/map.h +++ b/src/map.h @@ -23,8 +23,8 @@ namespace YAML // ordering virtual int Compare(Content *pContent); - virtual int Compare(Scalar *pScalar) { return 1; } - virtual int Compare(Sequence *pSeq) { return 1; } + virtual int Compare(Scalar *) { return 1; } + virtual int Compare(Sequence *) { return 1; } virtual int Compare(Map *pMap); private: diff --git a/src/node.cpp b/src/node.cpp index cce1d7e..8c86882 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -37,6 +37,10 @@ namespace YAML { Clear(); + // an empty node *is* a possibility + if(pScanner->empty()) + return; + // save location m_line = pScanner->peek().line; m_column = pScanner->peek().column; diff --git a/src/regex.cpp b/src/regex.cpp index 3982301..4ffd711 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -90,7 +90,7 @@ namespace YAML return Match(str) >= 0; } - bool RegEx::Matches(const char *buffer) const + bool RegEx::Matches(const Buffer& buffer) const { return Match(buffer) >= 0; } @@ -109,7 +109,7 @@ namespace YAML int RegEx::Match(const std::string& str) const { if(!m_pOp) - return 0; + return str.empty() ? 0 : -1; // the empty regex only is successful on the empty string return m_pOp->Match(str, *this); } @@ -121,15 +121,12 @@ namespace YAML } // Match - // . The stream version does the same thing as the string version; - // REMEMBER that we only match from the start of the stream! - // . Note: the istream is not a const reference, but we guarantee - // that the pointer will be in the same spot, and we'll clear its - // flags before we end. - int RegEx::Match(const char *buffer) const + // . The buffer version does the same thing as the string version; + // REMEMBER that we only match from the start of the buffer! + int RegEx::Match(const Buffer& buffer) const { if(!m_pOp) - return -1; + return !buffer ? 0 : -1; // see above return m_pOp->Match(buffer, *this); } @@ -177,9 +174,9 @@ namespace YAML } - int RegEx::MatchOperator::Match(const char *buffer, const RegEx& regex) const + int RegEx::MatchOperator::Match(const Buffer& buffer, const RegEx& regex) const { - if(buffer[0] != regex.m_a) + if(!buffer || buffer[0] != regex.m_a) return -1; return 1; } @@ -192,9 +189,9 @@ namespace YAML return 1; } - int RegEx::RangeOperator::Match(const char *buffer, const RegEx& regex) const + int RegEx::RangeOperator::Match(const Buffer& buffer, const RegEx& regex) const { - if(regex.m_a > buffer[0] || regex.m_z < buffer[0]) + if(!buffer || regex.m_a > buffer[0] || regex.m_z < buffer[0]) return -1; return 1; } @@ -210,7 +207,7 @@ namespace YAML return -1; } - int RegEx::OrOperator::Match(const char *buffer, const RegEx& regex) const + int RegEx::OrOperator::Match(const Buffer& buffer, const RegEx& regex) const { for(unsigned i=0;ipubseekoff(0, std::ios::end, std::ios::in); pBuf->pubseekpos(0, std::ios::in); buffer = new char[size]; - pBuf->sgetn(buffer, size); + size = pBuf->sgetn(buffer, size); // Note: when reading a Windows CR/LF file, + // pubseekoff() counts CR/LF as two characters, + // setgn() reads CR/LF as a single LF character! } Stream::~Stream() diff --git a/src/stream.h b/src/stream.h index 5f12f79..d35f3fe 100644 --- a/src/stream.h +++ b/src/stream.h @@ -5,6 +5,19 @@ namespace YAML { + // a simple buffer wrapper that knows how big it is + struct Buffer { + Buffer(char *b, int s): buffer(b), size(s) {} + + operator bool() const { return size > 0; } + bool operator !() const { return !static_cast (*this); } + char operator [] (int i) const { return buffer[i]; } + const Buffer operator + (int offset) const { return Buffer(buffer + offset, size - offset); } + + char *buffer; + int size; + }; + class Stream { public: @@ -14,7 +27,7 @@ namespace YAML operator bool() const; bool operator !() const { return !static_cast (*this); } - const char *current() const { return buffer + pos; } + const Buffer current() const { return Buffer(buffer + pos, size - pos); } char peek(); char get(); std::string get(int n); diff --git a/yaml-reader/tests/test.yaml b/yaml-reader/tests/test.yaml index 32d3ff8..00e30f5 100644 --- a/yaml-reader/tests/test.yaml +++ b/yaml-reader/tests/test.yaml @@ -1 +1,2 @@ -- test +--- +... \ No newline at end of file diff --git a/yamlcpp.vcproj b/yamlcpp.vcproj index ee5923c..58a1736 100644 --- a/yamlcpp.vcproj +++ b/yamlcpp.vcproj @@ -47,7 +47,7 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" DebugInformationFormat="3" />