mirror of
https://github.com/RPCS3/yaml-cpp.git
synced 2026-07-25 20:55:22 -04:00
Compare commits
436 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d2c2ae3fb | |||
| 39171cf060 | |||
| b20e0a5e54 | |||
| cfb7d46246 | |||
| adc0e7e7e9 | |||
| bd9103f44a | |||
| 485afcb633 | |||
| b1a1f8ce2d | |||
| d50fbf59d7 | |||
| 8d0ee05dbe | |||
| 5647711578 | |||
| 2731f862a5 | |||
| e17734de33 | |||
| b66197bdf4 | |||
| 41a7f7a026 | |||
| 8d658bbf61 | |||
| b0b0c191b9 | |||
| 90f48fd035 | |||
| 9403ac04fa | |||
| b266447d2e | |||
| 88540cc96a | |||
| 60fa4d7f63 | |||
| 924bb8b00e | |||
| f3446cbcea | |||
| 2dbcc58912 | |||
| 29859af6c0 | |||
| e4838f0933 | |||
| 8123b27c09 | |||
| 2d166d1733 | |||
| 8f948b8f37 | |||
| 537063f907 | |||
| d2f5a6086a | |||
| c82122ba36 | |||
| 569a0461f2 | |||
| 66980da9d2 | |||
| c6e5ad350b | |||
| fe5fcbb84e | |||
| c4b3b5e52e | |||
| 50b6a02907 | |||
| a853a7a14d | |||
| e4e410af5b | |||
| df9bcd5f12 | |||
| a6961e8dae | |||
| b204169c65 | |||
| b9a708d5b3 | |||
| 692347fd97 | |||
| 488c3d6cef | |||
| 075f8449f8 | |||
| 482c0afe2f | |||
| 3663d5f24b | |||
| 0db8182839 | |||
| 0c50a9d861 | |||
| 4260b3460f | |||
| 36086448d2 | |||
| f21c96188d | |||
| 138b2f4733 | |||
| 4e6418ff12 | |||
| 0a1022a526 | |||
| 2798b20b31 | |||
| 183ba98d03 | |||
| d899562ba1 | |||
| de3377459a | |||
| c314860e00 | |||
| d2a10e3d53 | |||
| 8dcd96dbd2 | |||
| 535f81a387 | |||
| e61826e5a2 | |||
| 367d2f9112 | |||
| 4e90ee6201 | |||
| cec996ef81 | |||
| ef892a15b7 | |||
| 7f283a3a38 | |||
| 2b6f31dd0d | |||
| 78ebd14551 | |||
| 04152dae8f | |||
| 14955a2a63 | |||
| a2aa5a2f75 | |||
| b8cc21eb3c | |||
| ad95934844 | |||
| 95f763f466 | |||
| f38e38df09 | |||
| cf240daf63 | |||
| 2a71e8868b | |||
| cf5695e320 | |||
| 30ce282198 | |||
| 4dd9f036d3 | |||
| e8210b476c | |||
| d8955fc52c | |||
| d4e5a3ea93 | |||
| c8fc3c9592 | |||
| 9c6bd61398 | |||
| ad28ffc6f8 | |||
| 73a47d1c1c | |||
| bb1a816a3a | |||
| a9914342e0 | |||
| 10d712d060 | |||
| 4bbe984bdc | |||
| fb538c9490 | |||
| 2851f5f8c9 | |||
| 24c55b434a | |||
| 7cdf684ae6 | |||
| e905b74232 | |||
| 8fd372b0db | |||
| 33a71151ca | |||
| 59ce694ca3 | |||
| b3086ac260 | |||
| c12a03473e | |||
| 89f87d855d | |||
| 81243c87d4 | |||
| f809206baa | |||
| dcf9309ea8 | |||
| b8e9b52af7 | |||
| 8185fa48f1 | |||
| 91a3f020ff | |||
| f0ae0254d4 | |||
| b35a332fdd | |||
| f60fb95ab6 | |||
| 9de9ac7e7e | |||
| 603c726811 | |||
| 8e52497d96 | |||
| 7a1e47e03f | |||
| 255a392eb9 | |||
| e32b3cd93f | |||
| 37cd3bd53c | |||
| c080478444 | |||
| bb2eafc387 | |||
| 21fbb461c0 | |||
| 3b0cc619b2 | |||
| a9c7f8cc5a | |||
| 82fa4e71db | |||
| 980fb59d4b | |||
| 75f3a36547 | |||
| 2d75a631e2 | |||
| 7a3f425720 | |||
| 6fa53f9714 | |||
| a07642f156 | |||
| 555cfae28d | |||
| 74ffe6a61b | |||
| 57617cc5cc | |||
| 40605b78c7 | |||
| 1d7e6a6589 | |||
| d6811c42a8 | |||
| ae14042031 | |||
| 126dfdb155 | |||
| a8fdb1718d | |||
| ec3a9ecbf0 | |||
| ced351dec8 | |||
| f56d453050 | |||
| 44bee0b8ad | |||
| 301db885ea | |||
| b5eaeac0b0 | |||
| 088401fa88 | |||
| a1fc9d8d88 | |||
| dae85e28e2 | |||
| 7f9aa35edb | |||
| 9ec2b96b19 | |||
| ede50424ef | |||
| ee446d00ea | |||
| f7bee99fa3 | |||
| 2402c4d7e9 | |||
| 95d05dcfa5 | |||
| e468dd7d38 | |||
| e1f27488d1 | |||
| 509ba0d640 | |||
| 4941d8ff75 | |||
| d1221b4456 | |||
| 9d83747162 | |||
| 2ad6f06df5 | |||
| 0f0bd2bf2d | |||
| ddfbad6c7f | |||
| 1132c8df21 | |||
| cee0974abd | |||
| 5b1ca74376 | |||
| 77d20873dc | |||
| f5b09d3ec6 | |||
| 06eae35c31 | |||
| bbb19cf5c0 | |||
| bf2bb91dc6 | |||
| 9419d411f8 | |||
| 6f7995d27e | |||
| e6c1007043 | |||
| f1f983764f | |||
| 152e48f0d0 | |||
| 396e3309de | |||
| c6e085524a | |||
| 142a4bca9b | |||
| f4d2f11d2c | |||
| fb3b491734 | |||
| 357cd1e122 | |||
| 898d29d9b7 | |||
| 7b6e87277d | |||
| 0823af5369 | |||
| 3192d29e66 | |||
| 3f6254822d | |||
| 9e345650e1 | |||
| 7fd040c311 | |||
| 6f6e096316 | |||
| 6e06857bf9 | |||
| 8c913c8ce4 | |||
| 24dc58b68d | |||
| d6e56a0941 | |||
| cb8eee46f0 | |||
| 59745a4cff | |||
| 7bad58ba47 | |||
| 973ce78fe1 | |||
| 59d126f5b0 | |||
| 2d3722db85 | |||
| 91944e4538 | |||
| 7e511c41ad | |||
| 2a256f2870 | |||
| 12d2beda29 | |||
| 78db8b02c8 | |||
| d99cb95d2d | |||
| 11903da3fb | |||
| e58f0f31b7 | |||
| 8080400cb6 | |||
| b869aab8e1 | |||
| 3720ceb57b | |||
| 6d37c370ba | |||
| ac3d95f499 | |||
| f4b81e7349 | |||
| 8f0f0d62a7 | |||
| bbf510d6cc | |||
| 7b33c7c4b4 | |||
| 63cc5adefd | |||
| 71489e5abf | |||
| 472bb80c9c | |||
| ca79c3da7f | |||
| fea35e3e8f | |||
| a55970c879 | |||
| 4dd1b19e51 | |||
| b1f143cfaf | |||
| c3f222e4d9 | |||
| e8beb6c98f | |||
| 08ac48518f | |||
| 7c4a8dad85 | |||
| 011a608b5a | |||
| 72dceba671 | |||
| 5618157a1e | |||
| 72413bafd4 | |||
| cccbddb54c | |||
| 4f74f805c2 | |||
| 3d24383686 | |||
| 5986307b8e | |||
| d3b00fa6c5 | |||
| 50b026a3a9 | |||
| 7d5988401e | |||
| 47628bf25e | |||
| 52e3e0a4aa | |||
| 770466d5d4 | |||
| 9ee348d62e | |||
| 2b2fca758c | |||
| 2022379cf4 | |||
| 68df40c1dc | |||
| 0bf5b133e1 | |||
| 9a28c9178e | |||
| ae937a31d2 | |||
| afc7c1088d | |||
| dd29c8181a | |||
| 06b8d4bacf | |||
| 41a776b397 | |||
| 15d5b2b533 | |||
| fb443b3056 | |||
| 60fce621e8 | |||
| a20141bca7 | |||
| d957634c25 | |||
| 7b889b9f35 | |||
| 246d8993d2 | |||
| e4540f2c2a | |||
| 1d52e03750 | |||
| d38c4e6026 | |||
| afe01a86bd | |||
| 994e6af8e0 | |||
| d15ce26b58 | |||
| a725d4b190 | |||
| 315205298a | |||
| e1a112a761 | |||
| 21232e3bef | |||
| 90be7e75c2 | |||
| bdf6008dea | |||
| 21c87d4961 | |||
| e67e6e19f9 | |||
| fe47783b5f | |||
| dbcf401cbd | |||
| 2fe7e8d525 | |||
| 44750974e7 | |||
| f21456972c | |||
| ba472cc9a3 | |||
| a2f2ab8426 | |||
| 6594941d24 | |||
| a926fefe0d | |||
| f7a47e9f9f | |||
| 2e859413e7 | |||
| aadc5052bc | |||
| 3c35ab1e42 | |||
| 4457b7dd5b | |||
| c7ed85a4ac | |||
| fc22d55b53 | |||
| 8fcd09f30b | |||
| 2c4a7cf58c | |||
| 770d6de545 | |||
| c45372e2f3 | |||
| d1c888f57a | |||
| c456eab7cd | |||
| 952f72233e | |||
| cb2b5783fa | |||
| 49265fa12b | |||
| c043b9c64b | |||
| a2bd317397 | |||
| 4725c4fabb | |||
| 7e26c711cf | |||
| 25b5e9fec1 | |||
| c4e1446dff | |||
| d0870b4112 | |||
| 27055f178f | |||
| ab7c8b0df0 | |||
| 94cb26ae59 | |||
| e6a26ef104 | |||
| f8440aa0e5 | |||
| fd5bf7c29a | |||
| 64a5687656 | |||
| ba787edee4 | |||
| a48191c970 | |||
| 689c5fa7b7 | |||
| 10b5961f3c | |||
| 6752e25bcd | |||
| ae89793c28 | |||
| 616eafc3c1 | |||
| 907960850b | |||
| 4ba713bf43 | |||
| e7f1ca7fb1 | |||
| aa959e6705 | |||
| 8aefb675a2 | |||
| ed8f016c1f | |||
| 6e1fc798e1 | |||
| ec578d45f1 | |||
| f2ed49f720 | |||
| f09e4497b6 | |||
| 2fdf2475bb | |||
| ade7e7cd18 | |||
| b444913576 | |||
| c150e9945c | |||
| 51457eece9 | |||
| 0c34137d84 | |||
| 947356a64a | |||
| fcab73a9b6 | |||
| 7dd29ee5db | |||
| 3e41edd30e | |||
| e6617e3273 | |||
| cba20711b0 | |||
| 5abf31b991 | |||
| 7297387015 | |||
| 855d0d60df | |||
| e9512a5ac8 | |||
| 4e2e644c35 | |||
| d44502c979 | |||
| 6434b4f0c8 | |||
| 4cebe50a9f | |||
| 51ea36e444 | |||
| ad2b9fbaaf | |||
| 4b45a7185a | |||
| 27da48bac2 | |||
| 09d2858dc0 | |||
| d1ef1e8ef1 | |||
| bf01059c38 | |||
| ecba08e240 | |||
| d51888bc7e | |||
| 0b6edc6cfe | |||
| 1d92deff31 | |||
| c44b8e601e | |||
| b43f827188 | |||
| 859ac5e520 | |||
| 7f2c3591e3 | |||
| a57a5748f8 | |||
| aa25fadf94 | |||
| 2d93b6ce58 | |||
| 2601f5fd49 | |||
| 89ed418b83 | |||
| 57255a9898 | |||
| 557f81e622 | |||
| f4e522490f | |||
| 2ffc7dc6ac | |||
| 11eb40e636 | |||
| ef8e9415f8 | |||
| 4c1c0977ab | |||
| 516637fcdc | |||
| e6aeb45d09 | |||
| 0b2e0dd32b | |||
| 84bcdda342 | |||
| 5d5651861d | |||
| 2f5c19fa00 | |||
| 1acc0e4982 | |||
| 3cad5a2ed0 | |||
| ba97c9f719 | |||
| 5feaef3748 | |||
| c4c873733b | |||
| 99a9aaa591 | |||
| 620c322df5 | |||
| 807045bc14 | |||
| b4b287c4e9 | |||
| 81ff4946ae | |||
| 8eb50fe9d0 | |||
| 104da5c244 | |||
| d41503da5a | |||
| 146122f455 | |||
| 17533e22da | |||
| 2a7e20a315 | |||
| 795df7224b | |||
| a93584b065 | |||
| b58c0c94e4 | |||
| 67250833b8 | |||
| 4de9cb48a5 | |||
| 6efc5614ec | |||
| 8dfb5c0ea8 | |||
| 3c56fd49eb | |||
| 45dfc719e1 | |||
| ab27b9781e | |||
| 34cd7177cd | |||
| 566916ba19 | |||
| 1a96548fa5 | |||
| b1c60706d7 | |||
| 70afd130ad | |||
| fb9176a054 | |||
| ba132b01bc | |||
| 10c4a2687f | |||
| aad36b8c47 | |||
| bb4bc8c4ae | |||
| 20dba9cd75 | |||
| c7274ff2e8 | |||
| 2040e4de8b | |||
| 4b33531240 | |||
| e6977cbe4e | |||
| 2d0f324529 | |||
| ffaf6a19ca | |||
| 0134c553a5 | |||
| f959a475b7 |
+30
-53
@@ -8,11 +8,10 @@
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/binary.h"
|
||||
#include "yaml-cpp/emitterdef.h"
|
||||
#include "yaml-cpp/emittermanip.h"
|
||||
#include "yaml-cpp/ostream.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
@@ -25,12 +24,11 @@ namespace YAML
|
||||
{
|
||||
public:
|
||||
Emitter();
|
||||
explicit Emitter(std::ostream& stream);
|
||||
~Emitter();
|
||||
|
||||
// output
|
||||
const char *c_str() const;
|
||||
std::size_t size() const;
|
||||
unsigned size() const;
|
||||
|
||||
// state checking
|
||||
bool good() const;
|
||||
@@ -62,7 +60,7 @@ namespace YAML
|
||||
Emitter& Write(const _Anchor& anchor);
|
||||
Emitter& Write(const _Tag& tag);
|
||||
Emitter& Write(const _Comment& comment);
|
||||
Emitter& Write(const _Null& n);
|
||||
Emitter& Write(const _Null& null);
|
||||
Emitter& Write(const Binary& binary);
|
||||
|
||||
template <typename T>
|
||||
@@ -72,51 +70,39 @@ namespace YAML
|
||||
Emitter& WriteStreamable(T value);
|
||||
|
||||
private:
|
||||
void PreWriteIntegralType(std::stringstream& str);
|
||||
void PreWriteStreamable(std::stringstream& str);
|
||||
void PostWriteIntegralType(const std::stringstream& str);
|
||||
void PostWriteStreamable(const std::stringstream& str);
|
||||
|
||||
template<typename T> void SetStreamablePrecision(std::stringstream&) {}
|
||||
unsigned GetFloatPrecision() const;
|
||||
unsigned GetDoublePrecision() const;
|
||||
|
||||
void PrepareIntegralStream(std::stringstream& stream) const;
|
||||
void StartedScalar();
|
||||
|
||||
private:
|
||||
void PreAtomicWrite();
|
||||
bool GotoNextPreAtomicState();
|
||||
void PostAtomicWrite();
|
||||
void EmitSeparationIfNecessary();
|
||||
|
||||
void EmitBeginDoc();
|
||||
void EmitEndDoc();
|
||||
void EmitBeginSeq();
|
||||
void EmitEndSeq();
|
||||
void EmitBeginMap();
|
||||
void EmitEndMap();
|
||||
void EmitKey();
|
||||
void EmitValue();
|
||||
void EmitNewline();
|
||||
void EmitKindTag();
|
||||
void EmitTag(bool verbatim, const _Tag& tag);
|
||||
|
||||
void PrepareNode(EmitterNodeType::value child);
|
||||
void PrepareTopNode(EmitterNodeType::value child);
|
||||
void FlowSeqPrepareNode(EmitterNodeType::value child);
|
||||
void BlockSeqPrepareNode(EmitterNodeType::value child);
|
||||
|
||||
void FlowMapPrepareNode(EmitterNodeType::value child);
|
||||
|
||||
void FlowMapPrepareLongKey(EmitterNodeType::value child);
|
||||
void FlowMapPrepareLongKeyValue(EmitterNodeType::value child);
|
||||
void FlowMapPrepareSimpleKey(EmitterNodeType::value child);
|
||||
void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
|
||||
|
||||
void BlockMapPrepareNode(EmitterNodeType::value child);
|
||||
|
||||
void BlockMapPrepareLongKey(EmitterNodeType::value child);
|
||||
void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
|
||||
void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
|
||||
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
|
||||
|
||||
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
|
||||
|
||||
const char *ComputeFullBoolName(bool b) const;
|
||||
bool CanEmitNewline() const;
|
||||
|
||||
private:
|
||||
std::auto_ptr<EmitterState> m_pState;
|
||||
ostream_wrapper m_stream;
|
||||
ostream m_stream;
|
||||
std::auto_ptr <EmitterState> m_pState;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -125,15 +111,10 @@ namespace YAML
|
||||
if(!good())
|
||||
return *this;
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
|
||||
std::stringstream stream;
|
||||
PrepareIntegralStream(stream);
|
||||
stream << value;
|
||||
m_stream << stream.str();
|
||||
|
||||
StartedScalar();
|
||||
|
||||
std::stringstream str;
|
||||
PreWriteIntegralType(str);
|
||||
str << value;
|
||||
PostWriteIntegralType(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -143,28 +124,24 @@ namespace YAML
|
||||
if(!good())
|
||||
return *this;
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
|
||||
std::stringstream stream;
|
||||
SetStreamablePrecision<T>(stream);
|
||||
stream << value;
|
||||
m_stream << stream.str();
|
||||
|
||||
StartedScalar();
|
||||
|
||||
std::stringstream str;
|
||||
PreWriteStreamable(str);
|
||||
SetStreamablePrecision<T>(str);
|
||||
str << value;
|
||||
PostWriteStreamable(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream)
|
||||
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& str)
|
||||
{
|
||||
stream.precision(GetFloatPrecision());
|
||||
str.precision(GetFloatPrecision());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream)
|
||||
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& str)
|
||||
{
|
||||
stream.precision(GetDoublePrecision());
|
||||
str.precision(GetDoublePrecision());
|
||||
}
|
||||
|
||||
// overloads of insertion
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#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
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
struct EmitterNodeType { enum value { None, Property, Scalar, FlowSeq, BlockSeq, FlowMap, BlockMap }; };
|
||||
}
|
||||
|
||||
#endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
@@ -61,7 +61,6 @@ namespace YAML
|
||||
const char * const BAD_DEREFERENCE = "bad dereference";
|
||||
const char * const BAD_SUBSCRIPT = "operator[] call on a scalar";
|
||||
const char * const BAD_PUSHBACK = "appending to a non-sequence";
|
||||
const char * const BAD_INSERT = "inserting in a non-convertible-to-map";
|
||||
|
||||
const char * const UNMATCHED_GROUP_TAG = "unmatched group tag";
|
||||
const char * const UNEXPECTED_END_SEQ = "unexpected end sequence token";
|
||||
@@ -70,7 +69,10 @@ namespace YAML
|
||||
const char * const INVALID_ANCHOR = "invalid anchor";
|
||||
const char * const INVALID_ALIAS = "invalid alias";
|
||||
const char * const INVALID_TAG = "invalid tag";
|
||||
const char * const BAD_FILE = "bad file";
|
||||
const char * const EXPECTED_KEY_TOKEN = "expected key token";
|
||||
const char * const EXPECTED_VALUE_TOKEN = "expected value token";
|
||||
const char * const UNEXPECTED_KEY_TOKEN = "unexpected key token";
|
||||
const char * const UNEXPECTED_VALUE_TOKEN = "unexpected value token";
|
||||
|
||||
template <typename T>
|
||||
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) {
|
||||
@@ -152,7 +154,7 @@ namespace YAML
|
||||
class BadConversion: public RepresentationException {
|
||||
public:
|
||||
BadConversion()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_CONVERSION) {}
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_CONVERSION) {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -165,37 +167,26 @@ namespace YAML
|
||||
class BadDereference: public RepresentationException {
|
||||
public:
|
||||
BadDereference()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
|
||||
};
|
||||
|
||||
class BadSubscript: public RepresentationException {
|
||||
public:
|
||||
BadSubscript()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_SUBSCRIPT) {}
|
||||
};
|
||||
|
||||
class BadPushback: public RepresentationException {
|
||||
public:
|
||||
BadPushback()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_PUSHBACK) {}
|
||||
};
|
||||
|
||||
class BadInsert: public RepresentationException {
|
||||
public:
|
||||
BadInsert()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
|
||||
};
|
||||
|
||||
class EmitterException: public Exception {
|
||||
public:
|
||||
EmitterException(const std::string& msg_)
|
||||
: Exception(Mark::null_mark(), msg_) {}
|
||||
: Exception(Mark::null(), msg_) {}
|
||||
};
|
||||
|
||||
class BadFile: public Exception {
|
||||
public:
|
||||
BadFile(): Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace YAML
|
||||
struct YAML_CPP_API Mark {
|
||||
Mark(): pos(0), line(0), column(0) {}
|
||||
|
||||
static const Mark null_mark() { return Mark(-1, -1, -1); }
|
||||
static const Mark null() { return Mark(-1, -1, -1); }
|
||||
|
||||
int pos;
|
||||
int line, column;
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace YAML
|
||||
static Node encode(const std::map<K, V>& rhs) {
|
||||
Node node(NodeType::Map);
|
||||
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
|
||||
node.force_insert(it->first, it->second);
|
||||
node[it->first] = it->second;
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -138,12 +138,7 @@ namespace YAML
|
||||
|
||||
rhs.clear();
|
||||
for(const_iterator it=node.begin();it!=node.end();++it)
|
||||
#if defined(__GNUC__) && __GNUC__ < 4
|
||||
//workaround for GCC 3:
|
||||
rhs[it->first.template as<K>()] = it->second.template as<V>();
|
||||
#else
|
||||
rhs[it->first.as<K>()] = it->second.as<V>();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -164,12 +159,7 @@ namespace YAML
|
||||
|
||||
rhs.clear();
|
||||
for(const_iterator it=node.begin();it!=node.end();++it)
|
||||
#if defined(__GNUC__) && __GNUC__ < 4
|
||||
//workaround for GCC 3:
|
||||
rhs.push_back(it->template as<T>());
|
||||
#else
|
||||
rhs.push_back(it->as<T>());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -190,12 +180,7 @@ namespace YAML
|
||||
|
||||
rhs.clear();
|
||||
for(const_iterator it=node.begin();it!=node.end();++it)
|
||||
#if defined(__GNUC__) && __GNUC__ < 4
|
||||
//workaround for GCC 3:
|
||||
rhs.push_back(it->template as<T>());
|
||||
#else
|
||||
rhs.push_back(it->as<T>());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,27 +118,6 @@ namespace YAML
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
inline void node_data::force_insert(const Key& key, const Value& value, shared_memory_holder pMemory)
|
||||
{
|
||||
switch(m_type) {
|
||||
case NodeType::Map:
|
||||
break;
|
||||
case NodeType::Undefined:
|
||||
case NodeType::Null:
|
||||
case NodeType::Sequence:
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw BadInsert();
|
||||
}
|
||||
|
||||
node& k = convert_to_node(key, pMemory);
|
||||
node& v = convert_to_node(value, pMemory);
|
||||
insert_map_pair(k, v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory)
|
||||
|
||||
@@ -115,10 +115,6 @@ namespace YAML
|
||||
}
|
||||
bool remove(node& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory){ m_pRef->force_insert(key, value, pMemory); }
|
||||
|
||||
private:
|
||||
shared_node_ref m_pRef;
|
||||
typedef std::set<node *> nodes;
|
||||
|
||||
@@ -56,10 +56,6 @@ namespace YAML
|
||||
node& get(node& key, shared_memory_holder pMemory) const;
|
||||
node& get(node& key, shared_memory_holder pMemory);
|
||||
bool remove(node& key, shared_memory_holder pMemory);
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory);
|
||||
|
||||
public:
|
||||
static std::string empty_scalar;
|
||||
|
||||
@@ -55,10 +55,6 @@ namespace YAML
|
||||
node& get(node& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
||||
node& get(node& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
||||
bool remove(node& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory) { m_pData->force_insert(key, value, pMemory); }
|
||||
|
||||
private:
|
||||
shared_node_data m_pData;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
inline Node::Node(): m_pNode(NULL)
|
||||
inline Node::Node(): m_pNode(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace YAML
|
||||
return node.Scalar();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// access functions
|
||||
template<typename T>
|
||||
inline const T Node::as() const
|
||||
@@ -168,11 +168,6 @@ namespace YAML
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::clear()
|
||||
{
|
||||
m_pNode = NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Node::Assign(const T& rhs)
|
||||
{
|
||||
@@ -229,7 +224,7 @@ namespace YAML
|
||||
m_pMemory->merge(*rhs.m_pMemory);
|
||||
m_pNode = rhs.m_pNode;
|
||||
}
|
||||
|
||||
|
||||
// size/iterator
|
||||
inline std::size_t Node::size() const
|
||||
{
|
||||
@@ -272,57 +267,12 @@ namespace YAML
|
||||
m_pMemory->merge(*rhs.m_pMemory);
|
||||
}
|
||||
|
||||
// helpers for indexing
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
struct to_value_t {
|
||||
explicit to_value_t(const T& t_): t(t_) {}
|
||||
const T& t;
|
||||
typedef const T& return_type;
|
||||
|
||||
const T& operator()() const { return t; }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct to_value_t<const char*> {
|
||||
explicit to_value_t(const char *t_): t(t_) {}
|
||||
const char *t;
|
||||
typedef std::string return_type;
|
||||
|
||||
const std::string operator()() const { return t; }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct to_value_t<char*> {
|
||||
explicit to_value_t(char *t_): t(t_) {}
|
||||
const char *t;
|
||||
typedef std::string return_type;
|
||||
|
||||
const std::string operator()() const { return t; }
|
||||
};
|
||||
|
||||
template<std::size_t N>
|
||||
struct to_value_t<char [N]> {
|
||||
explicit to_value_t(const char *t_): t(t_) {}
|
||||
const char *t;
|
||||
typedef std::string return_type;
|
||||
|
||||
const std::string operator()() const { return t; }
|
||||
};
|
||||
|
||||
// converts C-strings to std::strings so they can be copied
|
||||
template<typename T>
|
||||
inline typename to_value_t<T>::return_type to_value(const T& t) {
|
||||
return to_value_t<T>(t)();
|
||||
}
|
||||
}
|
||||
|
||||
// indexing
|
||||
template<typename Key>
|
||||
inline const Node Node::operator[](const Key& key) const
|
||||
{
|
||||
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(key, m_pMemory);
|
||||
return Node(value, m_pMemory);
|
||||
}
|
||||
|
||||
@@ -330,7 +280,7 @@ namespace YAML
|
||||
inline Node Node::operator[](const Key& key)
|
||||
{
|
||||
EnsureNodeExists();
|
||||
detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
|
||||
detail::node& value = m_pNode->get(key, m_pMemory);
|
||||
return Node(value, m_pMemory);
|
||||
}
|
||||
|
||||
@@ -338,7 +288,7 @@ namespace YAML
|
||||
inline bool Node::remove(const Key& key)
|
||||
{
|
||||
EnsureNodeExists();
|
||||
return m_pNode->remove(detail::to_value(key), m_pMemory);
|
||||
return m_pNode->remove(key, m_pMemory);
|
||||
}
|
||||
|
||||
inline const Node Node::operator[](const Node& key) const
|
||||
@@ -363,16 +313,39 @@ namespace YAML
|
||||
key.EnsureNodeExists();
|
||||
return m_pNode->remove(*key.m_pNode, m_pMemory);
|
||||
}
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
inline void Node::force_insert(const Key& key, const Value& value)
|
||||
{
|
||||
EnsureNodeExists();
|
||||
m_pNode->force_insert(detail::to_value(key), detail::to_value(value), m_pMemory);
|
||||
}
|
||||
|
||||
inline const Node Node::operator[](const char *key) const
|
||||
{
|
||||
return operator[](std::string(key));
|
||||
}
|
||||
|
||||
inline Node Node::operator[](const char *key)
|
||||
{
|
||||
return operator[](std::string(key));
|
||||
}
|
||||
|
||||
inline bool Node::remove(const char *key)
|
||||
{
|
||||
return remove(std::string(key));
|
||||
}
|
||||
|
||||
inline const Node Node::operator[](char *key) const
|
||||
{
|
||||
return operator[](static_cast<const char *>(key));
|
||||
}
|
||||
|
||||
inline Node Node::operator[](char *key)
|
||||
{
|
||||
return operator[](static_cast<const char *>(key));
|
||||
}
|
||||
|
||||
inline bool Node::remove(char *key)
|
||||
{
|
||||
return remove(static_cast<const char *>(key));
|
||||
}
|
||||
|
||||
// free functions
|
||||
|
||||
inline bool operator==(const Node& lhs, const Node& rhs)
|
||||
{
|
||||
return lhs.is(rhs);
|
||||
|
||||
@@ -56,8 +56,7 @@ namespace YAML
|
||||
bool is(const Node& rhs) const;
|
||||
template<typename T> Node& operator=(const T& rhs);
|
||||
Node& operator=(const Node& rhs);
|
||||
void clear();
|
||||
|
||||
|
||||
// size/iterator
|
||||
std::size_t size() const;
|
||||
|
||||
@@ -79,11 +78,15 @@ namespace YAML
|
||||
const Node operator[](const Node& key) const;
|
||||
Node operator[](const Node& key);
|
||||
bool remove(const Node& key);
|
||||
|
||||
// map
|
||||
template<typename Key, typename Value>
|
||||
void force_insert(const Key& key, const Value& value);
|
||||
|
||||
const Node operator[](const char *key) const;
|
||||
Node operator[](const char *key);
|
||||
bool remove(const char *key);
|
||||
|
||||
const Node operator[](char *key) const;
|
||||
Node operator[](char *key);
|
||||
bool remove(char *key);
|
||||
|
||||
private:
|
||||
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
|
||||
|
||||
@@ -102,8 +105,6 @@ namespace YAML
|
||||
};
|
||||
|
||||
bool operator==(const Node& lhs, const Node& rhs);
|
||||
|
||||
Node Clone(const Node& node);
|
||||
|
||||
template<typename T>
|
||||
struct convert;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define OSTREAM_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 <string>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class ostream
|
||||
{
|
||||
public:
|
||||
ostream();
|
||||
~ostream();
|
||||
|
||||
void reserve(unsigned size);
|
||||
void put(char ch);
|
||||
const char *str() const { return m_buffer; }
|
||||
|
||||
unsigned row() const { return m_row; }
|
||||
unsigned col() const { return m_col; }
|
||||
unsigned pos() const { return m_pos; }
|
||||
|
||||
private:
|
||||
char *m_buffer;
|
||||
unsigned m_pos;
|
||||
unsigned m_size;
|
||||
|
||||
unsigned m_row, m_col;
|
||||
};
|
||||
|
||||
ostream& operator << (ostream& out, const char *str);
|
||||
ostream& operator << (ostream& out, const std::string& str);
|
||||
ostream& operator << (ostream& out, char ch);
|
||||
}
|
||||
|
||||
#endif // OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
@@ -1,69 +0,0 @@
|
||||
#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
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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 set_comment() { m_comment = true; }
|
||||
|
||||
const char *str() const {
|
||||
if(m_pStream) {
|
||||
return 0;
|
||||
} else {
|
||||
m_buffer[m_pos] = '\0';
|
||||
return &m_buffer[0];
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t row() const { return m_row; }
|
||||
std::size_t col() const { return m_col; }
|
||||
std::size_t pos() const { return m_pos; }
|
||||
bool comment() const { return m_comment; }
|
||||
|
||||
private:
|
||||
void update_pos(char ch);
|
||||
|
||||
private:
|
||||
mutable std::vector<char> m_buffer;
|
||||
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);
|
||||
return stream;
|
||||
}
|
||||
|
||||
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) {
|
||||
stream.write(&ch, 1);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
@@ -14,8 +14,10 @@
|
||||
namespace YAML
|
||||
{
|
||||
struct Directives;
|
||||
struct Mark;
|
||||
struct Token;
|
||||
class EventHandler;
|
||||
class Node;
|
||||
class Scanner;
|
||||
|
||||
class YAML_CPP_API Parser: private noncopyable
|
||||
@@ -29,7 +31,9 @@ namespace YAML
|
||||
|
||||
void Load(std::istream& in);
|
||||
bool HandleNextDocument(EventHandler& eventHandler);
|
||||
|
||||
|
||||
bool GetNextDocument(Node& document); // old API only
|
||||
|
||||
void PrintTokens(std::ostream& out);
|
||||
|
||||
private:
|
||||
|
||||
+2
-1
@@ -15,8 +15,9 @@ namespace YAML
|
||||
|
||||
std::ostream& operator << (std::ostream& out, const Node& node)
|
||||
{
|
||||
Emitter emitter(out);
|
||||
Emitter emitter;
|
||||
emitter << node;
|
||||
out << emitter.c_str();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
+529
-598
File diff suppressed because it is too large
Load Diff
+71
-171
@@ -4,8 +4,11 @@
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_hasAnchor(false), m_hasTag(false), m_hasNonContent(false), m_docCount(0)
|
||||
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_requiresSoftSeparation(false), m_requiresHardSeparation(false)
|
||||
{
|
||||
// start up
|
||||
m_stateStack.push(ES_WAITING_FOR_DOC);
|
||||
|
||||
// set default global manipulators
|
||||
m_charset.set(EmitNonAscii);
|
||||
m_strFmt.set(Auto);
|
||||
@@ -32,111 +35,21 @@ namespace YAML
|
||||
// . 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);
|
||||
SetBoolCaseFormat(value, FmtScope::Local);
|
||||
SetBoolLengthFormat(value, FmtScope::Local);
|
||||
SetIntFormat(value, FmtScope::Local);
|
||||
SetFlowType(GroupType::Seq, value, FmtScope::Local);
|
||||
SetFlowType(GroupType::Map, value, FmtScope::Local);
|
||||
SetMapKeyFormat(value, FmtScope::Local);
|
||||
SetOutputCharset(value, LOCAL);
|
||||
SetStringFormat(value, LOCAL);
|
||||
SetBoolFormat(value, LOCAL);
|
||||
SetBoolCaseFormat(value, LOCAL);
|
||||
SetBoolLengthFormat(value, LOCAL);
|
||||
SetIntFormat(value, LOCAL);
|
||||
SetFlowType(GT_SEQ, value, LOCAL);
|
||||
SetFlowType(GT_MAP, value, LOCAL);
|
||||
SetMapKeyFormat(value, LOCAL);
|
||||
}
|
||||
|
||||
void EmitterState::SetAnchor()
|
||||
{
|
||||
m_hasAnchor = true;
|
||||
}
|
||||
|
||||
void EmitterState::SetTag()
|
||||
{
|
||||
m_hasTag = true;
|
||||
}
|
||||
|
||||
void EmitterState::SetNonContent()
|
||||
{
|
||||
m_hasNonContent = true;
|
||||
}
|
||||
|
||||
void EmitterState::SetLongKey()
|
||||
{
|
||||
assert(!m_groups.empty());
|
||||
if(m_groups.empty())
|
||||
return;
|
||||
|
||||
assert(m_groups.top().type == GroupType::Map);
|
||||
m_groups.top().longKey = true;
|
||||
}
|
||||
|
||||
void EmitterState::ForceFlow()
|
||||
{
|
||||
assert(!m_groups.empty());
|
||||
if(m_groups.empty())
|
||||
return;
|
||||
|
||||
m_groups.top().flowType = FlowType::Flow;
|
||||
}
|
||||
|
||||
void EmitterState::StartedNode()
|
||||
{
|
||||
if(m_groups.empty()) {
|
||||
m_docCount++;
|
||||
} else {
|
||||
m_groups.top().childCount++;
|
||||
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)
|
||||
return EmitterNodeType::BlockSeq;
|
||||
else
|
||||
return EmitterNodeType::FlowSeq;
|
||||
} else {
|
||||
if(GetFlowType(type) == Block)
|
||||
return EmitterNodeType::BlockMap;
|
||||
else
|
||||
return EmitterNodeType::FlowMap;
|
||||
}
|
||||
|
||||
// can't happen
|
||||
assert(false);
|
||||
return EmitterNodeType::None;
|
||||
}
|
||||
|
||||
void EmitterState::StartedDoc()
|
||||
{
|
||||
m_hasAnchor = false;
|
||||
m_hasTag = false;
|
||||
m_hasNonContent = false;
|
||||
}
|
||||
|
||||
void EmitterState::EndedDoc()
|
||||
{
|
||||
m_hasAnchor = false;
|
||||
m_hasTag = false;
|
||||
m_hasNonContent = false;
|
||||
}
|
||||
|
||||
void EmitterState::StartedScalar()
|
||||
{
|
||||
StartedNode();
|
||||
ClearModifiedSettings();
|
||||
}
|
||||
|
||||
void EmitterState::StartedGroup(GroupType::value type)
|
||||
void EmitterState::BeginGroup(GROUP_TYPE type)
|
||||
{
|
||||
StartedNode();
|
||||
|
||||
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
||||
m_curIndent += lastGroupIndent;
|
||||
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
||||
m_curIndent += lastIndent;
|
||||
|
||||
std::auto_ptr<Group> pGroup(new Group(type));
|
||||
|
||||
@@ -144,23 +57,17 @@ namespace YAML
|
||||
pGroup->modifiedSettings = m_modifiedSettings;
|
||||
|
||||
// set up group
|
||||
if(GetFlowType(type) == Block)
|
||||
pGroup->flowType = FlowType::Block;
|
||||
else
|
||||
pGroup->flowType = FlowType::Flow;
|
||||
pGroup->flow = GetFlowType(type);
|
||||
pGroup->indent = GetIndent();
|
||||
pGroup->usingLongKey = (GetMapKeyFormat() == LongKey ? true : false);
|
||||
|
||||
m_groups.push(pGroup);
|
||||
}
|
||||
|
||||
void EmitterState::EndedGroup(GroupType::value type)
|
||||
void EmitterState::EndGroup(GROUP_TYPE type)
|
||||
{
|
||||
if(m_groups.empty()) {
|
||||
if(type == GroupType::Seq)
|
||||
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
||||
else
|
||||
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
|
||||
}
|
||||
if(m_groups.empty())
|
||||
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
||||
|
||||
// get rid of the current group
|
||||
{
|
||||
@@ -177,57 +84,49 @@ namespace YAML
|
||||
// some global settings that we changed may have been overridden
|
||||
// by a local setting we just popped, so we need to restore them
|
||||
m_globalModifiedSettings.restore();
|
||||
|
||||
ClearModifiedSettings();
|
||||
}
|
||||
|
||||
EmitterNodeType::value EmitterState::CurGroupNodeType() const
|
||||
{
|
||||
if(m_groups.empty())
|
||||
return EmitterNodeType::None;
|
||||
|
||||
return m_groups.top().NodeType();
|
||||
}
|
||||
|
||||
GroupType::value EmitterState::CurGroupType() const
|
||||
|
||||
GROUP_TYPE EmitterState::GetCurGroupType() const
|
||||
{
|
||||
return m_groups.empty() ? GroupType::None : m_groups.top().type;
|
||||
if(m_groups.empty())
|
||||
return GT_NONE;
|
||||
|
||||
return m_groups.top().type;
|
||||
}
|
||||
|
||||
FlowType::value EmitterState::CurGroupFlowType() const
|
||||
FLOW_TYPE EmitterState::GetCurGroupFlowType() const
|
||||
{
|
||||
return m_groups.empty() ? FlowType::None : m_groups.top().flowType;
|
||||
if(m_groups.empty())
|
||||
return FT_NONE;
|
||||
|
||||
return (m_groups.top().flow == Flow ? FT_FLOW : FT_BLOCK);
|
||||
}
|
||||
|
||||
bool EmitterState::CurrentlyInLongKey()
|
||||
{
|
||||
if(m_groups.empty())
|
||||
return false;
|
||||
return m_groups.top().usingLongKey;
|
||||
}
|
||||
|
||||
void EmitterState::StartLongKey()
|
||||
{
|
||||
if(!m_groups.empty())
|
||||
m_groups.top().usingLongKey = true;
|
||||
}
|
||||
|
||||
void EmitterState::StartSimpleKey()
|
||||
{
|
||||
if(!m_groups.empty())
|
||||
m_groups.top().usingLongKey = false;
|
||||
}
|
||||
|
||||
int EmitterState::CurGroupIndent() const
|
||||
{
|
||||
return m_groups.empty() ? 0 : m_groups.top().indent;
|
||||
}
|
||||
|
||||
std::size_t EmitterState::CurGroupChildCount() const
|
||||
{
|
||||
return m_groups.empty() ? m_docCount : m_groups.top().childCount;
|
||||
}
|
||||
|
||||
bool EmitterState::CurGroupLongKey() const
|
||||
{
|
||||
return m_groups.empty() ? false : m_groups.top().longKey;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case EmitNonAscii:
|
||||
@@ -239,7 +138,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case Auto:
|
||||
@@ -253,7 +152,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case OnOffBool:
|
||||
@@ -266,7 +165,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case LongBool:
|
||||
@@ -278,7 +177,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case UpperCase:
|
||||
@@ -291,7 +190,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case Dec:
|
||||
@@ -304,16 +203,16 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope)
|
||||
bool EmitterState::SetIndent(unsigned value, FMT_SCOPE scope)
|
||||
{
|
||||
if(value <= 1)
|
||||
if(value == 0)
|
||||
return false;
|
||||
|
||||
_Set(m_indent, value, scope);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope)
|
||||
bool EmitterState::SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
|
||||
{
|
||||
if(value == 0)
|
||||
return false;
|
||||
@@ -322,7 +221,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope)
|
||||
bool EmitterState::SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
|
||||
{
|
||||
if(value == 0)
|
||||
return false;
|
||||
@@ -331,29 +230,30 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case Block:
|
||||
case Flow:
|
||||
_Set(groupType == GroupType::Seq ? m_seqFmt : m_mapFmt, value, scope);
|
||||
_Set(groupType == GT_SEQ ? m_seqFmt : m_mapFmt, value, scope);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const
|
||||
EMITTER_MANIP EmitterState::GetFlowType(GROUP_TYPE groupType) const
|
||||
{
|
||||
// force flow style if we're currently in a flow
|
||||
if(CurGroupFlowType() == FlowType::Flow)
|
||||
FLOW_TYPE flowType = GetCurGroupFlowType();
|
||||
if(flowType == FT_FLOW)
|
||||
return Flow;
|
||||
|
||||
// otherwise, go with what's asked of us
|
||||
return (groupType == GroupType::Seq ? m_seqFmt.get() : m_mapFmt.get());
|
||||
// otherwise, go with what's asked of use
|
||||
return (groupType == GT_SEQ ? m_seqFmt.get() : m_mapFmt.get());
|
||||
}
|
||||
|
||||
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||
{
|
||||
switch(value) {
|
||||
case Auto:
|
||||
@@ -365,7 +265,7 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope)
|
||||
bool EmitterState::SetFloatPrecision(int value, FMT_SCOPE scope)
|
||||
{
|
||||
if(value < 0 || value > std::numeric_limits<float>::digits10)
|
||||
return false;
|
||||
@@ -373,7 +273,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope)
|
||||
bool EmitterState::SetDoublePrecision(int value, FMT_SCOPE scope)
|
||||
{
|
||||
if(value < 0 || value > std::numeric_limits<double>::digits10)
|
||||
return false;
|
||||
|
||||
+108
-81
@@ -8,20 +8,71 @@
|
||||
|
||||
#include "ptr_stack.h"
|
||||
#include "setting.h"
|
||||
#include "yaml-cpp/emitterdef.h"
|
||||
#include "yaml-cpp/emittermanip.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#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 }; };
|
||||
|
||||
enum FMT_SCOPE {
|
||||
LOCAL,
|
||||
GLOBAL
|
||||
};
|
||||
|
||||
enum GROUP_TYPE {
|
||||
GT_NONE,
|
||||
GT_SEQ,
|
||||
GT_MAP
|
||||
};
|
||||
|
||||
enum FLOW_TYPE {
|
||||
FT_NONE,
|
||||
FT_FLOW,
|
||||
FT_BLOCK
|
||||
};
|
||||
|
||||
enum NODE_STATE {
|
||||
NS_START,
|
||||
NS_READY_FOR_ATOM,
|
||||
NS_END
|
||||
};
|
||||
|
||||
enum EMITTER_STATE {
|
||||
ES_WAITING_FOR_DOC,
|
||||
ES_WRITING_DOC,
|
||||
ES_DONE_WITH_DOC,
|
||||
|
||||
// block seq
|
||||
ES_WAITING_FOR_BLOCK_SEQ_ENTRY,
|
||||
ES_WRITING_BLOCK_SEQ_ENTRY,
|
||||
ES_DONE_WITH_BLOCK_SEQ_ENTRY,
|
||||
|
||||
// flow seq
|
||||
ES_WAITING_FOR_FLOW_SEQ_ENTRY,
|
||||
ES_WRITING_FLOW_SEQ_ENTRY,
|
||||
ES_DONE_WITH_FLOW_SEQ_ENTRY,
|
||||
|
||||
// block map
|
||||
ES_WAITING_FOR_BLOCK_MAP_ENTRY,
|
||||
ES_WAITING_FOR_BLOCK_MAP_KEY,
|
||||
ES_WRITING_BLOCK_MAP_KEY,
|
||||
ES_DONE_WITH_BLOCK_MAP_KEY,
|
||||
ES_WAITING_FOR_BLOCK_MAP_VALUE,
|
||||
ES_WRITING_BLOCK_MAP_VALUE,
|
||||
ES_DONE_WITH_BLOCK_MAP_VALUE,
|
||||
|
||||
// flow map
|
||||
ES_WAITING_FOR_FLOW_MAP_ENTRY,
|
||||
ES_WAITING_FOR_FLOW_MAP_KEY,
|
||||
ES_WRITING_FLOW_MAP_KEY,
|
||||
ES_DONE_WITH_FLOW_MAP_KEY,
|
||||
ES_WAITING_FOR_FLOW_MAP_VALUE,
|
||||
ES_WRITING_FLOW_MAP_VALUE,
|
||||
ES_DONE_WITH_FLOW_MAP_VALUE
|
||||
};
|
||||
|
||||
class EmitterState
|
||||
{
|
||||
public:
|
||||
@@ -33,81 +84,76 @@ namespace YAML
|
||||
const std::string GetLastError() const { return m_lastError; }
|
||||
void SetError(const std::string& error) { m_isGood = false; m_lastError = error; }
|
||||
|
||||
// node handling
|
||||
void SetAnchor();
|
||||
void SetTag();
|
||||
void SetNonContent();
|
||||
void SetLongKey();
|
||||
void ForceFlow();
|
||||
void StartedDoc();
|
||||
void EndedDoc();
|
||||
void StartedScalar();
|
||||
void StartedGroup(GroupType::value type);
|
||||
void EndedGroup(GroupType::value type);
|
||||
// main state of the machine
|
||||
EMITTER_STATE GetCurState() const { return m_stateStack.top(); }
|
||||
void SwitchState(EMITTER_STATE state) { PopState(); PushState(state); }
|
||||
void PushState(EMITTER_STATE state) { m_stateStack.push(state); }
|
||||
void PopState() { m_stateStack.pop(); }
|
||||
|
||||
void SetLocalValue(EMITTER_MANIP value);
|
||||
|
||||
// group handling
|
||||
void BeginGroup(GROUP_TYPE type);
|
||||
void EndGroup(GROUP_TYPE type);
|
||||
|
||||
GROUP_TYPE GetCurGroupType() const;
|
||||
FLOW_TYPE GetCurGroupFlowType() const;
|
||||
int GetCurIndent() const { return m_curIndent; }
|
||||
|
||||
bool CurrentlyInLongKey();
|
||||
void StartLongKey();
|
||||
void StartSimpleKey();
|
||||
|
||||
EmitterNodeType::value NextGroupType(GroupType::value type) const;
|
||||
EmitterNodeType::value CurGroupNodeType() const;
|
||||
|
||||
GroupType::value CurGroupType() const;
|
||||
FlowType::value CurGroupFlowType() const;
|
||||
int CurGroupIndent() const;
|
||||
std::size_t CurGroupChildCount() const;
|
||||
bool CurGroupLongKey() const;
|
||||
|
||||
int LastIndent() const;
|
||||
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 HasBegunContent() const { return m_hasAnchor || m_hasTag; }
|
||||
bool RequiresSoftSeparation() const { return m_requiresSoftSeparation; }
|
||||
bool RequiresHardSeparation() const { return m_requiresHardSeparation; }
|
||||
void RequireSoftSeparation() { m_requiresSoftSeparation = true; }
|
||||
void RequireHardSeparation() { m_requiresSoftSeparation = true; m_requiresHardSeparation = true; }
|
||||
void ForceHardSeparation() { m_requiresSoftSeparation = false; }
|
||||
void UnsetSeparation() { m_requiresSoftSeparation = false; m_requiresHardSeparation = false; }
|
||||
|
||||
void ClearModifiedSettings();
|
||||
|
||||
// formatters
|
||||
void SetLocalValue(EMITTER_MANIP value);
|
||||
|
||||
bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
||||
|
||||
bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
||||
|
||||
bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
|
||||
|
||||
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
|
||||
|
||||
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
|
||||
|
||||
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
||||
|
||||
bool SetIndent(unsigned value, FmtScope::value scope);
|
||||
bool SetIndent(unsigned value, FMT_SCOPE scope);
|
||||
int GetIndent() const { return m_indent.get(); }
|
||||
|
||||
bool SetPreCommentIndent(unsigned value, FmtScope::value scope);
|
||||
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope);
|
||||
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
||||
bool SetPostCommentIndent(unsigned value, FmtScope::value scope);
|
||||
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope);
|
||||
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
||||
|
||||
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope);
|
||||
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
|
||||
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const;
|
||||
|
||||
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
||||
|
||||
bool SetFloatPrecision(int value, FmtScope::value scope);
|
||||
bool SetFloatPrecision(int value, FMT_SCOPE scope);
|
||||
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
|
||||
bool SetDoublePrecision(int value, FmtScope::value scope);
|
||||
bool SetDoublePrecision(int value, FMT_SCOPE scope);
|
||||
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
|
||||
|
||||
void StartedNode();
|
||||
void _Set(Setting<T>& fmt, T value, FMT_SCOPE scope);
|
||||
|
||||
private:
|
||||
// basic state ok?
|
||||
@@ -115,6 +161,8 @@ namespace YAML
|
||||
std::string m_lastError;
|
||||
|
||||
// other state
|
||||
std::stack<EMITTER_STATE> m_stateStack;
|
||||
|
||||
Setting<EMITTER_MANIP> m_charset;
|
||||
Setting<EMITTER_MANIP> m_strFmt;
|
||||
Setting<EMITTER_MANIP> m_boolFmt;
|
||||
@@ -133,50 +181,29 @@ namespace YAML
|
||||
SettingChanges m_globalModifiedSettings;
|
||||
|
||||
struct Group {
|
||||
explicit Group(GroupType::value type_): type(type_), indent(0), childCount(0), longKey(false) {}
|
||||
Group(GROUP_TYPE type_): type(type_), usingLongKey(false), indent(0) {}
|
||||
|
||||
GroupType::value type;
|
||||
FlowType::value flowType;
|
||||
GROUP_TYPE type;
|
||||
EMITTER_MANIP flow;
|
||||
bool usingLongKey;
|
||||
int indent;
|
||||
std::size_t childCount;
|
||||
bool longKey;
|
||||
|
||||
SettingChanges modifiedSettings;
|
||||
|
||||
EmitterNodeType::value NodeType() const {
|
||||
if(type == GroupType::Seq) {
|
||||
if(flowType == FlowType::Flow)
|
||||
return EmitterNodeType::FlowSeq;
|
||||
else
|
||||
return EmitterNodeType::BlockSeq;
|
||||
} else {
|
||||
if(flowType == FlowType::Flow)
|
||||
return EmitterNodeType::FlowMap;
|
||||
else
|
||||
return EmitterNodeType::BlockMap;
|
||||
}
|
||||
|
||||
// can't get here
|
||||
assert(false);
|
||||
return EmitterNodeType::None;
|
||||
}
|
||||
};
|
||||
|
||||
ptr_stack<Group> m_groups;
|
||||
unsigned m_curIndent;
|
||||
bool m_hasAnchor;
|
||||
bool m_hasTag;
|
||||
bool m_hasNonContent;
|
||||
std::size_t m_docCount;
|
||||
bool m_requiresSoftSeparation;
|
||||
bool m_requiresHardSeparation;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
||||
void EmitterState::_Set(Setting<T>& fmt, T value, FMT_SCOPE scope) {
|
||||
switch(scope) {
|
||||
case FmtScope::Local:
|
||||
case LOCAL:
|
||||
m_modifiedSettings.push(fmt.set(value));
|
||||
break;
|
||||
case FmtScope::Global:
|
||||
case GLOBAL:
|
||||
fmt.set(value);
|
||||
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
|
||||
|
||||
+53
-99
@@ -107,7 +107,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteCodePoint(ostream_wrapper& out, int codePoint) {
|
||||
void WriteCodePoint(ostream& out, int codePoint) {
|
||||
if (codePoint < 0 || codePoint > 0x10FFFF) {
|
||||
codePoint = REPLACEMENT_CHARACTER;
|
||||
}
|
||||
@@ -128,12 +128,12 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, bool allowOnlyAscii) {
|
||||
bool IsValidPlainScalar(const std::string& str, bool inFlow, bool allowOnlyAscii) {
|
||||
if(str.empty())
|
||||
return false;
|
||||
|
||||
// first check the start
|
||||
const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
|
||||
const RegEx& start = (inFlow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
|
||||
if(!start.Matches(str))
|
||||
return false;
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace YAML
|
||||
return false;
|
||||
|
||||
// then check until something is disallowed
|
||||
const RegEx& disallowed = (flowType == FlowType::Flow ? Exp::EndScalarInFlow() : Exp::EndScalar())
|
||||
const RegEx& disallowed = (inFlow ? Exp::EndScalarInFlow() : Exp::EndScalar())
|
||||
|| (Exp::BlankOrBreak() + Exp::Comment())
|
||||
|| Exp::NotPrintable()
|
||||
|| Exp::Utf8_ByteOrderMark()
|
||||
@@ -152,7 +152,7 @@ namespace YAML
|
||||
while(buffer) {
|
||||
if(disallowed.Matches(buffer))
|
||||
return false;
|
||||
if(allowOnlyAscii && (0x80 <= static_cast<unsigned char>(buffer[0])))
|
||||
if(allowOnlyAscii && (0x7F < static_cast<unsigned char>(buffer[0])))
|
||||
return false;
|
||||
++buffer;
|
||||
}
|
||||
@@ -160,53 +160,30 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
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])))
|
||||
return false;
|
||||
if(str[i] == '\n')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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])))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
|
||||
void WriteDoubleQuoteEscapeSequence(ostream& out, int codePoint) {
|
||||
static const char hexDigits[] = "0123456789abcdef";
|
||||
|
||||
out << "\\";
|
||||
char escSeq[] = "\\U00000000";
|
||||
int digits = 8;
|
||||
if(codePoint < 0xFF) {
|
||||
out << "x";
|
||||
if (codePoint < 0xFF) {
|
||||
escSeq[1] = 'x';
|
||||
digits = 2;
|
||||
} else if(codePoint < 0xFFFF) {
|
||||
out << "u";
|
||||
} else if (codePoint < 0xFFFF) {
|
||||
escSeq[1] = 'u';
|
||||
digits = 4;
|
||||
} else {
|
||||
out << "U";
|
||||
digits = 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Write digits into the escape sequence
|
||||
for (; digits > 0; --digits)
|
||||
out << hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
|
||||
int i = 2;
|
||||
for (; digits > 0; --digits, ++i) {
|
||||
escSeq[i] = hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
|
||||
}
|
||||
|
||||
escSeq[i] = 0; // terminate with NUL character
|
||||
out << escSeq;
|
||||
}
|
||||
|
||||
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
||||
bool WriteAliasName(ostream& out, const std::string& str) {
|
||||
int codePoint;
|
||||
for(std::string::const_iterator i = str.begin();
|
||||
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||
@@ -221,31 +198,16 @@ namespace YAML
|
||||
}
|
||||
}
|
||||
|
||||
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii)
|
||||
{
|
||||
switch(strFormat) {
|
||||
case Auto:
|
||||
if(IsValidPlainScalar(str, flowType, escapeNonAscii))
|
||||
return StringFormat::Plain;
|
||||
return StringFormat::DoubleQuoted;
|
||||
case SingleQuoted:
|
||||
if(IsValidSingleQuotedScalar(str, escapeNonAscii))
|
||||
return StringFormat::SingleQuoted;
|
||||
return StringFormat::DoubleQuoted;
|
||||
case DoubleQuoted:
|
||||
return StringFormat::DoubleQuoted;
|
||||
case Literal:
|
||||
if(IsValidLiteralScalar(str, flowType, escapeNonAscii))
|
||||
return StringFormat::Literal;
|
||||
return StringFormat::DoubleQuoted;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return StringFormat::DoubleQuoted;
|
||||
}
|
||||
|
||||
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str)
|
||||
bool WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii)
|
||||
{
|
||||
if(IsValidPlainScalar(str, inFlow, escapeNonAscii)) {
|
||||
out << str;
|
||||
return true;
|
||||
} else
|
||||
return WriteDoubleQuotedString(out, str, escapeNonAscii);
|
||||
}
|
||||
|
||||
bool WriteSingleQuotedString(ostream& out, const std::string& str)
|
||||
{
|
||||
out << "'";
|
||||
int codePoint;
|
||||
@@ -265,7 +227,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii)
|
||||
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii)
|
||||
{
|
||||
out << "\"";
|
||||
int codePoint;
|
||||
@@ -273,29 +235,24 @@ namespace YAML
|
||||
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
|
||||
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||
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);
|
||||
else
|
||||
WriteCodePoint(out, codePoint);
|
||||
}
|
||||
if (codePoint == '\"')
|
||||
out << "\\\"";
|
||||
else if (codePoint == '\\')
|
||||
out << "\\\\";
|
||||
else 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)
|
||||
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||
else if (escapeNonAscii && codePoint > 0x7E)
|
||||
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||
else
|
||||
WriteCodePoint(out, codePoint);
|
||||
}
|
||||
out << "\"";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent)
|
||||
bool WriteLiteralString(ostream& out, const std::string& str, int indent)
|
||||
{
|
||||
out << "|\n";
|
||||
out << IndentTo(indent);
|
||||
@@ -312,7 +269,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteChar(ostream_wrapper& out, char ch)
|
||||
bool WriteChar(ostream& out, char ch)
|
||||
{
|
||||
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
|
||||
out << ch;
|
||||
@@ -332,39 +289,36 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent)
|
||||
bool WriteComment(ostream& 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') {
|
||||
if(codePoint == '\n')
|
||||
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
||||
out.set_comment();
|
||||
} else {
|
||||
else
|
||||
WriteCodePoint(out, codePoint);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteAlias(ostream_wrapper& out, const std::string& str)
|
||||
bool WriteAlias(ostream& out, const std::string& str)
|
||||
{
|
||||
out << "*";
|
||||
return WriteAliasName(out, str);
|
||||
}
|
||||
|
||||
bool WriteAnchor(ostream_wrapper& out, const std::string& str)
|
||||
bool WriteAnchor(ostream& out, const std::string& str)
|
||||
{
|
||||
out << "&";
|
||||
return WriteAliasName(out, str);
|
||||
}
|
||||
|
||||
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim)
|
||||
bool WriteTag(ostream& out, const std::string& str, bool verbatim)
|
||||
{
|
||||
out << (verbatim ? "!<" : "!");
|
||||
StringCharSource buffer(str.c_str(), str.size());
|
||||
@@ -384,7 +338,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag)
|
||||
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag)
|
||||
{
|
||||
out << "!";
|
||||
StringCharSource prefixBuffer(prefix.c_str(), prefix.size());
|
||||
@@ -414,7 +368,7 @@ namespace YAML
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteBinary(ostream_wrapper& out, const Binary& binary)
|
||||
bool WriteBinary(ostream& out, const Binary& binary)
|
||||
{
|
||||
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false);
|
||||
return true;
|
||||
|
||||
+12
-16
@@ -6,30 +6,26 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "emitterstate.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include "yaml-cpp/ostream.h"
|
||||
#include <string>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Binary;
|
||||
|
||||
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);
|
||||
|
||||
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 WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii);
|
||||
bool WriteSingleQuotedString(ostream& out, const std::string& str);
|
||||
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii);
|
||||
bool WriteLiteralString(ostream& out, const std::string& str, int indent);
|
||||
bool WriteChar(ostream& out, char ch);
|
||||
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent);
|
||||
bool WriteAlias(ostream& out, const std::string& str);
|
||||
bool WriteAnchor(ostream& out, const std::string& str);
|
||||
bool WriteTag(ostream& out, const std::string& str, bool verbatim);
|
||||
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag);
|
||||
bool WriteBinary(ostream& out, const Binary& binary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace YAML
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Key() {
|
||||
static const RegEx e = RegEx('?') + BlankOrBreak();
|
||||
static const RegEx e = RegEx('?');
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& KeyInFlow() {
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include "yaml-cpp/ostream.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
@@ -16,7 +16,7 @@ namespace YAML
|
||||
unsigned n;
|
||||
};
|
||||
|
||||
inline ostream_wrapper& operator << (ostream_wrapper& out, const Indentation& indent) {
|
||||
inline ostream& operator << (ostream& out, const Indentation& indent) {
|
||||
for(unsigned i=0;i<indent.n;i++)
|
||||
out << ' ';
|
||||
return out;
|
||||
@@ -27,7 +27,7 @@ namespace YAML
|
||||
unsigned n;
|
||||
};
|
||||
|
||||
inline ostream_wrapper& operator << (ostream_wrapper& out, const IndentTo& indent) {
|
||||
inline ostream& operator << (ostream& out, const IndentTo& indent) {
|
||||
while(out.col() < indent.n)
|
||||
out << ' ';
|
||||
return out;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include "nodebuilder.h"
|
||||
#include "nodeevents.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Node Clone(const Node& node)
|
||||
{
|
||||
NodeEvents events(node);
|
||||
NodeBuilder builder;
|
||||
events.Emit(builder);
|
||||
return builder.Root();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "yaml-cpp/ostream.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
|
||||
{
|
||||
reserve(1024);
|
||||
}
|
||||
|
||||
ostream::~ostream()
|
||||
{
|
||||
delete [] m_buffer;
|
||||
}
|
||||
|
||||
void ostream::reserve(unsigned size)
|
||||
{
|
||||
if(size <= m_size)
|
||||
return;
|
||||
|
||||
char *newBuffer = new char[size];
|
||||
std::memset(newBuffer, 0, size * sizeof(char));
|
||||
std::memcpy(newBuffer, m_buffer, m_size * sizeof(char));
|
||||
delete [] m_buffer;
|
||||
m_buffer = newBuffer;
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void ostream::put(char ch)
|
||||
{
|
||||
if(m_pos >= m_size - 1) // an extra space for the NULL terminator
|
||||
reserve(m_size * 2);
|
||||
|
||||
m_buffer[m_pos] = ch;
|
||||
m_pos++;
|
||||
|
||||
if(ch == '\n') {
|
||||
m_row++;
|
||||
m_col = 0;
|
||||
} else
|
||||
m_col++;
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& out, const char *str)
|
||||
{
|
||||
std::size_t length = std::strlen(str);
|
||||
for(std::size_t i=0;i<length;i++)
|
||||
out.put(str[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& out, const std::string& str)
|
||||
{
|
||||
out << str.c_str();
|
||||
return out;
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& out, char ch)
|
||||
{
|
||||
out.put(ch);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
ostream_wrapper::ostream_wrapper(): m_pStream(0), m_pos(0), m_row(0), m_col(0), 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)
|
||||
{
|
||||
}
|
||||
|
||||
ostream_wrapper::~ostream_wrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void ostream_wrapper::write(const std::string& str)
|
||||
{
|
||||
if(m_pStream) {
|
||||
m_pStream->write(str.c_str(), str.size());
|
||||
} else {
|
||||
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
|
||||
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
|
||||
}
|
||||
|
||||
for(std::size_t i=0;i<str.size();i++)
|
||||
update_pos(str[i]);
|
||||
}
|
||||
|
||||
void ostream_wrapper::write(const char *str, std::size_t size)
|
||||
{
|
||||
if(m_pStream) {
|
||||
m_pStream->write(str, size);
|
||||
} else {
|
||||
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
|
||||
std::copy(str, str + size, &m_buffer[m_pos]);
|
||||
}
|
||||
|
||||
for(std::size_t i=0;i<size;i++)
|
||||
update_pos(str[i]);
|
||||
}
|
||||
|
||||
void ostream_wrapper::update_pos(char ch)
|
||||
{
|
||||
m_pos++;
|
||||
m_col++;
|
||||
|
||||
if(ch == '\n') {
|
||||
m_row++;
|
||||
m_col = 0;
|
||||
m_comment = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,6 @@ namespace YAML
|
||||
|
||||
Node LoadFile(const std::string& filename) {
|
||||
std::ifstream fin(filename.c_str());
|
||||
if(!fin)
|
||||
throw BadFile();
|
||||
return Load(fin);
|
||||
}
|
||||
|
||||
@@ -61,8 +59,6 @@ namespace YAML
|
||||
|
||||
std::vector<Node> LoadAllFromFile(const std::string& filename) {
|
||||
std::ifstream fin(filename.c_str());
|
||||
if(!fin)
|
||||
throw BadFile();
|
||||
return LoadAll(fin);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -38,10 +38,7 @@ public:
|
||||
}
|
||||
T& top() { return *m_data.back(); }
|
||||
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); }
|
||||
|
||||
|
||||
private:
|
||||
std::vector<T*> m_data;
|
||||
};
|
||||
|
||||
+1
-8
@@ -51,13 +51,6 @@ namespace YAML
|
||||
return m_tokens.front();
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -383,7 +376,7 @@ namespace YAML
|
||||
// . Does not parse any more tokens.
|
||||
void Scanner::ThrowParserException(const std::string& msg) const
|
||||
{
|
||||
Mark mark = Mark::null_mark();
|
||||
Mark mark = Mark::null();
|
||||
if(!m_tokens.empty()) {
|
||||
const Token& token = m_tokens.front();
|
||||
mark = token.mark;
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace YAML
|
||||
bool empty();
|
||||
void pop();
|
||||
Token& peek();
|
||||
Mark mark() const;
|
||||
|
||||
private:
|
||||
struct IndentMarker {
|
||||
|
||||
+6
-12
@@ -48,7 +48,7 @@ namespace YAML
|
||||
{
|
||||
// an empty node *is* a possibility
|
||||
if(m_scanner.empty()) {
|
||||
eventHandler.OnNull(m_scanner.mark(), NullAnchor);
|
||||
eventHandler.OnNull(Mark::null(), NullAnchor);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace YAML
|
||||
|
||||
// special case: a value node by itself must be a map, with no header
|
||||
if(m_scanner.peek().type == Token::VALUE) {
|
||||
eventHandler.OnMapStart(mark, "?", NullAnchor);
|
||||
eventHandler.OnMapStart(mark, "", NullAnchor);
|
||||
HandleMap(eventHandler);
|
||||
eventHandler.OnMapEnd();
|
||||
return;
|
||||
@@ -136,7 +136,7 @@ namespace YAML
|
||||
|
||||
while(1) {
|
||||
if(m_scanner.empty())
|
||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
|
||||
throw ParserException(Mark::null(), ErrorMsg::END_OF_SEQ);
|
||||
|
||||
Token token = m_scanner.peek();
|
||||
if(token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
|
||||
@@ -169,7 +169,7 @@ namespace YAML
|
||||
|
||||
while(1) {
|
||||
if(m_scanner.empty())
|
||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
|
||||
throw ParserException(Mark::null(), ErrorMsg::END_OF_SEQ_FLOW);
|
||||
|
||||
// first check for end
|
||||
if(m_scanner.peek().type == Token::FLOW_SEQ_END) {
|
||||
@@ -179,9 +179,6 @@ namespace YAML
|
||||
|
||||
// then read the node
|
||||
HandleNode(eventHandler);
|
||||
|
||||
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)
|
||||
Token& token = m_scanner.peek();
|
||||
@@ -214,7 +211,7 @@ namespace YAML
|
||||
|
||||
while(1) {
|
||||
if(m_scanner.empty())
|
||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP);
|
||||
throw ParserException(Mark::null(), ErrorMsg::END_OF_MAP);
|
||||
|
||||
Token token = m_scanner.peek();
|
||||
if(token.type != Token::KEY && token.type != Token::VALUE && token.type != Token::BLOCK_MAP_END)
|
||||
@@ -253,7 +250,7 @@ namespace YAML
|
||||
|
||||
while(1) {
|
||||
if(m_scanner.empty())
|
||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
|
||||
throw ParserException(Mark::null(), ErrorMsg::END_OF_MAP_FLOW);
|
||||
|
||||
Token& token = m_scanner.peek();
|
||||
// first check for end
|
||||
@@ -277,9 +274,6 @@ namespace YAML
|
||||
} else {
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
}
|
||||
|
||||
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)
|
||||
Token& nextToken = m_scanner.peek();
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#include "parsertests.h"
|
||||
#include "handlermacros.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace Test
|
||||
{
|
||||
namespace Parser {
|
||||
TEST NoEndOfMapFlow()
|
||||
{
|
||||
try {
|
||||
HANDLE("---{header: {id: 1");
|
||||
} 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()
|
||||
{
|
||||
HANDLE("foo: ?bar");
|
||||
EXPECT_DOC_START();
|
||||
EXPECT_MAP_START("?", 0);
|
||||
EXPECT_SCALAR("?", 0, "foo");
|
||||
EXPECT_SCALAR("?", 0, "?bar");
|
||||
EXPECT_MAP_END();
|
||||
EXPECT_DOC_END();
|
||||
DONE();
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||
TEST ret;
|
||||
try {
|
||||
ret = test();
|
||||
} catch(const YAML::Exception& e) {
|
||||
ret.ok = false;
|
||||
ret.error = std::string(" Exception caught: ") + e.what();
|
||||
}
|
||||
|
||||
if(!ret.ok) {
|
||||
std::cout << "Parser test failed: " << name << "\n";
|
||||
std::cout << ret.error << "\n";
|
||||
}
|
||||
|
||||
if(ret.ok)
|
||||
passed++;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,184 +0,0 @@
|
||||
import sys
|
||||
import yaml
|
||||
import hashlib
|
||||
|
||||
NS = 'Emitter'
|
||||
DEFINE = 'YAML_GEN_TESTS'
|
||||
EVENT_COUNT = 5
|
||||
|
||||
def encode_stream(line):
|
||||
for c in line:
|
||||
if c == '\n':
|
||||
yield '\\n'
|
||||
elif c == '"':
|
||||
yield '\\"'
|
||||
elif c == '\t':
|
||||
yield '\\t'
|
||||
elif ord(c) < 0x20:
|
||||
yield '\\x' + hex(ord(c))
|
||||
else:
|
||||
yield c
|
||||
|
||||
def encode(line):
|
||||
return ''.join(encode_stream(line))
|
||||
|
||||
def doc_start(implicit=False):
|
||||
if implicit:
|
||||
return {'emit': '', 'handle': 'DOC_START()'}
|
||||
else:
|
||||
return {'emit': 'YAML::BeginDoc', 'handle': 'DOC_START()'}
|
||||
|
||||
def doc_end(implicit=False):
|
||||
if implicit:
|
||||
return {'emit': '', 'handle': 'DOC_END()'}
|
||||
else:
|
||||
return {'emit': 'YAML::EndDoc', 'handle': 'DOC_END()'}
|
||||
|
||||
def scalar(value, tag='', anchor='', anchor_id=0):
|
||||
emit = []
|
||||
if tag:
|
||||
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['YAML::Anchor("%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
if value == encode(value):
|
||||
out_tag = '?'
|
||||
else:
|
||||
out_tag = '!'
|
||||
emit += ['"%s"' % encode(value)]
|
||||
return {'emit': emit, 'handle': 'SCALAR("%s", %s, "%s")' % (out_tag, anchor_id, encode(value))}
|
||||
|
||||
def comment(value):
|
||||
return {'emit': 'YAML::Comment("%s")' % value, 'handle': ''}
|
||||
|
||||
def seq_start(tag='', anchor='', anchor_id=0):
|
||||
emit = []
|
||||
if tag:
|
||||
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['YAML::Anchor("%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
out_tag = '?'
|
||||
emit += ['YAML::BeginSeq']
|
||||
return {'emit': emit, 'handle': 'SEQ_START("%s", %s)' % (out_tag, anchor_id)}
|
||||
|
||||
def seq_end():
|
||||
return {'emit': 'YAML::EndSeq', 'handle': 'SEQ_END()'}
|
||||
|
||||
def map_start(tag='', anchor='', anchor_id=0):
|
||||
emit = []
|
||||
if tag:
|
||||
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['YAML::Anchor("%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
out_tag = '?'
|
||||
emit += ['YAML::BeginMap']
|
||||
return {'emit': emit, 'handle': 'MAP_START("%s", %s)' % (out_tag, anchor_id)}
|
||||
|
||||
def map_end():
|
||||
return {'emit': 'YAML::EndMap', 'handle': 'MAP_END()'}
|
||||
|
||||
def gen_templates():
|
||||
yield [[doc_start(), doc_start(True)],
|
||||
[scalar('foo'), scalar('foo\n'), scalar('foo', 'tag'), scalar('foo', '', 'anchor', 1)],
|
||||
[doc_end(), doc_end(True)]]
|
||||
yield [[doc_start(), doc_start(True)],
|
||||
[seq_start()],
|
||||
[[], [scalar('foo')], [scalar('foo', 'tag')], [scalar('foo', '', 'anchor', 1)], [scalar('foo', 'tag', 'anchor', 1)], [scalar('foo'), scalar('bar')], [scalar('foo', 'tag', 'anchor', 1), scalar('bar', 'tag', 'other', 2)]],
|
||||
[seq_end()],
|
||||
[doc_end(), doc_end(True)]]
|
||||
yield [[doc_start(), doc_start(True)],
|
||||
[map_start()],
|
||||
[[], [scalar('foo'), scalar('bar')], [scalar('foo', 'tag', 'anchor', 1), scalar('bar', 'tag', 'other', 2)]],
|
||||
[map_end()],
|
||||
[doc_end(), doc_end(True)]]
|
||||
yield [[doc_start(True)],
|
||||
[map_start()],
|
||||
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
|
||||
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
|
||||
[map_end()],
|
||||
[doc_end(True)]]
|
||||
yield [[doc_start(True)],
|
||||
[seq_start()],
|
||||
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
|
||||
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
|
||||
[seq_end()],
|
||||
[doc_end(True)]]
|
||||
|
||||
def expand(template):
|
||||
if len(template) == 0:
|
||||
pass
|
||||
elif len(template) == 1:
|
||||
for item in template[0]:
|
||||
if isinstance(item, list):
|
||||
yield item
|
||||
else:
|
||||
yield [item]
|
||||
else:
|
||||
for car in expand(template[:1]):
|
||||
for cdr in expand(template[1:]):
|
||||
yield car + cdr
|
||||
|
||||
|
||||
def gen_events():
|
||||
for template in gen_templates():
|
||||
for events in expand(template):
|
||||
base = list(events)
|
||||
for i in range(0, len(base)+1):
|
||||
cpy = list(base)
|
||||
cpy.insert(i, comment('comment'))
|
||||
yield cpy
|
||||
|
||||
def gen_tests():
|
||||
for events in gen_events():
|
||||
name = 'test' + hashlib.sha1(''.join(yaml.dump(event) for event in events)).hexdigest()[:20]
|
||||
yield {'name': name, 'events': events}
|
||||
|
||||
|
||||
def create_emitter_tests(out):
|
||||
out.write('#ifdef %s\n' % DEFINE)
|
||||
out.write('namespace %s {\n' % NS)
|
||||
|
||||
tests = list(gen_tests())
|
||||
|
||||
for test in tests:
|
||||
out.write('TEST %s(YAML::Emitter& out)\n' % test['name'])
|
||||
out.write('{\n')
|
||||
for event in test['events']:
|
||||
emit = event['emit']
|
||||
if isinstance(emit, list):
|
||||
for e in emit:
|
||||
out.write(' out << %s;\n' % e)
|
||||
elif emit:
|
||||
out.write(' out << %s;\n' % emit)
|
||||
out.write('\n')
|
||||
out.write(' HANDLE(out.c_str());\n')
|
||||
for event in test['events']:
|
||||
handle = event['handle']
|
||||
if handle:
|
||||
out.write(' EXPECT_%s;\n' % handle)
|
||||
out.write(' DONE();\n')
|
||||
out.write('}\n')
|
||||
|
||||
out.write('}\n')
|
||||
out.write('#endif // %s\n\n' % DEFINE)
|
||||
|
||||
out.write('void RunGenEmitterTests(int& passed, int& total)\n')
|
||||
out.write('{\n')
|
||||
out.write('#ifdef %s\n' % DEFINE)
|
||||
for test in tests:
|
||||
out.write(' RunGenEmitterTest(&Emitter::%s, "%s", passed, total);\n' % (test['name'], encode(test['name'])))
|
||||
out.write('#else // %s\n' % DEFINE)
|
||||
out.write(' (void)passed; (void)total;\n')
|
||||
out.write('#endif // %s\n' % DEFINE)
|
||||
out.write('}\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_emitter_tests(sys.stdout)
|
||||
+62
-81
@@ -1,5 +1,4 @@
|
||||
#include "tests.h"
|
||||
#include "handlermacros.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -191,7 +190,7 @@ namespace Test
|
||||
out << YAML::Value << "demon";
|
||||
out << YAML::EndMap;
|
||||
|
||||
desiredOutput = "? - 1\n - 3\n: monster\n? [2, 0]\n: demon";
|
||||
desiredOutput = "?\n - 1\n - 3\n: monster\n? [2, 0]\n: demon";
|
||||
}
|
||||
|
||||
void AutoLongKey(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -205,7 +204,7 @@ namespace Test
|
||||
out << YAML::Value << "angel";
|
||||
out << YAML::EndMap;
|
||||
|
||||
desiredOutput = "? - 1\n - 3\n: monster\n[2, 0]: demon\nthe origin: angel";
|
||||
desiredOutput = "?\n - 1\n - 3\n: monster\n? [2, 0]\n: demon\nthe origin: angel";
|
||||
}
|
||||
|
||||
void ScalarFormat(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -219,7 +218,7 @@ namespace Test
|
||||
out << YAML::Literal << "literal scalar\nthat may span\nmany, many\nlines and have \"whatever\" crazy\tsymbols that we like";
|
||||
out << YAML::EndSeq;
|
||||
|
||||
desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n that may span\n many, many\n lines and have \"whatever\" crazy\tsymbols that we like";
|
||||
desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\x0adouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n that may span\n many, many\n lines and have \"whatever\" crazy\tsymbols that we like";
|
||||
}
|
||||
|
||||
void AutoLongKeyScalar(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -257,7 +256,7 @@ namespace Test
|
||||
out << "total value";
|
||||
out << YAML::EndMap;
|
||||
|
||||
desiredOutput = "? key: value\n next key: next value\n: total value";
|
||||
desiredOutput = "?\n key: value\n next key: next value\n: total value";
|
||||
}
|
||||
|
||||
void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -540,7 +539,7 @@ namespace Test
|
||||
{
|
||||
out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar" << YAML::EndSeq;
|
||||
|
||||
desiredOutput = "[foo, # foo!\nbar]";
|
||||
desiredOutput = "[foo # foo!\n, bar]";
|
||||
}
|
||||
|
||||
void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -551,7 +550,7 @@ namespace Test
|
||||
out << YAML::Key << "baz" << YAML::Value << "baz value" << YAML::Comment("baz!");
|
||||
out << YAML::EndMap;
|
||||
|
||||
desiredOutput = "{foo: foo value, bar: bar value, # bar!\nbaz: baz value, # baz!\n}";
|
||||
desiredOutput = "{foo: foo value, bar: bar value # bar!\n, baz: baz value # baz!\n}";
|
||||
}
|
||||
|
||||
void Indentation(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -564,7 +563,7 @@ namespace Test
|
||||
out << YAML::EndMap;
|
||||
out << YAML::EndSeq;
|
||||
|
||||
desiredOutput = "- key 1: value 1\n key 2:\n - a\n - b\n - c";
|
||||
desiredOutput = "- key 1: value 1\n key 2:\n - a\n - b\n - c";
|
||||
}
|
||||
|
||||
void SimpleGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -598,7 +597,7 @@ namespace Test
|
||||
out << YAML::EndMap;
|
||||
out << YAML::EndSeq;
|
||||
|
||||
desiredOutput = "- key 1: value 1\n key 2: [a, b, c]\n- [1, 2]:\n a: b";
|
||||
desiredOutput = "- key 1: value 1\n key 2: [a, b, c]\n- ? [1, 2]\n :\n a: b";
|
||||
}
|
||||
|
||||
void Null(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -721,7 +720,7 @@ namespace Test
|
||||
out << YAML::Flow << YAML::BeginSeq;
|
||||
out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
|
||||
out << YAML::EndSeq;
|
||||
desiredOutput = "[a,\nb, c,\nd]";
|
||||
desiredOutput = "[a\n, b, c\n, d]";
|
||||
}
|
||||
|
||||
void NewlineInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -731,7 +730,7 @@ namespace Test
|
||||
out << YAML::Key << "b" << YAML::Newline << YAML::Value << "bar";
|
||||
out << YAML::LongKey << YAML::Key << "c" << YAML::Newline << YAML::Value << "car";
|
||||
out << YAML::EndMap;
|
||||
desiredOutput = "a: foo\nb:\n bar\n? c\n\n: car";
|
||||
desiredOutput = "a: foo\n\nb: bar\n? c\n\n: car";
|
||||
}
|
||||
|
||||
void NewlineInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -740,7 +739,7 @@ namespace Test
|
||||
out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
|
||||
out << YAML::Key << "b" << YAML::Value << "bar";
|
||||
out << YAML::EndMap;
|
||||
desiredOutput = "{a: foo,\nb: bar}";
|
||||
desiredOutput = "{a: foo\n, b: bar}";
|
||||
}
|
||||
|
||||
void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -756,7 +755,7 @@ namespace Test
|
||||
out << YAML::LongKey << YAML::Key << "f" << YAML::Newline << YAML::Value << "foo";
|
||||
out << YAML::EndMap;
|
||||
out << YAML::EndSeq;
|
||||
desiredOutput = "- a\n\n-\n - b\n - c\n\n\n-\n d:\n e\n ? f\n\n : foo";
|
||||
desiredOutput = "- a\n\n-\n - b\n - c\n\n\n-\n d: e\n ? f\n\n : foo";
|
||||
}
|
||||
|
||||
void Binary(YAML::Emitter& out, std::string& desiredOutput)
|
||||
@@ -912,40 +911,7 @@ namespace Test
|
||||
desiredOutput = "[31, 0x1f, 037]";
|
||||
}
|
||||
|
||||
void CompactMapWithNewline(YAML::Emitter& out, std::string& desiredOutput)
|
||||
{
|
||||
out << YAML::Comment("Characteristics");
|
||||
out << YAML::BeginSeq;
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "color" << YAML::Value << "blue";
|
||||
out << YAML::Key << "height" << YAML::Value << 120;
|
||||
out << YAML::EndMap;
|
||||
out << YAML::Newline << YAML::Newline;
|
||||
out << YAML::Comment("Skills");
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "attack" << YAML::Value << 23;
|
||||
out << YAML::Key << "intelligence" << YAML::Value << 56;
|
||||
out << YAML::EndMap;
|
||||
out << YAML::EndSeq;
|
||||
|
||||
desiredOutput =
|
||||
"# Characteristics\n"
|
||||
"- color: blue\n"
|
||||
" height: 120\n"
|
||||
"\n"
|
||||
"# Skills\n"
|
||||
"- attack: 23\n"
|
||||
" intelligence: 56";
|
||||
}
|
||||
|
||||
void ForceSingleQuotedToDouble(YAML::Emitter& out, std::string& desiredOutput)
|
||||
{
|
||||
out << YAML::SingleQuoted << "Hello\nWorld";
|
||||
|
||||
desiredOutput = "\"Hello\\nWorld\"";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// incorrect emitting
|
||||
|
||||
void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError)
|
||||
@@ -969,6 +935,13 @@ namespace Test
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
void BadSingleQuoted(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::SINGLE_QUOTED_CHAR;
|
||||
|
||||
out << YAML::SingleQuoted << "Hello\nWorld";
|
||||
}
|
||||
|
||||
void InvalidAnchor(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::INVALID_ANCHOR;
|
||||
@@ -986,6 +959,43 @@ namespace Test
|
||||
out << YAML::Alias("new\nline");
|
||||
out << YAML::EndSeq;
|
||||
}
|
||||
|
||||
void MissingKey(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::EXPECTED_KEY_TOKEN;
|
||||
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "key" << YAML::Value << "value";
|
||||
out << "missing key" << YAML::Value << "value";
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
void MissingValue(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::EXPECTED_VALUE_TOKEN;
|
||||
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "key" << "value";
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
void UnexpectedKey(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::UNEXPECTED_KEY_TOKEN;
|
||||
|
||||
out << YAML::BeginSeq;
|
||||
out << YAML::Key << "hi";
|
||||
out << YAML::EndSeq;
|
||||
}
|
||||
|
||||
void UnexpectedValue(YAML::Emitter& out, std::string& desiredError)
|
||||
{
|
||||
desiredError = YAML::ErrorMsg::UNEXPECTED_VALUE_TOKEN;
|
||||
|
||||
out << YAML::BeginSeq;
|
||||
out << YAML::Value << "hi";
|
||||
out << YAML::EndSeq;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -1033,37 +1043,7 @@ namespace Test
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name, int& passed, int& total) {
|
||||
YAML::Emitter out;
|
||||
TEST ret;
|
||||
|
||||
try {
|
||||
ret = test(out);
|
||||
} catch(const YAML::Exception& e) {
|
||||
ret.ok = false;
|
||||
ret.error = std::string(" Exception caught: ") + e.what();
|
||||
}
|
||||
|
||||
if(!out.good()) {
|
||||
ret.ok = false;
|
||||
ret.error = out.GetLastError();
|
||||
}
|
||||
|
||||
if(!ret.ok) {
|
||||
std::cout << "Generated emitter test failed: " << name << "\n";
|
||||
std::cout << "Output:\n";
|
||||
std::cout << out.c_str() << "<<<\n";
|
||||
std::cout << ret.error << "\n";
|
||||
}
|
||||
|
||||
if(ret.ok)
|
||||
passed++;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
#include "genemittertests.h"
|
||||
|
||||
bool RunEmitterTests()
|
||||
{
|
||||
@@ -1146,16 +1126,17 @@ namespace Test
|
||||
RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
|
||||
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
|
||||
RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
|
||||
RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total);
|
||||
RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total);
|
||||
|
||||
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::BadSingleQuoted, "bad single quoted string", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::InvalidAnchor, "invalid anchor", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::MissingKey, "missing key", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::MissingValue, "missing value", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::UnexpectedKey, "unexpected key", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::UnexpectedValue, "unexpected value", passed, total);
|
||||
RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
|
||||
|
||||
RunGenEmitterTests(passed, total);
|
||||
|
||||
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
|
||||
-10256
File diff suppressed because it is too large
Load Diff
@@ -1,190 +0,0 @@
|
||||
#include "teststruct.h"
|
||||
#pragma once
|
||||
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
namespace Test {
|
||||
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 };
|
||||
|
||||
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_) {}
|
||||
|
||||
Type type;
|
||||
std::string tag;
|
||||
anchor_t anchor;
|
||||
std::string scalar;
|
||||
|
||||
std::ostream& write(std::ostream& out) const {
|
||||
switch(type) {
|
||||
case DocStart:
|
||||
return out << "DocStart";
|
||||
case DocEnd:
|
||||
return out << "DocEnd";
|
||||
case Null:
|
||||
return out << "Null(" << anchor << ")";
|
||||
case Alias:
|
||||
return out << "Alias(" << anchor << ")";
|
||||
case Scalar:
|
||||
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", " << Quote(scalar) << ")";
|
||||
case SeqStart:
|
||||
return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")";
|
||||
case SeqEnd:
|
||||
return out << "SeqEnd";
|
||||
case MapStart:
|
||||
return out << "MapStart(" << Quote(tag) << ", " << anchor << ")";
|
||||
case MapEnd:
|
||||
return out << "MapEnd";
|
||||
}
|
||||
assert(false);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
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 == b);
|
||||
}
|
||||
|
||||
class MockEventHandler: public YAML::EventHandler
|
||||
{
|
||||
public:
|
||||
typedef YAML::Mark Mark;
|
||||
typedef YAML::anchor_t anchor_t;
|
||||
|
||||
MockEventHandler() {}
|
||||
|
||||
virtual void OnDocumentStart(const Mark&) {
|
||||
m_actualEvents.push_back(Event(Event::DocStart, "", 0, ""));
|
||||
}
|
||||
|
||||
virtual void OnDocumentEnd() {
|
||||
m_actualEvents.push_back(Event(Event::DocEnd, "", 0, ""));
|
||||
}
|
||||
|
||||
virtual void OnNull(const Mark&, anchor_t anchor) {
|
||||
m_actualEvents.push_back(Event(Event::Null, "", anchor, ""));
|
||||
}
|
||||
|
||||
virtual void OnAlias(const Mark&, anchor_t anchor) {
|
||||
m_actualEvents.push_back(Event(Event::Alias, "", anchor, ""));
|
||||
}
|
||||
|
||||
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) {
|
||||
m_actualEvents.push_back(Event(Event::SeqStart, tag, anchor, ""));
|
||||
}
|
||||
|
||||
virtual void OnSequenceEnd() {
|
||||
m_actualEvents.push_back(Event(Event::SeqEnd, "", 0, ""));
|
||||
}
|
||||
|
||||
virtual void OnMapStart(const Mark&, const std::string& tag, anchor_t anchor) {
|
||||
m_actualEvents.push_back(Event(Event::MapStart, tag, anchor, ""));
|
||||
}
|
||||
|
||||
virtual void OnMapEnd() {
|
||||
m_actualEvents.push_back(Event(Event::MapEnd, "", 0, ""));
|
||||
}
|
||||
|
||||
void Expect(const Event& event) { m_expectedEvents.push_back(event); }
|
||||
|
||||
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()) {
|
||||
std::stringstream out;
|
||||
for(std::size_t j=0;j<i;j++) {
|
||||
out << " " << m_expectedEvents[j] << "\n";
|
||||
}
|
||||
out << " EXPECTED: (no event expected)\n";
|
||||
out << " ACTUAL : " << m_actualEvents[i] << "\n";
|
||||
return out.str().c_str();
|
||||
}
|
||||
|
||||
if(i >= m_actualEvents.size()) {
|
||||
std::stringstream out;
|
||||
for(std::size_t j=0;j<i;j++) {
|
||||
out << " " << m_expectedEvents[j] << "\n";
|
||||
}
|
||||
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
|
||||
out << " ACTUAL : (no event recorded)\n";
|
||||
return out.str().c_str();
|
||||
}
|
||||
|
||||
if(m_expectedEvents[i] != m_actualEvents[i]) {
|
||||
std::stringstream out;
|
||||
for(std::size_t j=0;j<i;j++) {
|
||||
out << " " << m_expectedEvents[j] << "\n";
|
||||
}
|
||||
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
|
||||
out << " ACTUAL : " << m_actualEvents[i] << "\n";
|
||||
return out.str().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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 EXPECT_DOC_START()\
|
||||
handler.Expect(Event(Event::DocStart, "", 0, ""))
|
||||
|
||||
#define EXPECT_DOC_END()\
|
||||
handler.Expect(Event(Event::DocEnd, "", 0, ""))
|
||||
|
||||
#define EXPECT_NULL(anchor)\
|
||||
handler.Expect(Event(Event::Null, "", 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_SEQ_START(tag, anchor)\
|
||||
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
|
||||
|
||||
#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_END()\
|
||||
handler.Expect(Event(Event::MapEnd, "", 0, ""))
|
||||
|
||||
#define DONE()\
|
||||
return handler.Check()
|
||||
|
||||
}
|
||||
@@ -373,86 +373,7 @@ namespace Test
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST CloneScalar()
|
||||
{
|
||||
YAML::Node node = YAML::Load("!foo monkey");
|
||||
YAML::Node clone = Clone(node);
|
||||
YAML_ASSERT(!(node == clone));
|
||||
YAML_ASSERT(node.as<std::string>() == clone.as<std::string>());
|
||||
YAML_ASSERT(node.Tag() == clone.Tag());
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST CloneSeq()
|
||||
{
|
||||
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
|
||||
YAML::Node clone = Clone(node);
|
||||
YAML_ASSERT(!(node == clone));
|
||||
YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
|
||||
YAML_ASSERT(node.size() == clone.size());
|
||||
for(std::size_t i=0;i<node.size();i++)
|
||||
YAML_ASSERT(node[i].as<int>() == clone[i].as<int>());
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST CloneMap()
|
||||
{
|
||||
YAML::Node node = YAML::Load("{foo: bar}");
|
||||
YAML::Node clone = Clone(node);
|
||||
YAML_ASSERT(!(node == clone));
|
||||
YAML_ASSERT(clone.Type() == YAML::NodeType::Map);
|
||||
YAML_ASSERT(node.size() == clone.size());
|
||||
YAML_ASSERT(node["foo"].as<std::string>() == clone["foo"].as<std::string>());
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST CloneAlias()
|
||||
{
|
||||
YAML::Node node = YAML::Load("&foo [*foo]");
|
||||
YAML::Node clone = Clone(node);
|
||||
YAML_ASSERT(!(node == clone));
|
||||
YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
|
||||
YAML_ASSERT(node.size() == clone.size());
|
||||
YAML_ASSERT(clone == clone[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST ForceInsertIntoMap()
|
||||
{
|
||||
YAML::Node node;
|
||||
node["a"] = "b";
|
||||
node.force_insert("x", "y");
|
||||
node.force_insert("a", 5);
|
||||
YAML_ASSERT(node.size() == 3);
|
||||
YAML_ASSERT(node.Type() == YAML::NodeType::Map);
|
||||
bool ab = false;
|
||||
bool a5 = false;
|
||||
bool xy = false;
|
||||
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
|
||||
if(it->first.as<std::string>() == "a") {
|
||||
if(it->second.as<std::string>() == "b")
|
||||
ab = true;
|
||||
else if(it->second.as<std::string>() == "5")
|
||||
a5 = true;
|
||||
} else if(it->first.as<std::string>() == "x" && it->second.as<std::string>() == "y")
|
||||
xy = true;
|
||||
}
|
||||
YAML_ASSERT(ab);
|
||||
YAML_ASSERT(a5);
|
||||
YAML_ASSERT(xy);
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST ClearNode()
|
||||
{
|
||||
YAML::Node node = YAML::Load("[1, 2, 3]");
|
||||
YAML_ASSERT(!node.IsNull());
|
||||
node.clear();
|
||||
YAML_ASSERT(node.IsNull());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||
TEST ret;
|
||||
@@ -505,12 +426,6 @@ namespace Test
|
||||
RunNodeTest(&Node::IterateMap, "iterate map", passed, total);
|
||||
RunNodeTest(&Node::ForEach, "for each", passed, total);
|
||||
RunNodeTest(&Node::ForEachMap, "for each map", passed, total);
|
||||
RunNodeTest(&Node::CloneScalar, "clone scalar", passed, total);
|
||||
RunNodeTest(&Node::CloneSeq, "clone seq", passed, total);
|
||||
RunNodeTest(&Node::CloneMap, "clone map", passed, total);
|
||||
RunNodeTest(&Node::CloneAlias, "clone alias", passed, total);
|
||||
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
|
||||
RunNodeTest(&Node::ClearNode, "clear node", passed, total);
|
||||
|
||||
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
|
||||
+10
-1
@@ -5,9 +5,18 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "teststruct.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
namespace Spec {
|
||||
// 2.1
|
||||
TEST SeqScalars();
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#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_) {}
|
||||
|
||||
bool ok;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,8 +1,2 @@
|
||||
add_executable(parse parse.cpp)
|
||||
target_link_libraries(parse yaml-cpp)
|
||||
|
||||
add_executable(sandbox sandbox.cpp)
|
||||
target_link_libraries(sandbox yaml-cpp)
|
||||
|
||||
add_executable(read read.cpp)
|
||||
target_link_libraries(read yaml-cpp)
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include <iostream>
|
||||
|
||||
class NullEventHandler: public YAML::EventHandler
|
||||
{
|
||||
public:
|
||||
typedef YAML::Mark Mark;
|
||||
typedef YAML::anchor_t anchor_t;
|
||||
|
||||
NullEventHandler() {}
|
||||
|
||||
virtual void OnDocumentStart(const Mark&) {}
|
||||
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 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()
|
||||
{
|
||||
YAML::Parser parser(std::cin);
|
||||
NullEventHandler handler;
|
||||
parser.HandleNextDocument(handler);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include <iostream>
|
||||
|
||||
class NullEventHandler: public YAML::EventHandler
|
||||
{
|
||||
public:
|
||||
typedef YAML::Mark Mark;
|
||||
typedef YAML::anchor_t anchor_t;
|
||||
|
||||
NullEventHandler() {}
|
||||
|
||||
virtual void OnDocumentStart(const Mark&) {}
|
||||
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 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()
|
||||
{
|
||||
std::stringstream stream("---{header: {id: 1");
|
||||
YAML::Parser parser(stream);
|
||||
// parser.PrintTokens(std::cout);
|
||||
NullEventHandler handler;
|
||||
parser.HandleNextDocument(handler);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user