mirror of
https://github.com/loot/yaml-cpp.git
synced 2026-07-27 14:13:42 -07:00
Added CMake scripts for other platforms\nFixed some bugs that gcc complained about\nFixed CR/LF vs LF bug
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
project (YAML_CPP)
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
add_subdirectory (src)
|
||||||
|
add_subdirectory (yaml-reader)
|
||||||
@@ -8,3 +8,4 @@
|
|||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
|
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace YAML
|
|||||||
public:
|
public:
|
||||||
ParserException(int line_, int column_, const std::string& msg_)
|
ParserException(int line_, int column_, const std::string& msg_)
|
||||||
: line(line_), column(column_), msg(msg_) {}
|
: line(line_), column(column_), msg(msg_) {}
|
||||||
|
virtual ~ParserException() throw () {}
|
||||||
|
|
||||||
int line, column;
|
int line, column;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|||||||
@@ -5,3 +5,4 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "iterator.h"
|
#include "iterator.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
set(FILES content.cpp iterator.cpp node.cpp parserstate.cpp
|
||||||
|
scalar.cpp scanscalar.cpp sequence.cpp stream.cpp
|
||||||
|
exp.cpp map.cpp parser.cpp regex.cpp scanner.cpp
|
||||||
|
scantoken.cpp simplekey.cpp)
|
||||||
|
|
||||||
|
include_directories(${YAML_CPP_SOURCE_DIR}/include)
|
||||||
|
add_library(yaml-cpp ${FILES})
|
||||||
+3
-3
@@ -16,8 +16,6 @@ namespace YAML
|
|||||||
class Sequence;
|
class Sequence;
|
||||||
class Map;
|
class Map;
|
||||||
|
|
||||||
enum CONTENT_TYPE;
|
|
||||||
|
|
||||||
class Content
|
class Content
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +31,9 @@ namespace YAML
|
|||||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
||||||
virtual Node *GetNode(unsigned i) const { return 0; }
|
virtual Node *GetNode(unsigned i) const { return 0; }
|
||||||
virtual unsigned GetSize() const { return 0; }
|
virtual unsigned GetSize() const { return 0; }
|
||||||
virtual CONTENT_TYPE GetType() const = 0;
|
virtual bool IsScalar() const { return false; }
|
||||||
|
virtual bool IsMap() const { return false; }
|
||||||
|
virtual bool IsSequence() const { return false; }
|
||||||
|
|
||||||
// extraction
|
// extraction
|
||||||
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
// misc
|
// misc
|
||||||
const RegEx Blank = RegEx(' ') || RegEx('\t');
|
const RegEx Blank = RegEx(' ') || RegEx('\t');
|
||||||
const RegEx Break = RegEx('\n');
|
const RegEx Break = RegEx('\n') || RegEx("\r\n");
|
||||||
const RegEx BlankOrBreak = Blank || Break;
|
const RegEx BlankOrBreak = Blank || Break;
|
||||||
const RegEx Digit = RegEx('0', '9');
|
const RegEx Digit = RegEx('0', '9');
|
||||||
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||||
|
|||||||
+3
-7
@@ -4,6 +4,7 @@
|
|||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -142,7 +143,7 @@ namespace YAML
|
|||||||
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||||
{
|
{
|
||||||
if(startedLine && !onlyOneCharOnLine)
|
if(startedLine && !onlyOneCharOnLine)
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
|
|
||||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||||
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
||||||
@@ -160,12 +161,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(m_data.empty())
|
if(m_data.empty())
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
}
|
|
||||||
|
|
||||||
CONTENT_TYPE Map::GetType() const
|
|
||||||
{
|
|
||||||
return CT_MAP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::Compare(Content *pContent)
|
int Map::Compare(Content *pContent)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsMap() const { return true; }
|
||||||
|
|
||||||
// ordering
|
// ordering
|
||||||
virtual int Compare(Content *pContent);
|
virtual int Compare(Content *pContent);
|
||||||
|
|||||||
+13
-6
@@ -122,23 +122,23 @@ namespace YAML
|
|||||||
// write anchor/alias
|
// write anchor/alias
|
||||||
if(m_anchor != "") {
|
if(m_anchor != "") {
|
||||||
if(m_alias)
|
if(m_alias)
|
||||||
out << "*";
|
out << std::string("*");
|
||||||
else
|
else
|
||||||
out << "&";
|
out << std::string("&");
|
||||||
out << m_anchor << " ";
|
out << m_anchor << std::string(" ");
|
||||||
startedLine = true;
|
startedLine = true;
|
||||||
onlyOneCharOnLine = false;
|
onlyOneCharOnLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write tag
|
// write tag
|
||||||
if(m_tag != "") {
|
if(m_tag != "") {
|
||||||
out << "!<" << m_tag << "> ";
|
out << std::string("!<") << m_tag << std::string("> ");
|
||||||
startedLine = true;
|
startedLine = true;
|
||||||
onlyOneCharOnLine = false;
|
onlyOneCharOnLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!m_pContent) {
|
if(!m_pContent) {
|
||||||
out << std::endl;
|
out << std::string("\n");
|
||||||
} else {
|
} else {
|
||||||
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,14 @@ namespace YAML
|
|||||||
if(!m_pContent)
|
if(!m_pContent)
|
||||||
return CT_NONE;
|
return CT_NONE;
|
||||||
|
|
||||||
return m_pContent->GetType();
|
if(m_pContent->IsScalar())
|
||||||
|
return CT_SCALAR;
|
||||||
|
else if(m_pContent->IsSequence())
|
||||||
|
return CT_SEQUENCE;
|
||||||
|
else if(m_pContent->IsMap())
|
||||||
|
return CT_MAP;
|
||||||
|
|
||||||
|
return CT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin
|
// begin
|
||||||
|
|||||||
+1
-1
@@ -126,7 +126,7 @@ namespace YAML
|
|||||||
if(m_pScanner->empty())
|
if(m_pScanner->empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
out << m_pScanner->peek() << std::endl;
|
out << m_pScanner->peek() << "\n";
|
||||||
m_pScanner->pop();
|
m_pScanner->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "crt.h"
|
#include "crt.h"
|
||||||
#include "regex.h"
|
#include "regex.h"
|
||||||
|
#include "stream.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -92,6 +94,11 @@ namespace YAML
|
|||||||
return Match(in) >= 0;
|
return Match(in) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RegEx::Matches(Stream& in) const
|
||||||
|
{
|
||||||
|
return Match(in) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Match
|
// Match
|
||||||
// . Matches the given string against this regular expression.
|
// . Matches the given string against this regular expression.
|
||||||
// . Returns the number of characters matched.
|
// . Returns the number of characters matched.
|
||||||
@@ -106,6 +113,12 @@ namespace YAML
|
|||||||
return m_pOp->Match(str, *this);
|
return m_pOp->Match(str, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Match
|
||||||
|
int RegEx::Match(Stream& in) const
|
||||||
|
{
|
||||||
|
return Match(in.stream());
|
||||||
|
}
|
||||||
|
|
||||||
// Match
|
// Match
|
||||||
// . The stream version does the same thing as the string version;
|
// . The stream version does the same thing as the string version;
|
||||||
// REMEMBER that we only match from the start of the stream!
|
// REMEMBER that we only match from the start of the stream!
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
class Stream;
|
||||||
|
|
||||||
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
||||||
|
|
||||||
// simplified regular expressions
|
// simplified regular expressions
|
||||||
@@ -65,8 +67,10 @@ namespace YAML
|
|||||||
bool Matches(char ch) const;
|
bool Matches(char ch) const;
|
||||||
bool Matches(const std::string& str) const;
|
bool Matches(const std::string& str) const;
|
||||||
bool Matches(std::istream& in) const;
|
bool Matches(std::istream& in) const;
|
||||||
|
bool Matches(Stream& in) const;
|
||||||
int Match(const std::string& str) const;
|
int Match(const std::string& str) const;
|
||||||
int Match(std::istream& in) const;
|
int Match(std::istream& in) const;
|
||||||
|
int Match(Stream& in) const;
|
||||||
|
|
||||||
friend RegEx operator ! (const RegEx& ex);
|
friend RegEx operator ! (const RegEx& ex);
|
||||||
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
||||||
|
|||||||
@@ -38,11 +38,6 @@ namespace YAML
|
|||||||
out << "\"\n";
|
out << "\"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
CONTENT_TYPE Scalar::GetType() const
|
|
||||||
{
|
|
||||||
return CT_SCALAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scalar::Read(std::string& s)
|
void Scalar::Read(std::string& s)
|
||||||
{
|
{
|
||||||
s = m_data;
|
s = m_data;
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsScalar() const { return true; }
|
||||||
|
|
||||||
// extraction
|
// extraction
|
||||||
virtual void Read(std::string& s);
|
virtual void Read(std::string& s);
|
||||||
|
|||||||
+3
-7
@@ -3,6 +3,7 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -134,7 +135,7 @@ namespace YAML
|
|||||||
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||||
{
|
{
|
||||||
if(startedLine && !onlyOneCharOnLine)
|
if(startedLine && !onlyOneCharOnLine)
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
|
|
||||||
for(unsigned i=0;i<m_data.size();i++) {
|
for(unsigned i=0;i<m_data.size();i++) {
|
||||||
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
||||||
@@ -147,12 +148,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(m_data.empty())
|
if(m_data.empty())
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
}
|
|
||||||
|
|
||||||
CONTENT_TYPE Sequence::GetType() const
|
|
||||||
{
|
|
||||||
return CT_SEQUENCE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sequence::Compare(Content *pContent)
|
int Sequence::Compare(Content *pContent)
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsSequence() const { return true; }
|
||||||
|
|
||||||
// ordering
|
// ordering
|
||||||
virtual int Compare(Content *pContent);
|
virtual int Compare(Content *pContent);
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
#include "crt.h"
|
#include "crt.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
int Stream::pos() const
|
||||||
|
{
|
||||||
|
return input.tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
char Stream::peek()
|
||||||
|
{
|
||||||
|
return input.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream::operator bool()
|
||||||
|
{
|
||||||
|
return input.good();
|
||||||
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
// . Extracts a character from the stream and updates our position
|
// . Extracts a character from the stream and updates our position
|
||||||
char Stream::get()
|
char Stream::get()
|
||||||
@@ -33,4 +49,5 @@ namespace YAML
|
|||||||
for(int i=0;i<n;i++)
|
for(int i=0;i<n;i++)
|
||||||
get();
|
get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -9,12 +9,12 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
Stream(std::istream& input_): input(input_), line(0), column(0) {}
|
Stream(std::istream& input_): input(input_), line(0), column(0) {}
|
||||||
|
|
||||||
int pos() const { return input.tellg(); }
|
int pos() const;
|
||||||
operator std::istream& () { return input; }
|
operator bool();
|
||||||
operator bool() { return input.good(); }
|
bool operator !() { return !(*this); }
|
||||||
bool operator !() { return !input; }
|
|
||||||
|
|
||||||
char peek() { return input.peek(); }
|
std::istream& stream() const { return input; }
|
||||||
|
char peek();
|
||||||
char get();
|
char get();
|
||||||
std::string get(int n);
|
std::string get(int n);
|
||||||
void eat(int n = 1);
|
void eat(int n = 1);
|
||||||
|
|||||||
+2
-2
@@ -53,9 +53,9 @@ namespace YAML
|
|||||||
Token(TOKEN_TYPE type_, int line_, int column_): status(TS_VALID), type(type_), line(line_), column(column_) {}
|
Token(TOKEN_TYPE type_, int line_, int column_): status(TS_VALID), type(type_), line(line_), column(column_) {}
|
||||||
|
|
||||||
friend std::ostream& operator << (std::ostream& out, const Token& token) {
|
friend std::ostream& operator << (std::ostream& out, const Token& token) {
|
||||||
out << TokenNames[token.type] << ": " << token.value;
|
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||||
for(unsigned i=0;i<token.params.size();i++)
|
for(unsigned i=0;i<token.params.size();i++)
|
||||||
out << " " << token.params[i];
|
out << std::string(" ") << token.params[i];
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user