Merge clang-format from core

This commit is contained in:
Jesse Beder
2014-03-22 13:03:18 -05:00
72 changed files with 20508 additions and 20365 deletions

View File

@@ -1,16 +1,17 @@
#ifndef ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <cstddef>
namespace YAML
{
typedef std::size_t anchor_t;
const anchor_t NullAnchor = 0;
namespace YAML {
typedef std::size_t anchor_t;
const anchor_t NullAnchor = 0;
}
#endif // ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,29 +1,33 @@
#ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <vector>
namespace YAML
{
std::string EncodeBase64(const unsigned char *data, std::size_t size);
std::vector<unsigned char> DecodeBase64(const std::string& input);
namespace YAML {
std::string EncodeBase64(const unsigned char *data, std::size_t size);
std::vector<unsigned char> DecodeBase64(const std::string &input);
class Binary {
class Binary {
public:
Binary(): m_unownedData(0), m_unownedSize(0) {}
Binary(const unsigned char *data_, std::size_t size_): m_unownedData(data_), m_unownedSize(size_) {}
Binary() : m_unownedData(0), m_unownedSize(0) {}
Binary(const unsigned char *data_, std::size_t size_)
: m_unownedData(data_), m_unownedSize(size_) {}
bool owned() const { return !m_unownedData; }
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
const unsigned char *data() const { return owned() ? &m_data[0] : m_unownedData; }
const unsigned char *data() const {
return owned() ? &m_data[0] : m_unownedData;
}
void swap(std::vector<unsigned char>& rhs) {
if(m_unownedData) {
void swap(std::vector<unsigned char> &rhs) {
if (m_unownedData) {
m_data.swap(rhs);
rhs.clear();
rhs.resize(m_unownedSize);
@@ -35,28 +39,26 @@ namespace YAML
}
}
bool operator == (const Binary& rhs) const {
bool operator==(const Binary &rhs) const {
const std::size_t s = size();
if(s != rhs.size())
if (s != rhs.size())
return false;
const unsigned char *d1 = data();
const unsigned char *d2 = rhs.data();
for(std::size_t i=0;i<s;i++) {
if(*d1++ != *d2++)
for (std::size_t i = 0; i < s; i++) {
if (*d1++ != *d2++)
return false;
}
return true;
}
bool operator != (const Binary& rhs) const {
return !(*this == rhs);
}
bool operator!=(const Binary &rhs) const { return !(*this == rhs); }
private:
std::vector<unsigned char> m_data;
const unsigned char *m_unownedData;
std::size_t m_unownedSize;
};
};
}
#endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,7 +1,9 @@
#ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -9,34 +11,27 @@
#include "../anchor.h"
namespace YAML
{
/// AnchorDict
/// . An object that stores and retrieves values correlating to anchor_t
/// values.
/// . Efficient implementation that can make assumptions about how anchor_t
/// values are assigned by the Parser class.
template <class T>
class AnchorDict
{
namespace YAML {
/// AnchorDict
/// . An object that stores and retrieves values correlating to anchor_t
/// values.
/// . Efficient implementation that can make assumptions about how anchor_t
/// values are assigned by the Parser class.
template <class T>
class AnchorDict {
public:
void Register(anchor_t anchor, T value)
{
if (anchor > m_data.size())
{
void Register(anchor_t anchor, T value) {
if (anchor > m_data.size()) {
m_data.resize(anchor);
}
m_data[anchor - 1] = value;
}
T Get(anchor_t anchor) const
{
return m_data[anchor - 1];
}
T Get(anchor_t anchor) const { return m_data[anchor - 1]; }
private:
std::vector<T> m_data;
};
};
}
#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,89 +1,101 @@
#ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/mark.h"
#include <string>
namespace YAML
{
class Parser;
namespace YAML {
class Parser;
// GraphBuilderInterface
// . Abstraction of node creation
// . pParentNode is always NULL or the return value of one of the NewXXX()
// functions.
class GraphBuilderInterface
{
// GraphBuilderInterface
// . Abstraction of node creation
// . pParentNode is always NULL or the return value of one of the NewXXX()
// functions.
class GraphBuilderInterface {
public:
// Create and return a new node with a null value.
virtual void *NewNull(const Mark& mark, void *pParentNode) = 0;
virtual void *NewNull(const Mark &mark, void *pParentNode) = 0;
// Create and return a new node with the given tag and value.
virtual void *NewScalar(const Mark& mark, const std::string& tag, void *pParentNode, const std::string& value) = 0;
virtual void *NewScalar(const Mark &mark, const std::string &tag,
void *pParentNode, const std::string &value) = 0;
// Create and return a new sequence node
virtual void *NewSequence(const Mark& mark, const std::string& tag, void *pParentNode) = 0;
virtual void *NewSequence(const Mark &mark, const std::string &tag,
void *pParentNode) = 0;
// Add pNode to pSequence. pNode was created with one of the NewXxx()
// functions and pSequence with NewSequence().
virtual void AppendToSequence(void *pSequence, void *pNode) = 0;
// Note that no moew entries will be added to pSequence
virtual void SequenceComplete(void *pSequence) {(void)pSequence;}
virtual void SequenceComplete(void *pSequence) { (void)pSequence; }
// Create and return a new map node
virtual void *NewMap(const Mark& mark, const std::string& tag, void *pParentNode) = 0;
virtual void *NewMap(const Mark &mark, const std::string &tag,
void *pParentNode) = 0;
// Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode
// were created with one of the NewXxx() methods and pMap with NewMap().
virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0;
// Note that no more assignments will be made in pMap
virtual void MapComplete(void *pMap) {(void)pMap;}
virtual void MapComplete(void *pMap) { (void)pMap; }
// Return the node that should be used in place of an alias referencing
// pNode (pNode by default)
virtual void *AnchorReference(const Mark& mark, void *pNode) {(void)mark; return pNode;}
};
virtual void *AnchorReference(const Mark &mark, void *pNode) {
(void)mark;
return pNode;
}
};
// Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines
// Node, Sequence, and Map types. Sequence and Map must derive from Node
// (unless Node is defined as void). Impl must also implement function with
// all of the same names as the virtual functions in GraphBuilderInterface
// -- including the ones with default implementations -- but with the
// prototypes changed to accept an explicit Node*, Sequence*, or Map* where
// appropriate.
template <class Impl>
class GraphBuilder : public GraphBuilderInterface
{
// Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines
// Node, Sequence, and Map types. Sequence and Map must derive from Node
// (unless Node is defined as void). Impl must also implement function with
// all of the same names as the virtual functions in GraphBuilderInterface
// -- including the ones with default implementations -- but with the
// prototypes changed to accept an explicit Node*, Sequence*, or Map* where
// appropriate.
template <class Impl>
class GraphBuilder : public GraphBuilderInterface {
public:
typedef typename Impl::Node Node;
typedef typename Impl::Sequence Sequence;
typedef typename Impl::Map Map;
GraphBuilder(Impl& impl) : m_impl(impl)
{
Map* pMap = NULL;
Sequence* pSeq = NULL;
Node* pNode = NULL;
GraphBuilder(Impl &impl) : m_impl(impl) {
Map *pMap = NULL;
Sequence *pSeq = NULL;
Node *pNode = NULL;
// Type consistency checks
pNode = pMap;
pNode = pSeq;
}
GraphBuilderInterface& AsBuilderInterface() {return *this;}
GraphBuilderInterface &AsBuilderInterface() { return *this; }
virtual void *NewNull(const Mark& mark, void* pParentNode) {
virtual void *NewNull(const Mark &mark, void *pParentNode) {
return CheckType<Node>(m_impl.NewNull(mark, AsNode(pParentNode)));
}
virtual void *NewScalar(const Mark& mark, const std::string& tag, void *pParentNode, const std::string& value) {
return CheckType<Node>(m_impl.NewScalar(mark, tag, AsNode(pParentNode), value));
virtual void *NewScalar(const Mark &mark, const std::string &tag,
void *pParentNode, const std::string &value) {
return CheckType<Node>(
m_impl.NewScalar(mark, tag, AsNode(pParentNode), value));
}
virtual void *NewSequence(const Mark& mark, const std::string& tag, void *pParentNode) {
return CheckType<Sequence>(m_impl.NewSequence(mark, tag, AsNode(pParentNode)));
virtual void *NewSequence(const Mark &mark, const std::string &tag,
void *pParentNode) {
return CheckType<Sequence>(
m_impl.NewSequence(mark, tag, AsNode(pParentNode)));
}
virtual void AppendToSequence(void *pSequence, void *pNode) {
m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode));
@@ -92,42 +104,44 @@ namespace YAML
m_impl.SequenceComplete(AsSequence(pSequence));
}
virtual void *NewMap(const Mark& mark, const std::string& tag, void *pParentNode) {
virtual void *NewMap(const Mark &mark, const std::string &tag,
void *pParentNode) {
return CheckType<Map>(m_impl.NewMap(mark, tag, AsNode(pParentNode)));
}
virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) {
m_impl.AssignInMap(AsMap(pMap), AsNode(pKeyNode), AsNode(pValueNode));
}
virtual void MapComplete(void *pMap) {
m_impl.MapComplete(AsMap(pMap));
}
virtual void MapComplete(void *pMap) { m_impl.MapComplete(AsMap(pMap)); }
virtual void *AnchorReference(const Mark& mark, void *pNode) {
virtual void *AnchorReference(const Mark &mark, void *pNode) {
return CheckType<Node>(m_impl.AnchorReference(mark, AsNode(pNode)));
}
private:
Impl& m_impl;
Impl &m_impl;
// Static check for pointer to T
template <class T, class U>
static T* CheckType(U* p) {return p;}
static Node *AsNode(void *pNode) {return static_cast<Node*>(pNode);}
static Sequence *AsSequence(void *pSeq) {return static_cast<Sequence*>(pSeq);}
static Map *AsMap(void *pMap) {return static_cast<Map*>(pMap);}
};
void *BuildGraphOfNextDocument(Parser& parser, GraphBuilderInterface& graphBuilder);
template <class Impl>
typename Impl::Node *BuildGraphOfNextDocument(Parser& parser, Impl& impl)
{
GraphBuilder<Impl> graphBuilder(impl);
return static_cast<typename Impl::Node *>(BuildGraphOfNextDocument(
parser, graphBuilder
));
static T *CheckType(U *p) {
return p;
}
static Node *AsNode(void *pNode) { return static_cast<Node *>(pNode); }
static Sequence *AsSequence(void *pSeq) {
return static_cast<Sequence *>(pSeq);
}
static Map *AsMap(void *pMap) { return static_cast<Map *>(pMap); }
};
void *BuildGraphOfNextDocument(Parser &parser,
GraphBuilderInterface &graphBuilder);
template <class Impl>
typename Impl::Node *BuildGraphOfNextDocument(Parser &parser, Impl &impl) {
GraphBuilder<Impl> graphBuilder(impl);
return static_cast<typename Impl::Node *>(
BuildGraphOfNextDocument(parser, graphBuilder));
}
}
#endif // GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,27 +1,36 @@
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the yaml_cpp_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// YAML_CPP_API functions as being imported from a DLL, whereas this DLL sees symbols
// The following ifdef block is the standard way of creating macros which make
// exporting
// from a DLL simpler. All files within this DLL are compiled with the
// yaml_cpp_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any
// project
// that uses this DLL. This way any other project whose source files include
// this file see
// YAML_CPP_API functions as being imported from a DLL, whereas this DLL sees
// symbols
// defined with this macro as being exported.
#undef YAML_CPP_API
#ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined manually)
#ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake or defined manually)
// #pragma message( "Defining YAML_CPP_API for DLL export" )
#define YAML_CPP_API __declspec(dllexport)
#else // yaml_cpp_EXPORTS
// #pragma message( "Defining YAML_CPP_API for DLL import" )
#define YAML_CPP_API __declspec(dllimport)
#endif // yaml_cpp_EXPORTS
#else //YAML_CPP_DLL
#ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined
// manually)
#ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake
// or defined manually)
// #pragma message( "Defining YAML_CPP_API for DLL export" )
#define YAML_CPP_API __declspec(dllexport)
#else // yaml_cpp_EXPORTS
// #pragma message( "Defining YAML_CPP_API for DLL import" )
#define YAML_CPP_API __declspec(dllimport)
#endif // yaml_cpp_EXPORTS
#else // YAML_CPP_DLL
#define YAML_CPP_API
#endif // YAML_CPP_DLL

View File

@@ -1,19 +1,19 @@
#ifndef EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/eventhandler.h"
#include <stack>
namespace YAML
{
class Emitter;
namespace YAML {
class Emitter;
class EmitFromEvents: public EventHandler
{
class EmitFromEvents : public EventHandler {
public:
EmitFromEvents(Emitter& emitter);
@@ -22,12 +22,15 @@ namespace YAML
virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnMapEnd();
private:
@@ -37,9 +40,15 @@ namespace YAML
private:
Emitter& m_emitter;
struct State { enum value { WaitingForSequenceEntry, WaitingForKey, WaitingForValue }; };
std::stack<State::value> m_stateStack;
struct State {
enum value {
WaitingForSequenceEntry,
WaitingForKey,
WaitingForValue
};
};
std::stack<State::value> m_stateStack;
};
}
#endif // EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,11 +1,12 @@
#ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/binary.h"
#include "yaml-cpp/emitterdef.h"
@@ -17,19 +18,17 @@
#include <string>
#include <sstream>
namespace YAML
{
class EmitterState;
namespace YAML {
class EmitterState;
class YAML_CPP_API Emitter: private noncopyable
{
class YAML_CPP_API Emitter : private noncopyable {
public:
Emitter();
explicit Emitter(std::ostream& stream);
~Emitter();
// output
const char *c_str() const;
const char* c_str() const;
std::size_t size() const;
// state checking
@@ -72,7 +71,8 @@ namespace YAML
Emitter& WriteStreamable(T value);
private:
template<typename T> void SetStreamablePrecision(std::stringstream&) {}
template <typename T>
void SetStreamablePrecision(std::stringstream&) {}
unsigned GetFloatPrecision() const;
unsigned GetDoublePrecision() const;
@@ -111,18 +111,17 @@ namespace YAML
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
const char *ComputeFullBoolName(bool b) const;
const char* ComputeFullBoolName(bool b) const;
bool CanEmitNewline() const;
private:
std::auto_ptr<EmitterState> m_pState;
ostream_wrapper m_stream;
};
};
template <typename T>
inline Emitter& Emitter::WriteIntegralType(T value)
{
if(!good())
template <typename T>
inline Emitter& Emitter::WriteIntegralType(T value) {
if (!good())
return *this;
PrepareNode(EmitterNodeType::Scalar);
@@ -135,12 +134,11 @@ namespace YAML
StartedScalar();
return *this;
}
}
template <typename T>
inline Emitter& Emitter::WriteStreamable(T value)
{
if(!good())
template <typename T>
inline Emitter& Emitter::WriteStreamable(T value) {
if (!good())
return *this;
PrepareNode(EmitterNodeType::Scalar);
@@ -153,57 +151,97 @@ namespace YAML
StartedScalar();
return *this;
}
}
template<>
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream)
{
template <>
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream) {
stream.precision(GetFloatPrecision());
}
}
template<>
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream)
{
template <>
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) {
stream.precision(GetDoublePrecision());
}
}
// overloads of insertion
inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, char v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, unsigned char v) { return emitter.Write(static_cast<char>(v)); }
inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const Binary& b) { return emitter.Write(b); }
// overloads of insertion
inline Emitter& operator<<(Emitter& emitter, const std::string& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, bool v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, char v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned char v) {
return emitter.Write(static_cast<char>(v));
}
inline Emitter& operator<<(Emitter& emitter, const _Alias& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, const _Anchor& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, const _Tag& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, const _Comment& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, const _Null& v) {
return emitter.Write(v);
}
inline Emitter& operator<<(Emitter& emitter, const Binary& b) {
return emitter.Write(b);
}
inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
inline Emitter& operator<<(Emitter& emitter, const char* v) {
return emitter.Write(std::string(v));
}
inline Emitter& operator << (Emitter& emitter, int v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, unsigned int v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, short v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, long long v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator << (Emitter& emitter, unsigned long long v) { return emitter.WriteIntegralType(v); }
inline Emitter& operator<<(Emitter& emitter, int v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned int v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, short v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned short v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, long long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned long long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); }
inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); }
inline Emitter& operator<<(Emitter& emitter, float v) {
return emitter.WriteStreamable(v);
}
inline Emitter& operator<<(Emitter& emitter, double v) {
return emitter.WriteStreamable(v);
}
inline Emitter& operator << (Emitter& emitter, EMITTER_MANIP value) {
inline Emitter& operator<<(Emitter& emitter, EMITTER_MANIP value) {
return emitter.SetLocalValue(value);
}
}
inline Emitter& operator << (Emitter& emitter, _Indent indent) {
inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
return emitter.SetLocalIndent(indent);
}
}
inline Emitter& operator << (Emitter& emitter, _Precision precision) {
inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
return emitter.SetLocalPrecision(precision);
}
}
}
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,13 +1,24 @@
#ifndef EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace YAML
{
struct EmitterNodeType { enum value { None, Property, Scalar, FlowSeq, BlockSeq, FlowMap, BlockMap }; };
namespace YAML {
struct EmitterNodeType {
enum value {
None,
Property,
Scalar,
FlowSeq,
BlockSeq,
FlowMap,
BlockMap
};
};
}
#endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,16 +1,16 @@
#ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace YAML
{
enum EMITTER_MANIP {
namespace YAML {
enum EMITTER_MANIP {
// general manipulators
Auto,
TagByKind,
@@ -60,90 +60,82 @@ namespace YAML
// Block, // duplicate
// Auto, // duplicate
LongKey
};
};
struct _Indent {
_Indent(int value_): value(value_) {}
struct _Indent {
_Indent(int value_) : value(value_) {}
int value;
};
};
inline _Indent Indent(int value) {
return _Indent(value);
}
inline _Indent Indent(int value) { return _Indent(value); }
struct _Alias {
_Alias(const std::string& content_): content(content_) {}
struct _Alias {
_Alias(const std::string& content_) : content(content_) {}
std::string content;
};
};
inline _Alias Alias(const std::string content) {
return _Alias(content);
}
inline _Alias Alias(const std::string content) { return _Alias(content); }
struct _Anchor {
_Anchor(const std::string& content_): content(content_) {}
struct _Anchor {
_Anchor(const std::string& content_) : content(content_) {}
std::string content;
};
inline _Anchor Anchor(const std::string content) { return _Anchor(content); }
struct _Tag {
struct Type {
enum value {
Verbatim,
PrimaryHandle,
NamedHandle
};
};
inline _Anchor Anchor(const std::string content) {
return _Anchor(content);
}
struct _Tag {
struct Type { enum value { Verbatim, PrimaryHandle, NamedHandle }; };
explicit _Tag(const std::string& prefix_, const std::string& content_, Type::value type_)
: prefix(prefix_), content(content_), type(type_)
{
}
explicit _Tag(const std::string& prefix_, const std::string& content_,
Type::value type_)
: prefix(prefix_), content(content_), type(type_) {}
std::string prefix;
std::string content;
Type::value type;
};
};
inline _Tag VerbatimTag(const std::string content) {
inline _Tag VerbatimTag(const std::string content) {
return _Tag("", content, _Tag::Type::Verbatim);
}
}
inline _Tag LocalTag(const std::string content) {
inline _Tag LocalTag(const std::string content) {
return _Tag("", content, _Tag::Type::PrimaryHandle);
}
}
inline _Tag LocalTag(const std::string& prefix, const std::string content) {
inline _Tag LocalTag(const std::string& prefix, const std::string content) {
return _Tag(prefix, content, _Tag::Type::NamedHandle);
}
}
inline _Tag SecondaryTag(const std::string content) {
inline _Tag SecondaryTag(const std::string content) {
return _Tag("", content, _Tag::Type::NamedHandle);
}
}
struct _Comment {
_Comment(const std::string& content_): content(content_) {}
struct _Comment {
_Comment(const std::string& content_) : content(content_) {}
std::string content;
};
};
inline _Comment Comment(const std::string content) {
return _Comment(content);
}
inline _Comment Comment(const std::string content) { return _Comment(content); }
struct _Precision {
_Precision(int floatPrecision_, int doublePrecision_): floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
struct _Precision {
_Precision(int floatPrecision_, int doublePrecision_)
: floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
int floatPrecision;
int doublePrecision;
};
};
inline _Precision FloatPrecision(int n) {
return _Precision(n, -1);
}
inline _Precision FloatPrecision(int n) { return _Precision(n, -1); }
inline _Precision DoublePrecision(int n) {
return _Precision(-1, n);
}
inline _Precision DoublePrecision(int n) { return _Precision(-1, n); }
inline _Precision Precision(int n) {
return _Precision(n, n);
}
inline _Precision Precision(int n) { return _Precision(n, n); }
}
#endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,19 +1,19 @@
#ifndef EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/anchor.h"
#include <string>
namespace YAML
{
struct Mark;
namespace YAML {
struct Mark;
class EventHandler
{
class EventHandler {
public:
virtual ~EventHandler() {}
@@ -22,15 +22,17 @@ namespace YAML
virtual void OnNull(const Mark& mark, anchor_t anchor) = 0;
virtual void OnAlias(const Mark& mark, anchor_t anchor) = 0;
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value) = 0;
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value) = 0;
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor) = 0;
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor) = 0;
virtual void OnSequenceEnd() = 0;
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor) = 0;
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor) = 0;
virtual void OnMapEnd() = 0;
};
};
}
#endif // EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,17 +1,17 @@
#ifndef MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
struct YAML_CPP_API Mark {
Mark(): pos(0), line(0), column(0) {}
namespace YAML {
struct YAML_CPP_API Mark {
Mark() : pos(0), line(0), column(0) {}
static const Mark null_mark() { return Mark(-1, -1, -1); }
@@ -19,8 +19,9 @@ namespace YAML
int line, column;
private:
Mark(int pos_, int line_, int column_): pos(pos_), line(line_), column(column_) {}
};
Mark(int pos_, int line_, int column_)
: pos(pos_), line(line_), column(column_) {}
};
}
#endif // MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,25 +1,25 @@
#ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
// this is basically boost::noncopyable
class YAML_CPP_API noncopyable
{
namespace YAML {
// this is basically boost::noncopyable
class YAML_CPP_API noncopyable {
protected:
noncopyable() {}
~noncopyable() {}
private:
noncopyable(const noncopyable&);
const noncopyable& operator = (const noncopyable&);
};
const noncopyable& operator=(const noncopyable&);
};
}
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,25 +1,24 @@
#ifndef NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
class Node;
namespace YAML {
class Node;
struct YAML_CPP_API _Null {};
inline bool operator == (const _Null&, const _Null&) { return true; }
inline bool operator != (const _Null&, const _Null&) { return false; }
struct YAML_CPP_API _Null {};
inline bool operator==(const _Null&, const _Null&) { return true; }
inline bool operator!=(const _Null&, const _Null&) { return false; }
YAML_CPP_API bool IsNull(const Node& node); // old API only
YAML_CPP_API bool IsNull(const Node& node); // old API only
extern YAML_CPP_API _Null Null;
extern YAML_CPP_API _Null Null;
}
#endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,30 +1,29 @@
#ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <vector>
namespace YAML
{
class ostream_wrapper
{
namespace YAML {
class ostream_wrapper {
public:
ostream_wrapper();
explicit ostream_wrapper(std::ostream& stream);
~ostream_wrapper();
void write(const std::string& str);
void write(const char *str, std::size_t size);
void write(const char* str, std::size_t size);
void set_comment() { m_comment = true; }
const char *str() const {
if(m_pStream) {
const char* str() const {
if (m_pStream) {
return 0;
} else {
m_buffer[m_pos] = '\0';
@@ -42,28 +41,30 @@ namespace YAML
private:
mutable std::vector<char> m_buffer;
std::ostream *m_pStream;
std::ostream* m_pStream;
std::size_t m_pos;
std::size_t m_row, m_col;
bool m_comment;
};
};
template<std::size_t N>
inline ostream_wrapper& operator << (ostream_wrapper& stream, const char (&str)[N]) {
stream.write(str, N-1);
template <std::size_t N>
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
const char (&str)[N]) {
stream.write(str, N - 1);
return stream;
}
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, const std::string& str) {
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
const std::string& str) {
stream.write(str);
return stream;
}
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, char ch) {
inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
stream.write(&ch, 1);
return stream;
}
}
}
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,51 +1,51 @@
#ifndef STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <vector>
#include <list>
#include <set>
#include <map>
namespace YAML
{
template<typename Seq>
inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) {
namespace YAML {
template <typename Seq>
inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) {
emitter << BeginSeq;
for(typename Seq::const_iterator it=seq.begin();it!=seq.end();++it)
for (typename Seq::const_iterator it = seq.begin(); it != seq.end(); ++it)
emitter << *it;
emitter << EndSeq;
return emitter;
}
}
template<typename T>
inline Emitter& operator << (Emitter& emitter, const std::vector<T>& v) {
template <typename T>
inline Emitter& operator<<(Emitter& emitter, const std::vector<T>& v) {
return EmitSeq(emitter, v);
}
}
template<typename T>
inline Emitter& operator << (Emitter& emitter, const std::list<T>& v) {
template <typename T>
inline Emitter& operator<<(Emitter& emitter, const std::list<T>& v) {
return EmitSeq(emitter, v);
}
}
template<typename T>
inline Emitter& operator << (Emitter& emitter, const std::set<T>& v) {
template <typename T>
inline Emitter& operator<<(Emitter& emitter, const std::set<T>& v) {
return EmitSeq(emitter, v);
}
}
template <typename K, typename V>
inline Emitter& operator << (Emitter& emitter, const std::map<K, V>& m) {
typedef typename std::map <K, V> map;
template <typename K, typename V>
inline Emitter& operator<<(Emitter& emitter, const std::map<K, V>& m) {
typedef typename std::map<K, V> map;
emitter << BeginMap;
for(typename map::const_iterator it=m.begin();it!=m.end();++it)
for (typename map::const_iterator it = m.begin(); it != m.end(); ++it)
emitter << Key << it->first << Value << it->second;
emitter << EndMap;
return emitter;
}
}
}
#endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,57 +1,135 @@
#ifndef TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace YAML {
template <typename>
struct is_numeric {
enum {
value = false
};
};
namespace YAML
{
template <typename>
struct is_numeric { enum { value = false }; };
template <> struct is_numeric <char> { enum { value = true }; };
template <> struct is_numeric <unsigned char> { enum { value = true }; };
template <> struct is_numeric <int> { enum { value = true }; };
template <> struct is_numeric <unsigned int> { enum { value = true }; };
template <> struct is_numeric <long int> { enum { value = true }; };
template <> struct is_numeric <unsigned long int> { enum { value = true }; };
template <> struct is_numeric <short int> { enum { value = true }; };
template <> struct is_numeric <unsigned short int> { enum { value = true }; };
template <>
struct is_numeric<char> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned char> {
enum {
value = true
};
};
template <>
struct is_numeric<int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned int> {
enum {
value = true
};
};
template <>
struct is_numeric<long int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned long int> {
enum {
value = true
};
};
template <>
struct is_numeric<short int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned short int> {
enum {
value = true
};
};
#if defined(_MSC_VER) && (_MSC_VER < 1310)
template <> struct is_numeric <__int64> { enum { value = true }; };
template <> struct is_numeric <unsigned __int64> { enum { value = true }; };
template <>
struct is_numeric<__int64> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned __int64> {
enum {
value = true
};
};
#else
template <> struct is_numeric <long long> { enum { value = true }; };
template <> struct is_numeric <unsigned long long> { enum { value = true }; };
template <>
struct is_numeric<long long> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned long long> {
enum {
value = true
};
};
#endif
template <> struct is_numeric <float> { enum { value = true }; };
template <> struct is_numeric <double> { enum { value = true }; };
template <> struct is_numeric <long double> { enum { value = true }; };
template <bool, class T = void>
struct enable_if_c {
typedef T type;
template <>
struct is_numeric<float> {
enum {
value = true
};
template <class T>
struct enable_if_c<false, T> {};
template <class Cond, class T = void>
struct enable_if : public enable_if_c<Cond::value, T> {};
template <bool, class T = void>
struct disable_if_c {
typedef T type;
};
template <>
struct is_numeric<double> {
enum {
value = true
};
};
template <>
struct is_numeric<long double> {
enum {
value = true
};
};
template <class T>
struct disable_if_c<true, T> {};
template <bool, class T = void>
struct enable_if_c {
typedef T type;
};
template <class Cond, class T = void>
struct disable_if : public disable_if_c<Cond::value, T> {};
template <class T>
struct enable_if_c<false, T> {};
template <class Cond, class T = void>
struct enable_if : public enable_if_c<Cond::value, T> {};
template <bool, class T = void>
struct disable_if_c {
typedef T type;
};
template <class T>
struct disable_if_c<true, T> {};
template <class Cond, class T = void>
struct disable_if : public disable_if_c<Cond::value, T> {};
}
#endif // TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,11 +1,10 @@
#include "yaml-cpp/binary.h"
namespace YAML
{
static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
namespace YAML {
static const char encoding[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::string EncodeBase64(const unsigned char *data, std::size_t size)
{
std::string EncodeBase64(const unsigned char *data, std::size_t size) {
const char PAD = '=';
std::string ret;
@@ -15,14 +14,14 @@ namespace YAML
std::size_t chunks = size / 3;
std::size_t remainder = size % 3;
for(std::size_t i=0;i<chunks;i++, data += 3) {
for (std::size_t i = 0; i < chunks; i++, data += 3) {
*out++ = encoding[data[0] >> 2];
*out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
*out++ = encoding[((data[1] & 0xf) << 2) | (data[2] >> 6)];
*out++ = encoding[data[2] & 0x3f];
}
switch(remainder) {
switch (remainder) {
case 0:
break;
case 1:
@@ -41,53 +40,53 @@ namespace YAML
ret.resize(out - &ret[0]);
return ret;
}
}
static const unsigned char decoding[] = {
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255,
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255,
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
};
static const unsigned char decoding[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, };
std::vector<unsigned char> DecodeBase64(const std::string& input)
{
std::vector<unsigned char> DecodeBase64(const std::string &input) {
typedef std::vector<unsigned char> ret_type;
if(input.empty())
if (input.empty())
return ret_type();
ret_type ret(3 * input.size() / 4 + 1);
unsigned char *out = &ret[0];
unsigned value = 0;
for(std::size_t i=0;i<input.size();i++) {
for (std::size_t i = 0; i < input.size(); i++) {
unsigned char d = decoding[static_cast<unsigned>(input[i])];
if(d == 255)
if (d == 255)
return ret_type();
value = (value << 6) | d;
if(i % 4 == 3) {
if (i % 4 == 3) {
*out++ = value >> 16;
if(i > 0 && input[i - 1] != '=')
if (i > 0 && input[i - 1] != '=')
*out++ = value >> 8;
if(input[i] != '=')
if (input[i] != '=')
*out++ = value;
}
}
ret.resize(out - &ret[0]);
return ret;
}
}
}

View File

@@ -1,35 +1,46 @@
#ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <stack>
#include <cassert>
namespace YAML
{
struct CollectionType {
enum value { None, BlockMap, BlockSeq, FlowMap, FlowSeq, CompactMap };
namespace YAML {
struct CollectionType {
enum value {
None,
BlockMap,
BlockSeq,
FlowMap,
FlowSeq,
CompactMap
};
};
class CollectionStack
{
class CollectionStack {
public:
CollectionType::value GetCurCollectionType() const {
if(collectionStack.empty())
if (collectionStack.empty())
return CollectionType::None;
return collectionStack.top();
}
void PushCollectionType(CollectionType::value type) { collectionStack.push(type); }
void PopCollectionType(CollectionType::value type) { assert(type == GetCurCollectionType()); collectionStack.pop(); }
void PushCollectionType(CollectionType::value type) {
collectionStack.push(type);
}
void PopCollectionType(CollectionType::value type) {
assert(type == GetCurCollectionType());
collectionStack.pop();
}
private:
std::stack<CollectionType::value> collectionStack;
};
};
}
#endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -2,15 +2,14 @@
#include "yaml-cpp/contrib/graphbuilder.h"
#include "graphbuilderadapter.h"
namespace YAML
{
void *BuildGraphOfNextDocument(Parser& parser, GraphBuilderInterface& graphBuilder)
{
namespace YAML {
void* BuildGraphOfNextDocument(Parser& parser,
GraphBuilderInterface& graphBuilder) {
GraphBuilderAdapter eventHandler(graphBuilder);
if (parser.HandleNextDocument(eventHandler)) {
return eventHandler.RootNode();
} else {
return NULL;
}
}
}
}

View File

@@ -1,81 +1,74 @@
#include "graphbuilderadapter.h"
namespace YAML
{
int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
namespace YAML {
int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
void GraphBuilderAdapter::OnNull(const Mark& mark, anchor_t anchor)
{
void GraphBuilderAdapter::OnNull(const Mark &mark, anchor_t anchor) {
void *pParent = GetCurrentParent();
void *pNode = m_builder.NewNull(mark, pParent);
RegisterAnchor(anchor, pNode);
DispositionNode(pNode);
}
}
void GraphBuilderAdapter::OnAlias(const Mark& mark, anchor_t anchor)
{
void GraphBuilderAdapter::OnAlias(const Mark &mark, anchor_t anchor) {
void *pReffedNode = m_anchors.Get(anchor);
DispositionNode(m_builder.AnchorReference(mark, pReffedNode));
}
}
void GraphBuilderAdapter::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value)
{
void GraphBuilderAdapter::OnScalar(const Mark &mark, const std::string &tag,
anchor_t anchor, const std::string &value) {
void *pParent = GetCurrentParent();
void *pNode = m_builder.NewScalar(mark, tag, pParent, value);
RegisterAnchor(anchor, pNode);
DispositionNode(pNode);
}
}
void GraphBuilderAdapter::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor)
{
void GraphBuilderAdapter::OnSequenceStart(const Mark &mark,
const std::string &tag,
anchor_t anchor) {
void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent());
m_containers.push(ContainerFrame(pNode));
RegisterAnchor(anchor, pNode);
}
}
void GraphBuilderAdapter::OnSequenceEnd()
{
void GraphBuilderAdapter::OnSequenceEnd() {
void *pSequence = m_containers.top().pContainer;
m_containers.pop();
DispositionNode(pSequence);
}
}
void GraphBuilderAdapter::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor)
{
void GraphBuilderAdapter::OnMapStart(const Mark &mark, const std::string &tag,
anchor_t anchor) {
void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent());
m_containers.push(ContainerFrame(pNode, m_pKeyNode));
m_pKeyNode = NULL;
RegisterAnchor(anchor, pNode);
}
}
void GraphBuilderAdapter::OnMapEnd()
{
void GraphBuilderAdapter::OnMapEnd() {
void *pMap = m_containers.top().pContainer;
m_pKeyNode = m_containers.top().pPrevKeyNode;
m_containers.pop();
DispositionNode(pMap);
}
}
void *GraphBuilderAdapter::GetCurrentParent() const
{
void *GraphBuilderAdapter::GetCurrentParent() const {
if (m_containers.empty()) {
return NULL;
}
return m_containers.top().pContainer;
}
}
void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode)
{
void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode) {
if (anchor) {
m_anchors.Register(anchor, pNode);
}
}
}
void GraphBuilderAdapter::DispositionNode(void *pNode)
{
void GraphBuilderAdapter::DispositionNode(void *pNode) {
if (m_containers.empty()) {
m_pRootNode = pNode;
return;
@@ -92,5 +85,5 @@ namespace YAML
} else {
m_builder.AppendToSequence(pContainer, pNode);
}
}
}
}

View File

@@ -1,7 +1,9 @@
#ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -12,45 +14,41 @@
#include "yaml-cpp/contrib/anchordict.h"
#include "yaml-cpp/contrib/graphbuilder.h"
namespace YAML
{
class GraphBuilderAdapter : public EventHandler
{
namespace YAML {
class GraphBuilderAdapter : public EventHandler {
public:
GraphBuilderAdapter(GraphBuilderInterface& builder)
: m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL)
{
}
: m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL) {}
virtual void OnDocumentStart(const Mark& mark) {(void)mark;}
virtual void OnDocumentStart(const Mark& mark) { (void)mark; }
virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnMapEnd();
void *RootNode() const {return m_pRootNode;}
void* RootNode() const { return m_pRootNode; }
private:
struct ContainerFrame
{
ContainerFrame(void *pSequence)
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker)
{}
ContainerFrame(void *pMap, void* pPrevKeyNode)
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode)
{}
struct ContainerFrame {
ContainerFrame(void* pSequence)
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {}
ContainerFrame(void* pMap, void* pPrevKeyNode)
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode) {}
void *pContainer;
void *pPrevKeyNode;
void* pContainer;
void* pPrevKeyNode;
bool isMap() const {return pPrevKeyNode != &sequenceMarker;}
bool isMap() const { return pPrevKeyNode != &sequenceMarker; }
private:
static int sequenceMarker;
@@ -61,13 +59,13 @@ namespace YAML
GraphBuilderInterface& m_builder;
ContainerStack m_containers;
AnchorMap m_anchors;
void *m_pRootNode;
void *m_pKeyNode;
void* m_pRootNode;
void* m_pKeyNode;
void *GetCurrentParent() const;
void RegisterAnchor(anchor_t anchor, void *pNode);
void DispositionNode(void *pNode);
};
void* GetCurrentParent() const;
void RegisterAnchor(anchor_t anchor, void* pNode);
void DispositionNode(void* pNode);
};
}
#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,24 +1,22 @@
#include "directives.h"
namespace YAML
{
Directives::Directives()
{
namespace YAML {
Directives::Directives() {
// version
version.isDefault = true;
version.major = 1;
version.minor = 2;
}
}
const std::string Directives::TranslateTagHandle(const std::string& handle) const
{
std::map <std::string, std::string>::const_iterator it = tags.find(handle);
if(it == tags.end()) {
if(handle == "!!")
const std::string Directives::TranslateTagHandle(const std::string& handle)
const {
std::map<std::string, std::string>::const_iterator it = tags.find(handle);
if (it == tags.end()) {
if (handle == "!!")
return "tag:yaml.org,2002:";
return handle;
}
return it->second;
}
}
}

View File

@@ -1,29 +1,29 @@
#ifndef DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <map>
namespace YAML
{
struct Version {
namespace YAML {
struct Version {
bool isDefault;
int major, minor;
};
};
struct Directives {
struct Directives {
Directives();
const std::string TranslateTagHandle(const std::string& handle) const;
Version version;
std::map<std::string, std::string> tags;
};
};
}
#endif // DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -5,83 +5,71 @@
#include <sstream>
namespace {
std::string ToString(YAML::anchor_t anchor) {
std::string ToString(YAML::anchor_t anchor) {
std::stringstream stream;
stream << anchor;
return stream.str();
}
}
}
namespace YAML
{
EmitFromEvents::EmitFromEvents(Emitter& emitter): m_emitter(emitter)
{
}
namespace YAML {
EmitFromEvents::EmitFromEvents(Emitter& emitter) : m_emitter(emitter) {}
void EmitFromEvents::OnDocumentStart(const Mark&)
{
}
void EmitFromEvents::OnDocumentStart(const Mark&) {}
void EmitFromEvents::OnDocumentEnd()
{
}
void EmitFromEvents::OnDocumentEnd() {}
void EmitFromEvents::OnNull(const Mark&, anchor_t anchor)
{
void EmitFromEvents::OnNull(const Mark&, anchor_t anchor) {
BeginNode();
EmitProps("", anchor);
m_emitter << Null;
}
}
void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor)
{
void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor) {
BeginNode();
m_emitter << Alias(ToString(anchor));
}
}
void EmitFromEvents::OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value)
{
void EmitFromEvents::OnScalar(const Mark&, const std::string& tag,
anchor_t anchor, const std::string& value) {
BeginNode();
EmitProps(tag, anchor);
m_emitter << value;
}
}
void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor)
{
void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag,
anchor_t anchor) {
BeginNode();
EmitProps(tag, anchor);
m_emitter << BeginSeq;
m_stateStack.push(State::WaitingForSequenceEntry);
}
}
void EmitFromEvents::OnSequenceEnd()
{
void EmitFromEvents::OnSequenceEnd() {
m_emitter << EndSeq;
assert(m_stateStack.top() == State::WaitingForSequenceEntry);
m_stateStack.pop();
}
}
void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag, anchor_t anchor)
{
void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag,
anchor_t anchor) {
BeginNode();
EmitProps(tag, anchor);
m_emitter << BeginMap;
m_stateStack.push(State::WaitingForKey);
}
}
void EmitFromEvents::OnMapEnd()
{
void EmitFromEvents::OnMapEnd() {
m_emitter << EndMap;
assert(m_stateStack.top() == State::WaitingForKey);
m_stateStack.pop();
}
}
void EmitFromEvents::BeginNode()
{
if(m_stateStack.empty())
void EmitFromEvents::BeginNode() {
if (m_stateStack.empty())
return;
switch(m_stateStack.top()) {
switch (m_stateStack.top()) {
case State::WaitingForKey:
m_emitter << Key;
m_stateStack.top() = State::WaitingForValue;
@@ -93,13 +81,12 @@ namespace YAML
default:
break;
}
}
void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor)
{
if(!tag.empty() && tag != "?")
m_emitter << VerbatimTag(tag);
if(anchor)
m_emitter << Anchor(ToString(anchor));
}
}
void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
if (!tag.empty() && tag != "?")
m_emitter << VerbatimTag(tag);
if (anchor)
m_emitter << Anchor(ToString(anchor));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,10 +2,14 @@
#include "yaml-cpp/exceptions.h"
#include <limits>
namespace YAML
{
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_hasAnchor(false), m_hasTag(false), m_hasNonContent(false), m_docCount(0)
{
namespace YAML {
EmitterState::EmitterState()
: m_isGood(true),
m_curIndent(0),
m_hasAnchor(false),
m_hasTag(false),
m_hasNonContent(false),
m_docCount(0) {
// set default global manipulators
m_charset.set(EmitNonAscii);
m_strFmt.set(Auto);
@@ -21,17 +25,14 @@ namespace YAML
m_mapKeyFmt.set(Auto);
m_floatPrecision.set(std::numeric_limits<float>::digits10 + 1);
m_doublePrecision.set(std::numeric_limits<double>::digits10 + 1);
}
}
EmitterState::~EmitterState()
{
}
EmitterState::~EmitterState() {}
// SetLocalValue
// . We blindly tries to set all possible formatters to this value
// . Only the ones that make sense will be accepted
void EmitterState::SetLocalValue(EMITTER_MANIP value)
{
// SetLocalValue
// . We blindly tries to set all possible formatters to this value
// . Only the ones that make sense will be accepted
void EmitterState::SetLocalValue(EMITTER_MANIP value) {
SetOutputCharset(value, FmtScope::Local);
SetStringFormat(value, FmtScope::Local);
SetBoolFormat(value, FmtScope::Local);
@@ -41,66 +42,54 @@ namespace YAML
SetFlowType(GroupType::Seq, value, FmtScope::Local);
SetFlowType(GroupType::Map, value, FmtScope::Local);
SetMapKeyFormat(value, FmtScope::Local);
}
}
void EmitterState::SetAnchor()
{
m_hasAnchor = true;
}
void EmitterState::SetAnchor() { m_hasAnchor = true; }
void EmitterState::SetTag()
{
m_hasTag = true;
}
void EmitterState::SetTag() { m_hasTag = true; }
void EmitterState::SetNonContent()
{
m_hasNonContent = true;
}
void EmitterState::SetNonContent() { m_hasNonContent = true; }
void EmitterState::SetLongKey()
{
void EmitterState::SetLongKey() {
assert(!m_groups.empty());
if(m_groups.empty())
if (m_groups.empty())
return;
assert(m_groups.top().type == GroupType::Map);
m_groups.top().longKey = true;
}
}
void EmitterState::ForceFlow()
{
void EmitterState::ForceFlow() {
assert(!m_groups.empty());
if(m_groups.empty())
if (m_groups.empty())
return;
m_groups.top().flowType = FlowType::Flow;
}
}
void EmitterState::StartedNode()
{
if(m_groups.empty()) {
void EmitterState::StartedNode() {
if (m_groups.empty()) {
m_docCount++;
} else {
m_groups.top().childCount++;
if(m_groups.top().childCount % 2 == 0)
if (m_groups.top().childCount % 2 == 0)
m_groups.top().longKey = false;
}
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
}
EmitterNodeType::value EmitterState::NextGroupType(GroupType::value type) const
{
if(type == GroupType::Seq) {
if(GetFlowType(type) == Block)
EmitterNodeType::value EmitterState::NextGroupType(GroupType::value type)
const {
if (type == GroupType::Seq) {
if (GetFlowType(type) == Block)
return EmitterNodeType::BlockSeq;
else
return EmitterNodeType::FlowSeq;
} else {
if(GetFlowType(type) == Block)
if (GetFlowType(type) == Block)
return EmitterNodeType::BlockMap;
else
return EmitterNodeType::FlowMap;
@@ -109,30 +98,26 @@ namespace YAML
// can't happen
assert(false);
return EmitterNodeType::None;
}
}
void EmitterState::StartedDoc()
{
void EmitterState::StartedDoc() {
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
}
void EmitterState::EndedDoc()
{
void EmitterState::EndedDoc() {
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
}
void EmitterState::StartedScalar()
{
void EmitterState::StartedScalar() {
StartedNode();
ClearModifiedSettings();
}
}
void EmitterState::StartedGroup(GroupType::value type)
{
void EmitterState::StartedGroup(GroupType::value type) {
StartedNode();
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
@@ -144,19 +129,18 @@ namespace YAML
pGroup->modifiedSettings = m_modifiedSettings;
// set up group
if(GetFlowType(type) == Block)
if (GetFlowType(type) == Block)
pGroup->flowType = FlowType::Block;
else
pGroup->flowType = FlowType::Flow;
pGroup->indent = GetIndent();
m_groups.push(pGroup);
}
}
void EmitterState::EndedGroup(GroupType::value type)
{
if(m_groups.empty()) {
if(type == GroupType::Seq)
void EmitterState::EndedGroup(GroupType::value type) {
if (m_groups.empty()) {
if (type == GroupType::Seq)
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
else
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
@@ -165,7 +149,7 @@ namespace YAML
// get rid of the current group
{
std::auto_ptr<Group> pFinishedGroup = m_groups.pop();
if(pFinishedGroup->type != type)
if (pFinishedGroup->type != type)
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
}
@@ -179,57 +163,47 @@ namespace YAML
m_globalModifiedSettings.restore();
ClearModifiedSettings();
}
}
EmitterNodeType::value EmitterState::CurGroupNodeType() const
{
if(m_groups.empty())
EmitterNodeType::value EmitterState::CurGroupNodeType() const {
if (m_groups.empty())
return EmitterNodeType::None;
return m_groups.top().NodeType();
}
}
GroupType::value EmitterState::CurGroupType() const
{
GroupType::value EmitterState::CurGroupType() const {
return m_groups.empty() ? GroupType::None : m_groups.top().type;
}
}
FlowType::value EmitterState::CurGroupFlowType() const
{
FlowType::value EmitterState::CurGroupFlowType() const {
return m_groups.empty() ? FlowType::None : m_groups.top().flowType;
}
}
int EmitterState::CurGroupIndent() const
{
int EmitterState::CurGroupIndent() const {
return m_groups.empty() ? 0 : m_groups.top().indent;
}
}
std::size_t EmitterState::CurGroupChildCount() const
{
std::size_t EmitterState::CurGroupChildCount() const {
return m_groups.empty() ? m_docCount : m_groups.top().childCount;
}
}
bool EmitterState::CurGroupLongKey() const
{
bool EmitterState::CurGroupLongKey() const {
return m_groups.empty() ? false : m_groups.top().longKey;
}
}
int EmitterState::LastIndent() const
{
if(m_groups.size() <= 1)
int EmitterState::LastIndent() const {
if (m_groups.size() <= 1)
return 0;
return m_curIndent - m_groups.top(-1).indent;
}
}
void EmitterState::ClearModifiedSettings()
{
m_modifiedSettings.clear();
}
void EmitterState::ClearModifiedSettings() { m_modifiedSettings.clear(); }
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetOutputCharset(EMITTER_MANIP value,
FmtScope::value scope) {
switch (value) {
case EmitNonAscii:
case EscapeNonAscii:
_Set(m_charset, value, scope);
@@ -237,11 +211,10 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope) {
switch (value) {
case Auto:
case SingleQuoted:
case DoubleQuoted:
@@ -251,11 +224,10 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope) {
switch (value) {
case OnOffBool:
case TrueFalseBool:
case YesNoBool:
@@ -264,11 +236,11 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value,
FmtScope::value scope) {
switch (value) {
case LongBool:
case ShortBool:
_Set(m_boolLengthFmt, value, scope);
@@ -276,11 +248,11 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value,
FmtScope::value scope) {
switch (value) {
case UpperCase:
case LowerCase:
case CamelCase:
@@ -289,11 +261,10 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope) {
switch (value) {
case Dec:
case Hex:
case Oct:
@@ -302,38 +273,35 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope)
{
if(value <= 1)
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope) {
if (value <= 1)
return false;
_Set(m_indent, value, scope);
return true;
}
}
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope)
{
if(value == 0)
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope) {
if (value == 0)
return false;
_Set(m_preCommentIndent, value, scope);
return true;
}
}
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope)
{
if(value == 0)
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope) {
if (value == 0)
return false;
_Set(m_postCommentIndent, value, scope);
return true;
}
}
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
FmtScope::value scope) {
switch (value) {
case Block:
case Flow:
_Set(groupType == GroupType::Seq ? m_seqFmt : m_mapFmt, value, scope);
@@ -341,21 +309,19 @@ namespace YAML
default:
return false;
}
}
}
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const
{
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const {
// force flow style if we're currently in a flow
if(CurGroupFlowType() == FlowType::Flow)
if (CurGroupFlowType() == FlowType::Flow)
return Flow;
// otherwise, go with what's asked of us
return (groupType == GroupType::Seq ? m_seqFmt.get() : m_mapFmt.get());
}
}
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope)
{
switch(value) {
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
switch (value) {
case Auto:
case LongKey:
_Set(m_mapKeyFmt, value, scope);
@@ -363,22 +329,19 @@ namespace YAML
default:
return false;
}
}
}
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope)
{
if(value < 0 || value > std::numeric_limits<float>::digits10 + 1)
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope) {
if (value < 0 || value > std::numeric_limits<float>::digits10 + 1)
return false;
_Set(m_floatPrecision, value, scope);
return true;
}
}
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope)
{
if(value < 0 || value > std::numeric_limits<double>::digits10 + 1)
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope) {
if (value < 0 || value > std::numeric_limits<double>::digits10 + 1)
return false;
_Set(m_doublePrecision, value, scope);
return true;
}
}
}

View File

@@ -1,11 +1,12 @@
#ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "ptr_stack.h"
#include "setting.h"
#include "yaml-cpp/emitterdef.h"
@@ -16,14 +17,29 @@
#include <memory>
#include <stdexcept>
namespace YAML
{
struct FmtScope { enum value { Local, Global }; };
struct GroupType { enum value { None, Seq, Map }; };
struct FlowType { enum value { None, Flow, Block }; };
namespace YAML {
struct FmtScope {
enum value {
Local,
Global
};
};
struct GroupType {
enum value {
None,
Seq,
Map
};
};
struct FlowType {
enum value {
None,
Flow,
Block
};
};
class EmitterState
{
class EmitterState {
public:
EmitterState();
~EmitterState();
@@ -31,7 +47,10 @@ namespace YAML
// basic state checking
bool good() const { return m_isGood; }
const std::string GetLastError() const { return m_lastError; }
void SetError(const std::string& error) { m_isGood = false; m_lastError = error; }
void SetError(const std::string& error) {
m_isGood = false;
m_lastError = error;
}
// node handling
void SetAnchor();
@@ -58,7 +77,9 @@ namespace YAML
int CurIndent() const { return m_curIndent; }
bool HasAnchor() const { return m_hasAnchor; }
bool HasTag() const { return m_hasTag; }
bool HasBegunNode() const { return m_hasAnchor || m_hasTag || m_hasNonContent; }
bool HasBegunNode() const {
return m_hasAnchor || m_hasTag || m_hasNonContent;
}
bool HasBegunContent() const { return m_hasAnchor || m_hasTag; }
void ClearModifiedSettings();
@@ -92,7 +113,8 @@ namespace YAML
bool SetPostCommentIndent(unsigned value, FmtScope::value scope);
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope);
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
FmtScope::value scope);
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
@@ -133,7 +155,8 @@ namespace YAML
SettingChanges m_globalModifiedSettings;
struct Group {
explicit Group(GroupType::value type_): type(type_), indent(0), childCount(0), longKey(false) {}
explicit Group(GroupType::value type_)
: type(type_), indent(0), childCount(0), longKey(false) {}
GroupType::value type;
FlowType::value flowType;
@@ -144,13 +167,13 @@ namespace YAML
SettingChanges modifiedSettings;
EmitterNodeType::value NodeType() const {
if(type == GroupType::Seq) {
if(flowType == FlowType::Flow)
if (type == GroupType::Seq) {
if (flowType == FlowType::Flow)
return EmitterNodeType::FlowSeq;
else
return EmitterNodeType::BlockSeq;
} else {
if(flowType == FlowType::Flow)
if (flowType == FlowType::Flow)
return EmitterNodeType::FlowMap;
else
return EmitterNodeType::BlockMap;
@@ -168,23 +191,24 @@ namespace YAML
bool m_hasTag;
bool m_hasNonContent;
std::size_t m_docCount;
};
};
template <typename T>
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
switch(scope) {
template <typename T>
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
switch (scope) {
case FmtScope::Local:
m_modifiedSettings.push(fmt.set(value));
break;
case FmtScope::Global:
fmt.set(value);
m_globalModifiedSettings.push(fmt.set(value)); // this pushes an identity set, so when we restore,
m_globalModifiedSettings.push(
fmt.set(value)); // this pushes an identity set, so when we restore,
// it restores to the value here, and not the previous one
break;
default:
assert(false);
}
}
}
}
#endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,19 +7,25 @@
#include <sstream>
#include <iomanip>
namespace YAML
{
namespace Utils
{
namespace {
enum {REPLACEMENT_CHARACTER = 0xFFFD};
namespace YAML {
namespace Utils {
namespace {
enum {
REPLACEMENT_CHARACTER = 0xFFFD
};
bool IsAnchorChar(int ch) { // test for ns-anchor-char
bool IsAnchorChar(int ch) { // test for ns-anchor-char
switch (ch) {
case ',': case '[': case ']': case '{': case '}': // c-flow-indicator
case ' ': case '\t': // s-white
case ',':
case '[':
case ']':
case '{':
case '}': // c-flow-indicator
case ' ':
case '\t': // s-white
case 0xFEFF: // c-byte-order-mark
case 0xA: case 0xD: // b-char
case 0xA:
case 0xD: // b-char
return false;
case 0x85:
return true;
@@ -43,14 +49,22 @@ namespace YAML
return false;
return true;
}
}
int Utf8BytesIndicated(char ch) {
int Utf8BytesIndicated(char ch) {
int byteVal = static_cast<unsigned char>(ch);
switch (byteVal >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
return 1;
case 12: case 13:
case 12:
case 13:
return 2;
case 14:
return 3;
@@ -59,13 +73,13 @@ namespace YAML
default:
return -1;
}
}
}
bool IsTrailingByte(char ch) {
return (ch & 0xC0) == 0x80;
}
bool IsTrailingByte(char ch) { return (ch & 0xC0) == 0x80; }
bool GetNextCodePointAndAdvance(int& codePoint, std::string::const_iterator& first, std::string::const_iterator last) {
bool GetNextCodePointAndAdvance(int& codePoint,
std::string::const_iterator& first,
std::string::const_iterator last) {
if (first == last)
return false;
@@ -105,9 +119,9 @@ namespace YAML
else if (codePoint >= 0xFDD0 && codePoint <= 0xFDEF)
codePoint = REPLACEMENT_CHARACTER;
return true;
}
}
void WriteCodePoint(ostream_wrapper& out, int codePoint) {
void WriteCodePoint(ostream_wrapper& out, int codePoint) {
if (codePoint < 0 || codePoint > 0x10FFFF) {
codePoint = REPLACEMENT_CHARACTER;
}
@@ -126,74 +140,75 @@ namespace YAML
<< static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F))
<< static_cast<char>(0x80 | (codePoint & 0x3F));
}
}
}
bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, bool allowOnlyAscii) {
if(str.empty())
bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
bool allowOnlyAscii) {
if (str.empty())
return false;
// first check the start
const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
if(!start.Matches(str))
const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow()
: Exp::PlainScalar());
if (!start.Matches(str))
return false;
// and check the end for plain whitespace (which can't be faithfully kept in a plain scalar)
if(!str.empty() && *str.rbegin() == ' ')
// and check the end for plain whitespace (which can't be faithfully kept in a
// plain scalar)
if (!str.empty() && *str.rbegin() == ' ')
return false;
// then check until something is disallowed
const RegEx& disallowed = (flowType == FlowType::Flow ? Exp::EndScalarInFlow() : Exp::EndScalar())
|| (Exp::BlankOrBreak() + Exp::Comment())
|| Exp::NotPrintable()
|| Exp::Utf8_ByteOrderMark()
|| Exp::Break()
|| Exp::Tab();
const RegEx& disallowed = (flowType == FlowType::Flow ? Exp::EndScalarInFlow()
: Exp::EndScalar()) ||
(Exp::BlankOrBreak() + Exp::Comment()) ||
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() ||
Exp::Break() || Exp::Tab();
StringCharSource buffer(str.c_str(), str.size());
while(buffer) {
if(disallowed.Matches(buffer))
while (buffer) {
if (disallowed.Matches(buffer))
return false;
if(allowOnlyAscii && (0x80 <= static_cast<unsigned char>(buffer[0])))
if (allowOnlyAscii && (0x80 <= static_cast<unsigned char>(buffer[0])))
return false;
++buffer;
}
return true;
}
}
bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii)
{
bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii) {
// TODO: check for non-printable characters?
for(std::size_t i=0;i<str.size();i++) {
if(escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
for (std::size_t i = 0; i < str.size(); i++) {
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
return false;
if(str[i] == '\n')
if (str[i] == '\n')
return false;
}
return true;
}
}
bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType, bool escapeNonAscii)
{
if(flowType == FlowType::Flow)
bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
bool escapeNonAscii) {
if (flowType == FlowType::Flow)
return false;
// TODO: check for non-printable characters?
for(std::size_t i=0;i<str.size();i++) {
if(escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
for (std::size_t i = 0; i < str.size(); i++) {
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
return false;
}
return true;
}
}
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
static const char hexDigits[] = "0123456789abcdef";
out << "\\";
int digits = 8;
if(codePoint < 0xFF) {
if (codePoint < 0xFF) {
out << "x";
digits = 2;
} else if(codePoint < 0xFFFF) {
} else if (codePoint < 0xFFFF) {
out << "u";
digits = 4;
} else {
@@ -204,38 +219,38 @@ namespace YAML
// Write digits into the escape sequence
for (; digits > 0; --digits)
out << hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
}
}
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
if (!IsAnchorChar(codePoint))
return false;
WriteCodePoint(out, codePoint);
}
return true;
}
}
}
}
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii)
{
switch(strFormat) {
StringFormat::value ComputeStringFormat(const std::string& str,
EMITTER_MANIP strFormat,
FlowType::value flowType,
bool escapeNonAscii) {
switch (strFormat) {
case Auto:
if(IsValidPlainScalar(str, flowType, escapeNonAscii))
if (IsValidPlainScalar(str, flowType, escapeNonAscii))
return StringFormat::Plain;
return StringFormat::DoubleQuoted;
case SingleQuoted:
if(IsValidSingleQuotedScalar(str, escapeNonAscii))
if (IsValidSingleQuotedScalar(str, escapeNonAscii))
return StringFormat::SingleQuoted;
return StringFormat::DoubleQuoted;
case DoubleQuoted:
return StringFormat::DoubleQuoted;
case Literal:
if(IsValidLiteralScalar(str, flowType, escapeNonAscii))
if (IsValidLiteralScalar(str, flowType, escapeNonAscii))
return StringFormat::Literal;
return StringFormat::DoubleQuoted;
default:
@@ -243,18 +258,16 @@ namespace YAML
}
return StringFormat::DoubleQuoted;
}
}
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str)
{
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str) {
out << "'";
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
if (codePoint == '\n')
return false; // We can't handle a new line and the attendant indentation yet
return false; // We can't handle a new line and the attendant indentation
// yet
if (codePoint == '\'')
out << "''";
@@ -263,27 +276,40 @@ namespace YAML
}
out << "'";
return true;
}
}
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii)
{
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
bool escapeNonAscii) {
out << "\"";
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
switch(codePoint) {
case '\"': out << "\\\""; break;
case '\\': out << "\\\\"; break;
case '\n': out << "\\n"; break;
case '\t': out << "\\t"; break;
case '\r': out << "\\r"; break;
case '\b': out << "\\b"; break;
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
switch (codePoint) {
case '\"':
out << "\\\"";
break;
case '\\':
out << "\\\\";
break;
case '\n':
out << "\\n";
break;
case '\t':
out << "\\t";
break;
case '\r':
out << "\\r";
break;
case '\b':
out << "\\b";
break;
default:
if(codePoint < 0x20 || (codePoint >= 0x80 && codePoint <= 0xA0)) // Control characters and non-breaking space
if (codePoint < 0x20 ||
(codePoint >= 0x80 &&
codePoint <= 0xA0)) // Control characters and non-breaking space
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (codePoint == 0xFEFF) // Byte order marks (ZWNS) should be escaped (YAML 1.2, sec. 5.2)
else if (codePoint == 0xFEFF) // Byte order marks (ZWNS) should be
// escaped (YAML 1.2, sec. 5.2)
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (escapeNonAscii && codePoint > 0x7E)
WriteDoubleQuoteEscapeSequence(out, codePoint);
@@ -293,36 +319,33 @@ namespace YAML
}
out << "\"";
return true;
}
}
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent)
{
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
int indent) {
out << "|\n";
out << IndentTo(indent);
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
if (codePoint == '\n')
out << "\n" << IndentTo(indent);
else
WriteCodePoint(out, codePoint);
}
return true;
}
}
bool WriteChar(ostream_wrapper& out, char ch)
{
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
bool WriteChar(ostream_wrapper& out, char ch) {
if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
out << ch;
else if((0x20 <= ch && ch <= 0x7e) || ch == ' ')
else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ')
out << "\"" << ch << "\"";
else if(ch == '\t')
else if (ch == '\t')
out << "\"\\t\"";
else if(ch == '\n')
else if (ch == '\n')
out << "\"\\n\"";
else if(ch == '\b')
else if (ch == '\b')
out << "\"\\b\"";
else {
out << "\"";
@@ -330,51 +353,47 @@ namespace YAML
out << "\"";
}
return true;
}
}
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent)
{
bool WriteComment(ostream_wrapper& out, const std::string& str,
int postCommentIndent) {
const unsigned curIndent = out.col();
out << "#" << Indentation(postCommentIndent);
out.set_comment();
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
if(codePoint == '\n') {
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
if (codePoint == '\n') {
out << "\n" << IndentTo(curIndent) << "#"
<< Indentation(postCommentIndent);
out.set_comment();
} else {
WriteCodePoint(out, codePoint);
}
}
return true;
}
}
bool WriteAlias(ostream_wrapper& out, const std::string& str)
{
bool WriteAlias(ostream_wrapper& out, const std::string& str) {
out << "*";
return WriteAliasName(out, str);
}
}
bool WriteAnchor(ostream_wrapper& out, const std::string& str)
{
bool WriteAnchor(ostream_wrapper& out, const std::string& str) {
out << "&";
return WriteAliasName(out, str);
}
}
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim)
{
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim) {
out << (verbatim ? "!<" : "!");
StringCharSource buffer(str.c_str(), str.size());
const RegEx& reValid = verbatim ? Exp::URI() : Exp::Tag();
while(buffer) {
while (buffer) {
int n = reValid.Match(buffer);
if(n <= 0)
if (n <= 0)
return false;
while(--n >= 0) {
while (--n >= 0) {
out << buffer[0];
++buffer;
}
@@ -382,18 +401,18 @@ namespace YAML
if (verbatim)
out << ">";
return true;
}
}
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag)
{
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix,
const std::string& tag) {
out << "!";
StringCharSource prefixBuffer(prefix.c_str(), prefix.size());
while(prefixBuffer) {
while (prefixBuffer) {
int n = Exp::URI().Match(prefixBuffer);
if(n <= 0)
if (n <= 0)
return false;
while(--n >= 0) {
while (--n >= 0) {
out << prefixBuffer[0];
++prefixBuffer;
}
@@ -401,24 +420,23 @@ namespace YAML
out << "!";
StringCharSource tagBuffer(tag.c_str(), tag.size());
while(tagBuffer) {
while (tagBuffer) {
int n = Exp::Tag().Match(tagBuffer);
if(n <= 0)
if (n <= 0)
return false;
while(--n >= 0) {
while (--n >= 0) {
out << tagBuffer[0];
++tagBuffer;
}
}
return true;
}
bool WriteBinary(ostream_wrapper& out, const Binary& binary)
{
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false);
return true;
}
}
}
bool WriteBinary(ostream_wrapper& out, const Binary& binary) {
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()),
false);
return true;
}
}
}

View File

@@ -1,36 +1,49 @@
#ifndef EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "emitterstate.h"
#include "yaml-cpp/ostream_wrapper.h"
#include <string>
namespace YAML
{
class Binary;
namespace YAML {
class Binary;
struct StringFormat { enum value { Plain, SingleQuoted, DoubleQuoted, Literal }; };
struct StringFormat {
enum value {
Plain,
SingleQuoted,
DoubleQuoted,
Literal
};
};
namespace Utils
{
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii);
namespace Utils {
StringFormat::value ComputeStringFormat(const std::string& str,
EMITTER_MANIP strFormat,
FlowType::value flowType,
bool escapeNonAscii);
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii);
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent);
bool WriteChar(ostream_wrapper& out, char ch);
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent);
bool WriteAlias(ostream_wrapper& out, const std::string& str);
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag);
bool WriteBinary(ostream_wrapper& out, const Binary& binary);
}
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
bool escapeNonAscii);
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
int indent);
bool WriteChar(ostream_wrapper& out, char ch);
bool WriteComment(ostream_wrapper& out, const std::string& str,
int postCommentIndent);
bool WriteAlias(ostream_wrapper& out, const std::string& str);
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix,
const std::string& tag);
bool WriteBinary(ostream_wrapper& out, const Binary& binary);
}
}
#endif // EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -2,21 +2,18 @@
#include "yaml-cpp/exceptions.h"
#include <sstream>
namespace YAML
{
namespace Exp
{
unsigned ParseHex(const std::string& str, const Mark& mark)
{
namespace YAML {
namespace Exp {
unsigned ParseHex(const std::string& str, const Mark& mark) {
unsigned value = 0;
for(std::size_t i=0;i<str.size();i++) {
for (std::size_t i = 0; i < str.size(); i++) {
char ch = str[i];
int digit = 0;
if('a' <= ch && ch <= 'f')
if ('a' <= ch && ch <= 'f')
digit = ch - 'a' + 10;
else if('A' <= ch && ch <= 'F')
else if ('A' <= ch && ch <= 'F')
digit = ch - 'A' + 10;
else if('0' <= ch && ch <= '9')
else if ('0' <= ch && ch <= '9')
digit = ch - '0';
else
throw ParserException(mark, ErrorMsg::INVALID_HEX);
@@ -25,51 +22,49 @@ namespace YAML
}
return value;
}
}
std::string Str(unsigned ch)
{
return std::string(1, static_cast<char>(ch));
}
std::string Str(unsigned ch) { return std::string(1, static_cast<char>(ch)); }
// Escape
// . Translates the next 'codeLength' characters into a hex number and returns the result.
// . Throws if it's not actually hex.
std::string Escape(Stream& in, int codeLength)
{
// Escape
// . Translates the next 'codeLength' characters into a hex number and returns
// the result.
// . Throws if it's not actually hex.
std::string Escape(Stream& in, int codeLength) {
// grab string
std::string str;
for(int i=0;i<codeLength;i++)
for (int i = 0; i < codeLength; i++)
str += in.get();
// get the value
unsigned value = ParseHex(str, in.mark());
// legal unicode?
if((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
std::stringstream msg;
msg << ErrorMsg::INVALID_UNICODE << value;
throw ParserException(in.mark(), msg.str());
}
// now break it up into chars
if(value <= 0x7F)
if (value <= 0x7F)
return Str(value);
else if(value <= 0x7FF)
else if (value <= 0x7FF)
return Str(0xC0 + (value >> 6)) + Str(0x80 + (value & 0x3F));
else if(value <= 0xFFFF)
return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F));
else if (value <= 0xFFFF)
return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) +
Str(0x80 + (value & 0x3F));
else
return Str(0xF0 + (value >> 18)) + Str(0x80 + ((value >> 12) & 0x3F)) +
Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F));
}
}
// Escape
// . Escapes the sequence starting 'in' (it must begin with a '\' or single quote)
// and returns the result.
// . Throws if it's an unknown escape character.
std::string Escape(Stream& in)
{
// Escape
// . Escapes the sequence starting 'in' (it must begin with a '\' or single
// quote)
// and returns the result.
// . Throws if it's an unknown escape character.
std::string Escape(Stream& in) {
// eat slash
char escape = in.get();
@@ -77,37 +72,59 @@ namespace YAML
char ch = in.get();
// first do single quote, since it's easier
if(escape == '\'' && ch == '\'')
if (escape == '\'' && ch == '\'')
return "\'";
// now do the slash (we're not gonna check if it's a slash - you better pass one!)
switch(ch) {
case '0': return std::string(1, '\x00');
case 'a': return "\x07";
case 'b': return "\x08";
// now do the slash (we're not gonna check if it's a slash - you better pass
// one!)
switch (ch) {
case '0':
return std::string(1, '\x00');
case 'a':
return "\x07";
case 'b':
return "\x08";
case 't':
case '\t': return "\x09";
case 'n': return "\x0A";
case 'v': return "\x0B";
case 'f': return "\x0C";
case 'r': return "\x0D";
case 'e': return "\x1B";
case ' ': return "\x20";
case '\"': return "\"";
case '\'': return "\'";
case '\\': return "\\";
case '/': return "/";
case 'N': return "\x85";
case '_': return "\xA0";
case 'L': return "\xE2\x80\xA8"; // LS (#x2028)
case 'P': return "\xE2\x80\xA9"; // PS (#x2029)
case 'x': return Escape(in, 2);
case 'u': return Escape(in, 4);
case 'U': return Escape(in, 8);
case '\t':
return "\x09";
case 'n':
return "\x0A";
case 'v':
return "\x0B";
case 'f':
return "\x0C";
case 'r':
return "\x0D";
case 'e':
return "\x1B";
case ' ':
return "\x20";
case '\"':
return "\"";
case '\'':
return "\'";
case '\\':
return "\\";
case '/':
return "/";
case 'N':
return "\x85";
case '_':
return "\xA0";
case 'L':
return "\xE2\x80\xA8"; // LS (#x2028)
case 'P':
return "\xE2\x80\xA9"; // PS (#x2029)
case 'x':
return Escape(in, 2);
case 'u':
return Escape(in, 4);
case 'U':
return Escape(in, 8);
}
std::stringstream msg;
throw ParserException(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch);
}
}
}
}
}

232
src/exp.h
View File

@@ -1,196 +1,208 @@
#ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "regex.h"
#include <string>
#include <ios>
#include "stream.h"
namespace YAML
{
////////////////////////////////////////////////////////////////////////////////
// Here we store a bunch of expressions for matching different parts of the file.
namespace YAML {
////////////////////////////////////////////////////////////////////////////////
// Here we store a bunch of expressions for matching different parts of the
// file.
namespace Exp
{
// misc
inline const RegEx& Space() {
namespace Exp {
// misc
inline const RegEx& Space() {
static const RegEx e = RegEx(' ');
return e;
}
inline const RegEx& Tab() {
}
inline const RegEx& Tab() {
static const RegEx e = RegEx('\t');
return e;
}
inline const RegEx& Blank() {
}
inline const RegEx& Blank() {
static const RegEx e = Space() || Tab();
return e;
}
inline const RegEx& Break() {
}
inline const RegEx& Break() {
static const RegEx e = RegEx('\n') || RegEx("\r\n");
return e;
}
inline const RegEx& BlankOrBreak() {
}
inline const RegEx& BlankOrBreak() {
static const RegEx e = Blank() || Break();
return e;
}
inline const RegEx& Digit() {
}
inline const RegEx& Digit() {
static const RegEx e = RegEx('0', '9');
return e;
}
inline const RegEx& Alpha() {
}
inline const RegEx& Alpha() {
static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
return e;
}
inline const RegEx& AlphaNumeric() {
}
inline const RegEx& AlphaNumeric() {
static const RegEx e = Alpha() || Digit();
return e;
}
inline const RegEx& Word() {
}
inline const RegEx& Word() {
static const RegEx e = AlphaNumeric() || RegEx('-');
return e;
}
inline const RegEx& Hex() {
}
inline const RegEx& Hex() {
static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
return e;
}
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. 5.1)
inline const RegEx& NotPrintable() {
static const RegEx e = RegEx(0) ||
}
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec.
// 5.1)
inline const RegEx& NotPrintable() {
static const RegEx e =
RegEx(0) ||
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) ||
RegEx(0x0E, 0x1F) ||
(RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
return e;
}
inline const RegEx& Utf8_ByteOrderMark() {
}
inline const RegEx& Utf8_ByteOrderMark() {
static const RegEx e = RegEx("\xEF\xBB\xBF");
return e;
}
}
// actual tags
// actual tags
inline const RegEx& DocStart() {
inline const RegEx& DocStart() {
static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
return e;
}
inline const RegEx& DocEnd() {
}
inline const RegEx& DocEnd() {
static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
return e;
}
inline const RegEx& DocIndicator() {
}
inline const RegEx& DocIndicator() {
static const RegEx e = DocStart() || DocEnd();
return e;
}
inline const RegEx& BlockEntry() {
}
inline const RegEx& BlockEntry() {
static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
return e;
}
inline const RegEx& Key() {
}
inline const RegEx& Key() {
static const RegEx e = RegEx('?') + BlankOrBreak();
return e;
}
inline const RegEx& KeyInFlow() {
}
inline const RegEx& KeyInFlow() {
static const RegEx e = RegEx('?') + BlankOrBreak();
return e;
}
inline const RegEx& Value() {
}
inline const RegEx& Value() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
return e;
}
inline const RegEx& ValueInFlow() {
}
inline const RegEx& ValueInFlow() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
return e;
}
inline const RegEx& ValueInJSONFlow() {
}
inline const RegEx& ValueInJSONFlow() {
static const RegEx e = RegEx(':');
return e;
}
inline const RegEx Comment() {
}
inline const RegEx Comment() {
static const RegEx e = RegEx('#');
return e;
}
inline const RegEx& Anchor() {
}
inline const RegEx& Anchor() {
static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
return e;
}
inline const RegEx& AnchorEnd() {
}
inline const RegEx& AnchorEnd() {
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
return e;
}
inline const RegEx& URI() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) || (RegEx('%') + Hex() + Hex());
}
inline const RegEx& URI() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) ||
(RegEx('%') + Hex() + Hex());
return e;
}
inline const RegEx& Tag() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'", REGEX_OR) || (RegEx('%') + Hex() + Hex());
}
inline const RegEx& Tag() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'", REGEX_OR) ||
(RegEx('%') + Hex() + Hex());
return e;
}
}
// Plain scalar rules:
// . Cannot start with a blank.
// . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
// . In the block context - ? : must be not be followed with a space.
// . In the flow context ? is illegal and : and - must not be followed with a space.
inline const RegEx& PlainScalar() {
static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
// Plain scalar rules:
// . Cannot start with a blank.
// . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
// . In the block context - ? : must be not be followed with a space.
// . In the flow context ? is illegal and : and - must not be followed with a
// space.
inline const RegEx& PlainScalar() {
static const RegEx e =
!(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) ||
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
return e;
}
inline const RegEx& PlainScalarInFlow() {
static const RegEx e = !(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank()));
}
inline const RegEx& PlainScalarInFlow() {
static const RegEx e =
!(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) ||
(RegEx("-:", REGEX_OR) + Blank()));
return e;
}
inline const RegEx& EndScalar() {
}
inline const RegEx& EndScalar() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
return e;
}
inline const RegEx& EndScalarInFlow() {
static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
}
inline const RegEx& EndScalarInFlow() {
static const RegEx e =
(RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) ||
RegEx(",?[]{}", REGEX_OR);
return e;
}
}
inline const RegEx& EscSingleQuote() {
inline const RegEx& EscSingleQuote() {
static const RegEx e = RegEx("\'\'");
return e;
}
inline const RegEx& EscBreak() {
}
inline const RegEx& EscBreak() {
static const RegEx e = RegEx('\\') + Break();
return e;
}
}
inline const RegEx& ChompIndicator() {
inline const RegEx& ChompIndicator() {
static const RegEx e = RegEx("+-", REGEX_OR);
return e;
}
inline const RegEx& Chomp() {
static const RegEx e = (ChompIndicator() + Digit()) || (Digit() + ChompIndicator()) || ChompIndicator() || Digit();
}
inline const RegEx& Chomp() {
static const RegEx e = (ChompIndicator() + Digit()) ||
(Digit() + ChompIndicator()) || ChompIndicator() ||
Digit();
return e;
}
}
// and some functions
std::string Escape(Stream& in);
}
// and some functions
std::string Escape(Stream& in);
}
namespace Keys
{
const char Directive = '%';
const char FlowSeqStart = '[';
const char FlowSeqEnd = ']';
const char FlowMapStart = '{';
const char FlowMapEnd = '}';
const char FlowEntry = ',';
const char Alias = '*';
const char Anchor = '&';
const char Tag = '!';
const char LiteralScalar = '|';
const char FoldedScalar = '>';
const char VerbatimTagStart = '<';
const char VerbatimTagEnd = '>';
}
namespace Keys {
const char Directive = '%';
const char FlowSeqStart = '[';
const char FlowSeqEnd = ']';
const char FlowMapStart = '{';
const char FlowMapEnd = '}';
const char FlowEntry = ',';
const char Alias = '*';
const char Anchor = '&';
const char Tag = '!';
const char LiteralScalar = '|';
const char FoldedScalar = '>';
const char VerbatimTagStart = '<';
const char VerbatimTagEnd = '>';
}
}
#endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,38 +1,39 @@
#ifndef INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/ostream_wrapper.h"
#include <iostream>
namespace YAML
{
struct Indentation {
Indentation(unsigned n_): n(n_) {}
namespace YAML {
struct Indentation {
Indentation(unsigned n_) : n(n_) {}
unsigned n;
};
};
inline ostream_wrapper& operator << (ostream_wrapper& out, const Indentation& indent) {
for(unsigned i=0;i<indent.n;i++)
inline ostream_wrapper& operator<<(ostream_wrapper& out,
const Indentation& indent) {
for (unsigned i = 0; i < indent.n; i++)
out << ' ';
return out;
}
struct IndentTo {
IndentTo(unsigned n_): n(n_) {}
unsigned n;
};
inline ostream_wrapper& operator << (ostream_wrapper& out, const IndentTo& indent) {
while(out.col() < indent.n)
out << ' ';
return out;
}
}
struct IndentTo {
IndentTo(unsigned n_) : n(n_) {}
unsigned n;
};
inline ostream_wrapper& operator<<(ostream_wrapper& out,
const IndentTo& indent) {
while (out.col() < indent.n)
out << ' ';
return out;
}
}
#endif // INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,6 +1,5 @@
#include "yaml-cpp/null.h"
namespace YAML
{
_Null Null;
namespace YAML {
_Null Null;
}

View File

@@ -9,133 +9,119 @@
#include <sstream>
#include <cstdio>
namespace YAML
{
Parser::Parser()
{
}
namespace YAML {
Parser::Parser() {}
Parser::Parser(std::istream& in)
{
Load(in);
}
Parser::Parser(std::istream& in) { Load(in); }
Parser::~Parser()
{
}
Parser::~Parser() {}
Parser::operator bool() const
{
Parser::operator bool() const {
return m_pScanner.get() && !m_pScanner->empty();
}
}
void Parser::Load(std::istream& in)
{
void Parser::Load(std::istream& in) {
m_pScanner.reset(new Scanner(in));
m_pDirectives.reset(new Directives);
}
}
// HandleNextDocument
// . Handles the next document
// . Throws a ParserException on error.
// . Returns false if there are no more documents
bool Parser::HandleNextDocument(EventHandler& eventHandler)
{
if(!m_pScanner.get())
// HandleNextDocument
// . Handles the next document
// . Throws a ParserException on error.
// . Returns false if there are no more documents
bool Parser::HandleNextDocument(EventHandler& eventHandler) {
if (!m_pScanner.get())
return false;
ParseDirectives();
if(m_pScanner->empty())
if (m_pScanner->empty())
return false;
SingleDocParser sdp(*m_pScanner, *m_pDirectives);
sdp.HandleDocument(eventHandler);
return true;
}
}
// ParseDirectives
// . Reads any directives that are next in the queue.
void Parser::ParseDirectives()
{
// ParseDirectives
// . Reads any directives that are next in the queue.
void Parser::ParseDirectives() {
bool readDirective = false;
while(1) {
if(m_pScanner->empty())
while (1) {
if (m_pScanner->empty())
break;
Token& token = m_pScanner->peek();
if(token.type != Token::DIRECTIVE)
if (token.type != Token::DIRECTIVE)
break;
// we keep the directives from the last document if none are specified;
// but if any directives are specific, then we reset them
if(!readDirective)
if (!readDirective)
m_pDirectives.reset(new Directives);
readDirective = true;
HandleDirective(token);
m_pScanner->pop();
}
}
}
void Parser::HandleDirective(const Token& token)
{
if(token.value == "YAML")
void Parser::HandleDirective(const Token& token) {
if (token.value == "YAML")
HandleYamlDirective(token);
else if(token.value == "TAG")
else if (token.value == "TAG")
HandleTagDirective(token);
}
}
// HandleYamlDirective
// . Should be of the form 'major.minor' (like a version number)
void Parser::HandleYamlDirective(const Token& token)
{
if(token.params.size() != 1)
// HandleYamlDirective
// . Should be of the form 'major.minor' (like a version number)
void Parser::HandleYamlDirective(const Token& token) {
if (token.params.size() != 1)
throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS);
if(!m_pDirectives->version.isDefault)
if (!m_pDirectives->version.isDefault)
throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE);
std::stringstream str(token.params[0]);
str >> m_pDirectives->version.major;
str.get();
str >> m_pDirectives->version.minor;
if(!str || str.peek() != EOF)
throw ParserException(token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]);
if (!str || str.peek() != EOF)
throw ParserException(
token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]);
if(m_pDirectives->version.major > 1)
if (m_pDirectives->version.major > 1)
throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION);
m_pDirectives->version.isDefault = false;
// TODO: warning on major == 1, minor > 2?
}
}
// HandleTagDirective
// . Should be of the form 'handle prefix', where 'handle' is converted to 'prefix' in the file.
void Parser::HandleTagDirective(const Token& token)
{
if(token.params.size() != 2)
// HandleTagDirective
// . Should be of the form 'handle prefix', where 'handle' is converted to
// 'prefix' in the file.
void Parser::HandleTagDirective(const Token& token) {
if (token.params.size() != 2)
throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS);
const std::string& handle = token.params[0];
const std::string& prefix = token.params[1];
if(m_pDirectives->tags.find(handle) != m_pDirectives->tags.end())
if (m_pDirectives->tags.find(handle) != m_pDirectives->tags.end())
throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE);
m_pDirectives->tags[handle] = prefix;
}
}
void Parser::PrintTokens(std::ostream& out)
{
if(!m_pScanner.get())
void Parser::PrintTokens(std::ostream& out) {
if (!m_pScanner.get())
return;
while(1) {
if(m_pScanner->empty())
while (1) {
if (m_pScanner->empty())
break;
out << m_pScanner->peek() << "\n";
m_pScanner->pop();
}
}
}
}

View File

@@ -1,7 +1,9 @@
#ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -12,14 +14,13 @@
#include <vector>
template <typename T>
class ptr_stack: private YAML::noncopyable
{
public:
class ptr_stack : private YAML::noncopyable {
public:
ptr_stack() {}
~ptr_stack() { clear(); }
void clear() {
for(unsigned i=0;i<m_data.size();i++)
for (unsigned i = 0; i < m_data.size(); i++)
delete m_data[i];
m_data.clear();
}
@@ -40,9 +41,11 @@ public:
const T& top() const { return *m_data.back(); }
T& top(std::ptrdiff_t diff) { return **(m_data.end() - 1 + diff); }
const T& top(std::ptrdiff_t diff) const { return **(m_data.end() - 1 + diff); }
const T& top(std::ptrdiff_t diff) const {
return **(m_data.end() - 1 + diff);
}
private:
private:
std::vector<T*> m_data;
};

View File

@@ -1,7 +1,9 @@
#ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -13,15 +15,14 @@
namespace YAML {
template <typename T>
class ptr_vector: private YAML::noncopyable
{
template <typename T>
class ptr_vector : private YAML::noncopyable {
public:
ptr_vector() {}
~ptr_vector() { clear(); }
void clear() {
for(unsigned i=0;i<m_data.size();i++)
for (unsigned i = 0; i < m_data.size(); i++)
delete m_data[i];
m_data.clear();
}
@@ -41,7 +42,7 @@ namespace YAML {
private:
std::vector<T*> m_data;
};
};
}
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,60 +1,45 @@
#include "regex.h"
namespace YAML
{
// constructors
RegEx::RegEx(): m_op(REGEX_EMPTY)
{
}
namespace YAML {
// constructors
RegEx::RegEx() : m_op(REGEX_EMPTY) {}
RegEx::RegEx(REGEX_OP op): m_op(op)
{
}
RegEx::RegEx(REGEX_OP op) : m_op(op) {}
RegEx::RegEx(char ch): m_op(REGEX_MATCH), m_a(ch)
{
}
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch) {}
RegEx::RegEx(char a, char z): m_op(REGEX_RANGE), m_a(a), m_z(z)
{
}
RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z) {}
RegEx::RegEx(const std::string& str, REGEX_OP op): m_op(op)
{
for(std::size_t i=0;i<str.size();i++)
RegEx::RegEx(const std::string& str, REGEX_OP op) : m_op(op) {
for (std::size_t i = 0; i < str.size(); i++)
m_params.push_back(RegEx(str[i]));
}
}
// combination constructors
RegEx operator ! (const RegEx& ex)
{
// combination constructors
RegEx operator!(const RegEx & ex) {
RegEx ret(REGEX_NOT);
ret.m_params.push_back(ex);
return ret;
}
}
RegEx operator || (const RegEx& ex1, const RegEx& ex2)
{
RegEx operator||(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_OR);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
}
RegEx operator && (const RegEx& ex1, const RegEx& ex2)
{
RegEx operator&&(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_AND);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
}
RegEx operator + (const RegEx& ex1, const RegEx& ex2)
{
RegEx operator+(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_SEQ);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
}
}

View File

@@ -1,25 +1,32 @@
#ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <vector>
#include <string>
namespace YAML
{
class Stream;
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
// . Only straightforward matches (no repeated characters)
// . Only matches from start of string
class RegEx
{
// simplified regular expressions
// . Only straightforward matches (no repeated characters)
// . Only matches from start of string
class RegEx {
public:
RegEx();
RegEx(char ch);
@@ -27,39 +34,50 @@ namespace YAML
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
~RegEx() {}
friend RegEx operator ! (const RegEx& ex);
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
friend RegEx operator && (const RegEx& ex1, const RegEx& ex2);
friend RegEx operator + (const RegEx& ex1, const RegEx& ex2);
friend RegEx operator!(const RegEx & ex);
friend RegEx operator||(const RegEx& ex1, const RegEx& ex2);
friend RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
friend RegEx operator+(const RegEx& ex1, const RegEx& ex2);
bool Matches(char ch) const;
bool Matches(const std::string& str) const;
bool Matches(const Stream& in) const;
template <typename Source> bool Matches(const Source& source) const;
template <typename Source>
bool Matches(const Source& source) const;
int Match(const std::string& str) const;
int Match(const Stream& in) const;
template <typename Source> int Match(const Source& source) const;
template <typename Source>
int Match(const Source& source) const;
private:
RegEx(REGEX_OP op);
template <typename Source> bool IsValidSource(const Source& source) const;
template <typename Source> int MatchUnchecked(const Source& source) const;
template <typename Source>
bool IsValidSource(const Source& source) const;
template <typename Source>
int MatchUnchecked(const Source& source) const;
template <typename Source> int MatchOpEmpty(const Source& source) const;
template <typename Source> int MatchOpMatch(const Source& source) const;
template <typename Source> int MatchOpRange(const Source& source) const;
template <typename Source> int MatchOpOr(const Source& source) const;
template <typename Source> int MatchOpAnd(const Source& source) const;
template <typename Source> int MatchOpNot(const Source& source) const;
template <typename Source> int MatchOpSeq(const Source& source) const;
template <typename Source>
int MatchOpEmpty(const Source& source) const;
template <typename Source>
int MatchOpMatch(const Source& source) const;
template <typename Source>
int MatchOpRange(const Source& source) const;
template <typename Source>
int MatchOpOr(const Source& source) const;
template <typename Source>
int MatchOpAnd(const Source& source) const;
template <typename Source>
int MatchOpNot(const Source& source) const;
template <typename Source>
int MatchOpSeq(const Source& source) const;
private:
REGEX_OP m_op;
char m_a, m_z;
std::vector <RegEx> m_params;
};
std::vector<RegEx> m_params;
};
}
#include "regeximpl.h"

View File

@@ -1,84 +1,77 @@
#ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "stream.h"
#include "stringsource.h"
#include "streamcharsource.h"
namespace YAML
{
// query matches
inline bool RegEx::Matches(char ch) const {
namespace YAML {
// query matches
inline bool RegEx::Matches(char ch) const {
std::string str;
str += ch;
return Matches(str);
}
}
inline bool RegEx::Matches(const std::string& str) const {
inline bool RegEx::Matches(const std::string& str) const {
return Match(str) >= 0;
}
}
inline bool RegEx::Matches(const Stream& in) const {
return Match(in) >= 0;
}
inline bool RegEx::Matches(const Stream& in) const { return Match(in) >= 0; }
template <typename Source>
inline bool RegEx::Matches(const Source& source) const {
template <typename Source>
inline bool RegEx::Matches(const Source& source) const {
return Match(source) >= 0;
}
}
// Match
// . Matches the given string against this regular expression.
// . Returns the number of characters matched.
// . Returns -1 if no characters were matched (the reason for
// not returning zero is that we may have an empty regex
// which is ALWAYS successful at matching zero characters).
// . REMEMBER that we only match from the start of the buffer!
inline int RegEx::Match(const std::string& str) const
{
// Match
// . Matches the given string against this regular expression.
// . Returns the number of characters matched.
// . Returns -1 if no characters were matched (the reason for
// not returning zero is that we may have an empty regex
// which is ALWAYS successful at matching zero characters).
// . REMEMBER that we only match from the start of the buffer!
inline int RegEx::Match(const std::string& str) const {
StringCharSource source(str.c_str(), str.size());
return Match(source);
}
}
inline int RegEx::Match(const Stream& in) const
{
inline int RegEx::Match(const Stream& in) const {
StreamCharSource source(in);
return Match(source);
}
}
template <typename Source>
inline bool RegEx::IsValidSource(const Source& source) const
{
template <typename Source>
inline bool RegEx::IsValidSource(const Source& source) const {
return source;
}
}
template<>
inline bool RegEx::IsValidSource<StringCharSource>(const StringCharSource&source) const
{
switch(m_op) {
template <>
inline bool RegEx::IsValidSource<StringCharSource>(
const StringCharSource& source) const {
switch (m_op) {
case REGEX_MATCH:
case REGEX_RANGE:
return source;
default:
return true;
}
}
}
template <typename Source>
inline int RegEx::Match(const Source& source) const
{
template <typename Source>
inline int RegEx::Match(const Source& source) const {
return IsValidSource(source) ? MatchUnchecked(source) : -1;
}
}
template <typename Source>
inline int RegEx::MatchUnchecked(const Source& source) const
{
switch(m_op) {
template <typename Source>
inline int RegEx::MatchUnchecked(const Source& source) const {
switch (m_op) {
case REGEX_EMPTY:
return MatchOpEmpty(source);
case REGEX_MATCH:
@@ -96,91 +89,98 @@ namespace YAML
}
return -1;
}
}
//////////////////////////////////////////////////////////////////////////////
// Operators
// Note: the convention MatchOp*<Source> is that we can assume IsSourceValid(source).
// So we do all our checks *before* we call these functions
//////////////////////////////////////////////////////////////////////////////
// Operators
// Note: the convention MatchOp*<Source> is that we can assume
// IsSourceValid(source).
// So we do all our checks *before* we call these functions
// EmptyOperator
template <typename Source>
inline int RegEx::MatchOpEmpty(const Source& source) const {
// EmptyOperator
template <typename Source>
inline int RegEx::MatchOpEmpty(const Source& source) const {
return source[0] == Stream::eof() ? 0 : -1;
}
}
template <>
inline int RegEx::MatchOpEmpty<StringCharSource>(const StringCharSource& source) const {
return !source ? 0 : -1; // the empty regex only is successful on the empty string
}
template <>
inline int RegEx::MatchOpEmpty<StringCharSource>(const StringCharSource& source)
const {
return !source
? 0
: -1; // the empty regex only is successful on the empty string
}
// MatchOperator
template <typename Source>
inline int RegEx::MatchOpMatch(const Source& source) const {
if(source[0] != m_a)
// MatchOperator
template <typename Source>
inline int RegEx::MatchOpMatch(const Source& source) const {
if (source[0] != m_a)
return -1;
return 1;
}
}
// RangeOperator
template <typename Source>
inline int RegEx::MatchOpRange(const Source& source) const {
if(m_a > source[0] || m_z < source[0])
// RangeOperator
template <typename Source>
inline int RegEx::MatchOpRange(const Source& source) const {
if (m_a > source[0] || m_z < source[0])
return -1;
return 1;
}
}
// OrOperator
template <typename Source>
inline int RegEx::MatchOpOr(const Source& source) const {
for(std::size_t i=0;i<m_params.size();i++) {
// OrOperator
template <typename Source>
inline int RegEx::MatchOpOr(const Source& source) const {
for (std::size_t i = 0; i < m_params.size(); i++) {
int n = m_params[i].MatchUnchecked(source);
if(n >= 0)
if (n >= 0)
return n;
}
return -1;
}
}
// AndOperator
// Note: 'AND' is a little funny, since we may be required to match things
// of different lengths. If we find a match, we return the length of
// the FIRST entry on the list.
template <typename Source>
inline int RegEx::MatchOpAnd(const Source& source) const {
// AndOperator
// Note: 'AND' is a little funny, since we may be required to match things
// of different lengths. If we find a match, we return the length of
// the FIRST entry on the list.
template <typename Source>
inline int RegEx::MatchOpAnd(const Source& source) const {
int first = -1;
for(std::size_t i=0;i<m_params.size();i++) {
for (std::size_t i = 0; i < m_params.size(); i++) {
int n = m_params[i].MatchUnchecked(source);
if(n == -1)
if (n == -1)
return -1;
if(i == 0)
if (i == 0)
first = n;
}
return first;
}
}
// NotOperator
template <typename Source>
inline int RegEx::MatchOpNot(const Source& source) const {
if(m_params.empty())
// NotOperator
template <typename Source>
inline int RegEx::MatchOpNot(const Source& source) const {
if (m_params.empty())
return -1;
if(m_params[0].MatchUnchecked(source) >= 0)
if (m_params[0].MatchUnchecked(source) >= 0)
return -1;
return 1;
}
}
// SeqOperator
template <typename Source>
inline int RegEx::MatchOpSeq(const Source& source) const {
// SeqOperator
template <typename Source>
inline int RegEx::MatchOpSeq(const Source& source) const {
int offset = 0;
for(std::size_t i=0;i<m_params.size();i++) {
int n = m_params[i].Match(source + offset); // note Match, not MatchUnchecked because we need to check validity after the offset
if(n == -1)
for (std::size_t i = 0; i < m_params.size(); i++) {
int n = m_params[i].Match(source + offset); // note Match, not
// MatchUnchecked because we
// need to check validity after
// the offset
if (n == -1)
return -1;
offset += n;
}
return offset;
}
}
}
#endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -5,40 +5,37 @@
#include <cassert>
#include <memory>
namespace YAML
{
Scanner::Scanner(std::istream& in)
: INPUT(in), m_startedStream(false), m_endedStream(false), m_simpleKeyAllowed(false), m_canBeJSONFlow(false)
{
}
namespace YAML {
Scanner::Scanner(std::istream& in)
: INPUT(in),
m_startedStream(false),
m_endedStream(false),
m_simpleKeyAllowed(false),
m_canBeJSONFlow(false) {}
Scanner::~Scanner()
{
}
Scanner::~Scanner() {}
// empty
// . Returns true if there are no more tokens to be read
bool Scanner::empty()
{
// empty
// . Returns true if there are no more tokens to be read
bool Scanner::empty() {
EnsureTokensInQueue();
return m_tokens.empty();
}
}
// pop
// . Simply removes the next token on the queue.
void Scanner::pop()
{
// pop
// . Simply removes the next token on the queue.
void Scanner::pop() {
EnsureTokensInQueue();
if(!m_tokens.empty())
if (!m_tokens.empty())
m_tokens.pop();
}
}
// peek
// . Returns (but does not remove) the next token on the queue.
Token& Scanner::peek()
{
// peek
// . Returns (but does not remove) the next token on the queue.
Token& Scanner::peek() {
EnsureTokensInQueue();
assert(!m_tokens.empty()); // should we be asserting here? I mean, we really just be checking
assert(!m_tokens.empty()); // should we be asserting here? I mean, we really
// just be checking
// if it's empty before peeking.
#if 0
@@ -49,30 +46,26 @@ namespace YAML
#endif
return m_tokens.front();
}
}
// mark
// . Returns the current mark in the stream
Mark Scanner::mark() const
{
return INPUT.mark();
}
// mark
// . Returns the current mark in the stream
Mark Scanner::mark() const { return INPUT.mark(); }
// EnsureTokensInQueue
// . Scan until there's a valid token at the front of the queue,
// or we're sure the queue is empty.
void Scanner::EnsureTokensInQueue()
{
while(1) {
if(!m_tokens.empty()) {
// EnsureTokensInQueue
// . Scan until there's a valid token at the front of the queue,
// or we're sure the queue is empty.
void Scanner::EnsureTokensInQueue() {
while (1) {
if (!m_tokens.empty()) {
Token& token = m_tokens.front();
// if this guy's valid, then we're done
if(token.status == Token::VALID)
if (token.status == Token::VALID)
return;
// here's where we clean up the impossible tokens
if(token.status == Token::INVALID) {
if (token.status == Token::INVALID) {
m_tokens.pop();
continue;
}
@@ -81,23 +74,22 @@ namespace YAML
}
// no token? maybe we've actually finished
if(m_endedStream)
if (m_endedStream)
return;
// no? then scan...
ScanNextToken();
}
}
}
// ScanNextToken
// . The main scanning function; here we branch out and
// scan whatever the next token should be.
void Scanner::ScanNextToken()
{
if(m_endedStream)
// ScanNextToken
// . The main scanning function; here we branch out and
// scan whatever the next token should be.
void Scanner::ScanNextToken() {
if (m_endedStream)
return;
if(!m_startedStream)
if (!m_startedStream)
return StartStream();
// get rid of whitespace, etc. (in between tokens it should be irrelevent)
@@ -111,83 +103,84 @@ namespace YAML
// *****
// end of stream
if(!INPUT)
if (!INPUT)
return EndStream();
if(INPUT.column() == 0 && INPUT.peek() == Keys::Directive)
if (INPUT.column() == 0 && INPUT.peek() == Keys::Directive)
return ScanDirective();
// document token
if(INPUT.column() == 0 && Exp::DocStart().Matches(INPUT))
if (INPUT.column() == 0 && Exp::DocStart().Matches(INPUT))
return ScanDocStart();
if(INPUT.column() == 0 && Exp::DocEnd().Matches(INPUT))
if (INPUT.column() == 0 && Exp::DocEnd().Matches(INPUT))
return ScanDocEnd();
// flow start/end/entry
if(INPUT.peek() == Keys::FlowSeqStart || INPUT.peek() == Keys::FlowMapStart)
if (INPUT.peek() == Keys::FlowSeqStart || INPUT.peek() == Keys::FlowMapStart)
return ScanFlowStart();
if(INPUT.peek() == Keys::FlowSeqEnd || INPUT.peek() == Keys::FlowMapEnd)
if (INPUT.peek() == Keys::FlowSeqEnd || INPUT.peek() == Keys::FlowMapEnd)
return ScanFlowEnd();
if(INPUT.peek() == Keys::FlowEntry)
if (INPUT.peek() == Keys::FlowEntry)
return ScanFlowEntry();
// block/map stuff
if(Exp::BlockEntry().Matches(INPUT))
if (Exp::BlockEntry().Matches(INPUT))
return ScanBlockEntry();
if((InBlockContext() ? Exp::Key() : Exp::KeyInFlow()).Matches(INPUT))
if ((InBlockContext() ? Exp::Key() : Exp::KeyInFlow()).Matches(INPUT))
return ScanKey();
if(GetValueRegex().Matches(INPUT))
if (GetValueRegex().Matches(INPUT))
return ScanValue();
// alias/anchor
if(INPUT.peek() == Keys::Alias || INPUT.peek() == Keys::Anchor)
if (INPUT.peek() == Keys::Alias || INPUT.peek() == Keys::Anchor)
return ScanAnchorOrAlias();
// tag
if(INPUT.peek() == Keys::Tag)
if (INPUT.peek() == Keys::Tag)
return ScanTag();
// special scalars
if(InBlockContext() && (INPUT.peek() == Keys::LiteralScalar || INPUT.peek() == Keys::FoldedScalar))
if (InBlockContext() && (INPUT.peek() == Keys::LiteralScalar ||
INPUT.peek() == Keys::FoldedScalar))
return ScanBlockScalar();
if(INPUT.peek() == '\'' || INPUT.peek() == '\"')
if (INPUT.peek() == '\'' || INPUT.peek() == '\"')
return ScanQuotedScalar();
// plain scalars
if((InBlockContext() ? Exp::PlainScalar() : Exp::PlainScalarInFlow()).Matches(INPUT))
if ((InBlockContext() ? Exp::PlainScalar() : Exp::PlainScalarInFlow())
.Matches(INPUT))
return ScanPlainScalar();
// don't know what it is!
throw ParserException(INPUT.mark(), ErrorMsg::UNKNOWN_TOKEN);
}
}
// ScanToNextToken
// . Eats input until we reach the next token-like thing.
void Scanner::ScanToNextToken()
{
while(1) {
// ScanToNextToken
// . Eats input until we reach the next token-like thing.
void Scanner::ScanToNextToken() {
while (1) {
// first eat whitespace
while(INPUT && IsWhitespaceToBeEaten(INPUT.peek())) {
if(InBlockContext() && Exp::Tab().Matches(INPUT))
while (INPUT && IsWhitespaceToBeEaten(INPUT.peek())) {
if (InBlockContext() && Exp::Tab().Matches(INPUT))
m_simpleKeyAllowed = false;
INPUT.eat(1);
}
// then eat a comment
if(Exp::Comment().Matches(INPUT)) {
if (Exp::Comment().Matches(INPUT)) {
// eat until line break
while(INPUT && !Exp::Break().Matches(INPUT))
while (INPUT && !Exp::Break().Matches(INPUT))
INPUT.eat(1);
}
// if it's NOT a line break, then we're done!
if(!Exp::Break().Matches(INPUT))
if (!Exp::Break().Matches(INPUT))
break;
// otherwise, let's eat the line break and keep going
@@ -198,60 +191,57 @@ namespace YAML
InvalidateSimpleKey();
// new line - we may be able to accept a simple key now
if(InBlockContext())
if (InBlockContext())
m_simpleKeyAllowed = true;
}
}
}
///////////////////////////////////////////////////////////////////////
// Misc. helpers
///////////////////////////////////////////////////////////////////////
// Misc. helpers
// IsWhitespaceToBeEaten
// . We can eat whitespace if it's a space or tab
// . Note: originally tabs in block context couldn't be eaten
// "where a simple key could be allowed
// (i.e., not at the beginning of a line, or following '-', '?', or ':')"
// I think this is wrong, since tabs can be non-content whitespace; it's just
// that they can't contribute to indentation, so once you've seen a tab in a
// line, you can't start a simple key
bool Scanner::IsWhitespaceToBeEaten(char ch)
{
if(ch == ' ')
// IsWhitespaceToBeEaten
// . We can eat whitespace if it's a space or tab
// . Note: originally tabs in block context couldn't be eaten
// "where a simple key could be allowed
// (i.e., not at the beginning of a line, or following '-', '?', or
// ':')"
// I think this is wrong, since tabs can be non-content whitespace; it's just
// that they can't contribute to indentation, so once you've seen a tab in a
// line, you can't start a simple key
bool Scanner::IsWhitespaceToBeEaten(char ch) {
if (ch == ' ')
return true;
if(ch == '\t')
if (ch == '\t')
return true;
return false;
}
}
// GetValueRegex
// . Get the appropriate regex to check if it's a value token
const RegEx& Scanner::GetValueRegex() const
{
if(InBlockContext())
// GetValueRegex
// . Get the appropriate regex to check if it's a value token
const RegEx& Scanner::GetValueRegex() const {
if (InBlockContext())
return Exp::Value();
return m_canBeJSONFlow ? Exp::ValueInJSONFlow() : Exp::ValueInFlow();
}
}
// StartStream
// . Set the initial conditions for starting a stream.
void Scanner::StartStream()
{
// StartStream
// . Set the initial conditions for starting a stream.
void Scanner::StartStream() {
m_startedStream = true;
m_simpleKeyAllowed = true;
std::auto_ptr<IndentMarker> pIndent(new IndentMarker(-1, IndentMarker::NONE));
m_indentRefs.push_back(pIndent);
m_indents.push(&m_indentRefs.back());
}
}
// EndStream
// . Close out the stream, finish up, etc.
void Scanner::EndStream()
{
// EndStream
// . Close out the stream, finish up, etc.
void Scanner::EndStream() {
// force newline
if(INPUT.column() > 0)
if (INPUT.column() > 0)
INPUT.ResetColumn();
PopAllIndents();
@@ -259,33 +249,35 @@ namespace YAML
m_simpleKeyAllowed = false;
m_endedStream = true;
}
}
Token *Scanner::PushToken(Token::TYPE type)
{
Token* Scanner::PushToken(Token::TYPE type) {
m_tokens.push(Token(type, INPUT.mark()));
return &m_tokens.back();
}
}
Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) const
{
switch(type) {
case IndentMarker::SEQ: return Token::BLOCK_SEQ_START;
case IndentMarker::MAP: return Token::BLOCK_MAP_START;
case IndentMarker::NONE: assert(false); break;
Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) const {
switch (type) {
case IndentMarker::SEQ:
return Token::BLOCK_SEQ_START;
case IndentMarker::MAP:
return Token::BLOCK_MAP_START;
case IndentMarker::NONE:
assert(false);
break;
}
assert(false);
throw std::runtime_error("yaml-cpp: internal error, invalid indent type");
}
}
// PushIndentTo
// . Pushes an indentation onto the stack, and enqueues the
// proper token (sequence start or mapping start).
// . Returns the indent marker it generates (if any).
Scanner::IndentMarker *Scanner::PushIndentTo(int column, IndentMarker::INDENT_TYPE type)
{
// PushIndentTo
// . Pushes an indentation onto the stack, and enqueues the
// proper token (sequence start or mapping start).
// . Returns the indent marker it generates (if any).
Scanner::IndentMarker* Scanner::PushIndentTo(int column,
IndentMarker::INDENT_TYPE type) {
// are we in flow?
if(InFlowContext())
if (InFlowContext())
return 0;
std::auto_ptr<IndentMarker> pIndent(new IndentMarker(column, type));
@@ -293,9 +285,11 @@ namespace YAML
const IndentMarker& lastIndent = *m_indents.top();
// is this actually an indentation?
if(indent.column < lastIndent.column)
if (indent.column < lastIndent.column)
return 0;
if(indent.column == lastIndent.column && !(indent.type == IndentMarker::SEQ && lastIndent.type == IndentMarker::MAP))
if (indent.column == lastIndent.column &&
!(indent.type == IndentMarker::SEQ &&
lastIndent.type == IndentMarker::MAP))
return 0;
// push a start token
@@ -305,90 +299,86 @@ namespace YAML
m_indents.push(&indent);
m_indentRefs.push_back(pIndent);
return &m_indentRefs.back();
}
}
// PopIndentToHere
// . Pops indentations off the stack until we reach the current indentation level,
// and enqueues the proper token each time.
// . Then pops all invalid indentations off.
void Scanner::PopIndentToHere()
{
// PopIndentToHere
// . Pops indentations off the stack until we reach the current indentation
// level,
// and enqueues the proper token each time.
// . Then pops all invalid indentations off.
void Scanner::PopIndentToHere() {
// are we in flow?
if(InFlowContext())
if (InFlowContext())
return;
// now pop away
while(!m_indents.empty()) {
while (!m_indents.empty()) {
const IndentMarker& indent = *m_indents.top();
if(indent.column < INPUT.column())
if (indent.column < INPUT.column())
break;
if(indent.column == INPUT.column() && !(indent.type == IndentMarker::SEQ && !Exp::BlockEntry().Matches(INPUT)))
if (indent.column == INPUT.column() && !(indent.type == IndentMarker::SEQ &&
!Exp::BlockEntry().Matches(INPUT)))
break;
PopIndent();
}
while(!m_indents.empty() && m_indents.top()->status == IndentMarker::INVALID)
while (!m_indents.empty() && m_indents.top()->status == IndentMarker::INVALID)
PopIndent();
}
}
// PopAllIndents
// . Pops all indentations (except for the base empty one) off the stack,
// and enqueues the proper token each time.
void Scanner::PopAllIndents()
{
// PopAllIndents
// . Pops all indentations (except for the base empty one) off the stack,
// and enqueues the proper token each time.
void Scanner::PopAllIndents() {
// are we in flow?
if(InFlowContext())
if (InFlowContext())
return;
// now pop away
while(!m_indents.empty()) {
while (!m_indents.empty()) {
const IndentMarker& indent = *m_indents.top();
if(indent.type == IndentMarker::NONE)
if (indent.type == IndentMarker::NONE)
break;
PopIndent();
}
}
}
// PopIndent
// . Pops a single indent, pushing the proper token
void Scanner::PopIndent()
{
// PopIndent
// . Pops a single indent, pushing the proper token
void Scanner::PopIndent() {
const IndentMarker& indent = *m_indents.top();
m_indents.pop();
if(indent.status != IndentMarker::VALID) {
if (indent.status != IndentMarker::VALID) {
InvalidateSimpleKey();
return;
}
if(indent.type == IndentMarker::SEQ)
if (indent.type == IndentMarker::SEQ)
m_tokens.push(Token(Token::BLOCK_SEQ_END, INPUT.mark()));
else if(indent.type == IndentMarker::MAP)
else if (indent.type == IndentMarker::MAP)
m_tokens.push(Token(Token::BLOCK_MAP_END, INPUT.mark()));
}
}
// GetTopIndent
int Scanner::GetTopIndent() const
{
if(m_indents.empty())
// GetTopIndent
int Scanner::GetTopIndent() const {
if (m_indents.empty())
return 0;
return m_indents.top()->column;
}
}
// ThrowParserException
// . Throws a ParserException with the current token location
// (if available).
// . Does not parse any more tokens.
void Scanner::ThrowParserException(const std::string& msg) const
{
// ThrowParserException
// . Throws a ParserException with the current token location
// (if available).
// . Does not parse any more tokens.
void Scanner::ThrowParserException(const std::string& msg) const {
Mark mark = Mark::null_mark();
if(!m_tokens.empty()) {
if (!m_tokens.empty()) {
const Token& token = m_tokens.front();
mark = token.mark;
}
throw ParserException(mark, msg);
}
}
}

View File

@@ -1,11 +1,12 @@
#ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <ios>
#include <string>
#include <queue>
@@ -16,28 +17,35 @@
#include "stream.h"
#include "token.h"
namespace YAML
{
class Node;
class RegEx;
namespace YAML {
class Node;
class RegEx;
class Scanner
{
class Scanner {
public:
Scanner(std::istream& in);
Scanner(std::istream &in);
~Scanner();
// token queue management (hopefully this looks kinda stl-ish)
bool empty();
void pop();
Token& peek();
Token &peek();
Mark mark() const;
private:
struct IndentMarker {
enum INDENT_TYPE { MAP, SEQ, NONE };
enum STATUS { VALID, INVALID, UNKNOWN };
IndentMarker(int column_, INDENT_TYPE type_): column(column_), type(type_), status(VALID), pStartToken(0) {}
enum INDENT_TYPE {
MAP,
SEQ,
NONE
};
enum STATUS {
VALID,
INVALID,
UNKNOWN
};
IndentMarker(int column_, INDENT_TYPE type_)
: column(column_), type(type_), status(VALID), pStartToken(0) {}
int column;
INDENT_TYPE type;
@@ -45,7 +53,10 @@ namespace YAML
Token *pStartToken;
};
enum FLOW_MARKER { FLOW_MAP, FLOW_SEQ };
enum FLOW_MARKER {
FLOW_MAP,
FLOW_SEQ
};
private:
// scanning
@@ -75,13 +86,13 @@ namespace YAML
bool VerifySimpleKey();
void PopAllSimpleKeys();
void ThrowParserException(const std::string& msg) const;
void ThrowParserException(const std::string &msg) const;
bool IsWhitespaceToBeEaten(char ch);
const RegEx& GetValueRegex() const;
const RegEx &GetValueRegex() const;
struct SimpleKey {
SimpleKey(const Mark& mark_, int flowLevel_);
SimpleKey(const Mark &mark_, int flowLevel_);
void Validate();
void Invalidate();
@@ -126,8 +137,7 @@ namespace YAML
std::stack<IndentMarker *> m_indents;
ptr_vector<IndentMarker> m_indentRefs; // for "garbage collection"
std::stack<FLOW_MARKER> m_flows;
};
};
}
#endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -4,20 +4,18 @@
#include "yaml-cpp/exceptions.h"
#include "token.h"
namespace YAML
{
// ScanScalar
// . This is where the scalar magic happens.
//
// . We do the scanning in three phases:
// 1. Scan until newline
// 2. Eat newline
// 3. Scan leading blanks.
//
// . Depending on the parameters given, we store or stop
// and different places in the above flow.
std::string ScanScalar(Stream& INPUT, ScanScalarParams& params)
{
namespace YAML {
// ScanScalar
// . This is where the scalar magic happens.
//
// . We do the scanning in three phases:
// 1. Scan until newline
// 2. Eat newline
// 3. Scan leading blanks.
//
// . Depending on the parameters given, we store or stop
// and different places in the above flow.
std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
bool foundNonEmptyLine = false;
bool pastOpeningBreak = (params.fold == FOLD_FLOW);
bool emptyLine = false, moreIndented = false;
@@ -27,21 +25,21 @@ namespace YAML
std::string scalar;
params.leadingSpaces = false;
while(INPUT) {
while (INPUT) {
// ********************************
// Phase #1: scan until line ending
std::size_t lastNonWhitespaceChar = scalar.size();
bool escapedNewline = false;
while(!params.end.Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
if(!INPUT)
while (!params.end.Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
if (!INPUT)
break;
// document indicator?
if(INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
if(params.onDocIndicator == BREAK)
if (INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
if (params.onDocIndicator == BREAK)
break;
else if(params.onDocIndicator == THROW)
else if (params.onDocIndicator == THROW)
throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
}
@@ -49,7 +47,7 @@ namespace YAML
pastOpeningBreak = true;
// escaped newline? (only if we're escaping on slash)
if(params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
if (params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
// eat escape character and get out (but preserve trailing whitespace!)
INPUT.get();
lastNonWhitespaceChar = scalar.size();
@@ -59,7 +57,7 @@ namespace YAML
}
// escape this?
if(INPUT.peek() == params.escape) {
if (INPUT.peek() == params.escape) {
scalar += Exp::Escape(INPUT);
lastNonWhitespaceChar = scalar.size();
lastEscapedChar = scalar.size();
@@ -69,31 +67,32 @@ namespace YAML
// otherwise, just add the damn character
char ch = INPUT.get();
scalar += ch;
if(ch != ' ' && ch != '\t')
if (ch != ' ' && ch != '\t')
lastNonWhitespaceChar = scalar.size();
}
// eof? if we're looking to eat something, then we throw
if(!INPUT) {
if(params.eatEnd)
if (!INPUT) {
if (params.eatEnd)
throw ParserException(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);
break;
}
// doc indicator?
if(params.onDocIndicator == BREAK && INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT))
if (params.onDocIndicator == BREAK && INPUT.column() == 0 &&
Exp::DocIndicator().Matches(INPUT))
break;
// are we done via character match?
int n = params.end.Match(INPUT);
if(n >= 0) {
if(params.eatEnd)
if (n >= 0) {
if (params.eatEnd)
INPUT.eat(n);
break;
}
// do we remove trailing whitespace?
if(params.fold == FOLD_FLOW)
if (params.fold == FOLD_FLOW)
scalar.erase(lastNonWhitespaceChar);
// ********************************
@@ -105,20 +104,22 @@ namespace YAML
// Phase #3: scan initial spaces
// first the required indentation
while(INPUT.peek() == ' ' && (INPUT.column() < params.indent || (params.detectIndent && !foundNonEmptyLine)))
while (INPUT.peek() == ' ' && (INPUT.column() < params.indent ||
(params.detectIndent && !foundNonEmptyLine)))
INPUT.eat(1);
// update indent if we're auto-detecting
if(params.detectIndent && !foundNonEmptyLine)
if (params.detectIndent && !foundNonEmptyLine)
params.indent = std::max(params.indent, INPUT.column());
// and then the rest of the whitespace
while(Exp::Blank().Matches(INPUT)) {
while (Exp::Blank().Matches(INPUT)) {
// we check for tabs that masquerade as indentation
if(INPUT.peek() == '\t'&& INPUT.column() < params.indent && params.onTabInIndentation == THROW)
if (INPUT.peek() == '\t' && INPUT.column() < params.indent &&
params.onTabInIndentation == THROW)
throw ParserException(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);
if(!params.eatLeadingWhitespace)
if (!params.eatLeadingWhitespace)
break;
INPUT.eat(1);
@@ -127,34 +128,37 @@ namespace YAML
// was this an empty line?
bool nextEmptyLine = Exp::Break().Matches(INPUT);
bool nextMoreIndented = Exp::Blank().Matches(INPUT);
if(params.fold == FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
if (params.fold == FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
foldedNewlineStartedMoreIndented = moreIndented;
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
if(pastOpeningBreak) {
switch(params.fold) {
// for block scalars, we always start with a newline, so we should ignore it
// (not fold or keep)
if (pastOpeningBreak) {
switch (params.fold) {
case DONT_FOLD:
scalar += "\n";
break;
case FOLD_BLOCK:
if(!emptyLine && !nextEmptyLine && !moreIndented && !nextMoreIndented && INPUT.column() >= params.indent)
if (!emptyLine && !nextEmptyLine && !moreIndented &&
!nextMoreIndented && INPUT.column() >= params.indent)
scalar += " ";
else if(nextEmptyLine)
else if (nextEmptyLine)
foldedNewlineCount++;
else
scalar += "\n";
if(!nextEmptyLine && foldedNewlineCount > 0) {
if (!nextEmptyLine && foldedNewlineCount > 0) {
scalar += std::string(foldedNewlineCount - 1, '\n');
if(foldedNewlineStartedMoreIndented || nextMoreIndented | !foundNonEmptyLine)
if (foldedNewlineStartedMoreIndented ||
nextMoreIndented | !foundNonEmptyLine)
scalar += "\n";
foldedNewlineCount = 0;
}
break;
case FOLD_FLOW:
if(nextEmptyLine)
if (nextEmptyLine)
scalar += "\n";
else if(!emptyLine && !nextEmptyLine && !escapedNewline)
else if (!emptyLine && !nextEmptyLine && !escapedNewline)
scalar += " ";
break;
}
@@ -165,44 +169,44 @@ namespace YAML
pastOpeningBreak = true;
// are we done via indentation?
if(!emptyLine && INPUT.column() < params.indent) {
if (!emptyLine && INPUT.column() < params.indent) {
params.leadingSpaces = true;
break;
}
}
// post-processing
if(params.trimTrailingSpaces) {
if (params.trimTrailingSpaces) {
std::size_t pos = scalar.find_last_not_of(' ');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos < scalar.size())
if (pos < scalar.size())
scalar.erase(pos + 1);
}
switch(params.chomp) {
switch (params.chomp) {
case CLIP: {
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
if (pos == std::string::npos)
scalar.erase();
else if(pos + 1 < scalar.size())
else if (pos + 1 < scalar.size())
scalar.erase(pos + 2);
} break;
case STRIP: {
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
if (pos == std::string::npos)
scalar.erase();
else if(pos < scalar.size())
else if (pos < scalar.size())
scalar.erase(pos + 1);
} break;
default:
@@ -210,5 +214,5 @@ namespace YAML
}
return scalar;
}
}
}

View File

@@ -1,45 +1,72 @@
#ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include "regex.h"
#include "stream.h"
namespace YAML
{
enum CHOMP { STRIP = -1, CLIP, KEEP };
enum ACTION { NONE, BREAK, THROW };
enum FOLD { DONT_FOLD, FOLD_BLOCK, FOLD_FLOW };
namespace YAML {
enum CHOMP {
STRIP = -1,
CLIP,
KEEP
};
enum ACTION {
NONE,
BREAK,
THROW
};
enum FOLD {
DONT_FOLD,
FOLD_BLOCK,
FOLD_FLOW
};
struct ScanScalarParams {
ScanScalarParams(): eatEnd(false), indent(0), detectIndent(false), eatLeadingWhitespace(0), escape(0), fold(DONT_FOLD),
trimTrailingSpaces(0), chomp(CLIP), onDocIndicator(NONE), onTabInIndentation(NONE), leadingSpaces(false) {}
struct ScanScalarParams {
ScanScalarParams()
: eatEnd(false),
indent(0),
detectIndent(false),
eatLeadingWhitespace(0),
escape(0),
fold(DONT_FOLD),
trimTrailingSpaces(0),
chomp(CLIP),
onDocIndicator(NONE),
onTabInIndentation(NONE),
leadingSpaces(false) {}
// input:
RegEx end; // what condition ends this scalar?
bool eatEnd; // should we eat that condition when we see it?
int indent; // what level of indentation should be eaten and ignored?
bool detectIndent; // should we try to autodetect the indent?
bool eatLeadingWhitespace; // should we continue eating this delicious indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote) (0 for none)
bool eatLeadingWhitespace; // should we continue eating this delicious
// indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote)
// (0 for none)
FOLD fold; // how do we fold line ends?
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very end)
// Note: strip means kill all, clip means keep at most one, keep means keep all
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very
// end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very
// end)
// Note: strip means kill all, clip means keep at most one, keep means keep
// all
ACTION onDocIndicator; // what do we do if we see a document indicator?
ACTION onTabInIndentation; // what do we do if we see a tab where we should be seeing indentation spaces
ACTION onTabInIndentation; // what do we do if we see a tab where we should
// be seeing indentation spaces
// output:
bool leadingSpaces;
};
};
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info);
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info);
}
#endif // SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -3,82 +3,77 @@
#include "exp.h"
#include "yaml-cpp/exceptions.h"
namespace YAML
{
const std::string ScanVerbatimTag(Stream& INPUT)
{
namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT) {
std::string tag;
// eat the start character
INPUT.get();
while(INPUT) {
if(INPUT.peek() == Keys::VerbatimTagEnd) {
while (INPUT) {
if (INPUT.peek() == Keys::VerbatimTagEnd) {
// eat the end character
INPUT.get();
return tag;
}
int n = Exp::URI().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
}
}
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle)
{
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
std::string tag;
canBeHandle = true;
Mark firstNonWordChar;
while(INPUT) {
if(INPUT.peek() == Keys::Tag) {
if(!canBeHandle)
while (INPUT) {
if (INPUT.peek() == Keys::Tag) {
if (!canBeHandle)
throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
break;
}
int n = 0;
if(canBeHandle) {
if (canBeHandle) {
n = Exp::Word().Match(INPUT);
if(n <= 0) {
if (n <= 0) {
canBeHandle = false;
firstNonWordChar = INPUT.mark();
}
}
if(!canBeHandle)
if (!canBeHandle)
n = Exp::Tag().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
return tag;
}
}
const std::string ScanTagSuffix(Stream& INPUT)
{
const std::string ScanTagSuffix(Stream& INPUT) {
std::string tag;
while(INPUT) {
while (INPUT) {
int n = Exp::Tag().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
if(tag.empty())
if (tag.empty())
throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
return tag;
}
}
}

View File

@@ -1,20 +1,19 @@
#ifndef SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include "stream.h"
namespace YAML
{
const std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagSuffix(Stream& INPUT);
namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagSuffix(Stream& INPUT);
}
#endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -7,17 +7,15 @@
#include "tag.h"
#include <sstream>
namespace YAML
{
///////////////////////////////////////////////////////////////////////
// Specialization for scanning specific tokens
namespace YAML {
///////////////////////////////////////////////////////////////////////
// Specialization for scanning specific tokens
// Directive
// . Note: no semantic checking is done here (that's for the parser to do)
void Scanner::ScanDirective()
{
// Directive
// . Note: no semantic checking is done here (that's for the parser to do)
void Scanner::ScanDirective() {
std::string name;
std::vector <std::string> params;
std::vector<std::string> params;
// pop indents and simple keys
PopAllIndents();
@@ -31,33 +29,32 @@ namespace YAML
INPUT.eat(1);
// read name
while(INPUT && !Exp::BlankOrBreak().Matches(INPUT))
while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
token.value += INPUT.get();
// read parameters
while(1) {
while (1) {
// first get rid of whitespace
while(Exp::Blank().Matches(INPUT))
while (Exp::Blank().Matches(INPUT))
INPUT.eat(1);
// break on newline or comment
if(!INPUT || Exp::Break().Matches(INPUT) || Exp::Comment().Matches(INPUT))
if (!INPUT || Exp::Break().Matches(INPUT) || Exp::Comment().Matches(INPUT))
break;
// now read parameter
std::string param;
while(INPUT && !Exp::BlankOrBreak().Matches(INPUT))
while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
param += INPUT.get();
token.params.push_back(param);
}
m_tokens.push(token);
}
}
// DocStart
void Scanner::ScanDocStart()
{
// DocStart
void Scanner::ScanDocStart() {
PopAllIndents();
PopAllSimpleKeys();
m_simpleKeyAllowed = false;
@@ -67,11 +64,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(3);
m_tokens.push(Token(Token::DOC_START, mark));
}
}
// DocEnd
void Scanner::ScanDocEnd()
{
// DocEnd
void Scanner::ScanDocEnd() {
PopAllIndents();
PopAllSimpleKeys();
m_simpleKeyAllowed = false;
@@ -81,11 +77,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(3);
m_tokens.push(Token(Token::DOC_END, mark));
}
}
// FlowStart
void Scanner::ScanFlowStart()
{
// FlowStart
void Scanner::ScanFlowStart() {
// flows can be simple keys
InsertPotentialSimpleKey();
m_simpleKeyAllowed = true;
@@ -96,21 +91,21 @@ namespace YAML
char ch = INPUT.get();
FLOW_MARKER flowType = (ch == Keys::FlowSeqStart ? FLOW_SEQ : FLOW_MAP);
m_flows.push(flowType);
Token::TYPE type = (flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START);
Token::TYPE type =
(flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START);
m_tokens.push(Token(type, mark));
}
}
// FlowEnd
void Scanner::ScanFlowEnd()
{
if(InBlockContext())
// FlowEnd
void Scanner::ScanFlowEnd() {
if (InBlockContext())
throw ParserException(INPUT.mark(), ErrorMsg::FLOW_END);
// we might have a solo entry in the flow context
if(InFlowContext()) {
if(m_flows.top() == FLOW_MAP && VerifySimpleKey())
if (InFlowContext()) {
if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
m_tokens.push(Token(Token::VALUE, INPUT.mark()));
else if(m_flows.top() == FLOW_SEQ)
else if (m_flows.top() == FLOW_SEQ)
InvalidateSimpleKey();
}
@@ -123,22 +118,21 @@ namespace YAML
// check that it matches the start
FLOW_MARKER flowType = (ch == Keys::FlowSeqEnd ? FLOW_SEQ : FLOW_MAP);
if(m_flows.top() != flowType)
if (m_flows.top() != flowType)
throw ParserException(mark, ErrorMsg::FLOW_END);
m_flows.pop();
Token::TYPE type = (flowType ? Token::FLOW_SEQ_END : Token::FLOW_MAP_END);
m_tokens.push(Token(type, mark));
}
}
// FlowEntry
void Scanner::ScanFlowEntry()
{
// FlowEntry
void Scanner::ScanFlowEntry() {
// we might have a solo entry in the flow context
if(InFlowContext()) {
if(m_flows.top() == FLOW_MAP && VerifySimpleKey())
if (InFlowContext()) {
if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
m_tokens.push(Token(Token::VALUE, INPUT.mark()));
else if(m_flows.top() == FLOW_SEQ)
else if (m_flows.top() == FLOW_SEQ)
InvalidateSimpleKey();
}
@@ -149,17 +143,16 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::FLOW_ENTRY, mark));
}
}
// BlockEntry
void Scanner::ScanBlockEntry()
{
// BlockEntry
void Scanner::ScanBlockEntry() {
// we better be in the block context!
if(InFlowContext())
if (InFlowContext())
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
// can we put it here?
if(!m_simpleKeyAllowed)
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
PushIndentTo(INPUT.column(), IndentMarker::SEQ);
@@ -170,14 +163,13 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::BLOCK_ENTRY, mark));
}
}
// Key
void Scanner::ScanKey()
{
// Key
void Scanner::ScanKey() {
// handle keys diffently in the block context (and manage indents)
if(InBlockContext()) {
if(!m_simpleKeyAllowed)
if (InBlockContext()) {
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::MAP_KEY);
PushIndentTo(INPUT.column(), IndentMarker::MAP);
@@ -190,22 +182,22 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::KEY, mark));
}
}
// Value
void Scanner::ScanValue()
{
// Value
void Scanner::ScanValue() {
// and check that simple key
bool isSimpleKey = VerifySimpleKey();
m_canBeJSONFlow = false;
if(isSimpleKey) {
// can't follow a simple key with another simple key (dunno why, though - it seems fine)
if (isSimpleKey) {
// can't follow a simple key with another simple key (dunno why, though - it
// seems fine)
m_simpleKeyAllowed = false;
} else {
// handle values diffently in the block context (and manage indents)
if(InBlockContext()) {
if(!m_simpleKeyAllowed)
if (InBlockContext()) {
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::MAP_VALUE);
PushIndentTo(INPUT.column(), IndentMarker::MAP);
@@ -219,11 +211,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::VALUE, mark));
}
}
// AnchorOrAlias
void Scanner::ScanAnchorOrAlias()
{
// AnchorOrAlias
void Scanner::ScanAnchorOrAlias() {
bool alias;
std::string name;
@@ -238,26 +229,27 @@ namespace YAML
alias = (indicator == Keys::Alias);
// now eat the content
while(INPUT && Exp::Anchor().Matches(INPUT))
while (INPUT && Exp::Anchor().Matches(INPUT))
name += INPUT.get();
// we need to have read SOMETHING!
if(name.empty())
throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND : ErrorMsg::ANCHOR_NOT_FOUND);
if (name.empty())
throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND
: ErrorMsg::ANCHOR_NOT_FOUND);
// and needs to end correctly
if(INPUT && !Exp::AnchorEnd().Matches(INPUT))
throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS : ErrorMsg::CHAR_IN_ANCHOR);
if (INPUT && !Exp::AnchorEnd().Matches(INPUT))
throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS
: ErrorMsg::CHAR_IN_ANCHOR);
// and we're done
Token token(alias ? Token::ALIAS : Token::ANCHOR, mark);
token.value = name;
m_tokens.push(token);
}
}
// Tag
void Scanner::ScanTag()
{
// Tag
void Scanner::ScanTag() {
// insert a potential simple key
InsertPotentialSimpleKey();
m_simpleKeyAllowed = false;
@@ -268,7 +260,7 @@ namespace YAML
// eat the indicator
INPUT.get();
if(INPUT && INPUT.peek() == Keys::VerbatimTagStart){
if (INPUT && INPUT.peek() == Keys::VerbatimTagStart) {
std::string tag = ScanVerbatimTag(INPUT);
token.value = tag;
@@ -276,15 +268,15 @@ namespace YAML
} else {
bool canBeHandle;
token.value = ScanTagHandle(INPUT, canBeHandle);
if(!canBeHandle && token.value.empty())
if (!canBeHandle && token.value.empty())
token.data = Tag::NON_SPECIFIC;
else if(token.value.empty())
else if (token.value.empty())
token.data = Tag::SECONDARY_HANDLE;
else
token.data = Tag::PRIMARY_HANDLE;
// is there a suffix?
if(canBeHandle && INPUT.peek() == Keys::Tag) {
if (canBeHandle && INPUT.peek() == Keys::Tag) {
// eat the indicator
INPUT.get();
token.params.push_back(ScanTagSuffix(INPUT));
@@ -293,16 +285,16 @@ namespace YAML
}
m_tokens.push(token);
}
}
// PlainScalar
void Scanner::ScanPlainScalar()
{
// PlainScalar
void Scanner::ScanPlainScalar() {
std::string scalar;
// set up the scanning parameters
ScanScalarParams params;
params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) || (Exp::BlankOrBreak() + Exp::Comment());
params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) ||
(Exp::BlankOrBreak() + Exp::Comment());
params.eatEnd = false;
params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1);
params.fold = FOLD_FLOW;
@@ -323,20 +315,20 @@ namespace YAML
m_canBeJSONFlow = false;
// finally, check and see if we ended on an illegal character
//if(Exp::IllegalCharInScalar.Matches(INPUT))
// if(Exp::IllegalCharInScalar.Matches(INPUT))
// throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR);
Token token(Token::PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
// QuotedScalar
void Scanner::ScanQuotedScalar()
{
// QuotedScalar
void Scanner::ScanQuotedScalar() {
std::string scalar;
// peek at single or double quote (don't eat because we need to preserve (for the time being) the input position)
// peek at single or double quote (don't eat because we need to preserve (for
// the time being) the input position)
char quote = INPUT.peek();
bool single = (quote == '\'');
@@ -368,14 +360,14 @@ namespace YAML
Token token(Token::NON_PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
// BlockScalarToken
// . These need a little extra processing beforehand.
// . We need to scan the line where the indicator is (this doesn't count as part of the scalar),
// and then we need to figure out what level of indentation we'll be using.
void Scanner::ScanBlockScalar()
{
// BlockScalarToken
// . These need a little extra processing beforehand.
// . We need to scan the line where the indicator is (this doesn't count as part
// of the scalar),
// and then we need to figure out what level of indentation we'll be using.
void Scanner::ScanBlockScalar() {
std::string scalar;
ScanScalarParams params;
@@ -390,14 +382,14 @@ namespace YAML
// eat chomping/indentation indicators
params.chomp = CLIP;
int n = Exp::Chomp().Match(INPUT);
for(int i=0;i<n;i++) {
for (int i = 0; i < n; i++) {
char ch = INPUT.get();
if(ch == '+')
if (ch == '+')
params.chomp = KEEP;
else if(ch == '-')
else if (ch == '-')
params.chomp = STRIP;
else if(Exp::Digit().Matches(ch)) {
if(ch == '0')
else if (Exp::Digit().Matches(ch)) {
if (ch == '0')
throw ParserException(INPUT.mark(), ErrorMsg::ZERO_INDENT_IN_BLOCK);
params.indent = ch - '0';
@@ -406,20 +398,20 @@ namespace YAML
}
// now eat whitespace
while(Exp::Blank().Matches(INPUT))
while (Exp::Blank().Matches(INPUT))
INPUT.eat(1);
// and comments to the end of the line
if(Exp::Comment().Matches(INPUT))
while(INPUT && !Exp::Break().Matches(INPUT))
if (Exp::Comment().Matches(INPUT))
while (INPUT && !Exp::Break().Matches(INPUT))
INPUT.eat(1);
// if it's not a line break, then we ran into a bad character inline
if(INPUT && !Exp::Break().Matches(INPUT))
if (INPUT && !Exp::Break().Matches(INPUT))
throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_BLOCK);
// set the initial indentation
if(GetTopIndent() >= 0)
if (GetTopIndent() >= 0)
params.indent += GetTopIndent();
params.eatLeadingWhitespace = false;
@@ -428,12 +420,13 @@ namespace YAML
scalar = ScanScalar(INPUT, params);
// simple keys always ok after block scalars (since we're gonna start a new line anyways)
// simple keys always ok after block scalars (since we're gonna start a new
// line anyways)
m_simpleKeyAllowed = true;
m_canBeJSONFlow = false;
Token token(Token::NON_PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
}

View File

@@ -1,69 +1,61 @@
#ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <memory>
#include <vector>
#include "yaml-cpp/noncopyable.h"
namespace YAML
{
class SettingChangeBase;
namespace YAML {
class SettingChangeBase;
template <typename T>
class Setting
{
template <typename T>
class Setting {
public:
Setting(): m_value() {}
Setting() : m_value() {}
const T get() const { return m_value; }
std::auto_ptr <SettingChangeBase> set(const T& value);
void restore(const Setting<T>& oldSetting) {
m_value = oldSetting.get();
}
std::auto_ptr<SettingChangeBase> set(const T& value);
void restore(const Setting<T>& oldSetting) { m_value = oldSetting.get(); }
private:
T m_value;
};
};
class SettingChangeBase
{
class SettingChangeBase {
public:
virtual ~SettingChangeBase() {}
virtual void pop() = 0;
};
};
template <typename T>
class SettingChange: public SettingChangeBase
{
template <typename T>
class SettingChange : public SettingChangeBase {
public:
SettingChange(Setting<T> *pSetting): m_pCurSetting(pSetting) {
SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) {
// copy old setting to save its state
m_oldSetting = *pSetting;
}
virtual void pop() {
m_pCurSetting->restore(m_oldSetting);
}
virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
private:
Setting<T> *m_pCurSetting;
Setting<T>* m_pCurSetting;
Setting<T> m_oldSetting;
};
};
template <typename T>
inline std::auto_ptr <SettingChangeBase> Setting<T>::set(const T& value) {
std::auto_ptr <SettingChangeBase> pChange(new SettingChange<T> (this));
template <typename T>
inline std::auto_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
std::auto_ptr<SettingChangeBase> pChange(new SettingChange<T>(this));
m_value = value;
return pChange;
}
}
class SettingChanges: private noncopyable
{
class SettingChanges : private noncopyable {
public:
SettingChanges() {}
~SettingChanges() { clear(); }
@@ -71,23 +63,25 @@ namespace YAML
void clear() {
restore();
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it)
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
delete *it;
m_settingChanges.clear();
}
void restore() {
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it)
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
(*it)->pop();
}
void push(std::auto_ptr <SettingChangeBase> pSettingChange) {
void push(std::auto_ptr<SettingChangeBase> pSettingChange) {
m_settingChanges.push_back(pSettingChange.release());
}
// like std::auto_ptr - assignment is transfer of ownership
SettingChanges& operator = (SettingChanges& rhs) {
if(this == &rhs)
SettingChanges& operator=(SettingChanges& rhs) {
if (this == &rhs)
return *this;
clear();
@@ -97,9 +91,9 @@ namespace YAML
}
private:
typedef std::vector <SettingChangeBase *> setting_changes;
typedef std::vector<SettingChangeBase*> setting_changes;
setting_changes m_settingChanges;
};
};
}
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -3,71 +3,64 @@
#include "yaml-cpp/exceptions.h"
#include "exp.h"
namespace YAML
{
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0)
{
}
namespace YAML {
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {}
void Scanner::SimpleKey::Validate()
{
void Scanner::SimpleKey::Validate() {
// Note: pIndent will *not* be garbage here;
// we "garbage collect" them so we can
// always refer to them
if(pIndent)
if (pIndent)
pIndent->status = IndentMarker::VALID;
if(pMapStart)
if (pMapStart)
pMapStart->status = Token::VALID;
if(pKey)
if (pKey)
pKey->status = Token::VALID;
}
}
void Scanner::SimpleKey::Invalidate()
{
if(pIndent)
void Scanner::SimpleKey::Invalidate() {
if (pIndent)
pIndent->status = IndentMarker::INVALID;
if(pMapStart)
if (pMapStart)
pMapStart->status = Token::INVALID;
if(pKey)
if (pKey)
pKey->status = Token::INVALID;
}
}
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const
{
if(!m_simpleKeyAllowed)
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const {
if (!m_simpleKeyAllowed)
return false;
return !ExistsActiveSimpleKey();
}
}
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow start token)
bool Scanner::ExistsActiveSimpleKey() const
{
if(m_simpleKeys.empty())
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow
// start token)
bool Scanner::ExistsActiveSimpleKey() const {
if (m_simpleKeys.empty())
return false;
const SimpleKey& key = m_simpleKeys.top();
return key.flowLevel == GetFlowLevel();
}
}
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey()
{
if(!CanInsertPotentialSimpleKey())
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey() {
if (!CanInsertPotentialSimpleKey())
return;
SimpleKey key(INPUT.mark(), GetFlowLevel());
// first add a map start, if necessary
if(InBlockContext()) {
if (InBlockContext()) {
key.pIndent = PushIndentTo(INPUT.column(), IndentMarker::MAP);
if(key.pIndent) {
if (key.pIndent) {
key.pIndent->status = IndentMarker::UNKNOWN;
key.pMapStart = key.pIndent->pStartToken;
key.pMapStart->status = Token::UNVERIFIED;
@@ -80,37 +73,35 @@ namespace YAML
key.pKey->status = Token::UNVERIFIED;
m_simpleKeys.push(key);
}
}
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey()
{
if(m_simpleKeys.empty())
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey() {
if (m_simpleKeys.empty())
return;
// grab top key
SimpleKey& key = m_simpleKeys.top();
if(key.flowLevel != GetFlowLevel())
if (key.flowLevel != GetFlowLevel())
return;
key.Invalidate();
m_simpleKeys.pop();
}
}
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey()
{
if(m_simpleKeys.empty())
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey() {
if (m_simpleKeys.empty())
return false;
// grab top key
SimpleKey key = m_simpleKeys.top();
// only validate if we're in the correct flow level
if(key.flowLevel != GetFlowLevel())
if (key.flowLevel != GetFlowLevel())
return false;
m_simpleKeys.pop();
@@ -118,22 +109,20 @@ namespace YAML
bool isValid = true;
// needs to be less than 1024 characters and inline
if(INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
if (INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
isValid = false;
// invalidate key
if(isValid)
if (isValid)
key.Validate();
else
key.Invalidate();
return isValid;
}
void Scanner::PopAllSimpleKeys()
{
while(!m_simpleKeys.empty())
m_simpleKeys.pop();
}
}
void Scanner::PopAllSimpleKeys() {
while (!m_simpleKeys.empty())
m_simpleKeys.pop();
}
}

View File

@@ -10,28 +10,26 @@
#include <cstdio>
#include <algorithm>
namespace YAML
{
SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives): m_scanner(scanner), m_directives(directives), m_pCollectionStack(new CollectionStack), m_curAnchor(0)
{
}
namespace YAML {
SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives)
: m_scanner(scanner),
m_directives(directives),
m_pCollectionStack(new CollectionStack),
m_curAnchor(0) {}
SingleDocParser::~SingleDocParser()
{
}
SingleDocParser::~SingleDocParser() {}
// HandleDocument
// . Handles the next document
// . Throws a ParserException on error.
void SingleDocParser::HandleDocument(EventHandler& eventHandler)
{
// HandleDocument
// . Handles the next document
// . Throws a ParserException on error.
void SingleDocParser::HandleDocument(EventHandler& eventHandler) {
assert(!m_scanner.empty()); // guaranteed that there are tokens
assert(!m_curAnchor);
eventHandler.OnDocumentStart(m_scanner.peek().mark);
// eat doc start
if(m_scanner.peek().type == Token::DOC_START)
if (m_scanner.peek().type == Token::DOC_START)
m_scanner.pop();
// recurse!
@@ -40,14 +38,13 @@ namespace YAML
eventHandler.OnDocumentEnd();
// and finally eat any doc ends we see
while(!m_scanner.empty() && m_scanner.peek().type == Token::DOC_END)
while (!m_scanner.empty() && m_scanner.peek().type == Token::DOC_END)
m_scanner.pop();
}
}
void SingleDocParser::HandleNode(EventHandler& eventHandler)
{
void SingleDocParser::HandleNode(EventHandler& eventHandler) {
// an empty node *is* a possibility
if(m_scanner.empty()) {
if (m_scanner.empty()) {
eventHandler.OnNull(m_scanner.mark(), NullAnchor);
return;
}
@@ -56,7 +53,7 @@ namespace YAML
Mark mark = m_scanner.peek().mark;
// special case: a value node by itself must be a map, with no header
if(m_scanner.peek().type == Token::VALUE) {
if (m_scanner.peek().type == Token::VALUE) {
eventHandler.OnMapStart(mark, "?", NullAnchor);
HandleMap(eventHandler);
eventHandler.OnMapEnd();
@@ -64,7 +61,7 @@ namespace YAML
}
// special case: an alias node
if(m_scanner.peek().type == Token::ALIAS) {
if (m_scanner.peek().type == Token::ALIAS) {
eventHandler.OnAlias(mark, LookupAnchor(mark, m_scanner.peek().value));
m_scanner.pop();
return;
@@ -76,18 +73,18 @@ namespace YAML
const Token& token = m_scanner.peek();
if(token.type == Token::PLAIN_SCALAR && token.value == "null") {
if (token.type == Token::PLAIN_SCALAR && token.value == "null") {
eventHandler.OnNull(mark, anchor);
m_scanner.pop();
return;
}
// add non-specific tags
if(tag.empty())
if (tag.empty())
tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?");
// now split based on what kind of node we should be
switch(token.type) {
switch (token.type) {
case Token::PLAIN_SCALAR:
case Token::NON_PLAIN_SCALAR:
eventHandler.OnScalar(mark, tag, anchor, token.value);
@@ -107,7 +104,8 @@ namespace YAML
return;
case Token::KEY:
// compact maps can only go in a flow sequence
if(m_pCollectionStack->GetCurCollectionType() == CollectionType::FlowSeq) {
if (m_pCollectionStack->GetCurCollectionType() ==
CollectionType::FlowSeq) {
eventHandler.OnMapStart(mark, tag, anchor);
HandleMap(eventHandler);
eventHandler.OnMapEnd();
@@ -118,44 +116,48 @@ namespace YAML
break;
}
if(tag == "?")
if (tag == "?")
eventHandler.OnNull(mark, anchor);
else
eventHandler.OnScalar(mark, tag, anchor, "");
}
}
void SingleDocParser::HandleSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleSequence(EventHandler& eventHandler) {
// split based on start token
switch(m_scanner.peek().type) {
case Token::BLOCK_SEQ_START: HandleBlockSequence(eventHandler); break;
case Token::FLOW_SEQ_START: HandleFlowSequence(eventHandler); break;
default: break;
}
switch (m_scanner.peek().type) {
case Token::BLOCK_SEQ_START:
HandleBlockSequence(eventHandler);
break;
case Token::FLOW_SEQ_START:
HandleFlowSequence(eventHandler);
break;
default:
break;
}
}
void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::BlockSeq);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
Token token = m_scanner.peek();
if(token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
if (token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ);
m_scanner.pop();
if(token.type == Token::BLOCK_SEQ_END)
if (token.type == Token::BLOCK_SEQ_END)
break;
// check for null
if(!m_scanner.empty()) {
if (!m_scanner.empty()) {
const Token& token = m_scanner.peek();
if(token.type == Token::BLOCK_ENTRY || token.type == Token::BLOCK_SEQ_END) {
if (token.type == Token::BLOCK_ENTRY ||
token.type == Token::BLOCK_SEQ_END) {
eventHandler.OnNull(token.mark, NullAnchor);
continue;
}
@@ -165,20 +167,19 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::BlockSeq);
}
}
void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::FlowSeq);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
// first check for end
if(m_scanner.peek().type == Token::FLOW_SEQ_END) {
if (m_scanner.peek().type == Token::FLOW_SEQ_END) {
m_scanner.pop();
break;
}
@@ -186,53 +187,62 @@ namespace YAML
// then read the node
HandleNode(eventHandler);
if(m_scanner.empty())
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a sequence end, which we ignore - but
// if it's neither, then it's a bad node)
Token& token = m_scanner.peek();
if(token.type == Token::FLOW_ENTRY)
if (token.type == Token::FLOW_ENTRY)
m_scanner.pop();
else if(token.type != Token::FLOW_SEQ_END)
else if (token.type != Token::FLOW_SEQ_END)
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ_FLOW);
}
m_pCollectionStack->PopCollectionType(CollectionType::FlowSeq);
}
}
void SingleDocParser::HandleMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleMap(EventHandler& eventHandler) {
// split based on start token
switch(m_scanner.peek().type) {
case Token::BLOCK_MAP_START: HandleBlockMap(eventHandler); break;
case Token::FLOW_MAP_START: HandleFlowMap(eventHandler); break;
case Token::KEY: HandleCompactMap(eventHandler); break;
case Token::VALUE: HandleCompactMapWithNoKey(eventHandler); break;
default: break;
}
switch (m_scanner.peek().type) {
case Token::BLOCK_MAP_START:
HandleBlockMap(eventHandler);
break;
case Token::FLOW_MAP_START:
HandleFlowMap(eventHandler);
break;
case Token::KEY:
HandleCompactMap(eventHandler);
break;
case Token::VALUE:
HandleCompactMapWithNoKey(eventHandler);
break;
default:
break;
}
}
void SingleDocParser::HandleBlockMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleBlockMap(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::BlockMap);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP);
Token token = m_scanner.peek();
if(token.type != Token::KEY && token.type != Token::VALUE && token.type != Token::BLOCK_MAP_END)
if (token.type != Token::KEY && token.type != Token::VALUE &&
token.type != Token::BLOCK_MAP_END)
throw ParserException(token.mark, ErrorMsg::END_OF_MAP);
if(token.type == Token::BLOCK_MAP_END) {
if (token.type == Token::BLOCK_MAP_END) {
m_scanner.pop();
break;
}
// grab key (if non-null)
if(token.type == Token::KEY) {
if (token.type == Token::KEY) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
@@ -240,7 +250,7 @@ namespace YAML
}
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
@@ -249,28 +259,27 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::BlockMap);
}
}
void SingleDocParser::HandleFlowMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleFlowMap(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::FlowMap);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
Token& token = m_scanner.peek();
const Mark mark = token.mark;
// first check for end
if(token.type == Token::FLOW_MAP_END) {
if (token.type == Token::FLOW_MAP_END) {
m_scanner.pop();
break;
}
// grab key (if non-null)
if(token.type == Token::KEY) {
if (token.type == Token::KEY) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
@@ -278,30 +287,30 @@ namespace YAML
}
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
eventHandler.OnNull(mark, NullAnchor);
}
if(m_scanner.empty())
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a map end, which we ignore - but if
// it's neither, then it's a bad node)
Token& nextToken = m_scanner.peek();
if(nextToken.type == Token::FLOW_ENTRY)
if (nextToken.type == Token::FLOW_ENTRY)
m_scanner.pop();
else if(nextToken.type != Token::FLOW_MAP_END)
else if (nextToken.type != Token::FLOW_MAP_END)
throw ParserException(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW);
}
m_pCollectionStack->PopCollectionType(CollectionType::FlowMap);
}
}
// . Single "key: value" pair in a flow sequence
void SingleDocParser::HandleCompactMap(EventHandler& eventHandler)
{
// . Single "key: value" pair in a flow sequence
void SingleDocParser::HandleCompactMap(EventHandler& eventHandler) {
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
// grab key
@@ -310,7 +319,7 @@ namespace YAML
HandleNode(eventHandler);
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
@@ -318,11 +327,10 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::CompactMap);
}
}
// . Single ": value" pair in a flow sequence
void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler)
{
// . Single ": value" pair in a flow sequence
void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler) {
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
// null key
@@ -333,62 +341,63 @@ namespace YAML
HandleNode(eventHandler);
m_pCollectionStack->PopCollectionType(CollectionType::CompactMap);
}
}
// ParseProperties
// . Grabs any tag or anchor tokens and deals with them.
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor)
{
// ParseProperties
// . Grabs any tag or anchor tokens and deals with them.
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
tag.clear();
anchor = NullAnchor;
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
return;
switch(m_scanner.peek().type) {
case Token::TAG: ParseTag(tag); break;
case Token::ANCHOR: ParseAnchor(anchor); break;
default: return;
}
switch (m_scanner.peek().type) {
case Token::TAG:
ParseTag(tag);
break;
case Token::ANCHOR:
ParseAnchor(anchor);
break;
default:
return;
}
}
}
void SingleDocParser::ParseTag(std::string& tag)
{
void SingleDocParser::ParseTag(std::string& tag) {
Token& token = m_scanner.peek();
if(!tag.empty())
if (!tag.empty())
throw ParserException(token.mark, ErrorMsg::MULTIPLE_TAGS);
Tag tagInfo(token);
tag = tagInfo.Translate(m_directives);
m_scanner.pop();
}
}
void SingleDocParser::ParseAnchor(anchor_t& anchor)
{
void SingleDocParser::ParseAnchor(anchor_t& anchor) {
Token& token = m_scanner.peek();
if(anchor)
if (anchor)
throw ParserException(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
anchor = RegisterAnchor(token.value);
m_scanner.pop();
}
}
anchor_t SingleDocParser::RegisterAnchor(const std::string& name)
{
if(name.empty())
anchor_t SingleDocParser::RegisterAnchor(const std::string& name) {
if (name.empty())
return NullAnchor;
return m_anchors[name] = ++m_curAnchor;
}
}
anchor_t SingleDocParser::LookupAnchor(const Mark& mark, const std::string& name) const
{
anchor_t SingleDocParser::LookupAnchor(const Mark& mark,
const std::string& name) const {
Anchors::const_iterator it = m_anchors.find(name);
if(it == m_anchors.end())
if (it == m_anchors.end())
throw ParserException(mark, ErrorMsg::UNKNOWN_ANCHOR);
return it->second;
}
}
}

View File

@@ -1,29 +1,28 @@
#ifndef SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/anchor.h"
#include "yaml-cpp/noncopyable.h"
#include <string>
#include <map>
#include <memory>
namespace YAML
{
struct Directives;
struct Mark;
struct Token;
class CollectionStack;
class EventHandler;
class Node;
class Scanner;
namespace YAML {
struct Directives;
struct Mark;
struct Token;
class CollectionStack;
class EventHandler;
class Node;
class Scanner;
class SingleDocParser: private noncopyable
{
class SingleDocParser : private noncopyable {
public:
SingleDocParser(Scanner& scanner, const Directives& directives);
~SingleDocParser();
@@ -59,7 +58,7 @@ namespace YAML
Anchors m_anchors;
anchor_t m_curAnchor;
};
};
}
#endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -6,14 +6,13 @@
#define YAML_PREFETCH_SIZE 2048
#endif
#define S_ARRAY_SIZE( A ) (sizeof(A)/sizeof(*(A)))
#define S_ARRAY_END( A ) ((A) + S_ARRAY_SIZE(A))
#define S_ARRAY_SIZE(A) (sizeof(A) / sizeof(*(A)))
#define S_ARRAY_END(A) ((A) + S_ARRAY_SIZE(A))
#define CP_REPLACEMENT_CHARACTER (0xFFFD)
namespace YAML
{
enum UtfIntroState {
namespace YAML {
enum UtfIntroState {
uis_start,
uis_utfbe_b1,
uis_utf32be_b2,
@@ -33,9 +32,9 @@ namespace YAML
uis_utf8_bom2,
uis_utf8,
uis_error
};
};
enum UtfIntroCharType {
enum UtfIntroCharType {
uict00,
uictBB,
uictBF,
@@ -45,53 +44,70 @@ namespace YAML
uictAscii,
uictOther,
uictMax
};
};
static bool s_introFinalState[] = {
false, //uis_start
false, //uis_utfbe_b1
false, //uis_utf32be_b2
false, //uis_utf32be_bom3
true, //uis_utf32be
true, //uis_utf16be
false, //uis_utf16be_bom1
false, //uis_utfle_bom1
false, //uis_utf16le_bom2
false, //uis_utf32le_bom3
true, //uis_utf16le
true, //uis_utf32le
false, //uis_utf8_imp
false, //uis_utf16le_imp
false, //uis_utf32le_imp3
false, //uis_utf8_bom1
false, //uis_utf8_bom2
true, //uis_utf8
true, //uis_error
};
static bool s_introFinalState[] = {false, // uis_start
false, // uis_utfbe_b1
false, // uis_utf32be_b2
false, // uis_utf32be_bom3
true, // uis_utf32be
true, // uis_utf16be
false, // uis_utf16be_bom1
false, // uis_utfle_bom1
false, // uis_utf16le_bom2
false, // uis_utf32le_bom3
true, // uis_utf16le
true, // uis_utf32le
false, // uis_utf8_imp
false, // uis_utf16le_imp
false, // uis_utf32le_imp3
false, // uis_utf8_bom1
false, // uis_utf8_bom2
true, // uis_utf8
true, // uis_error
};
static UtfIntroState s_introTransitions[][uictMax] = {
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
{uis_utfbe_b1, uis_utf8, uis_utf8, uis_utf8_bom1, uis_utf16be_bom1, uis_utfle_bom1, uis_utf8_imp, uis_utf8},
{uis_utf32be_b2, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16be, uis_utf8},
{uis_utf32be, uis_utf8, uis_utf8, uis_utf8, uis_utf32be_bom3, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf32be, uis_utf8, uis_utf8},
{uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be},
{uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16be, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16le_bom2, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_bom3, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le},
{uis_utf16le_imp, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_imp3, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf8, uis_utf8_bom2, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
};
static UtfIntroState s_introTransitions[][uictMax] = {
// uict00, uictBB, uictBF, uictEF,
// uictFE, uictFF, uictAscii, uictOther
{uis_utfbe_b1, uis_utf8, uis_utf8, uis_utf8_bom1,
uis_utf16be_bom1, uis_utfle_bom1, uis_utf8_imp, uis_utf8},
{uis_utf32be_b2, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf16be, uis_utf8},
{uis_utf32be, uis_utf8, uis_utf8, uis_utf8,
uis_utf32be_bom3, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf32be, uis_utf8, uis_utf8},
{uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be,
uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be},
{uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be,
uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf16be, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf16le_bom2, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_bom3, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le,
uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le},
{uis_utf16le_imp, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_imp3, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf8, uis_utf8_bom2, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8}, };
static char s_introUngetCount[][uictMax] = {
static char s_introUngetCount[][uictMax] = {
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
{0, 1, 1, 0, 0, 0, 0, 1},
{0, 2, 2, 2, 2, 2, 2, 2},
@@ -110,22 +126,26 @@ namespace YAML
{4, 4, 4, 4, 4, 4, 4, 4},
{2, 0, 2, 2, 2, 2, 2, 2},
{3, 3, 0, 3, 3, 3, 3, 3},
{1, 1, 1, 1, 1, 1, 1, 1},
};
{1, 1, 1, 1, 1, 1, 1, 1}, };
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch)
{
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
if (std::istream::traits_type::eof() == ch) {
return uictOther;
}
switch (ch) {
case 0: return uict00;
case 0xBB: return uictBB;
case 0xBF: return uictBF;
case 0xEF: return uictEF;
case 0xFE: return uictFE;
case 0xFF: return uictFF;
case 0:
return uict00;
case 0xBB:
return uictBB;
case 0xBF:
return uictBF;
case 0xEF:
return uictEF;
case 0xFE:
return uictFE;
case 0xFF:
return uictFF;
}
if ((ch > 0) && (ch < 0xFF)) {
@@ -133,58 +153,48 @@ namespace YAML
}
return uictOther;
}
}
inline char Utf8Adjust(unsigned long ch, unsigned char lead_bits, unsigned char rshift)
{
inline char Utf8Adjust(unsigned long ch, unsigned char lead_bits,
unsigned char rshift) {
const unsigned char header = ((1 << lead_bits) - 1) << (8 - lead_bits);
const unsigned char mask = (0xFF >> (lead_bits + 1));
return static_cast<char>(static_cast<unsigned char>(
header | ((ch >> rshift) & mask)
));
}
return static_cast<char>(
static_cast<unsigned char>(header | ((ch >> rshift) & mask)));
}
inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch)
{
inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) {
// We are not allowed to queue the Stream::eof() codepoint, so
// replace it with CP_REPLACEMENT_CHARACTER
if (static_cast<unsigned long>(Stream::eof()) == ch)
{
if (static_cast<unsigned long>(Stream::eof()) == ch) {
ch = CP_REPLACEMENT_CHARACTER;
}
if (ch < 0x80)
{
if (ch < 0x80) {
q.push_back(Utf8Adjust(ch, 0, 0));
}
else if (ch < 0x800)
{
} else if (ch < 0x800) {
q.push_back(Utf8Adjust(ch, 2, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
else if (ch < 0x10000)
{
} else if (ch < 0x10000) {
q.push_back(Utf8Adjust(ch, 3, 12));
q.push_back(Utf8Adjust(ch, 1, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
else
{
} else {
q.push_back(Utf8Adjust(ch, 4, 18));
q.push_back(Utf8Adjust(ch, 1, 12));
q.push_back(Utf8Adjust(ch, 1, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
}
}
Stream::Stream(std::istream& input)
Stream::Stream(std::istream& input)
: m_input(input),
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0)
{
m_nPrefetchedAvailable(0),
m_nPrefetchedUsed(0) {
typedef std::istream::traits_type char_traits;
if(!input)
if (!input)
return;
// Determine (or guess) the character-set by reading the BOM, if any. See
@@ -192,16 +202,16 @@ namespace YAML
char_traits::int_type intro[4];
int nIntroUsed = 0;
UtfIntroState state = uis_start;
for(; !s_introFinalState[state]; ) {
for (; !s_introFinalState[state];) {
std::istream::int_type ch = input.get();
intro[nIntroUsed++] = ch;
UtfIntroCharType charType = IntroCharTypeOf(ch);
UtfIntroState newState = s_introTransitions[state][charType];
int nUngets = s_introUngetCount[state][charType];
if(nUngets > 0) {
if (nUngets > 0) {
input.clear();
for(; nUngets > 0; --nUngets) {
if(char_traits::eof() != intro[--nIntroUsed])
for (; nUngets > 0; --nUngets) {
if (char_traits::eof() != intro[--nIntroUsed])
input.putback(char_traits::to_char_type(intro[nIntroUsed]));
}
}
@@ -209,166 +219,163 @@ namespace YAML
}
switch (state) {
case uis_utf8: m_charSet = utf8; break;
case uis_utf16le: m_charSet = utf16le; break;
case uis_utf16be: m_charSet = utf16be; break;
case uis_utf32le: m_charSet = utf32le; break;
case uis_utf32be: m_charSet = utf32be; break;
default: m_charSet = utf8; break;
case uis_utf8:
m_charSet = utf8;
break;
case uis_utf16le:
m_charSet = utf16le;
break;
case uis_utf16be:
m_charSet = utf16be;
break;
case uis_utf32le:
m_charSet = utf32le;
break;
case uis_utf32be:
m_charSet = utf32be;
break;
default:
m_charSet = utf8;
break;
}
ReadAheadTo(0);
}
}
Stream::~Stream()
{
delete[] m_pPrefetched;
}
Stream::~Stream() { delete[] m_pPrefetched; }
char Stream::peek() const
{
if (m_readahead.empty())
{
char Stream::peek() const {
if (m_readahead.empty()) {
return Stream::eof();
}
return m_readahead[0];
}
}
Stream::operator bool() const
{
return m_input.good() || (!m_readahead.empty() && m_readahead[0] != Stream::eof());
}
Stream::operator bool() const {
return m_input.good() ||
(!m_readahead.empty() && m_readahead[0] != Stream::eof());
}
// get
// . Extracts a character from the stream and updates our position
char Stream::get()
{
// get
// . Extracts a character from the stream and updates our position
char Stream::get() {
char ch = peek();
AdvanceCurrent();
m_mark.column++;
if(ch == '\n') {
if (ch == '\n') {
m_mark.column = 0;
m_mark.line++;
}
return ch;
}
}
// get
// . Extracts 'n' characters from the stream and updates our position
std::string Stream::get(int n)
{
// get
// . Extracts 'n' characters from the stream and updates our position
std::string Stream::get(int n) {
std::string ret;
ret.reserve(n);
for(int i=0;i<n;i++)
for (int i = 0; i < n; i++)
ret += get();
return ret;
}
}
// eat
// . Eats 'n' characters and updates our position.
void Stream::eat(int n)
{
for(int i=0;i<n;i++)
// eat
// . Eats 'n' characters and updates our position.
void Stream::eat(int n) {
for (int i = 0; i < n; i++)
get();
}
}
void Stream::AdvanceCurrent()
{
if (!m_readahead.empty())
{
void Stream::AdvanceCurrent() {
if (!m_readahead.empty()) {
m_readahead.pop_front();
m_mark.pos++;
}
ReadAheadTo(0);
}
}
bool Stream::_ReadAheadTo(size_t i) const
{
while (m_input.good() && (m_readahead.size() <= i))
{
switch (m_charSet)
{
case utf8: StreamInUtf8(); break;
case utf16le: StreamInUtf16(); break;
case utf16be: StreamInUtf16(); break;
case utf32le: StreamInUtf32(); break;
case utf32be: StreamInUtf32(); break;
bool Stream::_ReadAheadTo(size_t i) const {
while (m_input.good() && (m_readahead.size() <= i)) {
switch (m_charSet) {
case utf8:
StreamInUtf8();
break;
case utf16le:
StreamInUtf16();
break;
case utf16be:
StreamInUtf16();
break;
case utf32le:
StreamInUtf32();
break;
case utf32be:
StreamInUtf32();
break;
}
}
// signal end of stream
if(!m_input.good())
if (!m_input.good())
m_readahead.push_back(Stream::eof());
return m_readahead.size() > i;
}
}
void Stream::StreamInUtf8() const
{
void Stream::StreamInUtf8() const {
unsigned char b = GetNextByte();
if (m_input.good())
{
if (m_input.good()) {
m_readahead.push_back(b);
}
}
}
void Stream::StreamInUtf16() const
{
void Stream::StreamInUtf16() const {
unsigned long ch = 0;
unsigned char bytes[2];
int nBigEnd = (m_charSet == utf16be) ? 0 : 1;
bytes[0] = GetNextByte();
bytes[1] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
return;
}
ch = (static_cast<unsigned long>(bytes[nBigEnd]) << 8) |
static_cast<unsigned long>(bytes[1 ^ nBigEnd]);
if (ch >= 0xDC00 && ch < 0xE000)
{
if (ch >= 0xDC00 && ch < 0xE000) {
// Trailing (low) surrogate...ugh, wrong order
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
return;
}
else if (ch >= 0xD800 && ch < 0xDC00)
{
} else if (ch >= 0xD800 && ch < 0xDC00) {
// ch is a leading (high) surrogate
// Four byte UTF-8 code point
// Read the trailing (low) surrogate
for (;;)
{
for (;;) {
bytes[0] = GetNextByte();
bytes[1] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
return;
}
unsigned long chLow = (static_cast<unsigned long>(bytes[nBigEnd]) << 8) |
static_cast<unsigned long>(bytes[1 ^ nBigEnd]);
if (chLow < 0xDC00 || ch >= 0xE000)
{
// Trouble...not a low surrogate. Dump a REPLACEMENT CHARACTER into the stream.
if (chLow < 0xDC00 || ch >= 0xE000) {
// Trouble...not a low surrogate. Dump a REPLACEMENT CHARACTER into the
// stream.
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
// Deal with the next UTF-16 unit
if (chLow < 0xD800 || ch >= 0xE000)
{
if (chLow < 0xD800 || ch >= 0xE000) {
// Easiest case: queue the codepoint and return
QueueUnicodeCodepoint(m_readahead, ch);
return;
}
else
{
} else {
// Start the loop over with the new high surrogate
ch = chLow;
continue;
@@ -388,40 +395,32 @@ namespace YAML
}
QueueUnicodeCodepoint(m_readahead, ch);
}
}
inline char* ReadBuffer(unsigned char* pBuffer)
{
inline char* ReadBuffer(unsigned char* pBuffer) {
return reinterpret_cast<char*>(pBuffer);
}
}
unsigned char Stream::GetNextByte() const
{
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable)
{
std::streambuf *pBuf = m_input.rdbuf();
m_nPrefetchedAvailable = static_cast<std::size_t>(pBuf->sgetn(ReadBuffer(m_pPrefetched), YAML_PREFETCH_SIZE));
unsigned char Stream::GetNextByte() const {
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable) {
std::streambuf* pBuf = m_input.rdbuf();
m_nPrefetchedAvailable = static_cast<std::size_t>(
pBuf->sgetn(ReadBuffer(m_pPrefetched), YAML_PREFETCH_SIZE));
m_nPrefetchedUsed = 0;
if (!m_nPrefetchedAvailable)
{
if (!m_nPrefetchedAvailable) {
m_input.setstate(std::ios_base::eofbit);
}
if (0 == m_nPrefetchedAvailable)
{
if (0 == m_nPrefetchedAvailable) {
return 0;
}
}
return m_pPrefetched[m_nPrefetchedUsed++];
}
}
void Stream::StreamInUtf32() const
{
static int indexes[2][4] = {
{3, 2, 1, 0},
{0, 1, 2, 3}
};
void Stream::StreamInUtf32() const {
static int indexes[2][4] = {{3, 2, 1, 0}, {0, 1, 2, 3}};
unsigned long ch = 0;
unsigned char bytes[4];
@@ -431,17 +430,15 @@ namespace YAML
bytes[1] = GetNextByte();
bytes[2] = GetNextByte();
bytes[3] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
return;
}
for (int i = 0; i < 4; ++i)
{
for (int i = 0; i < 4; ++i) {
ch <<= 8;
ch |= bytes[pIndexes[i]];
}
QueueUnicodeCodepoint(m_readahead, ch);
}
}
}

View File

@@ -1,11 +1,12 @@
#ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/mark.h"
#include <cstddef>
@@ -15,10 +16,8 @@
#include <set>
#include <string>
namespace YAML
{
class Stream: private noncopyable
{
namespace YAML {
class Stream : private noncopyable {
public:
friend class StreamCharSource;
@@ -26,7 +25,7 @@ namespace YAML
~Stream();
operator bool() const;
bool operator !() const { return !static_cast <bool>(*this); }
bool operator!() const { return !static_cast<bool>(*this); }
char peek() const;
char get();
@@ -42,7 +41,13 @@ namespace YAML
void ResetColumn() { m_mark.column = 0; }
private:
enum CharacterSet {utf8, utf16le, utf16be, utf32le, utf32be};
enum CharacterSet {
utf8,
utf16le,
utf16be,
utf32le,
utf32be
};
std::istream& m_input;
Mark m_mark;
@@ -61,19 +66,17 @@ namespace YAML
void StreamInUtf16() const;
void StreamInUtf32() const;
unsigned char GetNextByte() const;
};
};
// CharAt
// . Unchecked access
inline char Stream::CharAt(size_t i) const {
return m_readahead[i];
}
// CharAt
// . Unchecked access
inline char Stream::CharAt(size_t i) const { return m_readahead[i]; }
inline bool Stream::ReadAheadTo(size_t i) const {
if(m_readahead.size() > i)
inline bool Stream::ReadAheadTo(size_t i) const {
if (m_readahead.size() > i)
return true;
return _ReadAheadTo(i);
}
}
}
#endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,48 +1,48 @@
#ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef>
namespace YAML
{
class StreamCharSource
{
namespace YAML {
class StreamCharSource {
public:
StreamCharSource(const Stream& stream): m_offset(0), m_stream(stream) {}
StreamCharSource(const StreamCharSource& source): m_offset(source.m_offset), m_stream(source.m_stream) {}
StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {}
StreamCharSource(const StreamCharSource& source)
: m_offset(source.m_offset), m_stream(source.m_stream) {}
~StreamCharSource() {}
operator bool() const;
char operator [] (std::size_t i) const { return m_stream.CharAt(m_offset + i); }
bool operator !() const { return !static_cast<bool>(*this); }
char operator[](std::size_t i) const { return m_stream.CharAt(m_offset + i); }
bool operator!() const { return !static_cast<bool>(*this); }
const StreamCharSource operator + (int i) const;
const StreamCharSource operator+(int i) const;
private:
std::size_t m_offset;
const Stream& m_stream;
StreamCharSource& operator = (const StreamCharSource&); // non-assignable
};
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
};
inline StreamCharSource::operator bool() const {
inline StreamCharSource::operator bool() const {
return m_stream.ReadAheadTo(m_offset);
}
}
inline const StreamCharSource StreamCharSource::operator + (int i) const {
inline const StreamCharSource StreamCharSource::operator+(int i) const {
StreamCharSource source(*this);
if(static_cast<int> (source.m_offset) + i >= 0)
if (static_cast<int>(source.m_offset) + i >= 0)
source.m_offset += i;
else
source.m_offset = 0;
return source;
}
}
}
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,47 +1,48 @@
#ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <cstddef>
namespace YAML
{
class StringCharSource
{
namespace YAML {
class StringCharSource {
public:
StringCharSource(const char *str, std::size_t size): m_str(str), m_size(size), m_offset(0) {}
StringCharSource(const char* str, std::size_t size)
: m_str(str), m_size(size), m_offset(0) {}
operator bool() const { return m_offset < m_size; }
char operator [] (std::size_t i) const { return m_str[m_offset + i]; }
bool operator !() const { return !static_cast<bool>(*this); }
char operator[](std::size_t i) const { return m_str[m_offset + i]; }
bool operator!() const { return !static_cast<bool>(*this); }
const StringCharSource operator + (int i) const {
const StringCharSource operator+(int i) const {
StringCharSource source(*this);
if(static_cast<int> (source.m_offset) + i >= 0)
if (static_cast<int>(source.m_offset) + i >= 0)
source.m_offset += i;
else
source.m_offset = 0;
return source;
}
StringCharSource& operator ++ () {
StringCharSource& operator++() {
++m_offset;
return *this;
}
StringCharSource& operator += (std::size_t offset) {
StringCharSource& operator+=(std::size_t offset) {
m_offset += offset;
return *this;
}
private:
const char *m_str;
const char* m_str;
std::size_t m_size;
std::size_t m_offset;
};
};
}
#endif // STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -4,11 +4,9 @@
#include <cassert>
#include <stdexcept>
namespace YAML
{
Tag::Tag(const Token& token): type(static_cast<TYPE>(token.data))
{
switch(type) {
namespace YAML {
Tag::Tag(const Token& token) : type(static_cast<TYPE>(token.data)) {
switch (type) {
case VERBATIM:
value = token.value;
break;
@@ -27,11 +25,10 @@ namespace YAML
default:
assert(false);
}
}
}
const std::string Tag::Translate(const Directives& directives)
{
switch(type) {
const std::string Tag::Translate(const Directives& directives) {
switch (type) {
case VERBATIM:
return value;
case PRIMARY_HANDLE:
@@ -47,6 +44,5 @@ namespace YAML
assert(false);
}
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
}
}
}

View File

@@ -1,20 +1,25 @@
#ifndef TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace YAML
{
struct Token;
struct Directives;
namespace YAML {
struct Token;
struct Directives;
struct Tag {
struct Tag {
enum TYPE {
VERBATIM, PRIMARY_HANDLE, SECONDARY_HANDLE, NAMED_HANDLE, NON_SPECIFIC
VERBATIM,
PRIMARY_HANDLE,
SECONDARY_HANDLE,
NAMED_HANDLE,
NON_SPECIFIC
};
Tag(const Token& token);
@@ -22,7 +27,7 @@ namespace YAML
TYPE type;
std::string handle, value;
};
};
}
#endif // TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,44 +1,32 @@
#ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/mark.h"
#include <iostream>
#include <string>
#include <vector>
namespace YAML
{
const std::string TokenNames[] = {
"DIRECTIVE",
"DOC_START",
"DOC_END",
"BLOCK_SEQ_START",
"BLOCK_MAP_START",
"BLOCK_SEQ_END",
"BLOCK_MAP_END",
"BLOCK_ENTRY",
"FLOW_SEQ_START",
"FLOW_MAP_START",
"FLOW_SEQ_END",
"FLOW_MAP_END",
"FLOW_MAP_COMPACT",
"FLOW_ENTRY",
"KEY",
"VALUE",
"ANCHOR",
"ALIAS",
"TAG",
"SCALAR"
};
namespace YAML {
const std::string TokenNames[] = {
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
"BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
"FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
"FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
"ANCHOR", "ALIAS", "TAG", "SCALAR"};
struct Token {
struct Token {
// enums
enum STATUS { VALID, INVALID, UNVERIFIED };
enum STATUS {
VALID,
INVALID,
UNVERIFIED
};
enum TYPE {
DIRECTIVE,
DOC_START,
@@ -64,11 +52,12 @@ namespace YAML
};
// data
Token(TYPE type_, const Mark& mark_): status(VALID), type(type_), mark(mark_), data(0) {}
Token(TYPE type_, const Mark& mark_)
: status(VALID), type(type_), mark(mark_), data(0) {}
friend std::ostream& operator << (std::ostream& out, const Token& token) {
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
out << TokenNames[token.type] << std::string(": ") << token.value;
for(std::size_t i=0;i<token.params.size();i++)
for (std::size_t i = 0; i < token.params.size(); i++)
out << std::string(" ") << token.params[i];
return out;
}
@@ -77,9 +66,9 @@ namespace YAML
TYPE type;
Mark mark;
std::string value;
std::vector <std::string> params;
std::vector<std::string> params;
int data;
};
};
}
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -3,22 +3,20 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace Parser {
TEST NoEndOfMapFlow()
{
namespace Test {
namespace Parser {
TEST NoEndOfMapFlow() {
try {
HANDLE("---{header: {id: 1");
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::END_OF_MAP_FLOW));
return true;
}
return " no exception caught";
}
}
TEST PlainScalarStartingWithQuestionMark()
{
TEST PlainScalarStartingWithQuestionMark() {
HANDLE("foo: ?bar");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
@@ -27,10 +25,9 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
TEST NullStringScalar()
{
TEST NullStringScalar() {
HANDLE("foo: null");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
@@ -39,39 +36,41 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
}
}
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed,
int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Parser test failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
bool RunParserTests()
{
bool RunParserTests() {
int passed = 0;
int total = 0;
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark,
"Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::NullStringScalar, "Null string scalar", passed, total);
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,14 @@
#ifndef EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace Test {
bool RunEmitterTests();
bool RunEmitterTests();
}
#endif // EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

File diff suppressed because it is too large Load Diff

View File

@@ -7,19 +7,31 @@
#include <cassert>
namespace Test {
inline std::string Quote(const std::string& text) {
inline std::string Quote(const std::string& text) {
YAML::Emitter out;
out << YAML::DoubleQuoted << text;
return out.c_str();
}
}
struct Event {
enum Type { DocStart, DocEnd, Null, Alias, Scalar, SeqStart, SeqEnd, MapStart, MapEnd };
struct Event {
enum Type {
DocStart,
DocEnd,
Null,
Alias,
Scalar,
SeqStart,
SeqEnd,
MapStart,
MapEnd
};
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
Event(Type type_, const std::string& tag_, anchor_t anchor_, const std::string& scalar_): type(type_), tag(tag_), anchor(anchor_), scalar(scalar_) {}
Event(Type type_, const std::string& tag_, anchor_t anchor_,
const std::string& scalar_)
: type(type_), tag(tag_), anchor(anchor_), scalar(scalar_) {}
Type type;
std::string tag;
@@ -27,7 +39,7 @@ namespace Test {
std::string scalar;
std::ostream& write(std::ostream& out) const {
switch(type) {
switch (type) {
case DocStart:
return out << "DocStart";
case DocEnd:
@@ -37,7 +49,8 @@ namespace Test {
case Alias:
return out << "Alias(" << anchor << ")";
case Scalar:
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", " << Quote(scalar) << ")";
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", "
<< Quote(scalar) << ")";
case SeqStart:
return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")";
case SeqEnd:
@@ -50,22 +63,20 @@ namespace Test {
assert(false);
return out;
}
};
};
inline std::ostream& operator << (std::ostream& out, const Event& event) {
inline std::ostream& operator<<(std::ostream& out, const Event& event) {
return event.write(out);
}
}
inline bool operator == (const Event& a, const Event& b) {
return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor && a.scalar == b.scalar;
}
inline bool operator==(const Event& a, const Event& b) {
return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor &&
a.scalar == b.scalar;
}
inline bool operator != (const Event& a, const Event& b) {
return !(a == b);
}
inline bool operator!=(const Event& a, const Event& b) { return !(a == b); }
class MockEventHandler: public YAML::EventHandler
{
class MockEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
@@ -88,11 +99,13 @@ namespace Test {
m_actualEvents.push_back(Event(Event::Alias, "", anchor, ""));
}
virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value) {
virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anchor,
const std::string& value) {
m_actualEvents.push_back(Event(Event::Scalar, tag, anchor, value));
}
virtual void OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor) {
virtual void OnSequenceStart(const Mark&, const std::string& tag,
anchor_t anchor) {
m_actualEvents.push_back(Event(Event::SeqStart, tag, anchor, ""));
}
@@ -100,7 +113,8 @@ namespace Test {
m_actualEvents.push_back(Event(Event::SeqEnd, "", 0, ""));
}
virtual void OnMapStart(const Mark&, const std::string& tag, anchor_t anchor) {
virtual void OnMapStart(const Mark&, const std::string& tag,
anchor_t anchor) {
m_actualEvents.push_back(Event(Event::MapStart, tag, anchor, ""));
}
@@ -112,10 +126,10 @@ namespace Test {
Test::TEST Check() const {
std::size_t N = std::max(m_expectedEvents.size(), m_actualEvents.size());
for(std::size_t i=0;i<N;i++) {
if(i >= m_expectedEvents.size()) {
for (std::size_t i = 0; i < N; i++) {
if (i >= m_expectedEvents.size()) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: (no event expected)\n";
@@ -123,9 +137,9 @@ namespace Test {
return out.str().c_str();
}
if(i >= m_actualEvents.size()) {
if (i >= m_actualEvents.size()) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
@@ -133,9 +147,9 @@ namespace Test {
return out.str().c_str();
}
if(m_expectedEvents[i] != m_actualEvents[i]) {
if (m_expectedEvents[i] != m_actualEvents[i]) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
@@ -149,42 +163,35 @@ namespace Test {
std::vector<Event> m_expectedEvents;
std::vector<Event> m_actualEvents;
};
};
#define HANDLE(ex)\
MockEventHandler handler;\
std::stringstream stream(ex);\
YAML::Parser parser(stream);\
while(parser.HandleNextDocument(handler)) {}
#define HANDLE(ex) \
MockEventHandler handler; \
std::stringstream stream(ex); \
YAML::Parser parser(stream); \
while (parser.HandleNextDocument(handler)) { \
}
#define EXPECT_DOC_START()\
handler.Expect(Event(Event::DocStart, "", 0, ""))
#define EXPECT_DOC_START() handler.Expect(Event(Event::DocStart, "", 0, ""))
#define EXPECT_DOC_END()\
handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_DOC_END() handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_NULL(anchor)\
handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_NULL(anchor) handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_ALIAS(anchor)\
handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_ALIAS(anchor) handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_SCALAR(tag, anchor, value)\
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SCALAR(tag, anchor, value) \
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SEQ_START(tag, anchor)\
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_SEQ_START(tag, anchor) \
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_SEQ_END()\
handler.Expect(Event(Event::SeqEnd, "", 0, ""))
#define EXPECT_SEQ_END() handler.Expect(Event(Event::SeqEnd, "", 0, ""))
#define EXPECT_MAP_START(tag, anchor)\
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define EXPECT_MAP_START(tag, anchor) \
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define EXPECT_MAP_END()\
handler.Expect(Event(Event::MapEnd, "", 0, ""))
#define DONE()\
return handler.Check()
#define EXPECT_MAP_END() handler.Expect(Event(Event::MapEnd, "", 0, ""))
#define DONE() return handler.Check()
}

View File

@@ -1,7 +1,6 @@
#include "tests.h"
int main()
{
int main() {
Test::RunAll();
return 0;
}

View File

@@ -1,13 +1,14 @@
#ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace Test {
bool RunParserTests();
bool RunParserTests();
}
#endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,16 +1,16 @@
namespace Test {
namespace Spec {
const char *ex2_1 =
namespace Spec {
const char *ex2_1 =
"- Mark McGwire\n"
"- Sammy Sosa\n"
"- Ken Griffey";
const char *ex2_2 =
const char *ex2_2 =
"hr: 65 # Home runs\n"
"avg: 0.278 # Batting average\n"
"rbi: 147 # Runs Batted In";
const char *ex2_3 =
const char *ex2_3 =
"american:\n"
"- Boston Red Sox\n"
"- Detroit Tigers\n"
@@ -20,7 +20,7 @@ namespace Test {
"- Chicago Cubs\n"
"- Atlanta Braves";
const char *ex2_4 =
const char *ex2_4 =
"-\n"
" name: Mark McGwire\n"
" hr: 65\n"
@@ -30,19 +30,19 @@ namespace Test {
" hr: 63\n"
" avg: 0.288";
const char *ex2_5 =
const char *ex2_5 =
"- [name , hr, avg ]\n"
"- [Mark McGwire, 65, 0.278]\n"
"- [Sammy Sosa , 63, 0.288]";
const char *ex2_6 =
const char *ex2_6 =
"Mark McGwire: {hr: 65, avg: 0.278}\n"
"Sammy Sosa: {\n"
" hr: 63,\n"
" avg: 0.288\n"
" }";
const char *ex2_7 =
const char *ex2_7 =
"# Ranking of 1998 home runs\n"
"---\n"
"- Mark McGwire\n"
@@ -54,7 +54,7 @@ namespace Test {
"- Chicago Cubs\n"
"- St Louis Cardinals";
const char *ex2_8 =
const char *ex2_8 =
"---\n"
"time: 20:03:20\n"
"player: Sammy Sosa\n"
@@ -66,7 +66,7 @@ namespace Test {
"action: grand slam\n"
"...";
const char *ex2_9 =
const char *ex2_9 =
"---\n"
"hr: # 1998 hr ranking\n"
" - Mark McGwire\n"
@@ -76,7 +76,7 @@ namespace Test {
" - Sammy Sosa\n"
" - Ken Griffey";
const char *ex2_10 =
const char *ex2_10 =
"---\n"
"hr:\n"
" - Mark McGwire\n"
@@ -86,7 +86,7 @@ namespace Test {
" - *SS # Subsequent occurrence\n"
" - Ken Griffey";
const char *ex2_11 =
const char *ex2_11 =
"? - Detroit Tigers\n"
" - Chicago cubs\n"
":\n"
@@ -97,7 +97,7 @@ namespace Test {
": [ 2001-07-02, 2001-08-12,\n"
" 2001-08-14 ]";
const char *ex2_12 =
const char *ex2_12 =
"---\n"
"# Products purchased\n"
"- item : Super Hoop\n"
@@ -107,19 +107,19 @@ namespace Test {
"- item : Big Shoes\n"
" quantity: 1";
const char *ex2_13 =
const char *ex2_13 =
"# ASCII Art\n"
"--- |\n"
" \\//||\\/||\n"
" // || ||__";
const char *ex2_14 =
const char *ex2_14 =
"--- >\n"
" Mark McGwire's\n"
" year was crippled\n"
" by a knee injury.";
const char *ex2_15 =
const char *ex2_15 =
">\n"
" Sammy Sosa completed another\n"
" fine season with great stats.\n"
@@ -129,7 +129,7 @@ namespace Test {
" \n"
" What a year!";
const char *ex2_16 =
const char *ex2_16 =
"name: Mark McGwire\n"
"accomplishment: >\n"
" Mark set a major league\n"
@@ -138,7 +138,7 @@ namespace Test {
" 65 Home Runs\n"
" 0.278 Batting Average\n";
const char *ex2_17 =
const char *ex2_17 =
"unicode: \"Sosa did fine.\\u263A\"\n"
"control: \"\\b1998\\t1999\\t2000\\n\"\n"
"hex esc: \"\\x0d\\x0a is \\r\\n\"\n"
@@ -147,7 +147,7 @@ namespace Test {
"quoted: ' # Not a ''comment''.'\n"
"tie-fighter: '|\\-*-/|'";
const char *ex2_18 =
const char *ex2_18 =
"plain:\n"
" This unquoted scalar\n"
" spans many lines.\n"
@@ -155,9 +155,9 @@ namespace Test {
"quoted: \"So does this\n"
" quoted scalar.\\n\"";
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
const char *ex2_23 =
const char *ex2_23 =
"---\n"
"not-date: !!str 2002-04-28\n"
"\n"
@@ -172,7 +172,7 @@ namespace Test {
" above may be different for\n"
" different documents.";
const char *ex2_24 =
const char *ex2_24 =
"%TAG ! tag:clarkevans.com,2002:\n"
"--- !shape\n"
" # Use the ! handle for presenting\n"
@@ -188,7 +188,7 @@ namespace Test {
" color: 0xFFEEBB\n"
" text: Pretty vector drawing.";
const char *ex2_25 =
const char *ex2_25 =
"# Sets are represented as a\n"
"# Mapping where each key is\n"
"# associated with a null value\n"
@@ -197,7 +197,7 @@ namespace Test {
"? Sammy Sosa\n"
"? Ken Griffey";
const char *ex2_26 =
const char *ex2_26 =
"# Ordered maps are represented as\n"
"# A sequence of mappings, with\n"
"# each mapping having one key\n"
@@ -206,7 +206,7 @@ namespace Test {
"- Sammy Sosa: 63\n"
"- Ken Griffey: 58";
const char *ex2_27 =
const char *ex2_27 =
"--- !<tag:clarkevans.com,2002:invoice>\n"
"invoice: 34843\n"
"date : 2001-01-23\n"
@@ -237,7 +237,7 @@ namespace Test {
" Backup contact is Nancy\n"
" Billsmer @ 338-4338.";
const char *ex2_28 =
const char *ex2_28 =
"---\n"
"Time: 2001-11-23 15:01:42 -5\n"
"User: ed\n"
@@ -265,9 +265,9 @@ namespace Test {
" code: |-\n"
" foo = bar";
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
const char *ex5_3 =
const char *ex5_3 =
"sequence:\n"
"- one\n"
"- two\n"
@@ -276,18 +276,17 @@ namespace Test {
" : blue\n"
" sea : green";
const char *ex5_4 =
const char *ex5_4 =
"sequence: [ one, two, ]\n"
"mapping: { sky: blue, sea: green }";
const char *ex5_5 =
"# Comment only.";
const char *ex5_5 = "# Comment only.";
const char *ex5_6 =
const char *ex5_6 =
"anchored: !local &anchor value\n"
"alias: *anchor";
const char *ex5_7 =
const char *ex5_7 =
"literal: |\n"
" some\n"
" text\n"
@@ -295,19 +294,19 @@ namespace Test {
" some\n"
" text\n";
const char *ex5_8 =
const char *ex5_8 =
"single: 'text'\n"
"double: \"text\"";
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
const char *ex5_11 =
const char *ex5_11 =
"|\n"
" Line break (no glyph)\n"
" Line break (glyphed)\n";
const char *ex5_12 =
const char *ex5_12 =
"# Tabs and spaces\n"
"quoted: \"Quoted\t\"\n"
"block: |\n"
@@ -315,19 +314,19 @@ namespace Test {
" \tprintf(\"Hello, world!\\n\");\n"
" }";
const char *ex5_13 =
const char *ex5_13 =
"\"Fun with \\\\\n"
"\\\" \\a \\b \\e \\f \\\n"
"\\n \\r \\t \\v \\0 \\\n"
"\\ \\_ \\N \\L \\P \\\n"
"\\x41 \\u0041 \\U00000041\"";
const char *ex5_14 =
const char *ex5_14 =
"Bad escapes:\n"
" \"\\c\n"
" \\xq-\"";
const char *ex6_1 =
const char *ex6_1 =
" # Leading comment line spaces are\n"
" # neither content nor indentation.\n"
" \n"
@@ -341,18 +340,18 @@ namespace Test {
" \tStill by two # content nor\n"
" ] # indentation.";
const char *ex6_2 =
const char *ex6_2 =
"? a\n"
": -\tb\n"
" - -\tc\n"
" - d";
const char *ex6_3 =
const char *ex6_3 =
"- foo:\t bar\n"
"- - baz\n"
" -\tbaz";
const char *ex6_4 =
const char *ex6_4 =
"plain: text\n"
" lines\n"
"quoted: \"text\n"
@@ -361,7 +360,7 @@ namespace Test {
" text\n"
" \tlines\n";
const char *ex6_5 =
const char *ex6_5 =
"Folding:\n"
" \"Empty line\n"
" \t\n"
@@ -370,7 +369,7 @@ namespace Test {
" Clipped empty lines\n"
" ";
const char *ex6_6 =
const char *ex6_6 =
">-\n"
" trimmed\n"
" \n"
@@ -379,7 +378,7 @@ namespace Test {
" as\n"
" space";
const char *ex6_7 =
const char *ex6_7 =
">\n"
" foo \n"
" \n"
@@ -387,7 +386,7 @@ namespace Test {
"\n"
" baz\n";
const char *ex6_8 =
const char *ex6_8 =
"\"\n"
" foo \n"
" \n"
@@ -396,22 +395,22 @@ namespace Test {
" baz\n"
"\"";
const char *ex6_9 =
const char *ex6_9 =
"key: # Comment\n"
" value";
const char *ex6_10 =
const char *ex6_10 =
" # Comment\n"
" \n"
"\n";
const char *ex6_11 =
const char *ex6_11 =
"key: # Comment\n"
" # lines\n"
" value\n"
"\n";
const char *ex6_12 =
const char *ex6_12 =
"{ first: Sammy, last: Sosa }:\n"
"# Statistics:\n"
" hr: # Home runs\n"
@@ -419,33 +418,33 @@ namespace Test {
" avg: # Average\n"
" 0.278";
const char *ex6_13 =
const char *ex6_13 =
"%FOO bar baz # Should be ignored\n"
" # with a warning.\n"
"--- \"foo\"";
const char *ex6_14 =
const char *ex6_14 =
"%YAML 1.3 # Attempt parsing\n"
" # with a warning\n"
"---\n"
"\"foo\"";
const char *ex6_15 =
const char *ex6_15 =
"%YAML 1.2\n"
"%YAML 1.1\n"
"foo";
const char *ex6_16 =
const char *ex6_16 =
"%TAG !yaml! tag:yaml.org,2002:\n"
"---\n"
"!yaml!str \"foo\"";
const char *ex6_17 =
const char *ex6_17 =
"%TAG ! !foo\n"
"%TAG ! !foo\n"
"bar";
const char *ex6_18 =
const char *ex6_18 =
"# Private\n"
"!foo \"bar\"\n"
"...\n"
@@ -454,17 +453,17 @@ namespace Test {
"---\n"
"!foo \"bar\"";
const char *ex6_19 =
const char *ex6_19 =
"%TAG !! tag:example.com,2000:app/\n"
"---\n"
"!!int 1 - 3 # Interval, not integer";
const char *ex6_20 =
const char *ex6_20 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"!e!foo \"bar\"";
const char *ex6_21 =
const char *ex6_21 =
"%TAG !m! !my-\n"
"--- # Bulb here\n"
"!m!light fluorescent\n"
@@ -473,102 +472,101 @@ namespace Test {
"--- # Color here\n"
"!m!light green";
const char *ex6_22 =
const char *ex6_22 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !e!foo \"bar\"";
const char *ex6_23 =
const char *ex6_23 =
"!!str &a1 \"foo\":\n"
" !!str bar\n"
"&a2 baz : *a1";
const char *ex6_24 =
const char *ex6_24 =
"!<tag:yaml.org,2002:str> foo :\n"
" !<!bar> baz";
const char *ex6_25 =
const char *ex6_25 =
"- !<!> foo\n"
"- !<$:?> bar\n";
const char *ex6_26 =
const char *ex6_26 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !local foo\n"
"- !!str bar\n"
"- !e!tag%21 baz\n";
const char *ex6_27a =
const char *ex6_27a =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !e! foo";
const char *ex6_27b =
const char *ex6_27b =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !h!bar baz";
const char *ex6_28 =
const char *ex6_28 =
"# Assuming conventional resolution:\n"
"- \"12\"\n"
"- 12\n"
"- ! 12";
const char *ex6_29 =
const char *ex6_29 =
"First occurrence: &anchor Value\n"
"Second occurrence: *anchor";
const char *ex7_1 =
const char *ex7_1 =
"First occurrence: &anchor Foo\n"
"Second occurrence: *anchor\n"
"Override anchor: &anchor Bar\n"
"Reuse anchor: *anchor";
const char *ex7_2 =
const char *ex7_2 =
"{\n"
" foo : !!str,\n"
" !!str : bar,\n"
"}";
const char *ex7_3 =
const char *ex7_3 =
"{\n"
" ? foo :,\n"
" : bar,\n"
"}\n";
const char *ex7_4 =
const char *ex7_4 =
"\"implicit block key\" : [\n"
" \"implicit flow key\" : value,\n"
" ]";
const char *ex7_5 =
const char *ex7_5 =
"\"folded \n"
"to a space,\t\n"
" \n"
"to a line feed, or \t\\\n"
" \\ \tnon-content\"";
const char *ex7_6 =
const char *ex7_6 =
"\" 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty \"";
const char *ex7_7 =
" 'here''s to \"quotes\"'";
const char *ex7_7 = " 'here''s to \"quotes\"'";
const char *ex7_8 =
const char *ex7_8 =
"'implicit block key' : [\n"
" 'implicit flow key' : value,\n"
" ]";
const char *ex7_9 =
const char *ex7_9 =
"' 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty '";
const char *ex7_10 =
const char *ex7_10 =
"# Outside flow collection:\n"
"- ::vector\n"
"- \": - ()\"\n"
@@ -582,22 +580,22 @@ namespace Test {
" -123,\n"
" http://example.com/foo#bar ]";
const char *ex7_11 =
const char *ex7_11 =
"implicit block key : [\n"
" implicit flow key : value,\n"
" ]";
const char *ex7_12 =
const char *ex7_12 =
"1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty";
const char *ex7_13 =
const char *ex7_13 =
"- [ one, two, ]\n"
"- [three ,four]";
const char *ex7_14 =
const char *ex7_14 =
"[\n"
"\"double\n"
" quoted\", 'single\n"
@@ -607,18 +605,18 @@ namespace Test {
"single: pair,\n"
"]";
const char *ex7_15 =
const char *ex7_15 =
"- { one : two , three: four , }\n"
"- {five: six,seven : eight}";
const char *ex7_16 =
const char *ex7_16 =
"{\n"
"? explicit: entry,\n"
"implicit: entry,\n"
"?\n"
"}";
const char *ex7_17 =
const char *ex7_17 =
"{\n"
"unquoted : \"separate\",\n"
"http://foo.com,\n"
@@ -626,48 +624,49 @@ namespace Test {
": omitted key,\n"
"}";
const char *ex7_18 =
const char *ex7_18 =
"{\n"
"\"adjacent\":value,\n"
"\"readable\":value,\n"
"\"empty\":\n"
"}";
const char *ex7_19 =
const char *ex7_19 =
"[\n"
"foo: bar\n"
"]";
const char *ex7_20 =
const char *ex7_20 =
"[\n"
"? foo\n"
" bar : baz\n"
"]";
const char *ex7_21 =
const char *ex7_21 =
"- [ YAML : separate ]\n"
"- [ : empty key entry ]\n"
"- [ {JSON: like}:adjacent ]";
const char *ex7_22 =
const char *ex7_22 =
"[ foo\n"
" bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an implicit key
" bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an
// implicit key
const char *ex7_23 =
const char *ex7_23 =
"- [ a, b ]\n"
"- { a: b }\n"
"- \"a\"\n"
"- 'b'\n"
"- c";
const char *ex7_24 =
const char *ex7_24 =
"- !!str \"a\"\n"
"- 'b'\n"
"- &anchor \"c\"\n"
"- *anchor\n"
"- !!str";
const char *ex8_1 =
const char *ex8_1 =
"- | # Empty header\n"
" literal\n"
"- >1 # Indentation indicator\n"
@@ -678,7 +677,7 @@ namespace Test {
"- >1- # Both indicators\n"
" strip\n";
const char *ex8_2 =
const char *ex8_2 =
"- |\n"
" detected\n"
"- >\n"
@@ -691,21 +690,21 @@ namespace Test {
" \t\n"
" detected\n";
const char *ex8_3a =
const char *ex8_3a =
"- |\n"
" \n"
" text";
const char *ex8_3b =
const char *ex8_3b =
"- >\n"
" text\n"
" text";
const char *ex8_3c =
const char *ex8_3c =
"- |2\n"
" text";
const char *ex8_4 =
const char *ex8_4 =
"strip: |-\n"
" text\n"
"clip: |\n"
@@ -713,7 +712,7 @@ namespace Test {
"keep: |+\n"
" text\n";
const char *ex8_5 =
const char *ex8_5 =
" # Strip\n"
" # Comments:\n"
"strip: |-\n"
@@ -734,7 +733,7 @@ namespace Test {
" # Trail\n"
" # Comments\n";
const char *ex8_6 =
const char *ex8_6 =
"strip: >-\n"
"\n"
"clip: >\n"
@@ -742,13 +741,13 @@ namespace Test {
"keep: |+\n"
"\n";
const char *ex8_7 =
const char *ex8_7 =
"|\n"
" literal\n"
" \ttext\n"
"\n";
const char *ex8_8 =
const char *ex8_8 =
"|\n"
" \n"
" \n"
@@ -759,13 +758,13 @@ namespace Test {
"\n"
" # Comment\n";
const char *ex8_9 =
const char *ex8_9 =
">\n"
" folded\n"
" text\n"
"\n";
const char *ex8_10 =
const char *ex8_10 =
">\n"
"\n"
" folded\n"
@@ -783,16 +782,16 @@ namespace Test {
"\n"
"# Comment\n";
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_14 =
const char *ex8_14 =
"block sequence:\n"
" - one\n"
" - two : three\n";
const char *ex8_15 =
const char *ex8_15 =
"- # Empty\n"
"- |\n"
" block node\n"
@@ -800,29 +799,29 @@ namespace Test {
" - two # sequence\n"
"- one: two # Compact mapping\n";
const char *ex8_16 =
const char *ex8_16 =
"block mapping:\n"
" key: value\n";
const char *ex8_17 =
const char *ex8_17 =
"? explicit key # Empty value\n"
"? |\n"
" block key\n"
": - one # Explicit compact\n"
" - two # block value\n";
const char *ex8_18 =
const char *ex8_18 =
"plain key: in-line value\n"
": # Both empty\n"
"\"quoted key\":\n"
"- entry\n";
const char *ex8_19 =
const char *ex8_19 =
"- sun: yellow\n"
"- ? earth: blue\n"
" : moon: white\n";
const char *ex8_20 =
const char *ex8_20 =
"-\n"
" \"flow in block\"\n"
"- >\n"
@@ -830,7 +829,7 @@ namespace Test {
"- !!map # Block collection\n"
" foo : bar\n";
const char *ex8_21 =
const char *ex8_21 =
"literal: |2\n"
" value\n"
"folded:\n"
@@ -838,13 +837,12 @@ namespace Test {
" >1\n"
" value\n";
const char *ex8_22 =
const char *ex8_22 =
"sequence: !!seq\n"
"- entry\n"
"- !!seq\n"
" - nested\n"
"mapping: !!map\n"
" foo: bar\n";
}
}
}

View File

@@ -2,148 +2,223 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace {
void RunSpecTest(TEST (*test)(), const std::string& index, const std::string& name, int& passed, int& total) {
namespace Test {
namespace {
void RunSpecTest(TEST (*test)(), const std::string& index,
const std::string& name, int& passed, int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Spec test " << index << " failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
bool RunSpecTests()
{
bool RunSpecTests() {
int passed = 0;
int total = 0;
RunSpecTest(&Spec::SeqScalars, "2.1", "Sequence of Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToScalars, "2.2", "Mapping Scalars to Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToSequences, "2.3", "Mapping Scalars to Sequences", passed, total);
RunSpecTest(&Spec::SequenceOfMappings, "2.4", "Sequence of Mappings", passed, total);
RunSpecTest(&Spec::SequenceOfSequences, "2.5", "Sequence of Sequences", passed, total);
RunSpecTest(&Spec::MappingOfMappings, "2.6", "Mapping of Mappings", passed, total);
RunSpecTest(&Spec::TwoDocumentsInAStream, "2.7", "Two Documents in a Stream", passed, total);
RunSpecTest(&Spec::PlayByPlayFeed, "2.8", "Play by Play Feed from a Game", passed, total);
RunSpecTest(&Spec::SingleDocumentWithTwoComments, "2.9", "Single Document with Two Comments", passed, total);
RunSpecTest(&Spec::SimpleAnchor, "2.10", "Node for \"Sammy Sosa\" appears twice in this document", passed, total);
RunSpecTest(&Spec::MappingBetweenSequences, "2.11", "Mapping between Sequences", passed, total);
RunSpecTest(&Spec::CompactNestedMapping, "2.12", "Compact Nested Mapping", passed, total);
RunSpecTest(&Spec::InLiteralsNewlinesArePreserved, "2.13", "In literals, newlines are preserved", passed, total);
RunSpecTest(&Spec::InFoldedScalarsNewlinesBecomeSpaces, "2.14", "In folded scalars, newlines become spaces", passed, total);
RunSpecTest(&Spec::FoldedNewlinesArePreservedForMoreIndentedAndBlankLines, "2.15", "Folded newlines are preserved for \"more indented\" and blank lines", passed, total);
RunSpecTest(&Spec::IndentationDeterminesScope, "2.16", "Indentation determines scope", passed, total);
RunSpecTest(&Spec::MappingScalarsToScalars, "2.2",
"Mapping Scalars to Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToSequences, "2.3",
"Mapping Scalars to Sequences", passed, total);
RunSpecTest(&Spec::SequenceOfMappings, "2.4", "Sequence of Mappings", passed,
total);
RunSpecTest(&Spec::SequenceOfSequences, "2.5", "Sequence of Sequences",
passed, total);
RunSpecTest(&Spec::MappingOfMappings, "2.6", "Mapping of Mappings", passed,
total);
RunSpecTest(&Spec::TwoDocumentsInAStream, "2.7", "Two Documents in a Stream",
passed, total);
RunSpecTest(&Spec::PlayByPlayFeed, "2.8", "Play by Play Feed from a Game",
passed, total);
RunSpecTest(&Spec::SingleDocumentWithTwoComments, "2.9",
"Single Document with Two Comments", passed, total);
RunSpecTest(&Spec::SimpleAnchor, "2.10",
"Node for \"Sammy Sosa\" appears twice in this document", passed,
total);
RunSpecTest(&Spec::MappingBetweenSequences, "2.11",
"Mapping between Sequences", passed, total);
RunSpecTest(&Spec::CompactNestedMapping, "2.12", "Compact Nested Mapping",
passed, total);
RunSpecTest(&Spec::InLiteralsNewlinesArePreserved, "2.13",
"In literals, newlines are preserved", passed, total);
RunSpecTest(&Spec::InFoldedScalarsNewlinesBecomeSpaces, "2.14",
"In folded scalars, newlines become spaces", passed, total);
RunSpecTest(
&Spec::FoldedNewlinesArePreservedForMoreIndentedAndBlankLines, "2.15",
"Folded newlines are preserved for \"more indented\" and blank lines",
passed, total);
RunSpecTest(&Spec::IndentationDeterminesScope, "2.16",
"Indentation determines scope", passed, total);
RunSpecTest(&Spec::QuotedScalars, "2.17", "Quoted scalars", passed, total);
RunSpecTest(&Spec::MultiLineFlowScalars, "2.18", "Multi-line flow scalars", passed, total);
RunSpecTest(&Spec::MultiLineFlowScalars, "2.18", "Multi-line flow scalars",
passed, total);
RunSpecTest(&Spec::VariousExplicitTags, "2.23", "Various Explicit Tags", passed, total);
RunSpecTest(&Spec::VariousExplicitTags, "2.23", "Various Explicit Tags",
passed, total);
RunSpecTest(&Spec::GlobalTags, "2.24", "Global Tags", passed, total);
RunSpecTest(&Spec::UnorderedSets, "2.25", "Unordered Sets", passed, total);
RunSpecTest(&Spec::OrderedMappings, "2.26", "Ordered Mappings", passed, total);
RunSpecTest(&Spec::OrderedMappings, "2.26", "Ordered Mappings", passed,
total);
RunSpecTest(&Spec::Invoice, "2.27", "Invoice", passed, total);
RunSpecTest(&Spec::LogFile, "2.28", "Log File", passed, total);
RunSpecTest(&Spec::BlockStructureIndicators, "5.3", "Block Structure Indicators", passed, total);
RunSpecTest(&Spec::FlowStructureIndicators, "5.4", "Flow Structure Indicators", passed, total);
RunSpecTest(&Spec::NodePropertyIndicators, "5.6", "Node Property Indicators", passed, total);
RunSpecTest(&Spec::BlockScalarIndicators, "5.7", "Block Scalar Indicators", passed, total);
RunSpecTest(&Spec::QuotedScalarIndicators, "5.8", "Quoted Scalar Indicators", passed, total);
RunSpecTest(&Spec::LineBreakCharacters, "5.11", "Line Break Characters", passed, total);
RunSpecTest(&Spec::BlockStructureIndicators, "5.3",
"Block Structure Indicators", passed, total);
RunSpecTest(&Spec::FlowStructureIndicators, "5.4",
"Flow Structure Indicators", passed, total);
RunSpecTest(&Spec::NodePropertyIndicators, "5.6", "Node Property Indicators",
passed, total);
RunSpecTest(&Spec::BlockScalarIndicators, "5.7", "Block Scalar Indicators",
passed, total);
RunSpecTest(&Spec::QuotedScalarIndicators, "5.8", "Quoted Scalar Indicators",
passed, total);
RunSpecTest(&Spec::LineBreakCharacters, "5.11", "Line Break Characters",
passed, total);
RunSpecTest(&Spec::TabsAndSpaces, "5.12", "Tabs and Spaces", passed, total);
RunSpecTest(&Spec::EscapedCharacters, "5.13", "Escaped Characters", passed, total);
RunSpecTest(&Spec::InvalidEscapedCharacters, "5.14", "Invalid Escaped Characters", passed, total);
RunSpecTest(&Spec::EscapedCharacters, "5.13", "Escaped Characters", passed,
total);
RunSpecTest(&Spec::InvalidEscapedCharacters, "5.14",
"Invalid Escaped Characters", passed, total);
RunSpecTest(&Spec::IndentationSpaces, "6.1", "Indentation Spaces", passed, total);
RunSpecTest(&Spec::IndentationIndicators, "6.2", "Indentation Indicators", passed, total);
RunSpecTest(&Spec::SeparationSpaces, "6.3", "Separation Spaces", passed, total);
RunSpecTest(&Spec::IndentationSpaces, "6.1", "Indentation Spaces", passed,
total);
RunSpecTest(&Spec::IndentationIndicators, "6.2", "Indentation Indicators",
passed, total);
RunSpecTest(&Spec::SeparationSpaces, "6.3", "Separation Spaces", passed,
total);
RunSpecTest(&Spec::LinePrefixes, "6.4", "Line Prefixes", passed, total);
RunSpecTest(&Spec::EmptyLines, "6.5", "Empty Lines", passed, total);
RunSpecTest(&Spec::LineFolding, "6.6", "Line Folding", passed, total);
RunSpecTest(&Spec::BlockFolding, "6.7", "Block Folding", passed, total);
RunSpecTest(&Spec::FlowFolding, "6.8", "Flow Folding", passed, total);
RunSpecTest(&Spec::SeparatedComment, "6.9", "Separated Comment", passed, total);
RunSpecTest(&Spec::SeparatedComment, "6.9", "Separated Comment", passed,
total);
RunSpecTest(&Spec::CommentLines, "6.10", "Comment Lines", passed, total);
RunSpecTest(&Spec::MultiLineComments, "6.11", "Multi-Line Comments", passed, total);
RunSpecTest(&Spec::SeparationSpacesII, "6.12", "Separation Spaces", passed, total);
RunSpecTest(&Spec::ReservedDirectives, "6.13", "Reserved Directives", passed, total);
RunSpecTest(&Spec::MultiLineComments, "6.11", "Multi-Line Comments", passed,
total);
RunSpecTest(&Spec::SeparationSpacesII, "6.12", "Separation Spaces", passed,
total);
RunSpecTest(&Spec::ReservedDirectives, "6.13", "Reserved Directives", passed,
total);
RunSpecTest(&Spec::YAMLDirective, "6.14", "YAML Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedYAMLDirective, "6.15", "Invalid Repeated YAML Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedYAMLDirective, "6.15",
"Invalid Repeated YAML Directive", passed, total);
RunSpecTest(&Spec::TagDirective, "6.16", "Tag Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedTagDirective, "6.17", "Invalid Repeated Tag Directive", passed, total);
RunSpecTest(&Spec::PrimaryTagHandle, "6.18", "Primary Tag Handle", passed, total);
RunSpecTest(&Spec::SecondaryTagHandle, "6.19", "SecondaryTagHandle", passed, total);
RunSpecTest(&Spec::InvalidRepeatedTagDirective, "6.17",
"Invalid Repeated Tag Directive", passed, total);
RunSpecTest(&Spec::PrimaryTagHandle, "6.18", "Primary Tag Handle", passed,
total);
RunSpecTest(&Spec::SecondaryTagHandle, "6.19", "SecondaryTagHandle", passed,
total);
RunSpecTest(&Spec::TagHandles, "6.20", "TagHandles", passed, total);
RunSpecTest(&Spec::LocalTagPrefix, "6.21", "LocalTagPrefix", passed, total);
RunSpecTest(&Spec::GlobalTagPrefix, "6.22", "GlobalTagPrefix", passed, total);
RunSpecTest(&Spec::NodeProperties, "6.23", "NodeProperties", passed, total);
RunSpecTest(&Spec::VerbatimTags, "6.24", "Verbatim Tags", passed, total);
RunSpecTest(&Spec::InvalidVerbatimTags, "6.25", "Invalid Verbatim Tags", passed, total);
RunSpecTest(&Spec::InvalidVerbatimTags, "6.25", "Invalid Verbatim Tags",
passed, total);
RunSpecTest(&Spec::TagShorthands, "6.26", "Tag Shorthands", passed, total);
RunSpecTest(&Spec::InvalidTagShorthands, "6.27", "Invalid Tag Shorthands", passed, total);
RunSpecTest(&Spec::NonSpecificTags, "6.28", "Non Specific Tags", passed, total);
RunSpecTest(&Spec::InvalidTagShorthands, "6.27", "Invalid Tag Shorthands",
passed, total);
RunSpecTest(&Spec::NonSpecificTags, "6.28", "Non Specific Tags", passed,
total);
RunSpecTest(&Spec::NodeAnchors, "6.29", "Node Anchors", passed, total);
RunSpecTest(&Spec::AliasNodes, "7.1", "Alias Nodes", passed, total);
RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total);
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes", passed, total);
RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4", "Double Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::DoubleQuotedLineBreaks, "7.5", "Double Quoted Line Breaks", passed, total);
RunSpecTest(&Spec::DoubleQuotedLines, "7.6", "Double Quoted Lines", passed, total);
RunSpecTest(&Spec::SingleQuotedCharacters, "7.7", "Single Quoted Characters", passed, total);
RunSpecTest(&Spec::SingleQuotedImplicitKeys, "7.8", "Single Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::SingleQuotedLines, "7.9", "Single Quoted Lines", passed, total);
RunSpecTest(&Spec::PlainCharacters, "7.10", "Plain Characters", passed, total);
RunSpecTest(&Spec::PlainImplicitKeys, "7.11", "Plain Implicit Keys", passed, total);
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes",
passed, total);
RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4",
"Double Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::DoubleQuotedLineBreaks, "7.5", "Double Quoted Line Breaks",
passed, total);
RunSpecTest(&Spec::DoubleQuotedLines, "7.6", "Double Quoted Lines", passed,
total);
RunSpecTest(&Spec::SingleQuotedCharacters, "7.7", "Single Quoted Characters",
passed, total);
RunSpecTest(&Spec::SingleQuotedImplicitKeys, "7.8",
"Single Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::SingleQuotedLines, "7.9", "Single Quoted Lines", passed,
total);
RunSpecTest(&Spec::PlainCharacters, "7.10", "Plain Characters", passed,
total);
RunSpecTest(&Spec::PlainImplicitKeys, "7.11", "Plain Implicit Keys", passed,
total);
RunSpecTest(&Spec::PlainLines, "7.12", "Plain Lines", passed, total);
RunSpecTest(&Spec::FlowSequence, "7.13", "Flow Sequence", passed, total);
RunSpecTest(&Spec::FlowSequenceEntries, "7.14", "Flow Sequence Entries", passed, total);
RunSpecTest(&Spec::FlowSequenceEntries, "7.14", "Flow Sequence Entries",
passed, total);
RunSpecTest(&Spec::FlowMappings, "7.15", "Flow Mappings", passed, total);
RunSpecTest(&Spec::FlowMappingEntries, "7.16", "Flow Mapping Entries", passed, total);
RunSpecTest(&Spec::FlowMappingSeparateValues, "7.17", "Flow Mapping Separate Values", passed, total);
RunSpecTest(&Spec::FlowMappingAdjacentValues, "7.18", "Flow Mapping Adjacent Values", passed, total);
RunSpecTest(&Spec::SinglePairFlowMappings, "7.19", "Single Pair Flow Mappings", passed, total);
RunSpecTest(&Spec::SinglePairExplicitEntry, "7.20", "Single Pair Explicit Entry", passed, total);
RunSpecTest(&Spec::SinglePairImplicitEntries, "7.21", "Single Pair Implicit Entries", passed, total);
RunSpecTest(&Spec::InvalidImplicitKeys, "7.22", "Invalid Implicit Keys", passed, total);
RunSpecTest(&Spec::FlowMappingEntries, "7.16", "Flow Mapping Entries", passed,
total);
RunSpecTest(&Spec::FlowMappingSeparateValues, "7.17",
"Flow Mapping Separate Values", passed, total);
RunSpecTest(&Spec::FlowMappingAdjacentValues, "7.18",
"Flow Mapping Adjacent Values", passed, total);
RunSpecTest(&Spec::SinglePairFlowMappings, "7.19",
"Single Pair Flow Mappings", passed, total);
RunSpecTest(&Spec::SinglePairExplicitEntry, "7.20",
"Single Pair Explicit Entry", passed, total);
RunSpecTest(&Spec::SinglePairImplicitEntries, "7.21",
"Single Pair Implicit Entries", passed, total);
RunSpecTest(&Spec::InvalidImplicitKeys, "7.22", "Invalid Implicit Keys",
passed, total);
RunSpecTest(&Spec::FlowContent, "7.23", "Flow Content", passed, total);
RunSpecTest(&Spec::FlowNodes, "7.24", "FlowNodes", passed, total);
RunSpecTest(&Spec::BlockScalarHeader, "8.1", "Block Scalar Header", passed, total);
RunSpecTest(&Spec::BlockIndentationHeader, "8.2", "Block Indentation Header", passed, total);
RunSpecTest(&Spec::InvalidBlockScalarIndentationIndicators, "8.3", "Invalid Block Scalar Indentation Indicators", passed, total);
RunSpecTest(&Spec::ChompingFinalLineBreak, "8.4", "Chomping Final Line Break", passed, total);
RunSpecTest(&Spec::ChompingTrailingLines, "8.5", "Chomping Trailing Lines", passed, total);
RunSpecTest(&Spec::EmptyScalarChomping, "8.6", "Empty Scalar Chomping", passed, total);
RunSpecTest(&Spec::BlockScalarHeader, "8.1", "Block Scalar Header", passed,
total);
RunSpecTest(&Spec::BlockIndentationHeader, "8.2", "Block Indentation Header",
passed, total);
RunSpecTest(&Spec::InvalidBlockScalarIndentationIndicators, "8.3",
"Invalid Block Scalar Indentation Indicators", passed, total);
RunSpecTest(&Spec::ChompingFinalLineBreak, "8.4", "Chomping Final Line Break",
passed, total);
RunSpecTest(&Spec::ChompingTrailingLines, "8.5", "Chomping Trailing Lines",
passed, total);
RunSpecTest(&Spec::EmptyScalarChomping, "8.6", "Empty Scalar Chomping",
passed, total);
RunSpecTest(&Spec::LiteralScalar, "8.7", "Literal Scalar", passed, total);
RunSpecTest(&Spec::LiteralContent, "8.8", "Literal Content", passed, total);
RunSpecTest(&Spec::FoldedScalar, "8.9", "Folded Scalar", passed, total);
RunSpecTest(&Spec::FoldedLines, "8.10", "Folded Lines", passed, total);
RunSpecTest(&Spec::MoreIndentedLines, "8.11", "More Indented Lines", passed, total);
RunSpecTest(&Spec::EmptySeparationLines, "8.12", "Empty Separation Lines", passed, total);
RunSpecTest(&Spec::FinalEmptyLines, "8.13", "Final Empty Lines", passed, total);
RunSpecTest(&Spec::MoreIndentedLines, "8.11", "More Indented Lines", passed,
total);
RunSpecTest(&Spec::EmptySeparationLines, "8.12", "Empty Separation Lines",
passed, total);
RunSpecTest(&Spec::FinalEmptyLines, "8.13", "Final Empty Lines", passed,
total);
RunSpecTest(&Spec::BlockSequence, "8.14", "Block Sequence", passed, total);
RunSpecTest(&Spec::BlockSequenceEntryTypes, "8.15", "Block Sequence Entry Types", passed, total);
RunSpecTest(&Spec::BlockSequenceEntryTypes, "8.15",
"Block Sequence Entry Types", passed, total);
RunSpecTest(&Spec::BlockMappings, "8.16", "Block Mappings", passed, total);
RunSpecTest(&Spec::ExplicitBlockMappingEntries, "8.17", "Explicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::ImplicitBlockMappingEntries, "8.18", "Implicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::CompactBlockMappings, "8.19", "Compact Block Mappings", passed, total);
RunSpecTest(&Spec::ExplicitBlockMappingEntries, "8.17",
"Explicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::ImplicitBlockMappingEntries, "8.18",
"Implicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::CompactBlockMappings, "8.19", "Compact Block Mappings",
passed, total);
RunSpecTest(&Spec::BlockNodeTypes, "8.20", "Block Node Types", passed, total);
RunSpecTest(&Spec::BlockScalarNodes, "8.21", "Block Scalar Nodes", passed, total);
RunSpecTest(&Spec::BlockCollectionNodes, "8.22", "Block Collection Nodes", passed, total);
RunSpecTest(&Spec::BlockScalarNodes, "8.21", "Block Scalar Nodes", passed,
total);
RunSpecTest(&Spec::BlockCollectionNodes, "8.22", "Block Collection Nodes",
passed, total);
std::cout << "Spec tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}

View File

@@ -1,351 +1,352 @@
#ifndef SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "teststruct.h"
namespace Test {
namespace Spec {
// 2.1
TEST SeqScalars();
namespace Spec {
// 2.1
TEST SeqScalars();
// 2.2
TEST MappingScalarsToScalars();
// 2.2
TEST MappingScalarsToScalars();
// 2.3
TEST MappingScalarsToSequences();
// 2.3
TEST MappingScalarsToSequences();
// 2.4
TEST SequenceOfMappings();
// 2.4
TEST SequenceOfMappings();
// 2.5
TEST SequenceOfSequences();
// 2.5
TEST SequenceOfSequences();
// 2.6
TEST MappingOfMappings();
// 2.6
TEST MappingOfMappings();
// 2.7
TEST TwoDocumentsInAStream();
// 2.7
TEST TwoDocumentsInAStream();
// 2.8
TEST PlayByPlayFeed();
// 2.8
TEST PlayByPlayFeed();
// 2.9
TEST SingleDocumentWithTwoComments();
// 2.9
TEST SingleDocumentWithTwoComments();
// 2.10
TEST SimpleAnchor();
// 2.10
TEST SimpleAnchor();
// 2.11
TEST MappingBetweenSequences();
// 2.11
TEST MappingBetweenSequences();
// 2.12
TEST CompactNestedMapping();
// 2.12
TEST CompactNestedMapping();
// 2.13
TEST InLiteralsNewlinesArePreserved();
// 2.13
TEST InLiteralsNewlinesArePreserved();
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.16
TEST IndentationDeterminesScope();
// 2.16
TEST IndentationDeterminesScope();
// 2.17
TEST QuotedScalars();
// 2.17
TEST QuotedScalars();
// 2.18
TEST MultiLineFlowScalars();
// 2.18
TEST MultiLineFlowScalars();
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags();
// 2.23
TEST VariousExplicitTags();
// 2.24
TEST GlobalTags();
// 2.24
TEST GlobalTags();
// 2.25
TEST UnorderedSets();
// 2.25
TEST UnorderedSets();
// 2.26
TEST OrderedMappings();
// 2.26
TEST OrderedMappings();
// 2.27
TEST Invoice();
// 2.27
TEST Invoice();
// 2.28
TEST LogFile();
// 2.28
TEST LogFile();
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators();
// 5.3
TEST BlockStructureIndicators();
// 5.4
TEST FlowStructureIndicators();
// 5.4
TEST FlowStructureIndicators();
// 5.5
TEST CommentIndicator();
// 5.5
TEST CommentIndicator();
// 5.6
TEST NodePropertyIndicators();
// 5.6
TEST NodePropertyIndicators();
// 5.7
TEST BlockScalarIndicators();
// 5.7
TEST BlockScalarIndicators();
// 5.8
TEST QuotedScalarIndicators();
// 5.8
TEST QuotedScalarIndicators();
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters();
// 5.11
TEST LineBreakCharacters();
// 5.12
TEST TabsAndSpaces();
// 5.12
TEST TabsAndSpaces();
// 5.13
TEST EscapedCharacters();
// 5.13
TEST EscapedCharacters();
// 5.14
TEST InvalidEscapedCharacters();
// 5.14
TEST InvalidEscapedCharacters();
// 6.1
TEST IndentationSpaces();
// 6.1
TEST IndentationSpaces();
// 6.2
TEST IndentationIndicators();
// 6.2
TEST IndentationIndicators();
// 6.3
TEST SeparationSpaces();
// 6.3
TEST SeparationSpaces();
// 6.4
TEST LinePrefixes();
// 6.4
TEST LinePrefixes();
// 6.5
TEST EmptyLines();
// 6.5
TEST EmptyLines();
// 6.6
TEST LineFolding();
// 6.6
TEST LineFolding();
// 6.7
TEST BlockFolding();
// 6.7
TEST BlockFolding();
// 6.8
TEST FlowFolding();
// 6.8
TEST FlowFolding();
// 6.9
TEST SeparatedComment();
// 6.9
TEST SeparatedComment();
// 6.10
TEST CommentLines();
// 6.10
TEST CommentLines();
// 6.11
TEST MultiLineComments();
// 6.11
TEST MultiLineComments();
// 6.12
TEST SeparationSpacesII();
// 6.12
TEST SeparationSpacesII();
// 6.13
TEST ReservedDirectives();
// 6.13
TEST ReservedDirectives();
// 6.14
TEST YAMLDirective();
// 6.14
TEST YAMLDirective();
// 6.15
TEST InvalidRepeatedYAMLDirective();
// 6.15
TEST InvalidRepeatedYAMLDirective();
// 6.16
TEST TagDirective();
// 6.16
TEST TagDirective();
// 6.17
TEST InvalidRepeatedTagDirective();
// 6.17
TEST InvalidRepeatedTagDirective();
// 6.18
TEST PrimaryTagHandle();
// 6.18
TEST PrimaryTagHandle();
// 6.19
TEST SecondaryTagHandle();
// 6.19
TEST SecondaryTagHandle();
// 6.20
TEST TagHandles();
// 6.20
TEST TagHandles();
// 6.21
TEST LocalTagPrefix();
// 6.21
TEST LocalTagPrefix();
// 6.22
TEST GlobalTagPrefix();
// 6.22
TEST GlobalTagPrefix();
// 6.23
TEST NodeProperties();
// 6.23
TEST NodeProperties();
// 6.24
TEST VerbatimTags();
// 6.24
TEST VerbatimTags();
// 6.25
TEST InvalidVerbatimTags();
// 6.25
TEST InvalidVerbatimTags();
// 6.26
TEST TagShorthands();
// 6.26
TEST TagShorthands();
// 6.27
TEST InvalidTagShorthands();
// 6.27
TEST InvalidTagShorthands();
// 6.28
TEST NonSpecificTags();
// 6.28
TEST NonSpecificTags();
// 6.29
TEST NodeAnchors();
// 6.29
TEST NodeAnchors();
// 7.1
TEST AliasNodes();
// 7.1
TEST AliasNodes();
// 7.2
TEST EmptyNodes();
// 7.2
TEST EmptyNodes();
// 7.3
TEST CompletelyEmptyNodes();
// 7.3
TEST CompletelyEmptyNodes();
// 7.4
TEST DoubleQuotedImplicitKeys();
// 7.4
TEST DoubleQuotedImplicitKeys();
// 7.5
TEST DoubleQuotedLineBreaks();
// 7.5
TEST DoubleQuotedLineBreaks();
// 7.6
TEST DoubleQuotedLines();
// 7.6
TEST DoubleQuotedLines();
// 7.7
TEST SingleQuotedCharacters();
// 7.7
TEST SingleQuotedCharacters();
// 7.8
TEST SingleQuotedImplicitKeys();
// 7.8
TEST SingleQuotedImplicitKeys();
// 7.9
TEST SingleQuotedLines();
// 7.9
TEST SingleQuotedLines();
// 7.10
TEST PlainCharacters();
// 7.10
TEST PlainCharacters();
// 7.11
TEST PlainImplicitKeys();
// 7.11
TEST PlainImplicitKeys();
// 7.12
TEST PlainLines();
// 7.12
TEST PlainLines();
// 7.13
TEST FlowSequence();
// 7.13
TEST FlowSequence();
// 7.14
TEST FlowSequenceEntries();
// 7.14
TEST FlowSequenceEntries();
// 7.15
TEST FlowMappings();
// 7.15
TEST FlowMappings();
// 7.16
TEST FlowMappingEntries();
// 7.16
TEST FlowMappingEntries();
// 7.17
TEST FlowMappingSeparateValues();
// 7.17
TEST FlowMappingSeparateValues();
// 7.18
TEST FlowMappingAdjacentValues();
// 7.18
TEST FlowMappingAdjacentValues();
// 7.19
TEST SinglePairFlowMappings();
// 7.19
TEST SinglePairFlowMappings();
// 7.20
TEST SinglePairExplicitEntry();
// 7.20
TEST SinglePairExplicitEntry();
// 7.21
TEST SinglePairImplicitEntries();
// 7.21
TEST SinglePairImplicitEntries();
// 7.22
TEST InvalidImplicitKeys();
// 7.22
TEST InvalidImplicitKeys();
// 7.23
TEST FlowContent();
// 7.23
TEST FlowContent();
// 7.24
TEST FlowNodes();
// 7.24
TEST FlowNodes();
// 8.1
TEST BlockScalarHeader();
// 8.1
TEST BlockScalarHeader();
// 8.2
TEST BlockIndentationHeader();
// 8.2
TEST BlockIndentationHeader();
// 8.3
TEST InvalidBlockScalarIndentationIndicators();
// 8.3
TEST InvalidBlockScalarIndentationIndicators();
// 8.4
TEST ChompingFinalLineBreak();
// 8.4
TEST ChompingFinalLineBreak();
// 8.5
TEST ChompingTrailingLines();
// 8.5
TEST ChompingTrailingLines();
// 8.6
TEST EmptyScalarChomping();
// 8.6
TEST EmptyScalarChomping();
// 8.7
TEST LiteralScalar();
// 8.7
TEST LiteralScalar();
// 8.8
TEST LiteralContent();
// 8.8
TEST LiteralContent();
// 8.9
TEST FoldedScalar();
// 8.9
TEST FoldedScalar();
// 8.10
TEST FoldedLines();
// 8.10
TEST FoldedLines();
// 8.11
TEST MoreIndentedLines();
// 8.11
TEST MoreIndentedLines();
// 8.12
TEST EmptySeparationLines();
// 8.12
TEST EmptySeparationLines();
// 8.13
TEST FinalEmptyLines();
// 8.13
TEST FinalEmptyLines();
// 8.14
TEST BlockSequence();
// 8.14
TEST BlockSequence();
// 8.15
TEST BlockSequenceEntryTypes();
// 8.15
TEST BlockSequenceEntryTypes();
// 8.16
TEST BlockMappings();
// 8.16
TEST BlockMappings();
// 8.17
TEST ExplicitBlockMappingEntries();
// 8.17
TEST ExplicitBlockMappingEntries();
// 8.18
TEST ImplicitBlockMappingEntries();
// 8.18
TEST ImplicitBlockMappingEntries();
// 8.19
TEST CompactBlockMappings();
// 8.19
TEST CompactBlockMappings();
// 8.20
TEST BlockNodeTypes();
// 8.20
TEST BlockNodeTypes();
// 8.21
TEST BlockScalarNodes();
// 8.21
TEST BlockScalarNodes();
// 8.22
TEST BlockCollectionNodes();
}
// 8.22
TEST BlockCollectionNodes();
}
bool RunSpecTests();
bool RunSpecTests();
}
#endif // SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,53 +1,56 @@
#ifndef TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace Test {
void RunAll();
void RunAll();
namespace Parser {
// scalar tests
void SimpleScalar(std::string& inputScalar, std::string& desiredOutput);
void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput);
void LiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalarWithIndent(std::string& inputScalar, std::string& desiredOutput);
void ColonScalar(std::string& inputScalar, std::string& desiredOutput);
void QuotedScalar(std::string& inputScalar, std::string& desiredOutput);
void CommaScalar(std::string& inputScalar, std::string& desiredOutput);
void DashScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput);
namespace Parser {
// scalar tests
void SimpleScalar(std::string& inputScalar, std::string& desiredOutput);
void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput);
void LiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalarWithIndent(std::string& inputScalar,
std::string& desiredOutput);
void ColonScalar(std::string& inputScalar, std::string& desiredOutput);
void QuotedScalar(std::string& inputScalar, std::string& desiredOutput);
void CommaScalar(std::string& inputScalar, std::string& desiredOutput);
void DashScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput);
// misc tests
bool SimpleSeq();
bool SimpleMap();
bool FlowSeq();
bool FlowMap();
bool FlowMapWithOmittedKey();
bool FlowMapWithOmittedValue();
bool FlowMapWithSoloEntry();
bool FlowMapEndingWithSoloEntry();
bool QuotedSimpleKeys();
bool CompressedMapAndSeq();
bool NullBlockSeqEntry();
bool NullBlockMapKey();
bool NullBlockMapValue();
bool SimpleAlias();
bool AliasWithNull();
bool AnchorInSimpleKey();
bool AliasAsSimpleKey();
bool ExplicitDoc();
bool MultipleDocs();
bool ExplicitEndDoc();
bool MultipleDocsWithSomeExplicitIndicators();
}
// misc tests
bool SimpleSeq();
bool SimpleMap();
bool FlowSeq();
bool FlowMap();
bool FlowMapWithOmittedKey();
bool FlowMapWithOmittedValue();
bool FlowMapWithSoloEntry();
bool FlowMapEndingWithSoloEntry();
bool QuotedSimpleKeys();
bool CompressedMapAndSeq();
bool NullBlockSeqEntry();
bool NullBlockMapKey();
bool NullBlockMapValue();
bool SimpleAlias();
bool AliasWithNull();
bool AnchorInSimpleKey();
bool AliasAsSimpleKey();
bool ExplicitDoc();
bool MultipleDocs();
bool ExplicitEndDoc();
bool MultipleDocsWithSomeExplicitIndicators();
}
}
#endif // TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -2,17 +2,19 @@
#include <string>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
#define YAML_ASSERT(cond) \
do { \
if (!(cond)) \
return " Assert failed: " #cond; \
} while (false)
namespace Test
{
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
namespace Test {
struct TEST {
TEST() : ok(false) {}
TEST(bool ok_) : ok(ok_) {}
TEST(const char *error_) : ok(false), error(error_) {}
bool ok;
std::string error;
};
};
}

View File

@@ -3,8 +3,7 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
int main()
{
int main() {
{
// test.yaml
// - foo
@@ -46,7 +45,8 @@ int main()
other.push_back(root); // &1 [5, ~, two, *1]
other[3][0] = 0; // &1 [0, ~, two, *1] # since it's a true alias
other.push_back(Copy(root)); // &1 [0, ~, two, *1, &2 [0, ~, two, *2]]
other[4][0] = 5; // &1 [0, ~, two, *1, &2 [5, ~, two, *2]] # they're really different
other[4][0] = 5; // &1 [0, ~, two, *1, &2 [5, ~, two, *2]] # they're
// really different
}
{
@@ -54,8 +54,10 @@ int main()
node[0] = 1; // [1] # auto-construct a sequence
node["key"] = 5; // {0: 1, key: 5} # auto-turn it into a map
node.push_back(10); // error, can't turn a map into a sequence
node.erase("key"); // {0: 1} # still a map, even if we remove the key that caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now just a plain scalar
node.erase("key"); // {0: 1} # still a map, even if we remove the key that
// caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now
// just a plain scalar
}
{
@@ -74,18 +76,22 @@ int main()
{
YAML::Value node;
YAML::Value subnode = node["key"]; // 'subnode' is not instantiated ('node' is still null)
YAML::Value subnode =
node["key"]; // 'subnode' is not instantiated ('node' is still null)
subnode = "value"; // {key: value} # now it is
YAML::Value subnode2 = node["key2"];
node["key3"] = subnode2; // subnode2 is still not instantiated, but node["key3"] is "pseudo" aliased to it
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it instantiates both
node["key3"] = subnode2; // subnode2 is still not instantiated, but
// node["key3"] is "pseudo" aliased to it
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it
// instantiates both
}
{
YAML::Value seq = YAML::Sequence();
seq[0] = "zero"; // [zero]
seq[1] = seq[0]; // [&1 zero, *1]
seq[0] = seq[1]; // [&1 zero, *1] # no-op (they both alias the same thing, so setting them equal is nothing)
seq[0] = seq[1]; // [&1 zero, *1] # no-op (they both alias the same thing,
// so setting them equal is nothing)
Is(seq[0], seq[1]); // true
seq[1] = "one"; // [&1 one, *1]
UnAlias(seq[1]); // [one, one]
@@ -98,9 +104,11 @@ int main()
root.push_back("one");
root.push_back("two");
YAML::Value two = root[2];
root = "scalar"; // 'two' is still "two", even though 'root' is "scalar" (the sequence effectively no longer exists)
root = "scalar"; // 'two' is still "two", even though 'root' is "scalar"
// (the sequence effectively no longer exists)
// Note: in all likelihood, the memory for nodes "zero" and "one" is still allocated. How can it go away? Weak pointers?
// Note: in all likelihood, the memory for nodes "zero" and "one" is still
// allocated. How can it go away? Weak pointers?
}
{

View File

@@ -2,9 +2,8 @@
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
class NullEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
@@ -14,15 +13,15 @@ public:
virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
int main() {
YAML::Parser parser(std::cin);
NullEventHandler handler;
parser.HandleNextDocument(handler);

View File

@@ -2,9 +2,8 @@
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
class NullEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
@@ -14,18 +13,18 @@ public:
virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
int main() {
std::stringstream stream("---{header: {id: 1");
YAML::Parser parser(stream);
// parser.PrintTokens(std::cout);
// parser.PrintTokens(std::cout);
NullEventHandler handler;
parser.HandleNextDocument(handler);
return 0;