Compare commits

...

149 Commits

Author SHA1 Message Date
Jesse Beder
572e940c83 Bumped version to 0.3.0 2012-01-21 02:51:56 -06:00
Jesse Beder
01eb370300 Added operator >> overload for Binary 2012-01-21 02:01:37 -06:00
Jesse Beder
d760d037ca Renamed the base64 methods, and switched the EncodeBase64 one to return a string (to make it easy to use elsewhere) 2012-01-21 01:33:49 -06:00
Jesse Beder
6105d4cfeb Refactored the base64 binary to its own space with a unified class that (will) be used for parsing (in addition to emitting) 2012-01-21 01:18:37 -06:00
Jesse Beder
e145488547 Added back yaml.h (since it used to be generated) 2012-01-21 00:08:35 -06:00
Jesse Beder
b688c93050 Put all the old-api stuff back in the main folder, for simplicity 2012-01-20 23:55:39 -06:00
Jesse Beder
1723523c43 Removed the new API from the default branch 2012-01-20 23:50:39 -06:00
Jesse Beder
d772361f15 Fixed hex and oct emitting (it now adds the 0x or 0 prefix) 2012-01-13 00:00:11 -06:00
Jesse Beder
a441e1a14c Added test for new API octal/hex conversion 2012-01-12 23:55:15 -06:00
Jesse Beder
fb0802097c Fixed double -> int conversion (now throws) for old API 2012-01-12 23:52:51 -06:00
Jesse Beder
643ea61a98 Updated new API conversion to handle nan/inf and to throw when the conversion didn't use the entire string (e.g., parsing 1.2 as an integer) 2012-01-12 23:49:05 -06:00
Jesse Beder
d1e4c2640c Added default parameters for the as<> function (new API) 2012-01-12 01:03:31 -06:00
Jesse Beder
ddc578dbd7 Added LoadFile and LoadAllFromFile (new API) 2012-01-11 21:31:01 -06:00
Jesse Beder
8906ae9a0d Fixed bug in parsing escaped newline (it was being clipped like a regular newline) 2012-01-11 17:55:27 -06:00
Jesse Beder
4e350e5808 Removed some extra stuff in the comment/newline in flow map tests, which really should be illegal (since implicit keys can't span multiple lines). It would be impossible to fix if we keep the immediate-output we're doing now - the only way to prevent it would be to hold on to a key's text until we got to the value token to make sure it could be an implicit key 2012-01-11 17:06:27 -06:00
Jesse Beder
7ace0e93d2 Fixed signed/unsigned mismatch with the new precision code 2012-01-11 16:50:06 -06:00
Jesse Beder
0e61ddb6d9 Added parsing emitter tests with the new API, two fail 2012-01-11 16:41:13 -06:00
Jesse Beder
97fa02a484 Disallowed a plain scalar with just a dash 2012-01-11 16:39:24 -06:00
Jesse Beder
5024caa69c Added float/double precision setters 2012-01-11 14:34:04 -06:00
Jesse Beder
21ed2b5817 Added explicit conversion from an iterator value to a Node. This conversion was always allowed (since the iterator value is derived from Node, but since Node has a templated constructor, that would take precedence over the derived-to-base conversion. This didn't seem to be a problem in gcc or clang, but MSVC seems to have trouble. (new API) 2012-01-11 13:58:18 -06:00
Jesse Beder
92a35581d7 Added boost find/includes to the new API CMake instructions 2012-01-11 13:19:31 -06:00
Jesse Beder
5b32d89222 Fixed compiler error in iterator_base friend forward declaration in node on clang (and I hope MSVC), plus warnings on clang 2012-01-07 01:42:21 -06:00
Jesse Beder
812a2dc684 Fixed assignment with an empty node (new API) - a segfault that only showed up in debuggable 2011-12-20 22:19:54 -06:00
Jesse Beder
add460947b Added overload for emitting unsigned char 2011-11-14 17:00:28 -06:00
Jesse Beder
3099d51ba4 Added single character emitting 2011-11-14 16:23:14 -06:00
Jesse Beder
6f4608ce05 Added missing includes (iostream) for the tests 2011-11-13 16:12:39 -06:00
Jesse Beder
5abfbf5aac Added (unspecified-type) bool conversions for Node (new API) 2011-11-13 16:05:42 -06:00
Jesse Beder
d78d16532a Set the default operator >> to not compile unless there is a scalar conversion, so it doesn't interfere with user-defined types 2011-11-01 17:19:03 -05:00
Jesse Beder
62634f53ec Fixed emitter bug with colon at the end of a scalar in a flow collection 2011-10-31 19:16:17 -05:00
Jesse Beder
860365b263 Switched the utf bom checking to putback in the stream (instead of keeping a secondary buffer), which fixes a bug when there's only one ascii character 2011-10-20 22:29:41 -05:00
Jesse Beder
e8e5d4bc40 Fixed typo in computing private headers (no effect on the build, just for the project files) 2011-10-20 21:50:47 -05:00
Jesse Beder
b077e8390e Added parser test for single char input (that fails) 2011-10-20 13:53:27 -05:00
Jesse Beder
c953ce0b07 Fixed broken includes when using the old api 2011-10-18 15:13:10 -05:00
Jesse Beder
f87dced5c9 Fixed installation (we now install the whole include header tree) 2011-10-18 14:55:31 -05:00
Jesse Beder
62361e6f27 Added a .hgignore file that ignores the generated yaml.h 2011-10-18 14:48:07 -05:00
Jesse Beder
70e1eb3f9c Fixed the #ifdefs for the api stuff 2011-10-18 14:47:35 -05:00
Jesse Beder
77cc54585f Couldn't get the copy command to work for yaml.h, so switched to configure_file 2011-10-18 14:43:48 -05:00
Jesse Beder
e69f51ee16 Split the yaml.h file into new/old API, which we'll then copy to yaml.h at build time (so the right one gets installed) 2011-10-18 00:16:51 -05:00
Jesse Beder
ee795d7e3e Merged with the main branch, which just updated version count to 0.2.7 2011-09-18 00:26:18 -05:00
Jesse Beder
f6d6c90aa9 Updated old api spectests with common spec examples 2011-09-17 23:57:40 -05:00
Jesse Beder
d9c7bcf32f Set the default build to the old API, and removed the duplicate spec test implementation for the old api 2011-09-17 23:46:48 -05:00
Jesse Beder
f3b230693a Moved conversion.cpp to the old api, where it belongs 2011-09-14 01:49:06 -05:00
Jesse Beder
f64f619c29 Added bool conversions 2011-09-14 01:48:36 -05:00
Jesse Beder
8e5fc0e304 Added tag release-0.2.7 for changeset d0bed6918076 2011-09-14 01:23:25 -05:00
Jesse Beder
976e8b184c Bumped version to 0.2.7 2011-09-14 01:23:15 -05:00
Jesse Beder
e5d0366797 Added Dump() 2011-09-13 14:49:00 -05:00
Jesse Beder
c3798d9bd4 Added tags to Node emitter output 2011-09-13 14:47:33 -05:00
Jesse Beder
40c47f6312 Finished adding old spec tests 2011-09-13 14:31:00 -05:00
Jesse Beder
e3d5ec189d Switched YAML::Parse to YAML::Load, and added LoadAll 2011-09-13 14:24:47 -05:00
Jesse Beder
5be19ccbfd Added 7.x and 8.x tests with tags - all that's left is multiple docs in stream 2011-09-13 14:20:32 -05:00
Jesse Beder
98830a4a15 Added 6.x tests with tags 2011-09-13 14:18:00 -05:00
Jesse Beder
3a88c4b4a1 Added IsNull, IsScalar, IsSequence, IsMap functions, so you don't have to query Type() 2011-09-13 14:10:27 -05:00
Jesse Beder
69af9b420a Copied 2.x tests with tags 2011-09-13 14:07:22 -05:00
Jesse Beder
0987b234c3 Added tags to Node 2011-09-13 14:00:47 -05:00
Jesse Beder
2dfccbb945 Added a convert<> specialization for YAML::_Null (so you can say node[YAML::Null]) 2011-09-13 02:03:56 -05:00
Jesse Beder
a9be4849d8 Copied over the 8.x tests that don't have tags 2011-09-13 01:56:44 -05:00
Jesse Beder
b1100d7c54 Copied over the 7.x tests that don't have tags 2011-09-13 01:46:42 -05:00
Jesse Beder
64e381f2c1 Copied over the 6.x tests that don't have tags 2011-09-13 01:36:27 -05:00
Jesse Beder
f6b728d56c Copied over the 5.x tests 2011-09-13 01:28:32 -05:00
Jesse Beder
edd6650536 Copied over all the 2.x tests that are (a) single doc and (b) don't have tags 2011-09-13 01:23:30 -05:00
Jesse Beder
a04dfdeb07 Factored out spec examples, and sketched skeleton for spec tests for new API 2011-09-12 22:55:37 -05:00
Jesse Beder
1721750d9e Added temp variable tests 2011-09-12 22:09:16 -05:00
Jesse Beder
a8f82af604 Switched Node::operator=(const Node&) to *not* force itself to create its node first (since we're just assigning them) 2011-09-12 22:05:43 -05:00
Jesse Beder
0c321a6dc6 Switched the node_ref to *always* create its data (since now the Node itself doesn't always create itself) 2011-09-12 22:03:11 -05:00
Jesse Beder
08b3ddfd3e Set the pimpl node in Node to be optional, so we don't create unnecessary guys every time you call Node tmp = foo[value]; 2011-09-12 21:59:47 -05:00
Jesse Beder
fddc991b60 Fixed NodeBuilder bug when an alias was in a map - we weren't pushing that guy as a key 2011-09-12 14:24:27 -05:00
Jesse Beder
3337df7ca2 Fixed new API node key/value insertion in NodeBuilder (it was using the wrong condition on when it had added a key already) 2011-09-12 13:25:41 -05:00
Jesse Beder
41533a8c49 Added failing self-reference tests 2011-09-12 12:48:51 -05:00
Jesse Beder
a6e1d4cf74 Added two alias tests 2011-09-12 12:42:23 -05:00
Jesse Beder
5397a93702 Implemented std::map decode (and fixed bug in the Node iterator - the reference_type should be just a plain value, since it's created on-the-fly) 2011-09-12 00:29:39 -05:00
Jesse Beder
b9583dde76 Added reading/writing std::list 2011-09-11 23:18:19 -05:00
Jesse Beder
f22f38f7f2 Added reading/writing std::vector 2011-09-11 23:14:52 -05:00
Jesse Beder
9e62bf8349 Removed the (unimplemented) operator <, and added operator == (in place of is()) for nodes 2011-09-11 22:56:04 -05:00
Jesse Beder
f9d826c22a Added mutable operator[] for integral types (you can only grow the sequence if you specify the *next* element) 2011-09-11 22:51:49 -05:00
Jesse Beder
4770ec798c Implemented operator[] specialization, but only const (should the sequence be mutable?) 2011-09-11 21:51:04 -05:00
Jesse Beder
4568dd0b19 Started specialization for operator[] for integers 2011-09-11 21:32:47 -05:00
Jesse Beder
a308b73e8a Set the map iterator to filter over undefined items 2011-09-11 19:44:27 -05:00
Jesse Beder
c2a8a2c1f7 Added failing map iterator count test 2011-09-11 17:36:08 -05:00
Jesse Beder
a03af5dd73 Implemented the map size computation 2011-09-11 17:16:26 -05:00
Jesse Beder
b50264e74d Switched the implementation of maps from list<pair> to map (but just pointer comparison) 2011-09-11 16:56:38 -05:00
Jesse Beder
ecdd9cc66d Added computing and caching the sequence size 2011-09-11 16:21:36 -05:00
Jesse Beder
3a90454d50 Added some small map tests 2011-09-11 16:02:31 -05:00
Jesse Beder
2d81e46655 Added dependency management (to cause nodes to become defined if their children do) 2011-09-11 15:59:53 -05:00
Jesse Beder
b4963ab0fa Added a few simple node tests, and the sequence one doesn't pass (let's work now) 2011-09-10 23:31:12 -05:00
Jesse Beder
432268917b Started Node tests (for the new API Node) 2011-09-10 23:22:30 -05:00
Jesse Beder
2d06df474b Fixed up the old API stuff, and removed the util/value (since it's no longer needed) 2011-09-10 23:11:28 -05:00
Jesse Beder
03fc837236 Set up util/parse for the new API 2011-09-10 23:03:02 -05:00
Jesse Beder
80cf3c98db Fixed minor things that used the old API, compiles/links/runs\! 2011-09-10 22:59:27 -05:00
Jesse Beder
f7b2247217 Added stubs for spec and parser tests with the new API 2011-09-10 18:05:35 -05:00
Jesse Beder
36c63980b9 Moved old api tests to subfolder 2011-09-10 18:02:07 -05:00
Jesse Beder
0d1b5224c8 Major switch from Value -> Node. The library compiles with the new API, but tests are still oldies, and don't compile 2011-09-10 17:57:23 -05:00
Jesse Beder
ac81d7c883 Start of moving Value -> Node and Node -> old API Node (with a #define toggle) 2011-09-10 17:18:15 -05:00
Jesse Beder
78b7a1b8a9 Added helper emitter functions, but we have a problem: YAML::Value is already a manipulator 2011-09-10 16:50:44 -05:00
Jesse Beder
12364895cb Implemented value events emitter 2011-09-10 16:23:18 -05:00
Jesse Beder
5012063143 Fixed node iterator 2011-09-10 14:36:10 -05:00
Jesse Beder
c3b0ba9d61 New iterators work\! 2011-09-10 14:16:50 -05:00
Jesse Beder
4fdbb748ec Updated the node/value classes with the new iterators, they compile until we try to instantiate anything 2011-09-10 14:11:42 -05:00
Jesse Beder
b1730ea3da Finished the main iterator stuff, now have to hook it to the nodes/values 2011-09-10 14:06:49 -05:00
Jesse Beder
3865d37bc7 Halfway towards factoring out a node_iterator, and then building iterator on top of it 2011-09-10 13:20:22 -05:00
Jesse Beder
f5a9d4c8e3 Started emitting events for Values 2011-09-10 12:42:42 -05:00
Jesse Beder
09beb5c47a Implemented sugar Parse() functions 2011-09-09 23:40:19 -05:00
Jesse Beder
6e03bebeb0 Implemented (untested) the value builder 2011-09-09 23:28:21 -05:00
Jesse Beder
a7bdf08c7e Map iterator works\! 2011-09-09 19:25:11 -05:00
Jesse Beder
cf198080d0 Sequence iterator works\! 2011-09-09 19:22:17 -05:00
Jesse Beder
190a556756 Switched iterators to typedef's, with a bit of finagling so we can forward-declare them 2011-09-09 19:07:37 -05:00
Jesse Beder
9aa3eb56f2 Base iterator stuff compiles :) 2011-09-09 18:46:37 -05:00
Jesse Beder
ff1a8fc59a Started writing new iterators 2011-09-09 16:17:59 -05:00
Jesse Beder
7bbf712c36 Made the 'data' member optional in node_ref - it's only created on-demand, so we don't waste extra memory every time we do Value tmp = v; 2011-09-09 14:26:55 -05:00
Jesse Beder
9b985c5ce2 Switched value = otherValue to assign the actual nodes after setting the reference (so that tmp = foo['bar']; tmp = other; is the same as foo['bar'] = other;) 2011-09-09 14:02:18 -05:00
Jesse Beder
d3bbd08273 Added append() 2011-09-09 02:51:35 -05:00
Jesse Beder
4f8680b540 Switched operator[] access to node reference equality, not node equality 2011-09-09 02:39:36 -05:00
Jesse Beder
ec95e61c04 Switched memory to using shared nodes, and node_data to keep only naked node pointers, not shared nodes (to break the cycle, and we don't need weak pointers because their memory is guaranteed to exist, via 'memory') 2011-09-09 02:29:17 -05:00
Jesse Beder
6ffc9ac788 Added half of the std::map conversion (we don't have reading from Values yet) 2011-09-08 02:10:04 -05:00
Jesse Beder
0e197b8723 Added back the streamable conversions 2011-09-08 02:05:03 -05:00
Jesse Beder
3d84f57008 Switched convert to a templated struct that can be specialized (so we can partially specialize it) 2011-09-08 02:02:15 -05:00
Jesse Beder
a7ebb3615a Added streamable conversions 2011-09-08 00:48:40 -05:00
Jesse Beder
a95baeafd6 Implemented conversion for std::string, including a bypass-accessor to the scalar value 2011-09-07 15:49:01 -05:00
Jesse Beder
1ab16bac62 Set the 'memory' to only store node_refs, not nodes 2011-09-07 14:56:04 -05:00
Jesse Beder
4aa61944fe Implemented is() 2011-09-07 14:46:25 -05:00
Jesse Beder
e225509210 Added (another) layer - now 'node_ref' is between node and node_data, and it decrees whether nodes are identical 2011-09-07 14:44:18 -05:00
Jesse Beder
d1eca90216 Implemented map get(), and it would work (I think) if we implemented convert() for strings 2011-09-07 03:36:50 -05:00
Jesse Beder
020cd97915 Set up map searching by templated key 2011-09-07 03:21:24 -05:00
Jesse Beder
f0174ca08b Reorganized so that we don't have cyclic include problems 2011-09-07 02:59:58 -05:00
Jesse Beder
fed95c5da4 Implemented map access by already-existing node 2011-09-07 02:39:59 -05:00
Jesse Beder
a530630f1c Started implementing node_data 2011-09-07 00:45:28 -05:00
Jesse Beder
00e4a56d15 Compiles/links assignment to string 2011-09-07 00:20:23 -05:00
Jesse Beder
1e6877043e Value stuff compiles/links with lots of placeholder functions 2011-09-07 00:12:24 -05:00
Jesse Beder
248b18a2d0 Sketched more of the implementation 2011-09-06 23:11:38 -05:00
Jesse Beder
7e79edc058 Moved the value header to its own subfolder 2011-09-06 16:06:46 -05:00
Jesse Beder
8b97dfe77e Sketched out interface for YAML::Value 2011-09-06 01:43:15 -05:00
Jesse Beder
3eeb270ef5 Merged from trunk 2011-09-06 01:10:27 -05:00
Jesse Beder
c1d75dd4f7 Added notes about the two failing tests - that they're (I think) bugs in the YAML spec 2011-09-06 01:05:14 -05:00
Jesse Beder
dd1eb715c4 Switched YAML::Binary interface to use unsigned chars, not chars 2011-09-06 00:39:31 -05:00
Jesse Beder
fadca5a89d Added overload for operator [] for char * (non-const version) 2011-09-06 00:32:53 -05:00
Jesse Beder
7e129c9b64 Fixed empty string emitter bug (it now with auto-quote it 2011-09-06 00:24:10 -05:00
Jesse Beder
3e94c0a037 Switched the 'pragma once' to only happen on MSVC, or gcc >= 3.4 (it was causing trouble on the sun compiler) 2011-09-06 00:16:03 -05:00
Jesse Beder
d7feb2e9b9 Added api sketch 2011-09-04 19:50:08 -05:00
Jesse Beder
8ba5e3fbf6 Added .hgeol for native eols 2011-08-24 02:59:58 -05:00
Jesse Beder
857c7d93a0 update tags 2011-08-24 13:44:56 +00:00
Jesse Beder
b690648308 Removed ATOMIC_TYPE, an old enum that wasn't used any more 2011-08-22 21:37:51 +00:00
Jesse Beder
d904b600a9 Added test for anchor/alias in flow 2011-08-04 21:50:04 +00:00
Jesse Beder
bacb74e8ec Forced a newline after any comments 2011-08-04 21:47:57 +00:00
Jesse Beder
b1ac3289b8 Included <cstddef> for NULL 2011-08-04 18:47:37 +00:00
Jesse Beder
835b86d9f7 Fixed negative infinity parsing 2011-07-10 18:29:44 +00:00
Jesse Beder
94dc63af04 Added parsing .inf and .nan (and friend) 2011-07-10 16:27:40 +00:00
Jesse Beder
50474b6b9f Fixed includedir for the .pc.cmake file 2011-05-29 02:17:49 +00:00
Jesse Beder
4c3926a5c7 Added emitting std::set (and refactored the stl emitters a bit) 2011-05-18 21:07:25 +00:00
Jesse Beder
9fbcfe9ec5 Added include <cstdlib> for using 'NULL' (apparently gcc 4.6 is more strict) 2011-05-03 21:55:49 +00:00
Jesse Beder
d98687afc3 Set version to 0.2.6 2011-03-30 01:33:02 +00:00
77 changed files with 3603 additions and 2483 deletions

4
.hgeol Normal file
View File

@@ -0,0 +1,4 @@
**.h = native
**.c = native
**.cpp = native
**.txt = native

1
.hgignore Normal file
View File

@@ -0,0 +1 @@
syntax: glob

View File

@@ -22,8 +22,8 @@ include(CheckCXXCompilerFlag)
project(YAML_CPP)
set(YAML_CPP_VERSION_MAJOR "0")
set(YAML_CPP_VERSION_MINOR "2")
set(YAML_CPP_VERSION_PATCH "5")
set(YAML_CPP_VERSION_MINOR "3")
set(YAML_CPP_VERSION_PATCH "0")
set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}")
enable_testing()
@@ -51,14 +51,15 @@ option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF)
###
### Sources, headers, directories and libs
###
set(header_directory "include/yaml-cpp/")
file(GLOB sources "src/[a-zA-Z]*.cpp")
file(GLOB public_headers "include/yaml-cpp/[a-zA-Z]*.h")
file(GLOB private_headers "src/[a-zA-Z]*.h")
if(YAML_CPP_BUILD_CONTRIB)
file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp")
file(GLOB contrib_public_headers "include/yaml-cpp/contrib/[a-zA-Z]*.h")
@@ -77,6 +78,7 @@ if(VERBOSE)
endif()
include_directories(${YAML_CPP_SOURCE_DIR}/include)
include_directories(${YAML_CPP_SOURCE_DIR}/src)
###
@@ -209,7 +211,9 @@ else()
set(_library_dir lib)
endif()
set(INCLUDE_INSTALL_DIR include/yaml-cpp)
set(INCLUDE_INSTALL_ROOT_DIR include)
set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_ROOT_DIR}/yaml-cpp)
set(LIB_INSTALL_DIR "${_library_dir}${LIB_SUFFIX}")
set(_INSTALL_DESTINATIONS
@@ -257,10 +261,9 @@ endif()
install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
install(
FILES
${public_headers}
${contrib_public_headers}
DIRECTORY ${header_directory}
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
)
if(UNIX)

View File

@@ -1,7 +1,7 @@
#ifndef ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

66
include/yaml-cpp/binary.h Normal file
View File

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

View File

@@ -1,7 +1,7 @@
#ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,18 +1,30 @@
#ifndef CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/null.h"
#include "yaml-cpp/traits.h"
#include <limits>
#include <string>
#include <sstream>
namespace YAML
{
// traits for conversion
template<typename T>
struct is_scalar_convertible { enum { value = is_numeric<T>::value }; };
template<> struct is_scalar_convertible<std::string> { enum { value = true }; };
template<> struct is_scalar_convertible<bool> { enum { value = true }; };
template<> struct is_scalar_convertible<_Null> { enum { value = true }; };
// actual conversion
inline bool Convert(const std::string& input, std::string& output) {
output = input;
return true;
@@ -21,12 +33,42 @@ namespace YAML
YAML_CPP_API bool Convert(const std::string& input, bool& output);
YAML_CPP_API bool Convert(const std::string& input, _Null& output);
inline bool IsInfinity(const std::string& input) {
return input == ".inf" || input == ".Inf" || input == ".INF" || input == "+.inf" || input == "+.Inf" || input == "+.INF";
}
inline bool IsNegativeInfinity(const std::string& input) {
return input == "-.inf" || input == "-.Inf" || input == "-.INF";
}
inline bool IsNaN(const std::string& input) {
return input == ".nan" || input == ".NaN" || input == ".NAN";
}
template <typename T>
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T> >::type * = 0) {
std::stringstream stream(input);
stream.unsetf(std::ios::dec);
stream >> output;
return !!stream;
if((stream >> output) && (stream >> std::ws).eof())
return true;
if(std::numeric_limits<T>::has_infinity) {
if(IsInfinity(input)) {
output = std::numeric_limits<T>::infinity();
return true;
} else if(IsNegativeInfinity(input)) {
output = -std::numeric_limits<T>::infinity();
return true;
}
}
if(std::numeric_limits<T>::has_quiet_NaN && IsNaN(input)) {
output = std::numeric_limits<T>::quiet_NaN();
return true;
}
return false;
}
}

View File

@@ -1,7 +1,7 @@
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,12 +1,13 @@
#ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/binary.h"
#include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/noncopyable.h"
@@ -43,20 +44,24 @@ namespace YAML
bool SetIndent(unsigned n);
bool SetPreCommentIndent(unsigned n);
bool SetPostCommentIndent(unsigned n);
bool SetFloatPrecision(unsigned n);
bool SetDoublePrecision(unsigned n);
// local setters
Emitter& SetLocalValue(EMITTER_MANIP value);
Emitter& SetLocalIndent(const _Indent& indent);
Emitter& SetLocalPrecision(const _Precision& precision);
// overloads of write
Emitter& Write(const std::string& str);
Emitter& Write(bool b);
Emitter& Write(char ch);
Emitter& Write(const _Alias& alias);
Emitter& Write(const _Anchor& anchor);
Emitter& Write(const _Tag& tag);
Emitter& Write(const _Comment& comment);
Emitter& Write(const _Null& null);
Emitter& Write(const _Binary& binary);
Emitter& Write(const Binary& binary);
template <typename T>
Emitter& WriteIntegralType(T value);
@@ -69,10 +74,12 @@ namespace YAML
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;
private:
enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
void PreAtomicWrite();
bool GotoNextPreAtomicState();
void PostAtomicWrite();
@@ -119,20 +126,35 @@ namespace YAML
std::stringstream str;
PreWriteStreamable(str);
SetStreamablePrecision<T>(str);
str << value;
PostWriteStreamable(str);
return *this;
}
template<>
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& str)
{
str.precision(GetFloatPrecision());
}
template<>
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& str)
{
str.precision(GetDoublePrecision());
}
// overloads of insertion
inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, char v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, unsigned char v) { return emitter.Write(static_cast<char>(v)); }
inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
inline Emitter& operator << (Emitter& emitter, const _Binary& b) { return emitter.Write(b); }
inline Emitter& operator << (Emitter& emitter, const Binary& b) { return emitter.Write(b); }
inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
@@ -155,6 +177,10 @@ namespace YAML
inline Emitter& operator << (Emitter& emitter, _Indent indent) {
return emitter.SetLocalIndent(indent);
}
inline Emitter& operator << (Emitter& emitter, _Precision precision) {
return emitter.SetLocalPrecision(precision);
}
}
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,7 +1,7 @@
#ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -125,16 +125,25 @@ namespace YAML
inline _Comment Comment(const std::string content) {
return _Comment(content);
}
struct _Binary {
_Binary(const char *data_, std::size_t size_): data(data_), size(size_) {}
const char *data;
std::size_t size;
};
inline _Binary Binary(const char *data, std::size_t size) {
return _Binary(data, size);
}
struct _Precision {
_Precision(int floatPrecision_, int doublePrecision_): floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
int floatPrecision;
int doublePrecision;
};
inline _Precision FloatPrecision(int n) {
return _Precision(n, -1);
}
inline _Precision DoublePrecision(int n) {
return _Precision(-1, n);
}
inline _Precision Precision(int n) {
return _Precision(n, n);
}
}
#endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,7 +1,7 @@
#ifndef EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,18 +1,18 @@
#ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/conversion.h"
#include "yaml-cpp/dll.h"
#include "yaml-cpp/exceptions.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/ltnode.h"
#include "yaml-cpp/mark.h"
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/conversion.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/ltnode.h"
#include <iostream>
#include <map>
#include <memory>
@@ -66,7 +66,7 @@ namespace YAML
const T to() const;
template <typename T>
friend YAML_CPP_API void operator >> (const Node& node, T& value);
friend YAML_CPP_API typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value);
// retrieval for maps and sequences
template <typename T>
@@ -77,7 +77,9 @@ namespace YAML
// specific to maps
const Node *FindValue(const char *key) const;
const Node *FindValue(char *key) const;
const Node& operator [] (const char *key) const;
const Node& operator [] (char *key) const;
// for tags
const std::string& Tag() const { return m_tag; }

View File

@@ -1,7 +1,7 @@
#ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -20,7 +20,7 @@ namespace YAML
}
template <typename T>
inline void operator >> (const Node& node, T& value) {
inline typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value) {
if(!ConvertScalar(node, value))
throw InvalidScalar(node.m_mark);
}
@@ -68,10 +68,18 @@ namespace YAML
inline const Node *Node::FindValue(const char *key) const {
return FindValue(std::string(key));
}
inline const Node *Node::FindValue(char *key) const {
return FindValue(std::string(key));
}
inline const Node& Node::operator [] (const char *key) const {
return GetValue(std::string(key));
}
inline const Node& Node::operator [] (char *key) const {
return GetValue(std::string(key));
}
}
#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -1,7 +1,7 @@
#ifndef NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

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

View File

@@ -1,7 +1,7 @@
#ifndef OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -32,7 +32,8 @@ namespace YAML
void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler);
bool GetNextDocument(Node& document);
bool GetNextDocument(Node& document); // old API only
void PrintTokens(std::ostream& out);
private:

View File

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

View File

@@ -1,7 +1,7 @@
#ifndef STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,17 +1,17 @@
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/parser.h"
#include "yaml-cpp/node.h"
#include "yaml-cpp/stlnode.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/stlemitter.h"
#include "yaml-cpp/exceptions.h"
#include "yaml-cpp/node.h"
#include "yaml-cpp/stlnode.h"
#include "yaml-cpp/iterator.h"
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66

102
src/binary.cpp Normal file
View File

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

View File

@@ -1,7 +1,7 @@
#ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,10 +1,11 @@
#ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <cstdlib>
#include <map>
#include <stack>
#include "yaml-cpp/eventhandler.h"

View File

@@ -1,7 +1,7 @@
#ifndef DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -93,6 +93,16 @@ namespace YAML
{
return m_pState->SetPostCommentIndent(n, GLOBAL);
}
bool Emitter::SetFloatPrecision(unsigned n)
{
return m_pState->SetFloatPrecision(n, GLOBAL);
}
bool Emitter::SetDoublePrecision(unsigned n)
{
return m_pState->SetDoublePrecision(n, GLOBAL);
}
// SetLocalValue
// . Either start/end a group, or set a modifier locally
@@ -145,6 +155,15 @@ namespace YAML
return *this;
}
Emitter& Emitter::SetLocalPrecision(const _Precision& precision)
{
if(precision.floatPrecision >= 0)
m_pState->SetFloatPrecision(precision.floatPrecision, LOCAL);
if(precision.doublePrecision >= 0)
m_pState->SetDoublePrecision(precision.doublePrecision, LOCAL);
return *this;
}
// GotoNextPreAtomicState
// . Runs the state machine, emitting if necessary, and returns 'true' if done (i.e., ready to emit an atom)
bool Emitter::GotoNextPreAtomicState()
@@ -186,6 +205,7 @@ namespace YAML
case ES_WRITING_FLOW_SEQ_ENTRY:
return true;
case ES_DONE_WITH_FLOW_SEQ_ENTRY:
EmitSeparationIfNecessary();
m_stream << ',';
m_pState->RequireSoftSeparation();
m_pState->SwitchState(ES_WAITING_FOR_FLOW_SEQ_ENTRY);
@@ -221,9 +241,9 @@ namespace YAML
m_pState->SetError(ErrorMsg::EXPECTED_KEY_TOKEN);
return true;
case ES_WAITING_FOR_FLOW_MAP_KEY:
EmitSeparationIfNecessary();
m_pState->SwitchState(ES_WRITING_FLOW_MAP_KEY);
if(m_pState->CurrentlyInLongKey()) {
EmitSeparationIfNecessary();
m_stream << '?';
m_pState->RequireSoftSeparation();
}
@@ -234,6 +254,7 @@ namespace YAML
m_pState->SetError(ErrorMsg::EXPECTED_VALUE_TOKEN);
return true;
case ES_WAITING_FOR_FLOW_MAP_VALUE:
EmitSeparationIfNecessary();
m_stream << ':';
m_pState->RequireSoftSeparation();
m_pState->SwitchState(ES_WRITING_FLOW_MAP_VALUE);
@@ -496,6 +517,7 @@ namespace YAML
} else if(flowType == FT_FLOW) {
// Note: flow maps are allowed to be empty
assert(curState == ES_DONE_WITH_FLOW_MAP_VALUE || curState == ES_WAITING_FOR_FLOW_MAP_ENTRY);
EmitSeparationIfNecessary();
m_stream << "}";
} else
assert(false);
@@ -526,6 +548,7 @@ namespace YAML
m_pState->UnsetSeparation();
m_pState->SwitchState(ES_WAITING_FOR_BLOCK_MAP_KEY);
} else if(flowType == FT_FLOW) {
EmitSeparationIfNecessary();
if(curState == ES_DONE_WITH_FLOW_MAP_VALUE) {
m_stream << ',';
m_pState->RequireSoftSeparation();
@@ -647,9 +670,11 @@ namespace YAML
str << std::dec;
break;
case Hex:
str << "0x";
str << std::hex;
break;
case Oct:
case Oct:
str << "0";
str << std::oct;
break;
default:
@@ -657,13 +682,22 @@ namespace YAML
}
}
void Emitter::PreWriteStreamable(std::stringstream& str)
void Emitter::PreWriteStreamable(std::stringstream&)
{
PreAtomicWrite();
EmitSeparationIfNecessary();
str.precision(15);
}
unsigned Emitter::GetFloatPrecision() const
{
return m_pState->GetFloatPrecision();
}
unsigned Emitter::GetDoublePrecision() const
{
return m_pState->GetDoublePrecision();
}
void Emitter::PostWriteIntegralType(const std::stringstream& str)
{
m_stream << str.str();
@@ -729,6 +763,20 @@ namespace YAML
return *this;
}
Emitter& Emitter::Write(char ch)
{
if(!good())
return *this;
PreAtomicWrite();
EmitSeparationIfNecessary();
Utils::WriteChar(m_stream, ch);
PostAtomicWrite();
return *this;
}
Emitter& Emitter::Write(const _Alias& alias)
{
if(!good())
@@ -796,8 +844,12 @@ namespace YAML
if(!good())
return *this;
m_stream << Indentation(m_pState->GetPreCommentIndent());
if(m_stream.col() > 0)
m_stream << Indentation(m_pState->GetPreCommentIndent());
Utils::WriteComment(m_stream, comment.content, m_pState->GetPostCommentIndent());
m_pState->RequireHardSeparation();
m_pState->ForceHardSeparation();
return *this;
}
@@ -813,7 +865,7 @@ namespace YAML
return *this;
}
Emitter& Emitter::Write(const _Binary& binary)
Emitter& Emitter::Write(const Binary& binary)
{
Write(SecondaryTag("binary"));
@@ -822,7 +874,7 @@ namespace YAML
PreAtomicWrite();
EmitSeparationIfNecessary();
Utils::WriteBinary(m_stream, binary.data, binary.size);
Utils::WriteBinary(m_stream, binary);
PostAtomicWrite();
return *this;
}

View File

@@ -1,5 +1,6 @@
#include "emitterstate.h"
#include "yaml-cpp/exceptions.h"
#include <limits>
namespace YAML
{
@@ -21,6 +22,8 @@ namespace YAML
m_seqFmt.set(Block);
m_mapFmt.set(Block);
m_mapKeyFmt.set(Auto);
m_floatPrecision.set(6);
m_doublePrecision.set(15);
}
EmitterState::~EmitterState()
@@ -261,5 +264,21 @@ namespace YAML
return false;
}
}
bool EmitterState::SetFloatPrecision(int value, FMT_SCOPE scope)
{
if(value < 0 || value > std::numeric_limits<float>::digits10)
return false;
_Set(m_floatPrecision, value, scope);
return true;
}
bool EmitterState::SetDoublePrecision(int value, FMT_SCOPE scope)
{
if(value < 0 || value > std::numeric_limits<double>::digits10)
return false;
_Set(m_doublePrecision, value, scope);
return true;
}
}

View File

@@ -1,7 +1,7 @@
#ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -145,6 +145,11 @@ namespace YAML
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
bool SetFloatPrecision(int value, FMT_SCOPE scope);
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
bool SetDoublePrecision(int value, FMT_SCOPE scope);
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
private:
template <typename T>
@@ -169,6 +174,8 @@ namespace YAML
Setting<EMITTER_MANIP> m_seqFmt;
Setting<EMITTER_MANIP> m_mapFmt;
Setting<EMITTER_MANIP> m_mapKeyFmt;
Setting<int> m_floatPrecision;
Setting<int> m_doublePrecision;
SettingChanges m_modifiedSettings;
SettingChanges m_globalModifiedSettings;

View File

@@ -1,6 +1,7 @@
#include "emitterutils.h"
#include "exp.h"
#include "indentation.h"
#include "yaml-cpp/binary.h"
#include "yaml-cpp/exceptions.h"
#include "stringsource.h"
#include <sstream>
@@ -128,6 +129,9 @@ namespace YAML
}
bool IsValidPlainScalar(const std::string& str, bool inFlow, bool allowOnlyAscii) {
if(str.empty())
return false;
// first check the start
const RegEx& start = (inFlow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
if(!start.Matches(str))
@@ -265,9 +269,29 @@ namespace YAML
return true;
}
bool WriteChar(ostream& out, char ch)
{
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
out << ch;
else if((0x20 <= ch && ch <= 0x7e) || ch == ' ')
out << "\"" << ch << "\"";
else if(ch == '\t')
out << "\"\\t\"";
else if(ch == '\n')
out << "\"\\n\"";
else if(ch == '\b')
out << "\"\\b\"";
else {
out << "\"";
WriteDoubleQuoteEscapeSequence(out, ch);
out << "\"";
}
return true;
}
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent)
{
unsigned curIndent = out.col();
const unsigned curIndent = out.col();
out << "#" << Indentation(postCommentIndent);
int codePoint;
for(std::string::const_iterator i = str.begin();
@@ -344,41 +368,10 @@ namespace YAML
return true;
}
bool WriteBinary(ostream& out, const char *data, std::size_t size)
bool WriteBinary(ostream& out, const Binary& binary)
{
static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char PAD = '=';
out << "\"";
std::size_t chunks = size / 3;
std::size_t remainder = size % 3;
for(std::size_t i=0;i<chunks;i++, data += 3) {
out << encoding[data[0] >> 2];
out << encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
out << encoding[((data[1] & 0xf) << 2) | (data[2] >> 6)];
out << encoding[data[2] & 0x3f];
}
switch(remainder) {
case 0:
break;
case 1:
out << encoding[data[0] >> 2];
out << encoding[((data[0] & 0x3) << 4)];
out << PAD;
out << PAD;
break;
case 2:
out << encoding[data[0] >> 2];
out << encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
out << encoding[((data[1] & 0xf) << 2)];
out << PAD;
break;
}
out << "\"";
return true;
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false);
return true;
}
}
}

View File

@@ -1,7 +1,7 @@
#ifndef EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -11,18 +11,21 @@
namespace YAML
{
class Binary;
namespace Utils
{
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 char *data, std::size_t size);
bool WriteBinary(ostream& out, const Binary& binary);
}
}

View File

@@ -1,7 +1,7 @@
#ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -137,7 +137,7 @@ namespace YAML
// . In the block context - ? : must be not be followed with a space.
// . In the flow context ? is illegal and : and - must not be followed with a space.
inline const RegEx& PlainScalar() {
static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + Blank()));
static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
return e;
}
inline const RegEx& PlainScalarInFlow() {
@@ -149,7 +149,7 @@ namespace YAML
return e;
}
inline const RegEx& EndScalarInFlow() {
static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
return e;
}

View File

@@ -1,7 +1,7 @@
#ifndef INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,14 +1,14 @@
#include "yaml-cpp/node.h"
#include "yaml-cpp/aliasmanager.h"
#include "yaml-cpp/emitfromevents.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/eventhandler.h"
#include "iterpriv.h"
#include "nodebuilder.h"
#include "nodeownership.h"
#include "scanner.h"
#include "tag.h"
#include "token.h"
#include "yaml-cpp/aliasmanager.h"
#include "yaml-cpp/emitfromevents.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/eventhandler.h"
#include <cassert>
#include <stdexcept>

View File

@@ -1,7 +1,7 @@
#ifndef NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,8 +1,8 @@
#include "yaml-cpp/parser.h"
#include "directives.h"
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/exceptions.h"
#include "yaml-cpp/node.h"
#include "directives.h"
#include "nodebuilder.h"
#include "scanner.h"
#include "singledocparser.h"

View File

@@ -1,11 +1,13 @@
#ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <vector>

View File

@@ -1,11 +1,13 @@
#ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <vector>

View File

@@ -1,7 +1,7 @@
#ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -23,6 +23,7 @@ namespace YAML
bool emptyLine = false, moreIndented = false;
int foldedNewlineCount = 0;
bool foldedNewlineStartedMoreIndented = false;
std::size_t lastEscapedChar = std::string::npos;
std::string scalar;
params.leadingSpaces = false;
@@ -52,6 +53,7 @@ namespace YAML
// eat escape character and get out (but preserve trailing whitespace!)
INPUT.get();
lastNonWhitespaceChar = scalar.size();
lastEscapedChar = scalar.size();
escapedNewline = true;
break;
}
@@ -60,6 +62,7 @@ namespace YAML
if(INPUT.peek() == params.escape) {
scalar += Exp::Escape(INPUT);
lastNonWhitespaceChar = scalar.size();
lastEscapedChar = scalar.size();
continue;
}
@@ -171,20 +174,32 @@ namespace YAML
// post-processing
if(params.trimTrailingSpaces) {
std::size_t pos = scalar.find_last_not_of(' ');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos < scalar.size())
scalar.erase(pos + 1);
}
switch(params.chomp) {
case CLIP: {
const std::size_t pos = scalar.find_last_not_of('\n');
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
scalar.erase();
else if(pos + 1 < scalar.size())
scalar.erase(pos + 2);
} break;
case STRIP: {
const std::size_t pos = scalar.find_last_not_of('\n');
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
scalar.erase();
else if(pos < scalar.size())

View File

@@ -1,7 +1,7 @@
#ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -178,7 +178,7 @@ namespace YAML
}
Stream::Stream(std::istream& input)
: m_input(input), m_nPushedBack(0),
: m_input(input),
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0)
{
@@ -192,18 +192,17 @@ namespace YAML
char_traits::int_type intro[4];
int nIntroUsed = 0;
UtfIntroState state = uis_start;
for (; !s_introFinalState[state]; ) {
for(; !s_introFinalState[state]; ) {
std::istream::int_type ch = input.get();
intro[nIntroUsed++] = ch;
UtfIntroCharType charType = IntroCharTypeOf(ch);
UtfIntroState newState = s_introTransitions[state][charType];
int nUngets = s_introUngetCount[state][charType];
if (nUngets > 0) {
for (; nUngets > 0; --nUngets) {
if (char_traits::eof() != intro[--nIntroUsed]) {
m_bufPushback[m_nPushedBack++] =
char_traits::to_char_type(intro[nIntroUsed]);
}
if(nUngets > 0) {
input.clear();
for(; nUngets > 0; --nUngets) {
if(char_traits::eof() != intro[--nIntroUsed])
input.putback(char_traits::to_char_type(intro[nIntroUsed]));
}
}
state = newState;
@@ -398,11 +397,6 @@ namespace YAML
unsigned char Stream::GetNextByte() const
{
if (m_nPushedBack)
{
return m_bufPushback[--m_nPushedBack];
}
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable)
{
std::streambuf *pBuf = m_input.rdbuf();

View File

@@ -1,7 +1,7 @@
#ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
@@ -17,8 +17,6 @@
namespace YAML
{
static const size_t MAX_PARSER_PUSHBACK = 8;
class Stream: private noncopyable
{
public:
@@ -50,8 +48,6 @@ namespace YAML
Mark m_mark;
CharacterSet m_charSet;
unsigned char m_bufPushback[MAX_PARSER_PUSHBACK];
mutable size_t m_nPushedBack;
mutable std::deque<char> m_readahead;
unsigned char* const m_pPrefetched;
mutable size_t m_nPrefetchedAvailable;

View File

@@ -1,7 +1,7 @@
#ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,7 +1,7 @@
#ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

View File

@@ -1,5 +1,10 @@
file(GLOB test_headers [a-z]*.h)
file(GLOB test_sources [a-z]*.cpp)
file(GLOB test_old_api_sources old-api/[a-z]*.cpp)
list(APPEND test_sources ${test_old_api_sources})
include_directories(${YAML_CPP_SOURCE_DIR}/test)
add_executable(run-tests
${test_sources}

View File

@@ -1,5 +1,6 @@
#include "tests.h"
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
@@ -282,6 +283,20 @@ namespace Test
desiredOutput = "- &fred ~\n- *fred";
}
void AliasAndAnchorInFlow(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginSeq;
out << YAML::Anchor("fred");
out << YAML::BeginMap;
out << YAML::Key << "name" << YAML::Value << "Fred";
out << YAML::Key << "age" << YAML::Value << 42;
out << YAML::EndMap;
out << YAML::Alias("fred");
out << YAML::EndSeq;
desiredOutput = "[&fred {name: Fred, age: 42}, *fred]";
}
void SimpleVerbatimTag(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::VerbatimTag("!foo") << "bar";
@@ -503,6 +518,40 @@ namespace Test
desiredOutput = "? long key # long key\n: value";
}
void InitialComment(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Comment("A comment describing the purpose of the file.");
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
desiredOutput = "# A comment describing the purpose of the file.\nkey: value";
}
void InitialCommentWithDocIndicator(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginDoc << YAML::Comment("A comment describing the purpose of the file.");
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
desiredOutput = "---\n# A comment describing the purpose of the file.\nkey: value";
}
void CommentInFlowSeq(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar" << YAML::EndSeq;
desiredOutput = "[foo # foo!\n, bar]";
}
void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << "foo" << YAML::Value << "foo value";
out << YAML::Key << "bar" << YAML::Value << "bar value" << YAML::Comment("bar!");
out << YAML::Key << "baz" << YAML::Value << "baz value" << YAML::Comment("baz!");
out << YAML::EndMap;
desiredOutput = "{foo: foo value, bar: bar value # bar!\n, baz: baz value # baz!\n}";
}
void Indentation(YAML::Emitter& out, std::string& desiredOutput)
{
@@ -688,9 +737,9 @@ namespace Test
{
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
out << YAML::Key << "b" << YAML::Newline << YAML::Value << "bar";
out << YAML::Key << "b" << YAML::Value << "bar";
out << YAML::EndMap;
desiredOutput = "{a: foo\n, b\n: bar}";
desiredOutput = "{a: foo\n, b: bar}";
}
void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput)
@@ -711,19 +760,19 @@ namespace Test
void Binary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary("Hello, World!", 13);
out << YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13);
desiredOutput = "!!binary \"SGVsbG8sIFdvcmxkIQ==\"";
}
void LongBinary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n", 270);
out << YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270);
desiredOutput = "!!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"";
}
void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary("", 0);
out << YAML::Binary(reinterpret_cast<const unsigned char *>(""), 0);
desiredOutput = "!!binary \"\"";
}
@@ -742,6 +791,12 @@ namespace Test
desiredOutput = "apple: \":\"\nbanana: \":\"";
}
void ColonAtEndOfScalarInFlow(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginMap << YAML::Key << "C:" << YAML::Value << "C:" << YAML::EndMap;
desiredOutput = "{\"C:\": \"C:\"}";
}
void BoolFormatting(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginSeq;
@@ -798,8 +853,65 @@ namespace Test
out << "Oops";
desiredOutput = "Hi\n---\nBye\n---\nOops";
}
void EmptyString(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginMap;
out << YAML::Key << "key" << YAML::Value << "";
out << YAML::EndMap;
desiredOutput = "key: \"\"";
}
void SingleChar(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginSeq;
out << 'a';
out << ':';
out << (char)0x10;
out << '\n';
out << ' ';
out << '\t';
out << YAML::EndSeq;
desiredOutput = "- a\n- \":\"\n- \"\\x10\"\n- \"\\n\"\n- \" \"\n- \"\\t\"";
}
void DefaultPrecision(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginSeq;
out << 1.234f;
out << 3.14159265358979;
out << YAML::EndSeq;
desiredOutput = "- 1.234\n- 3.14159265358979";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetPrecision(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginSeq;
out << YAML::FloatPrecision(3) << 1.234f;
out << YAML::DoublePrecision(6) << 3.14159265358979;
out << YAML::EndSeq;
desiredOutput = "- 1.23\n- 3.14159";
}
void DashInBlockContext(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginMap;
out << YAML::Key << "key" << YAML::Value << "-";
out << YAML::EndMap;
desiredOutput = "key: \"-\"";
}
void HexAndOct(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginSeq;
out << 31;
out << YAML::Hex << 31;
out << YAML::Oct << 31;
out << YAML::EndSeq;
desiredOutput = "[31, 0x1f, 037]";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// incorrect emitting
void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError)
@@ -963,6 +1075,7 @@ namespace Test
RunEmitterTest(&Emitter::BlockMapAsKey, "block map as key", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchor, "alias and anchor", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorWithNull, "alias and anchor with null", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorInFlow, "alias and anchor in flow", passed, total);
RunEmitterTest(&Emitter::SimpleVerbatimTag, "simple verbatim tag", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInBlockSeq, "verbatim tag in block seq", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowSeq, "verbatim tag in flow seq", passed, total);
@@ -980,6 +1093,10 @@ namespace Test
RunEmitterTest(&Emitter::SimpleComment, "simple comment", passed, total);
RunEmitterTest(&Emitter::MultiLineComment, "multi-line comment", passed, total);
RunEmitterTest(&Emitter::ComplexComments, "complex comments", passed, total);
RunEmitterTest(&Emitter::InitialComment, "initial comment", passed, total);
RunEmitterTest(&Emitter::InitialCommentWithDocIndicator, "initial comment with doc indicator", passed, total);
RunEmitterTest(&Emitter::CommentInFlowSeq, "comment in flow seq", passed, total);
RunEmitterTest(&Emitter::CommentInFlowMap, "comment in flow map", passed, total);
RunEmitterTest(&Emitter::Indentation, "indentation", passed, total);
RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings", passed, total);
RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings", passed, total);
@@ -1002,9 +1119,16 @@ namespace Test
RunEmitterTest(&Emitter::EmptyBinary, "empty binary", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalar, "colon at end of scalar", passed, total);
RunEmitterTest(&Emitter::ColonAsScalar, "colon as scalar", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalarInFlow, "colon at end of scalar in flow", passed, total);
RunEmitterTest(&Emitter::BoolFormatting, "bool formatting", passed, total);
RunEmitterTest(&Emitter::DocStartAndEnd, "doc start and end", passed, total);
RunEmitterTest(&Emitter::ImplicitDocStart, "implicit doc start", passed, total);
RunEmitterTest(&Emitter::EmptyString, "empty string", passed, total);
RunEmitterTest(&Emitter::SingleChar, "single char", passed, total);
RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total);
RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);

View File

@@ -1,7 +1,7 @@
#ifndef EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

13
test/nodetests.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODETESTS_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 Test {
bool RunNodeTests();
}
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666

View File

@@ -2,6 +2,7 @@
#include "yaml-cpp/yaml.h"
#include <sstream>
#include <algorithm>
#include <iostream>
namespace Test
{
@@ -803,7 +804,138 @@ namespace Test
return ExpectedTagValue(node, "!");
}
}
bool Infinity()
{
std::string input =
"- .inf\n"
"- .Inf\n"
"- .INF\n"
"- +.inf\n"
"- +.Inf\n"
"- +.INF\n"
"- -.inf\n"
"- -.Inf\n"
"- -.INF\n";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
for(unsigned i=0;i<doc.size();i++)
if(doc[i].to<double>() != (i < 6 ? +1 : -1) * std::numeric_limits<double>::infinity())
return false;
for(unsigned i=0;i<doc.size();i++)
if(doc[i].to<long double>() != (i < 6 ? +1 : -1) * std::numeric_limits<long double>::infinity())
return false;
for(unsigned i=0;i<doc.size();i++)
if(doc[i].to<float>() != (i < 6 ? +1 : -1) * std::numeric_limits<float>::infinity())
return false;
return true;
}
bool NaN()
{
std::string input =
"- .nan\n"
"- .NaN\n"
"- .NAN\n";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
for(unsigned i=0;i<doc.size();i++) {
double d;
doc[i] >> d;
if(d == d)
return false;
}
for(unsigned i=0;i<doc.size();i++) {
long double d;
doc[i] >> d;
if(d == d)
return false;
}
for(unsigned i=0;i<doc.size();i++) {
float d;
doc[i] >> d;
if(d == d)
return false;
}
return true;
}
bool NonConstKey()
{
std::string input = "{a: 1}";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
std::vector<char> key(2);
key[0] = 'a';
key[1] = '\0';
if(doc[&key[0]].to<int>() != 1)
return false;
return true;
}
bool SingleChar()
{
std::string input = "5";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
return doc.to<int>() == 5;
}
bool QuotedNewline()
{
std::string input = "foo: \"\\n\"";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
return doc["foo"].to<std::string>() == "\n";
}
bool DoubleAsInt()
{
std::string input = "1.5";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
try {
doc.to<int>();
} catch(const YAML::InvalidScalar& e) {
return true;
}
return false;
}
bool Binary()
{
std::string input = "[!!binary \"SGVsbG8sIFdvcmxkIQ==\", !!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"]";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
if(doc[0].to<YAML::Binary>() != YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13))
return false;
if(doc[1].to<YAML::Binary>() != YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270))
return false;
return true;
}
}
namespace {
void RunScalarParserTest(void (*test)(std::string&, std::string&), const std::string& name, int& passed, int& total) {
@@ -853,7 +985,7 @@ namespace Test
} else {
std::cout << "Parser test failed: " << name << "\n";
if(error != "")
std::cout << "Caught exception: " << error << "\n";
std::cout << " Caught exception: " << error << "\n";
}
total++;
}
@@ -1021,7 +1153,7 @@ namespace Test
} else {
std::cout << "Parser test failed: " << name << "\n";
if(error != "")
std::cout << "Caught exception: " << error << "\n";
std::cout << " Caught exception: " << error << "\n";
}
total++;
}
@@ -1079,6 +1211,13 @@ namespace Test
RunParserTest(&Parser::DefaultPlainScalarTag, "default plain scalar tag", passed, total);
RunParserTest(&Parser::DefaultSequenceTag, "default sequence tag", passed, total);
RunParserTest(&Parser::ExplicitNonSpecificSequenceTag, "explicit, non-specific sequence tag", passed, total);
RunParserTest(&Parser::Infinity, "infinity", passed, total);
RunParserTest(&Parser::NaN, "NaN", passed, total);
RunParserTest(&Parser::NonConstKey, "non const key", passed, total);
RunParserTest(&Parser::SingleChar, "single char", passed, total);
RunParserTest(&Parser::QuotedNewline, "quoted newline", passed, total);
RunParserTest(&Parser::DoubleAsInt, "double as int", passed, total);
RunParserTest(&Parser::Binary, "binary", passed, total);
RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed, total);
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed, total);

1456
test/old-api/spectests.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

850
test/specexamples.h Normal file
View File

@@ -0,0 +1,850 @@
namespace Test {
namespace Spec {
const char *ex2_1 =
"- Mark McGwire\n"
"- Sammy Sosa\n"
"- Ken Griffey";
const char *ex2_2 =
"hr: 65 # Home runs\n"
"avg: 0.278 # Batting average\n"
"rbi: 147 # Runs Batted In";
const char *ex2_3 =
"american:\n"
"- Boston Red Sox\n"
"- Detroit Tigers\n"
"- New York Yankees\n"
"national:\n"
"- New York Mets\n"
"- Chicago Cubs\n"
"- Atlanta Braves";
const char *ex2_4 =
"-\n"
" name: Mark McGwire\n"
" hr: 65\n"
" avg: 0.278\n"
"-\n"
" name: Sammy Sosa\n"
" hr: 63\n"
" avg: 0.288";
const char *ex2_5 =
"- [name , hr, avg ]\n"
"- [Mark McGwire, 65, 0.278]\n"
"- [Sammy Sosa , 63, 0.288]";
const char *ex2_6 =
"Mark McGwire: {hr: 65, avg: 0.278}\n"
"Sammy Sosa: {\n"
" hr: 63,\n"
" avg: 0.288\n"
" }";
const char *ex2_7 =
"# Ranking of 1998 home runs\n"
"---\n"
"- Mark McGwire\n"
"- Sammy Sosa\n"
"- Ken Griffey\n"
"\n"
"# Team ranking\n"
"---\n"
"- Chicago Cubs\n"
"- St Louis Cardinals";
const char *ex2_8 =
"---\n"
"time: 20:03:20\n"
"player: Sammy Sosa\n"
"action: strike (miss)\n"
"...\n"
"---\n"
"time: 20:03:47\n"
"player: Sammy Sosa\n"
"action: grand slam\n"
"...";
const char *ex2_9 =
"---\n"
"hr: # 1998 hr ranking\n"
" - Mark McGwire\n"
" - Sammy Sosa\n"
"rbi:\n"
" # 1998 rbi ranking\n"
" - Sammy Sosa\n"
" - Ken Griffey";
const char *ex2_10 =
"---\n"
"hr:\n"
" - Mark McGwire\n"
" # Following node labeled SS\n"
" - &SS Sammy Sosa\n"
"rbi:\n"
" - *SS # Subsequent occurrence\n"
" - Ken Griffey";
const char *ex2_11 =
"? - Detroit Tigers\n"
" - Chicago cubs\n"
":\n"
" - 2001-07-23\n"
"\n"
"? [ New York Yankees,\n"
" Atlanta Braves ]\n"
": [ 2001-07-02, 2001-08-12,\n"
" 2001-08-14 ]";
const char *ex2_12 =
"---\n"
"# Products purchased\n"
"- item : Super Hoop\n"
" quantity: 1\n"
"- item : Basketball\n"
" quantity: 4\n"
"- item : Big Shoes\n"
" quantity: 1";
const char *ex2_13 =
"# ASCII Art\n"
"--- |\n"
" \\//||\\/||\n"
" // || ||__";
const char *ex2_14 =
"--- >\n"
" Mark McGwire's\n"
" year was crippled\n"
" by a knee injury.";
const char *ex2_15 =
">\n"
" Sammy Sosa completed another\n"
" fine season with great stats.\n"
" \n"
" 63 Home Runs\n"
" 0.288 Batting Average\n"
" \n"
" What a year!";
const char *ex2_16 =
"name: Mark McGwire\n"
"accomplishment: >\n"
" Mark set a major league\n"
" home run record in 1998.\n"
"stats: |\n"
" 65 Home Runs\n"
" 0.278 Batting Average\n";
const char *ex2_17 =
"unicode: \"Sosa did fine.\\u263A\"\n"
"control: \"\\b1998\\t1999\\t2000\\n\"\n"
"hex esc: \"\\x0d\\x0a is \\r\\n\"\n"
"\n"
"single: '\"Howdy!\" he cried.'\n"
"quoted: ' # Not a ''comment''.'\n"
"tie-fighter: '|\\-*-/|'";
const char *ex2_18 =
"plain:\n"
" This unquoted scalar\n"
" spans many lines.\n"
"\n"
"quoted: \"So does this\n"
" quoted scalar.\\n\"";
// TODO: 2.19 - 2.22 schema tags
const char *ex2_23 =
"---\n"
"not-date: !!str 2002-04-28\n"
"\n"
"picture: !!binary |\n"
" R0lGODlhDAAMAIQAAP//9/X\n"
" 17unp5WZmZgAAAOfn515eXv\n"
" Pz7Y6OjuDg4J+fn5OTk6enp\n"
" 56enmleECcgggoBADs=\n"
"\n"
"application specific tag: !something |\n"
" The semantics of the tag\n"
" above may be different for\n"
" different documents.";
const char *ex2_24 =
"%TAG ! tag:clarkevans.com,2002:\n"
"--- !shape\n"
" # Use the ! handle for presenting\n"
" # tag:clarkevans.com,2002:circle\n"
"- !circle\n"
" center: &ORIGIN {x: 73, y: 129}\n"
" radius: 7\n"
"- !line\n"
" start: *ORIGIN\n"
" finish: { x: 89, y: 102 }\n"
"- !label\n"
" start: *ORIGIN\n"
" color: 0xFFEEBB\n"
" text: Pretty vector drawing.";
const char *ex2_25 =
"# Sets are represented as a\n"
"# Mapping where each key is\n"
"# associated with a null value\n"
"--- !!set\n"
"? Mark McGwire\n"
"? Sammy Sosa\n"
"? Ken Griffey";
const char *ex2_26 =
"# Ordered maps are represented as\n"
"# A sequence of mappings, with\n"
"# each mapping having one key\n"
"--- !!omap\n"
"- Mark McGwire: 65\n"
"- Sammy Sosa: 63\n"
"- Ken Griffey: 58";
const char *ex2_27 =
"--- !<tag:clarkevans.com,2002:invoice>\n"
"invoice: 34843\n"
"date : 2001-01-23\n"
"bill-to: &id001\n"
" given : Chris\n"
" family : Dumars\n"
" address:\n"
" lines: |\n"
" 458 Walkman Dr.\n"
" Suite #292\n"
" city : Royal Oak\n"
" state : MI\n"
" postal : 48046\n"
"ship-to: *id001\n"
"product:\n"
" - sku : BL394D\n"
" quantity : 4\n"
" description : Basketball\n"
" price : 450.00\n"
" - sku : BL4438H\n"
" quantity : 1\n"
" description : Super Hoop\n"
" price : 2392.00\n"
"tax : 251.42\n"
"total: 4443.52\n"
"comments:\n"
" Late afternoon is best.\n"
" Backup contact is Nancy\n"
" Billsmer @ 338-4338.";
const char *ex2_28 =
"---\n"
"Time: 2001-11-23 15:01:42 -5\n"
"User: ed\n"
"Warning:\n"
" This is an error message\n"
" for the log file\n"
"---\n"
"Time: 2001-11-23 15:02:31 -5\n"
"User: ed\n"
"Warning:\n"
" A slightly different error\n"
" message.\n"
"---\n"
"Date: 2001-11-23 15:03:17 -5\n"
"User: ed\n"
"Fatal:\n"
" Unknown variable \"bar\"\n"
"Stack:\n"
" - file: TopClass.py\n"
" line: 23\n"
" code: |\n"
" x = MoreObject(\"345\\n\")\n"
" - file: MoreClass.py\n"
" line: 58\n"
" code: |-\n"
" foo = bar";
// TODO: 5.1 - 5.2 BOM
const char *ex5_3 =
"sequence:\n"
"- one\n"
"- two\n"
"mapping:\n"
" ? sky\n"
" : blue\n"
" sea : green";
const char *ex5_4 =
"sequence: [ one, two, ]\n"
"mapping: { sky: blue, sea: green }";
const char *ex5_5 =
"# Comment only.";
const char *ex5_6 =
"anchored: !local &anchor value\n"
"alias: *anchor";
const char *ex5_7 =
"literal: |\n"
" some\n"
" text\n"
"folded: >\n"
" some\n"
" text\n";
const char *ex5_8 =
"single: 'text'\n"
"double: \"text\"";
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
const char *ex5_11 =
"|\n"
" Line break (no glyph)\n"
" Line break (glyphed)\n";
const char *ex5_12 =
"# Tabs and spaces\n"
"quoted: \"Quoted\t\"\n"
"block: |\n"
" void main() {\n"
" \tprintf(\"Hello, world!\\n\");\n"
" }";
const char *ex5_13 =
"\"Fun with \\\\\n"
"\\\" \\a \\b \\e \\f \\\n"
"\\n \\r \\t \\v \\0 \\\n"
"\\ \\_ \\N \\L \\P \\\n"
"\\x41 \\u0041 \\U00000041\"";
const char *ex5_14 =
"Bad escapes:\n"
" \"\\c\n"
" \\xq-\"";
const char *ex6_1 =
" # Leading comment line spaces are\n"
" # neither content nor indentation.\n"
" \n"
"Not indented:\n"
" By one space: |\n"
" By four\n"
" spaces\n"
" Flow style: [ # Leading spaces\n"
" By two, # in flow style\n"
" Also by two, # are neither\n"
" \tStill by two # content nor\n"
" ] # indentation.";
const char *ex6_2 =
"? a\n"
": -\tb\n"
" - -\tc\n"
" - d";
const char *ex6_3 =
"- foo:\t bar\n"
"- - baz\n"
" -\tbaz";
const char *ex6_4 =
"plain: text\n"
" lines\n"
"quoted: \"text\n"
" \tlines\"\n"
"block: |\n"
" text\n"
" \tlines\n";
const char *ex6_5 =
"Folding:\n"
" \"Empty line\n"
" \t\n"
" as a line feed\"\n"
"Chomping: |\n"
" Clipped empty lines\n"
" ";
const char *ex6_6 =
">-\n"
" trimmed\n"
" \n"
" \n"
"\n"
" as\n"
" space";
const char *ex6_7 =
">\n"
" foo \n"
" \n"
" \t bar\n"
"\n"
" baz\n";
const char *ex6_8 =
"\"\n"
" foo \n"
" \n"
" \t bar\n"
"\n"
" baz\n"
"\"";
const char *ex6_9 =
"key: # Comment\n"
" value";
const char *ex6_10 =
" # Comment\n"
" \n"
"\n";
const char *ex6_11 =
"key: # Comment\n"
" # lines\n"
" value\n"
"\n";
const char *ex6_12 =
"{ first: Sammy, last: Sosa }:\n"
"# Statistics:\n"
" hr: # Home runs\n"
" 65\n"
" avg: # Average\n"
" 0.278";
const char *ex6_13 =
"%FOO bar baz # Should be ignored\n"
" # with a warning.\n"
"--- \"foo\"";
const char *ex6_14 =
"%YAML 1.3 # Attempt parsing\n"
" # with a warning\n"
"---\n"
"\"foo\"";
const char *ex6_15 =
"%YAML 1.2\n"
"%YAML 1.1\n"
"foo";
const char *ex6_16 =
"%TAG !yaml! tag:yaml.org,2002:\n"
"---\n"
"!yaml!str \"foo\"";
const char *ex6_17 =
"%TAG ! !foo\n"
"%TAG ! !foo\n"
"bar";
const char *ex6_18 =
"# Private\n"
"!foo \"bar\"\n"
"...\n"
"# Global\n"
"%TAG ! tag:example.com,2000:app/\n"
"---\n"
"!foo \"bar\"";
const char *ex6_19 =
"%TAG !! tag:example.com,2000:app/\n"
"---\n"
"!!int 1 - 3 # Interval, not integer";
const char *ex6_20 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"!e!foo \"bar\"";
const char *ex6_21 =
"%TAG !m! !my-\n"
"--- # Bulb here\n"
"!m!light fluorescent\n"
"...\n"
"%TAG !m! !my-\n"
"--- # Color here\n"
"!m!light green";
const char *ex6_22 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !e!foo \"bar\"";
const char *ex6_23 =
"!!str &a1 \"foo\":\n"
" !!str bar\n"
"&a2 baz : *a1";
const char *ex6_24 =
"!<tag:yaml.org,2002:str> foo :\n"
" !<!bar> baz";
const char *ex6_25 =
"- !<!> foo\n"
"- !<$:?> bar\n";
const char *ex6_26 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !local foo\n"
"- !!str bar\n"
"- !e!tag%21 baz\n";
const char *ex6_27a =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !e! foo";
const char *ex6_27b =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !h!bar baz";
const char *ex6_28 =
"# Assuming conventional resolution:\n"
"- \"12\"\n"
"- 12\n"
"- ! 12";
const char *ex6_29 =
"First occurrence: &anchor Value\n"
"Second occurrence: *anchor";
const char *ex7_1 =
"First occurrence: &anchor Foo\n"
"Second occurrence: *anchor\n"
"Override anchor: &anchor Bar\n"
"Reuse anchor: *anchor";
const char *ex7_2 =
"{\n"
" foo : !!str,\n"
" !!str : bar,\n"
"}";
const char *ex7_3 =
"{\n"
" ? foo :,\n"
" : bar,\n"
"}\n";
const char *ex7_4 =
"\"implicit block key\" : [\n"
" \"implicit flow key\" : value,\n"
" ]";
const char *ex7_5 =
"\"folded \n"
"to a space,\t\n"
" \n"
"to a line feed, or \t\\\n"
" \\ \tnon-content\"";
const char *ex7_6 =
"\" 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty \"";
const char *ex7_7 =
" 'here''s to \"quotes\"'";
const char *ex7_8 =
"'implicit block key' : [\n"
" 'implicit flow key' : value,\n"
" ]";
const char *ex7_9 =
"' 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty '";
const char *ex7_10 =
"# Outside flow collection:\n"
"- ::vector\n"
"- \": - ()\"\n"
"- Up, up, and away!\n"
"- -123\n"
"- http://example.com/foo#bar\n"
"# Inside flow collection:\n"
"- [ ::vector,\n"
" \": - ()\",\n"
" \"Up, up, and away!\",\n"
" -123,\n"
" http://example.com/foo#bar ]";
const char *ex7_11 =
"implicit block key : [\n"
" implicit flow key : value,\n"
" ]";
const char *ex7_12 =
"1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty";
const char *ex7_13 =
"- [ one, two, ]\n"
"- [three ,four]";
const char *ex7_14 =
"[\n"
"\"double\n"
" quoted\", 'single\n"
" quoted',\n"
"plain\n"
" text, [ nested ],\n"
"single: pair,\n"
"]";
const char *ex7_15 =
"- { one : two , three: four , }\n"
"- {five: six,seven : eight}";
const char *ex7_16 =
"{\n"
"? explicit: entry,\n"
"implicit: entry,\n"
"?\n"
"}";
const char *ex7_17 =
"{\n"
"unquoted : \"separate\",\n"
"http://foo.com,\n"
"omitted value:,\n"
": omitted key,\n"
"}";
const char *ex7_18 =
"{\n"
"\"adjacent\":value,\n"
"\"readable\":value,\n"
"\"empty\":\n"
"}";
const char *ex7_19 =
"[\n"
"foo: bar\n"
"]";
const char *ex7_20 =
"[\n"
"? foo\n"
" bar : baz\n"
"]";
const char *ex7_21 =
"- [ YAML : separate ]\n"
"- [ : empty key entry ]\n"
"- [ {JSON: like}:adjacent ]";
const char *ex7_22 =
"[ foo\n"
" bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an implicit key
const char *ex7_23 =
"- [ a, b ]\n"
"- { a: b }\n"
"- \"a\"\n"
"- 'b'\n"
"- c";
const char *ex7_24 =
"- !!str \"a\"\n"
"- 'b'\n"
"- &anchor \"c\"\n"
"- *anchor\n"
"- !!str";
const char *ex8_1 =
"- | # Empty header\n"
" literal\n"
"- >1 # Indentation indicator\n"
" folded\n"
"- |+ # Chomping indicator\n"
" keep\n"
"\n"
"- >1- # Both indicators\n"
" strip\n";
const char *ex8_2 =
"- |\n"
" detected\n"
"- >\n"
" \n"
" \n"
" # detected\n"
"- |1\n"
" explicit\n"
"- >\n"
" \t\n"
" detected\n";
const char *ex8_3a =
"- |\n"
" \n"
" text";
const char *ex8_3b =
"- >\n"
" text\n"
" text";
const char *ex8_3c =
"- |2\n"
" text";
const char *ex8_4 =
"strip: |-\n"
" text\n"
"clip: |\n"
" text\n"
"keep: |+\n"
" text\n";
const char *ex8_5 =
" # Strip\n"
" # Comments:\n"
"strip: |-\n"
" # text\n"
" \n"
" # Clip\n"
" # comments:\n"
"\n"
"clip: |\n"
" # text\n"
" \n"
" # Keep\n"
" # comments:\n"
"\n"
"keep: |+\n"
" # text\n"
"\n"
" # Trail\n"
" # Comments\n";
const char *ex8_6 =
"strip: >-\n"
"\n"
"clip: >\n"
"\n"
"keep: |+\n"
"\n";
const char *ex8_7 =
"|\n"
" literal\n"
" \ttext\n"
"\n";
const char *ex8_8 =
"|\n"
" \n"
" \n"
" literal\n"
" \n"
" \n"
" text\n"
"\n"
" # Comment\n";
const char *ex8_9 =
">\n"
" folded\n"
" text\n"
"\n";
const char *ex8_10 =
">\n"
"\n"
" folded\n"
" line\n"
"\n"
" next\n"
" line\n"
" * bullet\n"
"\n"
" * list\n"
" * lines\n"
"\n"
" last\n"
" line\n"
"\n"
"# Comment\n";
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_14 =
"block sequence:\n"
" - one\n"
" - two : three\n";
const char *ex8_15 =
"- # Empty\n"
"- |\n"
" block node\n"
"- - one # Compact\n"
" - two # sequence\n"
"- one: two # Compact mapping\n";
const char *ex8_16 =
"block mapping:\n"
" key: value\n";
const char *ex8_17 =
"? explicit key # Empty value\n"
"? |\n"
" block key\n"
": - one # Explicit compact\n"
" - two # block value\n";
const char *ex8_18 =
"plain key: in-line value\n"
": # Both empty\n"
"\"quoted key\":\n"
"- entry\n";
const char *ex8_19 =
"- sun: yellow\n"
"- ? earth: blue\n"
" : moon: white\n";
const char *ex8_20 =
"-\n"
" \"flow in block\"\n"
"- >\n"
" Block scalar\n"
"- !!map # Block collection\n"
" foo : bar\n";
const char *ex8_21 =
"literal: |2\n"
" value\n"
"folded:\n"
" !foo\n"
" >1\n"
" value\n";
const char *ex8_22 =
"sequence: !!seq\n"
"- entry\n"
"- !!seq\n"
" - nested\n"
"mapping: !!map\n"
" foo: bar\n";
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,5 +1,6 @@
#include "tests.h"
#include "emittertests.h"
#include "nodetests.h"
#include "parsertests.h"
#include "spectests.h"
#include "yaml-cpp/yaml.h"

View File

@@ -1,7 +1,7 @@
#ifndef TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

129
util/api.cpp Normal file
View File

@@ -0,0 +1,129 @@
// a sketch of what the new API might look like
#include "yaml-cpp/yaml.h"
#include <iostream>
int main()
{
{
// test.yaml
// - foo
// - primes: [2, 3, 5, 7, 11]
// odds: [1, 3, 5, 7, 9, 11]
// - [x, y]
// move-like semantics
YAML::Value root = YAML::Parse("test.yaml");
std::cout << root[0].as<std::string>(); // "foo"
std::cout << str(root[0]); // "foo", shorthand?
std::cout << root[1]["primes"][3].as<int>(); // "7"
std::cout << root[1]["odds"][6].as<int>(); // throws?
root[2].push_back(5);
root[3] = "Hello, World";
root[0].reset();
root[0]["key"] = "value";
std::cout << root;
// # not sure about formatting
// - {key: value}
// - primes: [2, 3, 5, 7, 11]
// odds: [1, 3, 5, 7, 9, 11]
// - [x, y, 5]
// - Hello, World
}
{
// for all copy-like commands, think of python's "name/value" semantics
YAML::Value root = "Hello"; // Hello
root = YAML::Sequence(); // []
root[0] = 0; // [0]
root[2] = "two"; // [0, ~, two] # forces root[1] to be initialized to null
YAML::Value other = root; // both point to the same thing
other[0] = 5; // now root[0] is 0 also
other.push_back(root); // &1 [5, ~, two, *1]
other[3][0] = 0; // &1 [0, ~, two, *1] # since it's a true alias
other.push_back(Copy(root)); // &1 [0, ~, two, *1, &2 [0, ~, two, *2]]
other[4][0] = 5; // &1 [0, ~, two, *1, &2 [5, ~, two, *2]] # they're really different
}
{
YAML::Value node; // ~
node[0] = 1; // [1] # auto-construct a sequence
node["key"] = 5; // {0: 1, key: 5} # auto-turn it into a map
node.push_back(10); // error, can't turn a map into a sequence
node.erase("key"); // {0: 1} # still a map, even if we remove the key that caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now just a plain scalar
}
{
YAML::Value map; // ~
map[3] = 1; // {3: 1} # auto-constructs a map, *not* a sequence
YAML::Value seq; // ~
seq = YAML::Sequence(); // []
seq[3] = 1; // [~, ~, ~, 1]
}
{
YAML::Value node; // ~
node[0] = node; // &1 [*1] # fun stuff
}
{
YAML::Value node;
YAML::Value subnode = node["key"]; // 'subnode' is not instantiated ('node' is still null)
subnode = "value"; // {key: value} # now it is
YAML::Value subnode2 = node["key2"];
node["key3"] = subnode2; // subnode2 is still not instantiated, but node["key3"] is "pseudo" aliased to it
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it instantiates both
}
{
YAML::Value seq = YAML::Sequence();
seq[0] = "zero"; // [zero]
seq[1] = seq[0]; // [&1 zero, *1]
seq[0] = seq[1]; // [&1 zero, *1] # no-op (they both alias the same thing, so setting them equal is nothing)
Is(seq[0], seq[1]); // true
seq[1] = "one"; // [&1 one, *1]
UnAlias(seq[1]); // [one, one]
Is(seq[0], seq[1]); // false
}
{
YAML::Value root;
root.push_back("zero");
root.push_back("one");
root.push_back("two");
YAML::Value two = root[2];
root = "scalar"; // 'two' is still "two", even though 'root' is "scalar" (the sequence effectively no longer exists)
// Note: in all likelihood, the memory for nodes "zero" and "one" is still allocated. How can it go away? Weak pointers?
}
{
YAML::Value root; // ~
root[0] = root; // &1 [*1]
root[0] = 5; // [5]
}
{
YAML::Value root;
YAML::Value key;
key["key"] = "value";
root[key] = key; // &1 {key: value}: *1
}
{
YAML::Value root;
root[0] = "hi";
root[1][0] = "bye";
root[1][1] = root; // &1 [hi, [bye, *1]] # root
YAML::Value sub = root[1]; // &1 [bye, [hi, *1]] # sub
root = "gone"; // [bye, gone] # sub
}
return 0;
}

View File

@@ -39,7 +39,6 @@ void parse(std::istream& input)
try {
YAML::Parser parser(input);
YAML::Node doc;
NullEventHandler handler;
while(parser.GetNextDocument(doc)) {
YAML::Emitter emitter;
emitter << doc;

View File

@@ -1,7 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@LIB_INSTALL_DIR@
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
includedir=${prefix}/@INCLUDE_INSTALL_ROOT_DIR@
Name: Yaml-cpp
Description: A YAML parser and emitter for C++