Apply formatting/style tweaks to comply with compile time diagnostics for g++ and clang++ (#686)
* Add compilation flags: -Wshadow -Weffc++ -pedantic -pedantic-errors * Delete implicit copy & move constructors & assignment operators in classes with pointer data members. * An exception to the above: Add default copy & move constructors & assignment operators for the Binary class. * Convert boolean RegEx operators to binary operators. * Initialize all members in all classes in ctors. * Let default ctor delegate to the converting ctor in Binary and RegEx * Don't change any tests except regex_test (as a result of the change to binary operators). Note: https://bugzilla.redhat.com/show_bug.cgi?id=1544675 makes -Weffc++ report a false positive in "include/yaml-cpp/node/impl.h".
This commit is contained in:
parent
eca9cfd648
commit
0d5c57150c
@ -165,7 +165,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
||||
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} -fPIC")
|
||||
endif()
|
||||
#
|
||||
set(FLAG_TESTED "-Wextra")
|
||||
set(FLAG_TESTED "-Wextra -Wshadow -Weffc++ -pedantic -pedantic-errors")
|
||||
check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
|
||||
if(FLAG_WEXTRA)
|
||||
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
|
||||
|
@ -19,9 +19,13 @@ YAML_CPP_API std::vector<unsigned char> DecodeBase64(const std::string &input);
|
||||
|
||||
class YAML_CPP_API Binary {
|
||||
public:
|
||||
Binary() : m_unownedData(0), m_unownedSize(0) {}
|
||||
Binary(const unsigned char *data_, std::size_t size_)
|
||||
: m_unownedData(data_), m_unownedSize(size_) {}
|
||||
: m_data{}, m_unownedData(data_), m_unownedSize(size_) {}
|
||||
Binary() : Binary(nullptr, 0) {}
|
||||
Binary(const Binary &) = default;
|
||||
Binary(Binary &&) = default;
|
||||
Binary &operator=(const Binary &) = default;
|
||||
Binary &operator=(Binary &&) = default;
|
||||
|
||||
bool owned() const { return !m_unownedData; }
|
||||
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
|
||||
@ -62,6 +66,6 @@ class YAML_CPP_API Binary {
|
||||
const unsigned char *m_unownedData;
|
||||
std::size_t m_unownedSize;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -22,6 +22,7 @@ namespace YAML {
|
||||
template <class T>
|
||||
class AnchorDict {
|
||||
public:
|
||||
AnchorDict() : m_data{} {}
|
||||
void Register(anchor_t anchor, T value) {
|
||||
if (anchor > m_data.size()) {
|
||||
m_data.resize(anchor);
|
||||
@ -34,6 +35,6 @@ class AnchorDict {
|
||||
private:
|
||||
std::vector<T> m_data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/emitterdef.h"
|
||||
#include "yaml-cpp/emittermanip.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
|
||||
@ -28,10 +27,12 @@ struct _Null;
|
||||
namespace YAML {
|
||||
class EmitterState;
|
||||
|
||||
class YAML_CPP_API Emitter : private noncopyable {
|
||||
class YAML_CPP_API Emitter {
|
||||
public:
|
||||
Emitter();
|
||||
explicit Emitter(std::ostream& stream);
|
||||
Emitter(const Emitter&) = delete;
|
||||
Emitter& operator=(const Emitter&) = delete;
|
||||
~Emitter();
|
||||
|
||||
// output
|
||||
@ -249,6 +250,6 @@ inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
|
||||
inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
|
||||
return emitter.SetLocalPrecision(precision);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -22,6 +22,7 @@ namespace YAML {
|
||||
namespace detail {
|
||||
class YAML_CPP_API memory {
|
||||
public:
|
||||
memory() : m_nodes{} {}
|
||||
node& create_node();
|
||||
void merge(const memory& rhs);
|
||||
|
||||
@ -40,7 +41,7 @@ class YAML_CPP_API memory_holder {
|
||||
private:
|
||||
shared_memory m_pMemory;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -7,18 +7,18 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/emitterstyle.h"
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/node/type.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/emitterstyle.h"
|
||||
#include "yaml-cpp/node/detail/node_ref.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/node/type.h"
|
||||
#include <set>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
class node {
|
||||
public:
|
||||
node() : m_pRef(new node_ref) {}
|
||||
node() : m_pRef(new node_ref), m_dependencies{} {}
|
||||
node(const node&) = delete;
|
||||
node& operator=(const node&) = delete;
|
||||
|
||||
@ -163,7 +163,7 @@ class node {
|
||||
typedef std::set<node*> nodes;
|
||||
nodes m_dependencies;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -7,15 +7,15 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include "yaml-cpp/node/detail/memory.h"
|
||||
#include "yaml-cpp/node/detail/node.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include <string>
|
||||
|
||||
namespace YAML {
|
||||
inline Node::Node() : m_isValid(true), m_pNode(NULL) {}
|
||||
inline Node::Node() : m_isValid(true), m_pMemory(nullptr), m_pNode(nullptr) {}
|
||||
|
||||
inline Node::Node(NodeType::value type)
|
||||
: m_isValid(true),
|
||||
@ -42,7 +42,7 @@ inline Node::Node(const Node& rhs)
|
||||
m_pMemory(rhs.m_pMemory),
|
||||
m_pNode(rhs.m_pNode) {}
|
||||
|
||||
inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {}
|
||||
inline Node::Node(Zombie) : m_isValid(false), m_pMemory{}, m_pNode(nullptr) {}
|
||||
|
||||
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
|
||||
: m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
|
||||
@ -202,6 +202,15 @@ inline Node& Node::operator=(const T& rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
if (is(rhs))
|
||||
return *this;
|
||||
AssignNode(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::reset(const YAML::Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
@ -238,15 +247,6 @@ inline void Node::Assign(char* rhs) {
|
||||
m_pNode->set_scalar(rhs);
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
if (is(rhs))
|
||||
return *this;
|
||||
AssignNode(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::AssignData(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
@ -366,7 +366,7 @@ template <typename T>
|
||||
inline typename to_value_t<T>::return_type to_value(const T& t) {
|
||||
return to_value_t<T>(t)();
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
// indexing
|
||||
template <typename Key>
|
||||
@ -374,8 +374,8 @@ inline const Node Node::operator[](const Key& key) const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
EnsureNodeExists();
|
||||
detail::node* value = static_cast<const detail::node&>(*m_pNode)
|
||||
.get(detail::to_value(key), m_pMemory);
|
||||
detail::node* value = static_cast<const detail::node&>(*m_pNode).get(
|
||||
detail::to_value(key), m_pMemory);
|
||||
if (!value) {
|
||||
return Node(ZombieNode);
|
||||
}
|
||||
@ -443,6 +443,6 @@ inline void Node::force_insert(const Key& key, const Value& value) {
|
||||
|
||||
// free functions
|
||||
inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); }
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -1,25 +0,0 @@
|
||||
#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
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
|
||||
namespace YAML {
|
||||
// this is basically boost::noncopyable
|
||||
class YAML_CPP_API noncopyable {
|
||||
protected:
|
||||
noncopyable() {}
|
||||
~noncopyable() {}
|
||||
|
||||
private:
|
||||
noncopyable(const noncopyable&);
|
||||
const noncopyable& operator=(const noncopyable&);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@ -17,6 +17,10 @@ class YAML_CPP_API ostream_wrapper {
|
||||
public:
|
||||
ostream_wrapper();
|
||||
explicit ostream_wrapper(std::ostream& stream);
|
||||
ostream_wrapper(const ostream_wrapper&) = delete;
|
||||
ostream_wrapper(ostream_wrapper&&) = delete;
|
||||
ostream_wrapper& operator=(const ostream_wrapper&) = delete;
|
||||
ostream_wrapper& operator=(ostream_wrapper&&) = delete;
|
||||
~ostream_wrapper();
|
||||
|
||||
void write(const std::string& str);
|
||||
@ -52,7 +56,7 @@ class YAML_CPP_API ostream_wrapper {
|
||||
|
||||
template <std::size_t N>
|
||||
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
|
||||
const char(&str)[N]) {
|
||||
const char (&str)[N]) {
|
||||
stream.write(str, N - 1);
|
||||
return stream;
|
||||
}
|
||||
@ -67,6 +71,6 @@ inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
|
||||
stream.write(&ch, 1);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class EventHandler;
|
||||
@ -24,11 +23,17 @@ struct Token;
|
||||
* A parser turns a stream of bytes into one stream of "events" per YAML
|
||||
* document in the input stream.
|
||||
*/
|
||||
class YAML_CPP_API Parser : private noncopyable {
|
||||
class YAML_CPP_API Parser {
|
||||
public:
|
||||
/** Constructs an empty parser (with no input. */
|
||||
Parser();
|
||||
|
||||
/** non copyable but movable */
|
||||
Parser(const Parser&) = delete;
|
||||
Parser(Parser&&) = default;
|
||||
Parser& operator=(const Parser&) = delete;
|
||||
Parser& operator=(Parser&&) = default;
|
||||
|
||||
/**
|
||||
* Constructs a parser from the given input stream. The input stream must
|
||||
* live as long as the parser.
|
||||
@ -81,6 +86,6 @@ class YAML_CPP_API Parser : private noncopyable {
|
||||
std::unique_ptr<Scanner> m_pScanner;
|
||||
std::unique_ptr<Directives> m_pDirectives;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -7,8 +7,8 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <stack>
|
||||
#include <cassert>
|
||||
#include <stack>
|
||||
|
||||
namespace YAML {
|
||||
struct CollectionType {
|
||||
@ -17,6 +17,7 @@ struct CollectionType {
|
||||
|
||||
class CollectionStack {
|
||||
public:
|
||||
CollectionStack() : collectionStack{} {}
|
||||
CollectionType::value GetCurCollectionType() const {
|
||||
if (collectionStack.empty())
|
||||
return CollectionType::NoCollection;
|
||||
@ -35,6 +36,6 @@ class CollectionStack {
|
||||
private:
|
||||
std::stack<CollectionType::value> collectionStack;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -26,7 +26,15 @@ namespace YAML {
|
||||
class GraphBuilderAdapter : public EventHandler {
|
||||
public:
|
||||
GraphBuilderAdapter(GraphBuilderInterface& builder)
|
||||
: m_builder(builder), m_pRootNode(nullptr), m_pKeyNode(nullptr) {}
|
||||
: m_builder(builder),
|
||||
m_containers{},
|
||||
m_anchors{},
|
||||
m_pRootNode(nullptr),
|
||||
m_pKeyNode(nullptr) {}
|
||||
GraphBuilderAdapter(const GraphBuilderAdapter&) = delete;
|
||||
GraphBuilderAdapter(GraphBuilderAdapter&&) = delete;
|
||||
GraphBuilderAdapter& operator=(const GraphBuilderAdapter&) = delete;
|
||||
GraphBuilderAdapter& operator=(GraphBuilderAdapter&&) = delete;
|
||||
|
||||
virtual void OnDocumentStart(const Mark& mark) { (void)mark; }
|
||||
virtual void OnDocumentEnd() {}
|
||||
@ -50,8 +58,8 @@ class GraphBuilderAdapter : public EventHandler {
|
||||
struct ContainerFrame {
|
||||
ContainerFrame(void* pSequence)
|
||||
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {}
|
||||
ContainerFrame(void* pMap, void* pPrevKeyNode)
|
||||
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode) {}
|
||||
ContainerFrame(void* pMap, void* pPreviousKeyNode)
|
||||
: pContainer(pMap), pPrevKeyNode(pPreviousKeyNode) {}
|
||||
|
||||
void* pContainer;
|
||||
void* pPrevKeyNode;
|
||||
@ -74,6 +82,6 @@ class GraphBuilderAdapter : public EventHandler {
|
||||
void RegisterAnchor(anchor_t anchor, void* pNode);
|
||||
void DispositionNode(void* pNode);
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -1,12 +1,7 @@
|
||||
#include "directives.h"
|
||||
|
||||
namespace YAML {
|
||||
Directives::Directives() {
|
||||
// version
|
||||
version.isDefault = true;
|
||||
version.major = 1;
|
||||
version.minor = 2;
|
||||
}
|
||||
Directives::Directives() : version{true, 1, 2}, tags{} {}
|
||||
|
||||
const std::string Directives::TranslateTagHandle(
|
||||
const std::string& handle) const {
|
||||
@ -19,4 +14,4 @@ const std::string Directives::TranslateTagHandle(
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -16,10 +16,11 @@ std::string ToString(YAML::anchor_t anchor) {
|
||||
stream << anchor;
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace YAML {
|
||||
EmitFromEvents::EmitFromEvents(Emitter& emitter) : m_emitter(emitter) {}
|
||||
EmitFromEvents::EmitFromEvents(Emitter& emitter)
|
||||
: m_emitter(emitter), m_stateStack{} {}
|
||||
|
||||
void EmitFromEvents::OnDocumentStart(const Mark&) {}
|
||||
|
||||
@ -116,4 +117,4 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
|
||||
if (anchor)
|
||||
m_emitter << Anchor(ToString(anchor));
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -11,7 +11,7 @@ namespace YAML {
|
||||
class Binary;
|
||||
struct _Null;
|
||||
|
||||
Emitter::Emitter() : m_pState(new EmitterState) {}
|
||||
Emitter::Emitter() : m_pState(new EmitterState), m_stream{} {}
|
||||
|
||||
Emitter::Emitter(std::ostream& stream)
|
||||
: m_pState(new EmitterState), m_stream(stream) {}
|
||||
@ -906,4 +906,4 @@ Emitter& Emitter::Write(const Binary& binary) {
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -6,27 +6,31 @@
|
||||
namespace YAML {
|
||||
EmitterState::EmitterState()
|
||||
: m_isGood(true),
|
||||
m_lastError{},
|
||||
// default global manipulators
|
||||
m_charset(EmitNonAscii),
|
||||
m_strFmt(Auto),
|
||||
m_boolFmt(TrueFalseBool),
|
||||
m_boolLengthFmt(LongBool),
|
||||
m_boolCaseFmt(LowerCase),
|
||||
m_intFmt(Dec),
|
||||
m_indent(2),
|
||||
m_preCommentIndent(2),
|
||||
m_postCommentIndent(1),
|
||||
m_seqFmt(Block),
|
||||
m_mapFmt(Block),
|
||||
m_mapKeyFmt(Auto),
|
||||
m_floatPrecision(std::numeric_limits<float>::max_digits10),
|
||||
m_doublePrecision(std::numeric_limits<double>::max_digits10),
|
||||
//
|
||||
m_modifiedSettings{},
|
||||
m_globalModifiedSettings{},
|
||||
m_groups{},
|
||||
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);
|
||||
m_boolFmt.set(TrueFalseBool);
|
||||
m_boolLengthFmt.set(LongBool);
|
||||
m_boolCaseFmt.set(LowerCase);
|
||||
m_intFmt.set(Dec);
|
||||
m_indent.set(2);
|
||||
m_preCommentIndent.set(2);
|
||||
m_postCommentIndent.set(1);
|
||||
m_seqFmt.set(Block);
|
||||
m_mapFmt.set(Block);
|
||||
m_mapKeyFmt.set(Auto);
|
||||
m_floatPrecision.set(std::numeric_limits<float>::max_digits10);
|
||||
m_doublePrecision.set(std::numeric_limits<double>::max_digits10);
|
||||
}
|
||||
m_docCount(0) {}
|
||||
|
||||
EmitterState::~EmitterState() {}
|
||||
|
||||
@ -362,4 +366,4 @@ bool EmitterState::SetDoublePrecision(std::size_t value,
|
||||
_Set(m_doublePrecision, value, scope);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -145,7 +145,12 @@ class EmitterState {
|
||||
|
||||
struct Group {
|
||||
explicit Group(GroupType::value type_)
|
||||
: type(type_), indent(0), childCount(0), longKey(false) {}
|
||||
: type(type_),
|
||||
flowType{},
|
||||
indent(0),
|
||||
childCount(0),
|
||||
longKey(false),
|
||||
modifiedSettings{} {}
|
||||
|
||||
GroupType::value type;
|
||||
FlowType::value flowType;
|
||||
@ -198,6 +203,6 @@ void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "regeximpl.h"
|
||||
#include "stringsource.h"
|
||||
#include "yaml-cpp/binary.h" // IWYU pragma: keep
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
|
||||
namespace YAML {
|
||||
namespace Utils {
|
||||
@ -173,12 +173,12 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
|
||||
|
||||
// then check until something is disallowed
|
||||
static const RegEx& disallowed_flow =
|
||||
Exp::EndScalarInFlow() || (Exp::BlankOrBreak() + Exp::Comment()) ||
|
||||
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() ||
|
||||
Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) |
|
||||
Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
|
||||
Exp::Tab();
|
||||
static const RegEx& disallowed_block =
|
||||
Exp::EndScalar() || (Exp::BlankOrBreak() + Exp::Comment()) ||
|
||||
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() ||
|
||||
Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) |
|
||||
Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
|
||||
Exp::Tab();
|
||||
const RegEx& disallowed =
|
||||
flowType == FlowType::Flow ? disallowed_flow : disallowed_block;
|
||||
@ -258,7 +258,7 @@ bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
StringFormat::value ComputeStringFormat(const std::string& str,
|
||||
EMITTER_MANIP strFormat,
|
||||
@ -401,8 +401,8 @@ bool WriteComment(ostream_wrapper& out, const std::string& str,
|
||||
for (std::string::const_iterator i = str.begin();
|
||||
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
|
||||
if (codePoint == '\n') {
|
||||
out << "\n" << IndentTo(curIndent) << "#"
|
||||
<< Indentation(postCommentIndent);
|
||||
out << "\n"
|
||||
<< IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
||||
out.set_comment();
|
||||
} else {
|
||||
WriteCodePoint(out, codePoint);
|
||||
@ -479,5 +479,5 @@ bool WriteBinary(ostream_wrapper& out, const Binary& binary) {
|
||||
false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Utils
|
||||
} // namespace YAML
|
||||
|
60
src/exp.h
60
src/exp.h
@ -33,15 +33,15 @@ inline const RegEx& Tab() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Blank() {
|
||||
static const RegEx e = Space() || Tab();
|
||||
static const RegEx e = Space() | Tab();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Break() {
|
||||
static const RegEx e = RegEx('\n') || RegEx("\r\n");
|
||||
static const RegEx e = RegEx('\n') | RegEx("\r\n");
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& BlankOrBreak() {
|
||||
static const RegEx e = Blank() || Break();
|
||||
static const RegEx e = Blank() | Break();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Digit() {
|
||||
@ -49,29 +49,29 @@ inline const RegEx& Digit() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Alpha() {
|
||||
static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||
static const RegEx e = RegEx('a', 'z') | RegEx('A', 'Z');
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& AlphaNumeric() {
|
||||
static const RegEx e = Alpha() || Digit();
|
||||
static const RegEx e = Alpha() | Digit();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Word() {
|
||||
static const RegEx e = AlphaNumeric() || RegEx('-');
|
||||
static const RegEx e = AlphaNumeric() | RegEx('-');
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Hex() {
|
||||
static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
|
||||
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) ||
|
||||
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')));
|
||||
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() {
|
||||
@ -82,19 +82,19 @@ inline const RegEx& Utf8_ByteOrderMark() {
|
||||
// actual tags
|
||||
|
||||
inline const RegEx& DocStart() {
|
||||
static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& DocEnd() {
|
||||
static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx("...") + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& DocIndicator() {
|
||||
static const RegEx e = DocStart() || DocEnd();
|
||||
static const RegEx e = DocStart() | DocEnd();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& BlockEntry() {
|
||||
static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx('-') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Key() {
|
||||
@ -106,11 +106,11 @@ inline const RegEx& KeyInFlow() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Value() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& ValueInFlow() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx(",}", REGEX_OR));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& ValueInJSONFlow() {
|
||||
@ -122,20 +122,20 @@ inline const RegEx Comment() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Anchor() {
|
||||
static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
|
||||
static const RegEx e = !(RegEx("[]{},", REGEX_OR) | BlankOrBreak());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& AnchorEnd() {
|
||||
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
|
||||
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) | BlankOrBreak();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& URI() {
|
||||
static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) ||
|
||||
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) ||
|
||||
static const RegEx e = Word() | RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) |
|
||||
(RegEx('%') + Hex() + Hex());
|
||||
return e;
|
||||
}
|
||||
@ -148,34 +148,34 @@ inline const RegEx& Tag() {
|
||||
// space.
|
||||
inline const RegEx& PlainScalar() {
|
||||
static const RegEx e =
|
||||
!(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) ||
|
||||
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
|
||||
!(BlankOrBreak() | RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) |
|
||||
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() | RegEx())));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& PlainScalarInFlow() {
|
||||
static const RegEx e =
|
||||
!(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) ||
|
||||
!(BlankOrBreak() | RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) |
|
||||
(RegEx("-:", REGEX_OR) + Blank()));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EndScalar() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EndScalarInFlow() {
|
||||
static const RegEx e =
|
||||
(RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) ||
|
||||
(RegEx(':') + (BlankOrBreak() | RegEx() | RegEx(",]}", REGEX_OR))) |
|
||||
RegEx(",?[]{}", REGEX_OR);
|
||||
return e;
|
||||
}
|
||||
|
||||
inline const RegEx& ScanScalarEndInFlow() {
|
||||
static const RegEx e = (EndScalarInFlow() || (BlankOrBreak() + Comment()));
|
||||
static const RegEx e = (EndScalarInFlow() | (BlankOrBreak() + Comment()));
|
||||
return e;
|
||||
}
|
||||
|
||||
inline const RegEx& ScanScalarEnd() {
|
||||
static const RegEx e = EndScalar() || (BlankOrBreak() + Comment());
|
||||
static const RegEx e = EndScalar() | (BlankOrBreak() + Comment());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EscSingleQuote() {
|
||||
@ -192,8 +192,8 @@ inline const RegEx& ChompIndicator() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Chomp() {
|
||||
static const RegEx e = (ChompIndicator() + Digit()) ||
|
||||
(Digit() + ChompIndicator()) || ChompIndicator() ||
|
||||
static const RegEx e = (ChompIndicator() + Digit()) |
|
||||
(Digit() + ChompIndicator()) | ChompIndicator() |
|
||||
Digit();
|
||||
return e;
|
||||
}
|
||||
|
@ -14,16 +14,21 @@ namespace YAML {
|
||||
namespace detail {
|
||||
|
||||
const std::string& node_data::empty_scalar() {
|
||||
static const std::string svalue;
|
||||
return svalue;
|
||||
static const std::string svalue;
|
||||
return svalue;
|
||||
}
|
||||
|
||||
node_data::node_data()
|
||||
: m_isDefined(false),
|
||||
m_mark(Mark::null_mark()),
|
||||
m_type(NodeType::Null),
|
||||
m_tag{},
|
||||
m_style(EmitterStyle::Default),
|
||||
m_seqSize(0) {}
|
||||
m_scalar{},
|
||||
m_sequence{},
|
||||
m_seqSize(0),
|
||||
m_map{},
|
||||
m_undefinedPairs{} {}
|
||||
|
||||
void node_data::mark_defined() {
|
||||
if (m_type == NodeType::Undefined)
|
||||
@ -238,8 +243,8 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
|
||||
if (m_type != NodeType::Map)
|
||||
return false;
|
||||
|
||||
kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||
while (it != m_undefinedPairs.end()) {
|
||||
for (kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||
it != m_undefinedPairs.end();) {
|
||||
kv_pairs::iterator jt = std::next(it);
|
||||
if (it->first->is(key))
|
||||
m_undefinedPairs.erase(it);
|
||||
@ -307,5 +312,5 @@ void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
|
||||
reset_sequence();
|
||||
m_type = NodeType::Map;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
@ -11,7 +11,12 @@ namespace YAML {
|
||||
struct Mark;
|
||||
|
||||
NodeBuilder::NodeBuilder()
|
||||
: m_pMemory(new detail::memory_holder), m_pRoot(nullptr), m_mapDepth(0) {
|
||||
: m_pMemory(new detail::memory_holder),
|
||||
m_pRoot(nullptr),
|
||||
m_stack{},
|
||||
m_anchors{},
|
||||
m_keys{},
|
||||
m_mapDepth(0) {
|
||||
m_anchors.push_back(nullptr); // since the anchors start at 1
|
||||
}
|
||||
|
||||
@ -127,4 +132,4 @@ void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
|
||||
m_anchors.push_back(&node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -27,6 +27,10 @@ class Node;
|
||||
class NodeBuilder : public EventHandler {
|
||||
public:
|
||||
NodeBuilder();
|
||||
NodeBuilder(const NodeBuilder&) = delete;
|
||||
NodeBuilder(NodeBuilder&&) = delete;
|
||||
NodeBuilder& operator=(const NodeBuilder&) = delete;
|
||||
NodeBuilder& operator=(NodeBuilder&&) = delete;
|
||||
virtual ~NodeBuilder();
|
||||
|
||||
Node Root();
|
||||
@ -65,6 +69,6 @@ class NodeBuilder : public EventHandler {
|
||||
std::vector<PushedKey> m_keys;
|
||||
std::size_t m_mapDepth;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -20,7 +20,7 @@ anchor_t NodeEvents::AliasManager::LookupAnchor(
|
||||
}
|
||||
|
||||
NodeEvents::NodeEvents(const Node& node)
|
||||
: m_pMemory(node.m_pMemory), m_root(node.m_pNode) {
|
||||
: m_pMemory(node.m_pMemory), m_root(node.m_pNode), m_refCount{} {
|
||||
if (m_root)
|
||||
Setup(*m_root);
|
||||
}
|
||||
@ -98,4 +98,4 @@ bool NodeEvents::IsAliased(const detail::node& node) const {
|
||||
RefCount::const_iterator it = m_refCount.find(node.ref());
|
||||
return it != m_refCount.end() && it->second > 1;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -26,13 +26,17 @@ class Node;
|
||||
class NodeEvents {
|
||||
public:
|
||||
explicit NodeEvents(const Node& node);
|
||||
NodeEvents(const NodeEvents&) = delete;
|
||||
NodeEvents(NodeEvents&&) = delete;
|
||||
NodeEvents& operator=(const NodeEvents&) = delete;
|
||||
NodeEvents& operator=(NodeEvents&&) = delete;
|
||||
|
||||
void Emit(EventHandler& handler);
|
||||
|
||||
private:
|
||||
class AliasManager {
|
||||
public:
|
||||
AliasManager() : m_curAnchor(0) {}
|
||||
AliasManager() : m_anchorByIdentity{}, m_curAnchor(0) {}
|
||||
|
||||
void RegisterReference(const detail::node& node);
|
||||
anchor_t LookupAnchor(const detail::node& node) const;
|
||||
@ -59,6 +63,6 @@ class NodeEvents {
|
||||
typedef std::map<const detail::node_ref*, int> RefCount;
|
||||
RefCount m_refCount;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -14,7 +14,12 @@ ostream_wrapper::ostream_wrapper()
|
||||
m_comment(false) {}
|
||||
|
||||
ostream_wrapper::ostream_wrapper(std::ostream& stream)
|
||||
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
|
||||
: m_buffer{},
|
||||
m_pStream(&stream),
|
||||
m_pos(0),
|
||||
m_row(0),
|
||||
m_col(0),
|
||||
m_comment(false) {}
|
||||
|
||||
ostream_wrapper::~ostream_wrapper() {}
|
||||
|
||||
@ -54,4 +59,4 @@ void ostream_wrapper::update_pos(char ch) {
|
||||
m_comment = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -11,9 +11,9 @@
|
||||
namespace YAML {
|
||||
class EventHandler;
|
||||
|
||||
Parser::Parser() {}
|
||||
Parser::Parser() : m_pScanner{}, m_pDirectives{} {}
|
||||
|
||||
Parser::Parser(std::istream& in) { Load(in); }
|
||||
Parser::Parser(std::istream& in) : Parser() { Load(in); }
|
||||
|
||||
Parser::~Parser() {}
|
||||
|
||||
@ -126,4 +126,4 @@ void Parser::PrintTokens(std::ostream& out) {
|
||||
m_pScanner->pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -12,15 +12,17 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
|
||||
// TODO: This class is no longer needed
|
||||
template <typename T>
|
||||
class ptr_vector : private YAML::noncopyable {
|
||||
class ptr_vector {
|
||||
public:
|
||||
ptr_vector() {}
|
||||
ptr_vector() : m_data{} {}
|
||||
ptr_vector(const ptr_vector&) = delete;
|
||||
ptr_vector(ptr_vector&&) = default;
|
||||
ptr_vector& operator=(const ptr_vector&) = delete;
|
||||
ptr_vector& operator=(ptr_vector&&) = default;
|
||||
|
||||
void clear() { m_data.clear(); }
|
||||
|
||||
@ -38,6 +40,6 @@ class ptr_vector : private YAML::noncopyable {
|
||||
private:
|
||||
std::vector<std::unique_ptr<T>> m_data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -2,18 +2,16 @@
|
||||
|
||||
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), m_a(0), m_z(0), m_params{} {}
|
||||
RegEx::RegEx() : RegEx(REGEX_EMPTY) {}
|
||||
|
||||
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch) {}
|
||||
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch), m_z(0), m_params{} {}
|
||||
|
||||
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), m_params{} {}
|
||||
|
||||
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]));
|
||||
}
|
||||
RegEx::RegEx(const std::string& str, REGEX_OP op)
|
||||
: m_op(op), m_a(0), m_z(0), m_params(str.begin(), str.end()) {}
|
||||
|
||||
// combination constructors
|
||||
RegEx operator!(const RegEx& ex) {
|
||||
@ -22,14 +20,14 @@ RegEx operator!(const RegEx& 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);
|
||||
@ -42,4 +40,4 @@ RegEx operator+(const RegEx& ex1, const RegEx& ex2) {
|
||||
ret.m_params.push_back(ex2);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -31,14 +31,14 @@ enum REGEX_OP {
|
||||
class YAML_CPP_API RegEx {
|
||||
public:
|
||||
RegEx();
|
||||
RegEx(char ch);
|
||||
explicit RegEx(char ch);
|
||||
RegEx(char a, char z);
|
||||
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
||||
~RegEx() {}
|
||||
|
||||
friend YAML_CPP_API RegEx operator!(const RegEx& ex);
|
||||
friend YAML_CPP_API RegEx operator||(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator|(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator&(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2);
|
||||
|
||||
bool Matches(char ch) const;
|
||||
@ -53,7 +53,7 @@ class YAML_CPP_API RegEx {
|
||||
int Match(const Source& source) const;
|
||||
|
||||
private:
|
||||
RegEx(REGEX_OP op);
|
||||
explicit RegEx(REGEX_OP op);
|
||||
|
||||
template <typename Source>
|
||||
bool IsValidSource(const Source& source) const;
|
||||
|
@ -9,10 +9,15 @@
|
||||
namespace YAML {
|
||||
Scanner::Scanner(std::istream& in)
|
||||
: INPUT(in),
|
||||
m_tokens{},
|
||||
m_startedStream(false),
|
||||
m_endedStream(false),
|
||||
m_simpleKeyAllowed(false),
|
||||
m_canBeJSONFlow(false) {}
|
||||
m_canBeJSONFlow(false),
|
||||
m_simpleKeys{},
|
||||
m_indents{},
|
||||
m_indentRefs{},
|
||||
m_flows{} {}
|
||||
|
||||
Scanner::~Scanner() {}
|
||||
|
||||
|
@ -338,7 +338,7 @@ void Scanner::ScanQuotedScalar() {
|
||||
|
||||
// setup the scanning parameters
|
||||
ScanScalarParams params;
|
||||
RegEx end = (single ? RegEx(quote) && !Exp::EscSingleQuote() : RegEx(quote));
|
||||
RegEx end = (single ? RegEx(quote) & !Exp::EscSingleQuote() : RegEx(quote));
|
||||
params.end = &end;
|
||||
params.eatEnd = true;
|
||||
params.escape = (single ? '\'' : '\\');
|
||||
@ -434,4 +434,4 @@ void Scanner::ScanBlockScalar() {
|
||||
token.value = scalar;
|
||||
m_tokens.push(token);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -8,8 +8,8 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class SettingChangeBase;
|
||||
@ -18,6 +18,7 @@ template <typename T>
|
||||
class Setting {
|
||||
public:
|
||||
Setting() : m_value() {}
|
||||
Setting(const T& value) : m_value() { set(value); }
|
||||
|
||||
const T get() const { return m_value; }
|
||||
std::unique_ptr<SettingChangeBase> set(const T& value);
|
||||
@ -36,10 +37,14 @@ class SettingChangeBase {
|
||||
template <typename T>
|
||||
class SettingChange : public SettingChangeBase {
|
||||
public:
|
||||
SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) {
|
||||
// copy old setting to save its state
|
||||
m_oldSetting = *pSetting;
|
||||
}
|
||||
SettingChange(Setting<T>* pSetting)
|
||||
: m_pCurSetting(pSetting),
|
||||
m_oldSetting(*pSetting) // copy old setting to save its state
|
||||
{}
|
||||
SettingChange(const SettingChange&) = delete;
|
||||
SettingChange(SettingChange&&) = delete;
|
||||
SettingChange& operator=(const SettingChange&) = delete;
|
||||
SettingChange& operator=(SettingChange&&) = delete;
|
||||
|
||||
virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
|
||||
|
||||
@ -55,9 +60,12 @@ inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
|
||||
return pChange;
|
||||
}
|
||||
|
||||
class SettingChanges : private noncopyable {
|
||||
class SettingChanges {
|
||||
public:
|
||||
SettingChanges() {}
|
||||
SettingChanges() : m_settingChanges{} {}
|
||||
SettingChanges(const SettingChanges&) = delete;
|
||||
SettingChanges(SettingChanges&&) = default;
|
||||
SettingChanges& operator=(const SettingChanges&) = delete;
|
||||
~SettingChanges() { clear(); }
|
||||
|
||||
void clear() {
|
||||
@ -90,6 +98,6 @@ class SettingChanges : private noncopyable {
|
||||
typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes;
|
||||
setting_changes m_settingChanges;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -18,6 +18,7 @@ SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives)
|
||||
: m_scanner(scanner),
|
||||
m_directives(directives),
|
||||
m_pCollectionStack(new CollectionStack),
|
||||
m_anchors{},
|
||||
m_curAnchor(0) {}
|
||||
|
||||
SingleDocParser::~SingleDocParser() {}
|
||||
@ -170,10 +171,10 @@ void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
|
||||
|
||||
// check for null
|
||||
if (!m_scanner.empty()) {
|
||||
const Token& token = m_scanner.peek();
|
||||
if (token.type == Token::BLOCK_ENTRY ||
|
||||
token.type == Token::BLOCK_SEQ_END) {
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
const Token& nextToken = m_scanner.peek();
|
||||
if (nextToken.type == Token::BLOCK_ENTRY ||
|
||||
nextToken.type == Token::BLOCK_SEQ_END) {
|
||||
eventHandler.OnNull(nextToken.mark, NullAnchor);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "yaml-cpp/anchor.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class CollectionStack;
|
||||
@ -23,9 +22,13 @@ struct Directives;
|
||||
struct Mark;
|
||||
struct Token;
|
||||
|
||||
class SingleDocParser : private noncopyable {
|
||||
class SingleDocParser {
|
||||
public:
|
||||
SingleDocParser(Scanner& scanner, const Directives& directives);
|
||||
SingleDocParser(const SingleDocParser&) = delete;
|
||||
SingleDocParser(SingleDocParser&&) = delete;
|
||||
SingleDocParser& operator=(const SingleDocParser&) = delete;
|
||||
SingleDocParser& operator=(SingleDocParser&&) = delete;
|
||||
~SingleDocParser();
|
||||
|
||||
void HandleDocument(EventHandler& eventHandler);
|
||||
|
@ -111,24 +111,15 @@ static UtfIntroState s_introTransitions[][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},
|
||||
{3, 3, 3, 3, 0, 3, 3, 3},
|
||||
{4, 4, 4, 4, 4, 0, 4, 4},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{2, 2, 2, 2, 2, 0, 2, 2},
|
||||
{2, 2, 2, 2, 0, 2, 2, 2},
|
||||
{0, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{0, 3, 3, 3, 3, 3, 3, 3},
|
||||
{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},
|
||||
{0, 1, 1, 0, 0, 0, 0, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 3, 0, 3, 3, 3}, {4, 4, 4, 4, 4, 0, 4, 4},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{2, 2, 2, 2, 2, 0, 2, 2}, {2, 2, 2, 2, 0, 2, 2, 2},
|
||||
{0, 1, 1, 1, 1, 1, 1, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2}, {0, 3, 3, 3, 3, 3, 3, 3},
|
||||
{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},
|
||||
};
|
||||
|
||||
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
|
||||
@ -192,6 +183,9 @@ inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) {
|
||||
|
||||
Stream::Stream(std::istream& input)
|
||||
: m_input(input),
|
||||
m_mark{},
|
||||
m_charSet{},
|
||||
m_readahead{},
|
||||
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
|
||||
m_nPrefetchedAvailable(0),
|
||||
m_nPrefetchedUsed(0) {
|
||||
@ -445,4 +439,4 @@ void Stream::StreamInUtf32() const {
|
||||
|
||||
QueueUnicodeCodepoint(m_readahead, ch);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "yaml-cpp/mark.h"
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
@ -17,11 +16,15 @@
|
||||
#include <string>
|
||||
|
||||
namespace YAML {
|
||||
class Stream : private noncopyable {
|
||||
class Stream {
|
||||
public:
|
||||
friend class StreamCharSource;
|
||||
|
||||
Stream(std::istream& input);
|
||||
Stream(const Stream&) = delete;
|
||||
Stream(Stream&&) = delete;
|
||||
Stream& operator=(const Stream&) = delete;
|
||||
Stream& operator=(Stream&&) = delete;
|
||||
~Stream();
|
||||
|
||||
operator bool() const;
|
||||
@ -71,6 +74,6 @@ inline bool Stream::ReadAheadTo(size_t i) const {
|
||||
return true;
|
||||
return _ReadAheadTo(i);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace YAML {
|
||||
@ -16,6 +15,9 @@ class StreamCharSource {
|
||||
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(StreamCharSource&&) = default;
|
||||
StreamCharSource& operator=(const StreamCharSource&) = delete;
|
||||
StreamCharSource& operator=(StreamCharSource&&) = delete;
|
||||
~StreamCharSource() {}
|
||||
|
||||
operator bool() const;
|
||||
@ -27,8 +29,6 @@ class StreamCharSource {
|
||||
private:
|
||||
std::size_t m_offset;
|
||||
const Stream& m_stream;
|
||||
|
||||
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
|
||||
};
|
||||
|
||||
inline StreamCharSource::operator bool() const {
|
||||
@ -43,6 +43,6 @@ inline const StreamCharSource StreamCharSource::operator+(int i) const {
|
||||
source.m_offset = 0;
|
||||
return source;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -6,7 +6,8 @@
|
||||
#include "token.h"
|
||||
|
||||
namespace YAML {
|
||||
Tag::Tag(const Token& token) : type(static_cast<TYPE>(token.data)) {
|
||||
Tag::Tag(const Token& token)
|
||||
: type(static_cast<TYPE>(token.data)), handle{}, value{} {
|
||||
switch (type) {
|
||||
case VERBATIM:
|
||||
value = token.value;
|
||||
@ -46,4 +47,4 @@ const std::string Tag::Translate(const Directives& directives) {
|
||||
}
|
||||
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
13
src/token.h
13
src/token.h
@ -14,10 +14,11 @@
|
||||
|
||||
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"};
|
||||
"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 {
|
||||
// enums
|
||||
@ -48,7 +49,7 @@ struct Token {
|
||||
|
||||
// data
|
||||
Token(TYPE type_, const Mark& mark_)
|
||||
: status(VALID), type(type_), mark(mark_), data(0) {}
|
||||
: status(VALID), type(type_), mark(mark_), value{}, params{}, data(0) {}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
|
||||
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||
@ -64,6 +65,6 @@ struct Token {
|
||||
std::vector<std::string> params;
|
||||
int data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "regex_yaml.h"
|
||||
#include "stream.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using YAML::RegEx;
|
||||
using YAML::Stream;
|
||||
@ -106,8 +106,8 @@ TEST(RegExTest, OperatorOr) {
|
||||
for (int j = i + 1; j < 128; ++j) {
|
||||
auto iStr = std::string(1, char(i));
|
||||
auto jStr = std::string(1, char(j));
|
||||
RegEx ex1 = RegEx(iStr) || RegEx(jStr);
|
||||
RegEx ex2 = RegEx(jStr) || RegEx(iStr);
|
||||
RegEx ex1 = RegEx(iStr) | RegEx(jStr);
|
||||
RegEx ex2 = RegEx(jStr) | RegEx(iStr);
|
||||
|
||||
for (int k = MIN_CHAR; k < 128; ++k) {
|
||||
auto str = std::string(1, char(k));
|
||||
@ -128,8 +128,8 @@ TEST(RegExTest, OperatorOr) {
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorOrShortCircuits) {
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) || RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) || RegEx(std::string("aaaa"));
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) | RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) | RegEx(std::string("aaaa"));
|
||||
|
||||
EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
|
||||
EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
|
||||
@ -139,13 +139,13 @@ TEST(RegExTest, OperatorOrShortCircuits) {
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorAnd) {
|
||||
RegEx emptySet = RegEx('a') && RegEx();
|
||||
RegEx emptySet = RegEx('a') & RegEx();
|
||||
EXPECT_FALSE(emptySet.Matches(std::string("a")));
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorAndShortCircuits) {
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) && RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) && RegEx(std::string("aaaa"));
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) & RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) & RegEx(std::string("aaaa"));
|
||||
|
||||
EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
|
||||
EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
|
||||
@ -174,4 +174,4 @@ TEST(RegExTest, StringOr) {
|
||||
|
||||
EXPECT_EQ(1, ex.Match(str));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user