mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-10 04:51:17 +00: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:
7
src/CMakeLists.txt
Normal file
7
src/CMakeLists.txt
Normal file
@@ -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})
|
@@ -16,8 +16,6 @@ namespace YAML
|
||||
class Sequence;
|
||||
class Map;
|
||||
|
||||
enum CONTENT_TYPE;
|
||||
|
||||
class Content
|
||||
{
|
||||
public:
|
||||
@@ -33,7 +31,9 @@ namespace YAML
|
||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
||||
virtual Node *GetNode(unsigned i) 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
|
||||
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
||||
|
@@ -14,7 +14,7 @@ namespace YAML
|
||||
{
|
||||
// misc
|
||||
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 Digit = RegEx('0', '9');
|
||||
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||
|
12
src/map.cpp
12
src/map.cpp
@@ -3,7 +3,8 @@
|
||||
#include "node.h"
|
||||
#include "scanner.h"
|
||||
#include "token.h"
|
||||
#include "exceptions.h"
|
||||
#include "exceptions.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -142,7 +143,7 @@ namespace YAML
|
||||
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||
{
|
||||
if(startedLine && !onlyOneCharOnLine)
|
||||
out << std::endl;
|
||||
out << "\n";
|
||||
|
||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
||||
@@ -160,12 +161,7 @@ namespace YAML
|
||||
}
|
||||
|
||||
if(m_data.empty())
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
CONTENT_TYPE Map::GetType() const
|
||||
{
|
||||
return CT_MAP;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
int Map::Compare(Content *pContent)
|
||||
|
@@ -19,7 +19,7 @@ namespace YAML
|
||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsMap() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
|
21
src/node.cpp
21
src/node.cpp
@@ -122,23 +122,23 @@ namespace YAML
|
||||
// write anchor/alias
|
||||
if(m_anchor != "") {
|
||||
if(m_alias)
|
||||
out << "*";
|
||||
out << std::string("*");
|
||||
else
|
||||
out << "&";
|
||||
out << m_anchor << " ";
|
||||
out << std::string("&");
|
||||
out << m_anchor << std::string(" ");
|
||||
startedLine = true;
|
||||
onlyOneCharOnLine = false;
|
||||
}
|
||||
|
||||
// write tag
|
||||
if(m_tag != "") {
|
||||
out << "!<" << m_tag << "> ";
|
||||
out << std::string("!<") << m_tag << std::string("> ");
|
||||
startedLine = true;
|
||||
onlyOneCharOnLine = false;
|
||||
}
|
||||
|
||||
if(!m_pContent) {
|
||||
out << std::endl;
|
||||
out << std::string("\n");
|
||||
} else {
|
||||
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
||||
}
|
||||
@@ -148,8 +148,15 @@ namespace YAML
|
||||
{
|
||||
if(!m_pContent)
|
||||
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
|
||||
|
@@ -121,12 +121,12 @@ namespace YAML
|
||||
}
|
||||
|
||||
void Parser::PrintTokens(std::ostream& out)
|
||||
{
|
||||
{
|
||||
while(1) {
|
||||
if(m_pScanner->empty())
|
||||
break;
|
||||
|
||||
out << m_pScanner->peek() << std::endl;
|
||||
out << m_pScanner->peek() << "\n";
|
||||
m_pScanner->pop();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "crt.h"
|
||||
#include "regex.h"
|
||||
#include "regex.h"
|
||||
#include "stream.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -88,6 +90,11 @@ namespace YAML
|
||||
}
|
||||
|
||||
bool RegEx::Matches(std::istream& in) const
|
||||
{
|
||||
return Match(in) >= 0;
|
||||
}
|
||||
|
||||
bool RegEx::Matches(Stream& in) const
|
||||
{
|
||||
return Match(in) >= 0;
|
||||
}
|
||||
@@ -106,6 +113,12 @@ namespace YAML
|
||||
return m_pOp->Match(str, *this);
|
||||
}
|
||||
|
||||
// Match
|
||||
int RegEx::Match(Stream& in) const
|
||||
{
|
||||
return Match(in.stream());
|
||||
}
|
||||
|
||||
// Match
|
||||
// . The stream version does the same thing as the string version;
|
||||
// REMEMBER that we only match from the start of the stream!
|
||||
|
10
src/regex.h
10
src/regex.h
@@ -5,7 +5,9 @@
|
||||
#include <ios>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
{
|
||||
class Stream;
|
||||
|
||||
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
||||
|
||||
// simplified regular expressions
|
||||
@@ -64,9 +66,11 @@ namespace YAML
|
||||
|
||||
bool Matches(char ch) 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(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& ex1, const RegEx& ex2);
|
||||
|
@@ -38,11 +38,6 @@ namespace YAML
|
||||
out << "\"\n";
|
||||
}
|
||||
|
||||
CONTENT_TYPE Scalar::GetType() const
|
||||
{
|
||||
return CT_SCALAR;
|
||||
}
|
||||
|
||||
void Scalar::Read(std::string& s)
|
||||
{
|
||||
s = m_data;
|
||||
|
@@ -14,7 +14,7 @@ namespace YAML
|
||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsScalar() const { return true; }
|
||||
|
||||
// extraction
|
||||
virtual void Read(std::string& s);
|
||||
|
@@ -2,7 +2,8 @@
|
||||
#include "sequence.h"
|
||||
#include "node.h"
|
||||
#include "scanner.h"
|
||||
#include "token.h"
|
||||
#include "token.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -134,7 +135,7 @@ namespace YAML
|
||||
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||
{
|
||||
if(startedLine && !onlyOneCharOnLine)
|
||||
out << std::endl;
|
||||
out << "\n";
|
||||
|
||||
for(unsigned i=0;i<m_data.size();i++) {
|
||||
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
||||
@@ -147,12 +148,7 @@ namespace YAML
|
||||
}
|
||||
|
||||
if(m_data.empty())
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
CONTENT_TYPE Sequence::GetType() const
|
||||
{
|
||||
return CT_SEQUENCE;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
int Sequence::Compare(Content *pContent)
|
||||
|
@@ -22,7 +22,7 @@ namespace YAML
|
||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsSequence() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
|
@@ -1,8 +1,24 @@
|
||||
#include "crt.h"
|
||||
#include "stream.h"
|
||||
#include "stream.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
int Stream::pos() const
|
||||
{
|
||||
return input.tellg();
|
||||
}
|
||||
|
||||
char Stream::peek()
|
||||
{
|
||||
return input.peek();
|
||||
}
|
||||
|
||||
Stream::operator bool()
|
||||
{
|
||||
return input.good();
|
||||
}
|
||||
|
||||
// get
|
||||
// . Extracts a character from the stream and updates our position
|
||||
char Stream::get()
|
||||
@@ -32,5 +48,6 @@ namespace YAML
|
||||
{
|
||||
for(int i=0;i<n;i++)
|
||||
get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
10
src/stream.h
10
src/stream.h
@@ -9,12 +9,12 @@ namespace YAML
|
||||
{
|
||||
Stream(std::istream& input_): input(input_), line(0), column(0) {}
|
||||
|
||||
int pos() const { return input.tellg(); }
|
||||
operator std::istream& () { return input; }
|
||||
operator bool() { return input.good(); }
|
||||
bool operator !() { return !input; }
|
||||
int pos() const;
|
||||
operator bool();
|
||||
bool operator !() { return !(*this); }
|
||||
|
||||
char peek() { return input.peek(); }
|
||||
std::istream& stream() const { return input; }
|
||||
char peek();
|
||||
char get();
|
||||
std::string get(int n);
|
||||
void eat(int n = 1);
|
||||
|
@@ -53,9 +53,9 @@ namespace YAML
|
||||
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) {
|
||||
out << TokenNames[token.type] << ": " << token.value;
|
||||
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||
for(unsigned i=0;i<token.params.size();i++)
|
||||
out << " " << token.params[i];
|
||||
out << std::string(" ") << token.params[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user