From f996468a6af25aad7b2fd123ee0f6d53da6e1a94 Mon Sep 17 00:00:00 2001 From: maek Date: Sat, 24 Mar 2018 15:48:39 +0000 Subject: [PATCH 01/15] Fix UTF-8 code points emitting (#571) --- src/emitterutils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index 147738a..fffb775 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -134,12 +134,12 @@ void WriteCodePoint(ostream_wrapper& out, int codePoint) { if (codePoint < 0 || codePoint > 0x10FFFF) { codePoint = REPLACEMENT_CHARACTER; } - if (codePoint < 0x7F) { + if (codePoint <= 0x7F) { out << static_cast(codePoint); - } else if (codePoint < 0x7FF) { + } else if (codePoint <= 0x7FF) { out << static_cast(0xC0 | (codePoint >> 6)) << static_cast(0x80 | (codePoint & 0x3F)); - } else if (codePoint < 0xFFFF) { + } else if (codePoint <= 0xFFFF) { out << static_cast(0xE0 | (codePoint >> 12)) << static_cast(0x80 | ((codePoint >> 6) & 0x3F)) << static_cast(0x80 | (codePoint & 0x3F)); From 124ae4760062e2f5827a6238c122ccbf66eb4e6e Mon Sep 17 00:00:00 2001 From: Tanki Zhang Date: Tue, 10 Apr 2018 23:47:23 -0500 Subject: [PATCH 02/15] Update the iterator implementation for C++17 (#575) Fix the compiler error which prevents deriving from std::iterator in C++17 --- include/yaml-cpp/node/detail/iterator.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index deec8fb..966107d 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -8,19 +8,19 @@ #endif #include "yaml-cpp/dll.h" +#include "yaml-cpp/node/detail/node_iterator.h" #include "yaml-cpp/node/node.h" #include "yaml-cpp/node/ptr.h" -#include "yaml-cpp/node/detail/node_iterator.h" #include #include + namespace YAML { namespace detail { struct iterator_value; template -class iterator_base : public std::iterator { +class iterator_base { private: template @@ -37,7 +37,11 @@ class iterator_base : public std::iterator Date: Sat, 5 May 2018 18:03:13 +0200 Subject: [PATCH 03/15] Use target-based include_directories to enable modern CMake usage (#583) --- CMakeLists.txt | 15 ++++++++++++--- test/CMakeLists.txt | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d8810..715c846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,9 +116,10 @@ if(VERBOSE) message(STATUS "contrib_private_headers: ${contrib_private_headers}") endif() -include_directories(${YAML_CPP_SOURCE_DIR}/src) -include_directories(${YAML_CPP_SOURCE_DIR}/include) - +if (CMAKE_VERSION VERSION_LESS 2.8.12) + include_directories(${YAML_CPP_SOURCE_DIR}/src) + include_directories(${YAML_CPP_SOURCE_DIR}/include) +endif() ### @@ -275,6 +276,14 @@ set(_INSTALL_DESTINATIONS ### Library ### add_library(yaml-cpp ${library_sources}) + +if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) + target_include_directories(yaml-cpp + PUBLIC $ + $ + PRIVATE $) +endif() + set_target_properties(yaml-cpp PROPERTIES COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}" ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3633da5..ad61a3c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,6 +30,7 @@ file(GLOB test_new_api_sources new-api/[a-z]*.cpp) list(APPEND test_sources ${test_new_api_sources}) add_sources(${test_sources} ${test_headers}) +include_directories(${YAML_CPP_SOURCE_DIR}/src) include_directories(${YAML_CPP_SOURCE_DIR}/test) add_executable(run-tests From 4fb1c4b92bf8d94b32ebccdd890407d45b3bc794 Mon Sep 17 00:00:00 2001 From: Jiao <714239332@qq.com> Date: Mon, 14 May 2018 21:50:28 +0800 Subject: [PATCH 04/15] Enable items to be removed from a sequence (#582) --- .gitignore | 1 + include/yaml-cpp/node/detail/impl.h | 63 ++++++++++++++++++++++------- src/node_data.cpp | 8 ++++ test/node/node_test.cpp | 50 +++++++++++++++++++++-- util/CMakeLists.txt | 2 + 5 files changed, 105 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 567609b..0e29154 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +/tags diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index 09e55f8..2be4f78 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -32,7 +32,7 @@ struct get_idx& sequence, const Key& key, shared_memory_holder pMemory) { - if (key > sequence.size() || (key > 0 && !sequence[key-1]->is_defined())) + if (key > sequence.size() || (key > 0 && !sequence[key - 1]->is_defined())) return 0; if (key == sequence.size()) sequence.push_back(&pMemory->create_node()); @@ -56,6 +56,37 @@ struct get_idx::value>::type> { } }; +template +struct remove_idx { + static bool remove(std::vector&, const Key&) { return false; } +}; + +template +struct remove_idx< + Key, typename std::enable_if::value && + !std::is_same::value>::type> { + + static bool remove(std::vector& sequence, const Key& key) { + if (key >= sequence.size()) { + return false; + } else { + sequence.erase(sequence.begin() + key); + return true; + } + } +}; + +template +struct remove_idx::value>::type> { + + static bool remove(std::vector& sequence, const Key& key) { + return key >= 0 ? remove_idx::remove( + sequence, static_cast(key)) + : false; + } +}; + template inline bool node::equals(const T& rhs, shared_memory_holder pMemory) { T lhs; @@ -129,21 +160,23 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { template inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { - if (m_type != NodeType::Map) - return false; + if (m_type == NodeType::Sequence) { + return remove_idx::remove(m_sequence, key); + } else if (m_type == NodeType::Map) { + kv_pairs::iterator it = m_undefinedPairs.begin(); + while (it != m_undefinedPairs.end()) { + kv_pairs::iterator jt = std::next(it); + if (it->first->equals(key, pMemory)) { + m_undefinedPairs.erase(it); + } + it = jt; + } - for (kv_pairs::iterator it = m_undefinedPairs.begin(); - it != m_undefinedPairs.end();) { - kv_pairs::iterator jt = std::next(it); - if (it->first->equals(key, pMemory)) - m_undefinedPairs.erase(it); - it = jt; - } - - for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { - if (it->first->equals(key, pMemory)) { - m_map.erase(it); - return true; + for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { + if (it->first->equals(key, pMemory)) { + m_map.erase(it); + return true; + } } } diff --git a/src/node_data.cpp b/src/node_data.cpp index 77cd465..2dfcd7b 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -235,6 +235,14 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) { if (m_type != NodeType::Map) return false; + kv_pairs::iterator it = m_undefinedPairs.begin(); + while (it != m_undefinedPairs.end()) { + kv_pairs::iterator jt = std::next(it); + if (it->first->is(key)) + m_undefinedPairs.erase(it); + it = jt; + } + for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { if (it->first->is(key)) { m_map.erase(it); diff --git a/test/node/node_test.cpp b/test/node/node_test.cpp index 485ad09..61ba3e6 100644 --- a/test/node/node_test.cpp +++ b/test/node/node_test.cpp @@ -1,10 +1,10 @@ -#include "yaml-cpp/emitter.h" -#include "yaml-cpp/node/emit.h" #include "yaml-cpp/node/node.h" -#include "yaml-cpp/node/impl.h" +#include "yaml-cpp/emitter.h" #include "yaml-cpp/node/convert.h" -#include "yaml-cpp/node/iterator.h" #include "yaml-cpp/node/detail/impl.h" +#include "yaml-cpp/node/emit.h" +#include "yaml-cpp/node/impl.h" +#include "yaml-cpp/node/iterator.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -47,6 +47,30 @@ TEST(NodeTest, SimpleAppendSequence) { EXPECT_TRUE(node.IsSequence()); } +TEST(NodeTest, SequenceElementRemoval) { + Node node; + node[0] = "a"; + node[1] = "b"; + node[2] = "c"; + node.remove(1); + EXPECT_TRUE(node.IsSequence()); + EXPECT_EQ(2, node.size()); + EXPECT_EQ("a", node[0].as()); + EXPECT_EQ("c", node[1].as()); +} + +TEST(NodeTest, SequenceLastElementRemoval) { + Node node; + node[0] = "a"; + node[1] = "b"; + node[2] = "c"; + node.remove(2); + EXPECT_TRUE(node.IsSequence()); + EXPECT_EQ(2, node.size()); + EXPECT_EQ("a", node[0].as()); + EXPECT_EQ("b", node[1].as()); +} + TEST(NodeTest, MapElementRemoval) { Node node; node["foo"] = "bar"; @@ -54,6 +78,16 @@ TEST(NodeTest, MapElementRemoval) { EXPECT_TRUE(!node["foo"]); } +TEST(NodeTest, MapIntegerElementRemoval) { + Node node; + node[1] = "hello"; + node[2] = 'c'; + node["foo"] = "bar"; + EXPECT_TRUE(node.IsMap()); + node.remove(1); + EXPECT_TRUE(node.IsMap()); +} + TEST(NodeTest, SimpleAssignSequence) { Node node; node[0] = 10; @@ -106,6 +140,14 @@ TEST(NodeTest, RemoveUnassignedNode) { EXPECT_EQ(0, node.size()); } +TEST(NodeTest, RemoveUnassignedNodeFromMap) { + Node node(NodeType::Map); + Node n; + node[n]; + node.remove(n); + EXPECT_EQ(0, node.size()); +} + TEST(NodeTest, MapForceInsert) { Node node; Node k1("k1"); diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 2286627..931884f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.5) + add_sources(parse.cpp) add_executable(parse parse.cpp) target_link_libraries(parse yaml-cpp) From 0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sat, 30 Jun 2018 14:23:28 -0700 Subject: [PATCH 05/15] Fix _NOEXCEPT not available in VS2017 15.8. Use noexcept for VS2015+ (#597) --- include/yaml-cpp/exceptions.h | 2 +- src/exceptions.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h index 9c96859..87b92f5 100644 --- a/include/yaml-cpp/exceptions.h +++ b/include/yaml-cpp/exceptions.h @@ -15,7 +15,7 @@ // This is here for compatibility with older versions of Visual Studio // which don't support noexcept -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER < 1900 #define YAML_CPP_NOEXCEPT _NOEXCEPT #else #define YAML_CPP_NOEXCEPT noexcept diff --git a/src/exceptions.cpp b/src/exceptions.cpp index 9b6d891..841549e 100644 --- a/src/exceptions.cpp +++ b/src/exceptions.cpp @@ -2,7 +2,7 @@ // This is here for compatibility with older versions of Visual Studio // which don't support noexcept -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER < 1900 #define YAML_CPP_NOEXCEPT _NOEXCEPT #else #define YAML_CPP_NOEXCEPT noexcept From 1698b47b65feded180f44d762ddaf7181a270608 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 3 Jul 2018 07:59:04 +0300 Subject: [PATCH 06/15] Use nullptr instead of 0 or NULL (clang-tidy warns) (#603) --- src/contrib/graphbuilder.cpp | 2 +- src/contrib/graphbuilderadapter.cpp | 6 +++--- src/contrib/graphbuilderadapter.h | 2 +- src/node_data.cpp | 4 ++-- src/nodebuilder.cpp | 4 ++-- src/ostream_wrapper.cpp | 2 +- src/scanner.cpp | 6 +++--- src/scanner.h | 2 +- src/simplekey.cpp | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/contrib/graphbuilder.cpp b/src/contrib/graphbuilder.cpp index 416c135..bf25162 100644 --- a/src/contrib/graphbuilder.cpp +++ b/src/contrib/graphbuilder.cpp @@ -11,7 +11,7 @@ void* BuildGraphOfNextDocument(Parser& parser, if (parser.HandleNextDocument(eventHandler)) { return eventHandler.RootNode(); } else { - return NULL; + return nullptr; } } } diff --git a/src/contrib/graphbuilderadapter.cpp b/src/contrib/graphbuilderadapter.cpp index 02a3d97..b9e0b65 100644 --- a/src/contrib/graphbuilderadapter.cpp +++ b/src/contrib/graphbuilderadapter.cpp @@ -49,7 +49,7 @@ void GraphBuilderAdapter::OnMapStart(const Mark &mark, const std::string &tag, EmitterStyle::value /* style */) { void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent()); m_containers.push(ContainerFrame(pNode, m_pKeyNode)); - m_pKeyNode = NULL; + m_pKeyNode = nullptr; RegisterAnchor(anchor, pNode); } @@ -62,7 +62,7 @@ void GraphBuilderAdapter::OnMapEnd() { void *GraphBuilderAdapter::GetCurrentParent() const { if (m_containers.empty()) { - return NULL; + return nullptr; } return m_containers.top().pContainer; } @@ -83,7 +83,7 @@ void GraphBuilderAdapter::DispositionNode(void *pNode) { if (m_containers.top().isMap()) { if (m_pKeyNode) { m_builder.AssignInMap(pContainer, m_pKeyNode, pNode); - m_pKeyNode = NULL; + m_pKeyNode = nullptr; } else { m_pKeyNode = pNode; } diff --git a/src/contrib/graphbuilderadapter.h b/src/contrib/graphbuilderadapter.h index 0d1e579..62b40a1 100644 --- a/src/contrib/graphbuilderadapter.h +++ b/src/contrib/graphbuilderadapter.h @@ -26,7 +26,7 @@ namespace YAML { class GraphBuilderAdapter : public EventHandler { public: GraphBuilderAdapter(GraphBuilderInterface& builder) - : m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL) {} + : m_builder(builder), m_pRootNode(nullptr), m_pKeyNode(nullptr) {} virtual void OnDocumentStart(const Mark& mark) { (void)mark; } virtual void OnDocumentEnd() {} diff --git a/src/node_data.cpp b/src/node_data.cpp index 2dfcd7b..34d81f7 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -197,7 +197,7 @@ void node_data::insert(node& key, node& value, shared_memory_holder pMemory) { // indexing node* node_data::get(node& key, shared_memory_holder /* pMemory */) const { if (m_type != NodeType::Map) { - return NULL; + return nullptr; } for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) { @@ -205,7 +205,7 @@ node* node_data::get(node& key, shared_memory_holder /* pMemory */) const { return it->second; } - return NULL; + return nullptr; } node& node_data::get(node& key, shared_memory_holder pMemory) { diff --git a/src/nodebuilder.cpp b/src/nodebuilder.cpp index 093d2ef..e79ac50 100644 --- a/src/nodebuilder.cpp +++ b/src/nodebuilder.cpp @@ -11,8 +11,8 @@ namespace YAML { struct Mark; NodeBuilder::NodeBuilder() - : m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0) { - m_anchors.push_back(0); // since the anchors start at 1 + : m_pMemory(new detail::memory_holder), m_pRoot(nullptr), m_mapDepth(0) { + m_anchors.push_back(nullptr); // since the anchors start at 1 } NodeBuilder::~NodeBuilder() {} diff --git a/src/ostream_wrapper.cpp b/src/ostream_wrapper.cpp index 357fc00..a3c7597 100644 --- a/src/ostream_wrapper.cpp +++ b/src/ostream_wrapper.cpp @@ -7,7 +7,7 @@ namespace YAML { ostream_wrapper::ostream_wrapper() : m_buffer(1, '\0'), - m_pStream(0), + m_pStream(nullptr), m_pos(0), m_row(0), m_col(0), diff --git a/src/scanner.cpp b/src/scanner.cpp index b5cfcc1..546a2f0 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -282,7 +282,7 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column, IndentMarker::INDENT_TYPE type) { // are we in flow? if (InFlowContext()) { - return 0; + return nullptr; } std::unique_ptr pIndent(new IndentMarker(column, type)); @@ -291,12 +291,12 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column, // is this actually an indentation? if (indent.column < lastIndent.column) { - return 0; + return nullptr; } if (indent.column == lastIndent.column && !(indent.type == IndentMarker::SEQ && lastIndent.type == IndentMarker::MAP)) { - return 0; + return nullptr; } // push a start token diff --git a/src/scanner.h b/src/scanner.h index 7bb2ccc..c653ac6 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -49,7 +49,7 @@ class Scanner { enum INDENT_TYPE { MAP, SEQ, NONE }; enum STATUS { VALID, INVALID, UNKNOWN }; IndentMarker(int column_, INDENT_TYPE type_) - : column(column_), type(type_), status(VALID), pStartToken(0) {} + : column(column_), type(type_), status(VALID), pStartToken(nullptr) {} int column; INDENT_TYPE type; diff --git a/src/simplekey.cpp b/src/simplekey.cpp index 70f56b6..c7a2135 100644 --- a/src/simplekey.cpp +++ b/src/simplekey.cpp @@ -5,7 +5,7 @@ namespace YAML { struct Mark; Scanner::SimpleKey::SimpleKey(const Mark& mark_, std::size_t flowLevel_) - : mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {} + : mark(mark_), flowLevel(flowLevel_), pIndent(nullptr), pMapStart(nullptr), pKey(nullptr) {} void Scanner::SimpleKey::Validate() { // Note: pIndent will *not* be garbage here; From 3e33bb316651981916d623488caf2f8ee1b79b50 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Thu, 9 Aug 2018 15:11:50 +0300 Subject: [PATCH 07/15] Improvements to CMake buildsystem (#563) * Move enable_testing() into proper place * Added CMake's checks for C++11 standards Raised minimal version of CMake to 3.1, since on old systems there no decent compilers that supports c++11. Closes #377. * Externalize googletest project Externalize gtest to avoid installation, fixes #539. * Remove defined cmake_policies CMP0012 - OLD marked as deprecated for >=cmake-3.1 and will be removed CMP0015 - does not affect to build process CMP0042 - already NEW for >=cmake-3.1 Fixes #505 * Fix compiling in Windows MSVC --- CMakeLists.txt | 26 +++++-------------- test/CMakeLists.txt | 63 +++++++++++++++++++++++++++++---------------- util/CMakeLists.txt | 4 +-- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 715c846..154230a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,11 @@ ### ### CMake settings ### -## Due to Mac OSX we need to keep compatibility with CMake 2.6 # see http://www.cmake.org/Wiki/CMake_Policies -cmake_minimum_required(VERSION 2.6) -# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012 -if(POLICY CMP0012) - cmake_policy(SET CMP0012 OLD) -endif() -# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015 -if(POLICY CMP0015) - cmake_policy(SET CMP0015 OLD) -endif() -# see https://cmake.org/cmake/help/latest/policy/CMP0042.html -if(POLICY CMP0042) - # Enable MACOSX_RPATH by default. - cmake_policy(SET CMP0042 NEW) -endif() +cmake_minimum_required(VERSION 3.1) include(CheckCXXCompilerFlag) - ### ### Project settings ### @@ -31,8 +16,6 @@ set(YAML_CPP_VERSION_MINOR "6") set(YAML_CPP_VERSION_PATCH "2") set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}") -enable_testing() - ### ### Project options @@ -48,6 +31,10 @@ option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON) # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) +# Set minimum C++ to 2011 standards +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + # --> Apple option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) @@ -188,7 +175,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") endif() # - set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}") + set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}") ### Make specific if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake) @@ -360,6 +347,7 @@ endif() ### Extras ### if(YAML_CPP_BUILD_TESTS) + enable_testing() add_subdirectory(test) endif() if(YAML_CPP_BUILD_TOOLS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ad61a3c..a83d9dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,26 +1,39 @@ -set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL - "Use shared (DLL) run-time lib even when Google Test built as a static lib.") -add_subdirectory(gtest-1.8.0) -include_directories(SYSTEM gtest-1.8.0/googlemock/include) -include_directories(SYSTEM gtest-1.8.0/googletest/include) +include(ExternalProject) -if(WIN32 AND BUILD_SHARED_LIBS) - add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY") +if(MSVC) + # MS Visual Studio expects lib prefix on static libraries, + # but CMake compiles them without prefix + # See https://gitlab.kitware.com/cmake/cmake/issues/17338 + set(CMAKE_STATIC_LIBRARY_PREFIX "") endif() +ExternalProject_Add( + googletest_project + SOURCE_DIR "${CMAKE_SOURCE_DIR}/test/gtest-1.8.0" + INSTALL_DIR "${CMAKE_BINARY_DIR}/prefix" + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH= + -DBUILD_GMOCK=ON + -Dgtest_force_shared_crt=ON +) + +add_library(gmock UNKNOWN IMPORTED) +set_target_properties(gmock PROPERTIES + IMPORTED_LOCATION + ${PROJECT_BINARY_DIR}/prefix/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} +) + +find_package(Threads) + +include_directories(SYSTEM "${PROJECT_BINARY_DIR}/prefix/include") + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR - CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") + CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") - endif() - - if(CMAKE_COMPILER_IS_GNUCXX) - set(yaml_test_flags "${yaml_test_flags} -std=gnu++11") - else() - set(yaml_test_flags "${yaml_test_flags} -std=c++11") - endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") + endif() endif() file(GLOB test_headers [a-z_]*.h) @@ -34,12 +47,18 @@ include_directories(${YAML_CPP_SOURCE_DIR}/src) include_directories(${YAML_CPP_SOURCE_DIR}/test) add_executable(run-tests - ${test_sources} - ${test_headers} + ${test_sources} + ${test_headers} ) + +add_dependencies(run-tests googletest_project) + set_target_properties(run-tests PROPERTIES - COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" + COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" ) -target_link_libraries(run-tests yaml-cpp gmock) +target_link_libraries(run-tests + yaml-cpp + gmock + ${CMAKE_THREAD_LIBS_INIT}) add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 931884f..8a803b0 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,14 +3,12 @@ cmake_minimum_required(VERSION 3.5) add_sources(parse.cpp) add_executable(parse parse.cpp) target_link_libraries(parse yaml-cpp) -set_target_properties(parse PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(sandbox.cpp) add_executable(sandbox sandbox.cpp) target_link_libraries(sandbox yaml-cpp) -set_target_properties(sandbox PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(read.cpp) add_executable(read read.cpp) target_link_libraries(read yaml-cpp) -set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11") + From c90c08ccc9a08abcca609064fb9a856dfdbbb7b4 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 9 Aug 2018 10:05:07 -0500 Subject: [PATCH 08/15] Revert "Improvements to CMake buildsystem (#563)" This reverts commit 3e33bb316651981916d623488caf2f8ee1b79b50. The original commit broke the build (#612) when yaml-cpp is used as a git submodule. --- CMakeLists.txt | 26 ++++++++++++++----- test/CMakeLists.txt | 63 ++++++++++++++++----------------------------- util/CMakeLists.txt | 4 ++- 3 files changed, 44 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 154230a..715c846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,26 @@ ### ### CMake settings ### +## Due to Mac OSX we need to keep compatibility with CMake 2.6 # see http://www.cmake.org/Wiki/CMake_Policies -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 2.6) +# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012 +if(POLICY CMP0012) + cmake_policy(SET CMP0012 OLD) +endif() +# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015 +if(POLICY CMP0015) + cmake_policy(SET CMP0015 OLD) +endif() +# see https://cmake.org/cmake/help/latest/policy/CMP0042.html +if(POLICY CMP0042) + # Enable MACOSX_RPATH by default. + cmake_policy(SET CMP0042 NEW) +endif() include(CheckCXXCompilerFlag) + ### ### Project settings ### @@ -16,6 +31,8 @@ set(YAML_CPP_VERSION_MINOR "6") set(YAML_CPP_VERSION_PATCH "2") set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}") +enable_testing() + ### ### Project options @@ -31,10 +48,6 @@ option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON) # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) -# Set minimum C++ to 2011 standards -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - # --> Apple option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) @@ -175,7 +188,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") endif() # - set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}") + set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}") ### Make specific if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake) @@ -347,7 +360,6 @@ endif() ### Extras ### if(YAML_CPP_BUILD_TESTS) - enable_testing() add_subdirectory(test) endif() if(YAML_CPP_BUILD_TOOLS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a83d9dd..ad61a3c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,39 +1,26 @@ -include(ExternalProject) +set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL + "Use shared (DLL) run-time lib even when Google Test built as a static lib.") +add_subdirectory(gtest-1.8.0) +include_directories(SYSTEM gtest-1.8.0/googlemock/include) +include_directories(SYSTEM gtest-1.8.0/googletest/include) -if(MSVC) - # MS Visual Studio expects lib prefix on static libraries, - # but CMake compiles them without prefix - # See https://gitlab.kitware.com/cmake/cmake/issues/17338 - set(CMAKE_STATIC_LIBRARY_PREFIX "") +if(WIN32 AND BUILD_SHARED_LIBS) + add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY") endif() -ExternalProject_Add( - googletest_project - SOURCE_DIR "${CMAKE_SOURCE_DIR}/test/gtest-1.8.0" - INSTALL_DIR "${CMAKE_BINARY_DIR}/prefix" - CMAKE_ARGS - -DCMAKE_INSTALL_PREFIX:PATH= - -DBUILD_GMOCK=ON - -Dgtest_force_shared_crt=ON -) - -add_library(gmock UNKNOWN IMPORTED) -set_target_properties(gmock PROPERTIES - IMPORTED_LOCATION - ${PROJECT_BINARY_DIR}/prefix/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} -) - -find_package(Threads) - -include_directories(SYSTEM "${PROJECT_BINARY_DIR}/prefix/include") - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR - CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") + CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") - endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") + endif() + + if(CMAKE_COMPILER_IS_GNUCXX) + set(yaml_test_flags "${yaml_test_flags} -std=gnu++11") + else() + set(yaml_test_flags "${yaml_test_flags} -std=c++11") + endif() endif() file(GLOB test_headers [a-z_]*.h) @@ -47,18 +34,12 @@ include_directories(${YAML_CPP_SOURCE_DIR}/src) include_directories(${YAML_CPP_SOURCE_DIR}/test) add_executable(run-tests - ${test_sources} - ${test_headers} + ${test_sources} + ${test_headers} ) - -add_dependencies(run-tests googletest_project) - set_target_properties(run-tests PROPERTIES - COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" + COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" ) -target_link_libraries(run-tests - yaml-cpp - gmock - ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(run-tests yaml-cpp gmock) add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 8a803b0..931884f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,12 +3,14 @@ cmake_minimum_required(VERSION 3.5) add_sources(parse.cpp) add_executable(parse parse.cpp) target_link_libraries(parse yaml-cpp) +set_target_properties(parse PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(sandbox.cpp) add_executable(sandbox sandbox.cpp) target_link_libraries(sandbox yaml-cpp) +set_target_properties(sandbox PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(read.cpp) add_executable(read read.cpp) target_link_libraries(read yaml-cpp) - +set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11") From 5e79f5eed3d86125468681116e92814d2cf40067 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 3 Sep 2018 18:37:06 +0300 Subject: [PATCH 09/15] Improvements to CMake buildsystem Roll-forward of c90c08ccc9a08abcca609064fb9a856dfdbbb7b4 "Revert "Improvements to CMake buildsystem (#563)"" NEW: * Replace CMAKE_SOURCE_DIR with CMAKE_CURRENT_SOURCE_DIR Fixes #612 when yaml-cpp is used as a git submodule. ORIGINAL: * Move enable_testing() into proper place * Added CMake's checks for C++11 standards Raised minimal version of CMake to 3.1, since on old systems there no decent compilers that supports c++11. Closes #377. * Externalize googletest project Externalize gtest to avoid installation, fixes #539. * Remove defined cmake_policies CMP0012 - OLD marked as deprecated for >=cmake-3.1 and will be removed CMP0015 - does not affect to build process CMP0042 - already NEW for >=cmake-3.1 Fixes #505 * Fix compiling in Windows MSVC --- CMakeLists.txt | 26 +++++-------------- test/CMakeLists.txt | 63 +++++++++++++++++++++++++++++---------------- util/CMakeLists.txt | 4 +-- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 715c846..154230a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,11 @@ ### ### CMake settings ### -## Due to Mac OSX we need to keep compatibility with CMake 2.6 # see http://www.cmake.org/Wiki/CMake_Policies -cmake_minimum_required(VERSION 2.6) -# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012 -if(POLICY CMP0012) - cmake_policy(SET CMP0012 OLD) -endif() -# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015 -if(POLICY CMP0015) - cmake_policy(SET CMP0015 OLD) -endif() -# see https://cmake.org/cmake/help/latest/policy/CMP0042.html -if(POLICY CMP0042) - # Enable MACOSX_RPATH by default. - cmake_policy(SET CMP0042 NEW) -endif() +cmake_minimum_required(VERSION 3.1) include(CheckCXXCompilerFlag) - ### ### Project settings ### @@ -31,8 +16,6 @@ set(YAML_CPP_VERSION_MINOR "6") set(YAML_CPP_VERSION_PATCH "2") set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}") -enable_testing() - ### ### Project options @@ -48,6 +31,10 @@ option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON) # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) +# Set minimum C++ to 2011 standards +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + # --> Apple option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) @@ -188,7 +175,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") endif() # - set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}") + set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}") ### Make specific if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake) @@ -360,6 +347,7 @@ endif() ### Extras ### if(YAML_CPP_BUILD_TESTS) + enable_testing() add_subdirectory(test) endif() if(YAML_CPP_BUILD_TOOLS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ad61a3c..8bdf303 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,26 +1,39 @@ -set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL - "Use shared (DLL) run-time lib even when Google Test built as a static lib.") -add_subdirectory(gtest-1.8.0) -include_directories(SYSTEM gtest-1.8.0/googlemock/include) -include_directories(SYSTEM gtest-1.8.0/googletest/include) +include(ExternalProject) -if(WIN32 AND BUILD_SHARED_LIBS) - add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY") +if(MSVC) + # MS Visual Studio expects lib prefix on static libraries, + # but CMake compiles them without prefix + # See https://gitlab.kitware.com/cmake/cmake/issues/17338 + set(CMAKE_STATIC_LIBRARY_PREFIX "") endif() +ExternalProject_Add( + googletest_project + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.8.0" + INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/prefix" + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH= + -DBUILD_GMOCK=ON + -Dgtest_force_shared_crt=ON +) + +add_library(gmock UNKNOWN IMPORTED) +set_target_properties(gmock PROPERTIES + IMPORTED_LOCATION + ${PROJECT_BINARY_DIR}/test/prefix/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} +) + +find_package(Threads) + +include_directories(SYSTEM "${PROJECT_BINARY_DIR}/test/prefix/include") + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR - CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") + CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") - endif() - - if(CMAKE_COMPILER_IS_GNUCXX) - set(yaml_test_flags "${yaml_test_flags} -std=gnu++11") - else() - set(yaml_test_flags "${yaml_test_flags} -std=c++11") - endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions") + endif() endif() file(GLOB test_headers [a-z_]*.h) @@ -34,12 +47,18 @@ include_directories(${YAML_CPP_SOURCE_DIR}/src) include_directories(${YAML_CPP_SOURCE_DIR}/test) add_executable(run-tests - ${test_sources} - ${test_headers} + ${test_sources} + ${test_headers} ) + +add_dependencies(run-tests googletest_project) + set_target_properties(run-tests PROPERTIES - COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" + COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}" ) -target_link_libraries(run-tests yaml-cpp gmock) +target_link_libraries(run-tests + yaml-cpp + gmock + ${CMAKE_THREAD_LIBS_INIT}) add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 931884f..8a803b0 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,14 +3,12 @@ cmake_minimum_required(VERSION 3.5) add_sources(parse.cpp) add_executable(parse parse.cpp) target_link_libraries(parse yaml-cpp) -set_target_properties(parse PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(sandbox.cpp) add_executable(sandbox sandbox.cpp) target_link_libraries(sandbox yaml-cpp) -set_target_properties(sandbox PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(read.cpp) add_executable(read read.cpp) target_link_libraries(read yaml-cpp) -set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11") + From b71e672caf4862e555dbe8f1edb06ee56f35bcf1 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 3 Sep 2018 18:37:47 +0300 Subject: [PATCH 10/15] Suppress unused variable warning in release builds (#611) --- src/collectionstack.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/collectionstack.h b/src/collectionstack.h index 2302786..ebdc587 100644 --- a/src/collectionstack.h +++ b/src/collectionstack.h @@ -28,6 +28,7 @@ class CollectionStack { } void PopCollectionType(CollectionType::value type) { assert(type == GetCurCollectionType()); + (void)type; collectionStack.pop(); } From 45d9035a331c947e492caa70487d3b838327ec35 Mon Sep 17 00:00:00 2001 From: Stefan Reinhold Date: Mon, 3 Sep 2018 22:55:45 +0200 Subject: [PATCH 11/15] Skip newlines in binary decoding (Fix #387) (#616) * Skip newlines in binary decoding This fixes #387 * Skip all whitespace characters This also removes spaces and tabs in addition to newlines. --- src/binary.cpp | 11 +++++++++-- test/integration/load_node_test.cpp | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/binary.cpp b/src/binary.cpp index a7e5130..b987375 100644 --- a/src/binary.cpp +++ b/src/binary.cpp @@ -1,5 +1,7 @@ #include "yaml-cpp/binary.h" +#include + namespace YAML { static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -72,19 +74,24 @@ std::vector DecodeBase64(const std::string &input) { unsigned char *out = &ret[0]; unsigned value = 0; - for (std::size_t i = 0; i < input.size(); i++) { + for (std::size_t i = 0, cnt = 0; i < input.size(); i++) { + if (std::isspace(input[i])) { + // skip newlines + continue; + } unsigned char d = decoding[static_cast(input[i])]; if (d == 255) return ret_type(); value = (value << 6) | d; - if (i % 4 == 3) { + if (cnt % 4 == 3) { *out++ = value >> 16; if (i > 0 && input[i - 1] != '=') *out++ = value >> 8; if (input[i] != '=') *out++ = value; } + ++cnt; } ret.resize(out - &ret[0]); diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index 02bb8fe..4f4f28e 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -55,6 +55,26 @@ TEST(LoadNodeTest, Binary) { node[1].as()); } +TEST(LoadNodeTest, BinaryWithWhitespaces) { + Node node = Load( + "binaryText: !binary |-\n" + " TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieS\n" + " B0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG\n" + " x1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbi\n" + " B0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZG\n" + " dlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS\n" + " 4K"); + EXPECT_EQ(Binary(reinterpret_cast( + "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), + node["binaryText"].as()); +} + TEST(LoadNodeTest, IterateSequence) { Node node = Load("[1, 3, 5, 7]"); int seq[] = {1, 3, 5, 7}; From d0da14404ef7cc960ef01bbf97775ead08d3c477 Mon Sep 17 00:00:00 2001 From: Stefan Reinhold Date: Tue, 4 Sep 2018 15:34:18 +0200 Subject: [PATCH 12/15] Fix include for std::isspace, fixes #621 (#622) --- src/binary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/binary.cpp b/src/binary.cpp index b987375..4db6d0b 100644 --- a/src/binary.cpp +++ b/src/binary.cpp @@ -1,6 +1,6 @@ #include "yaml-cpp/binary.h" -#include +#include namespace YAML { static const char encoding[] = From ee99c4151c1af794a412b101a75921c086acaac0 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Thu, 6 Sep 2018 00:16:02 -0400 Subject: [PATCH 13/15] Fix a warning from -Wshadow (#627) Variable "it" was shadowed --- include/yaml-cpp/node/detail/impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index 2be4f78..c8853cf 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -172,9 +172,9 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { it = jt; } - for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { - if (it->first->equals(key, pMemory)) { - m_map.erase(it); + for (node_map::iterator iter = m_map.begin(); iter != m_map.end(); ++iter) { + if (iter->first->equals(key, pMemory)) { + m_map.erase(iter); return true; } } From ca77ef716e51ebec1be2bd2c28a02838cb8a4c32 Mon Sep 17 00:00:00 2001 From: Florian Eich Date: Mon, 24 Sep 2018 01:40:53 +0200 Subject: [PATCH 14/15] Fix -Wmaybe-uninitialized warning (#600) --- src/regex_yaml.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/regex_yaml.h b/src/regex_yaml.h index 8f28b85..1611cb2 100644 --- a/src/regex_yaml.h +++ b/src/regex_yaml.h @@ -77,10 +77,11 @@ class YAML_CPP_API RegEx { private: REGEX_OP m_op; - char m_a, m_z; + char m_a{}; + char m_z{}; std::vector m_params; }; -} +} // namespace YAML #include "regeximpl.h" From 774f25800e6f19f4b927023c85d1389af322da5e Mon Sep 17 00:00:00 2001 From: dand-oss Date: Tue, 25 Sep 2018 09:12:12 -0500 Subject: [PATCH 15/15] fix up static, so works as DLL (#559) * fix up static, so works as DLL --- include/yaml-cpp/node/detail/node_data.h | 2 +- include/yaml-cpp/node/impl.h | 4 ++-- src/node_data.cpp | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/yaml-cpp/node/detail/node_data.h b/include/yaml-cpp/node/detail/node_data.h index 50bcd74..82fb79a 100644 --- a/include/yaml-cpp/node/detail/node_data.h +++ b/include/yaml-cpp/node/detail/node_data.h @@ -81,7 +81,7 @@ class YAML_CPP_API node_data { shared_memory_holder pMemory); public: - static std::string empty_scalar; + static const std::string& empty_scalar(); private: void compute_seq_size() const; diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 20c487a..de2bf44 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -156,13 +156,13 @@ inline T Node::as(const S& fallback) const { inline const std::string& Node::Scalar() const { if (!m_isValid) throw InvalidNode(); - return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar; + return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar(); } inline const std::string& Node::Tag() const { if (!m_isValid) throw InvalidNode(); - return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar; + return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar(); } inline void Node::SetTag(const std::string& tag) { diff --git a/src/node_data.cpp b/src/node_data.cpp index 34d81f7..04104b7 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -13,7 +13,10 @@ namespace YAML { namespace detail { -std::string node_data::empty_scalar; +const std::string& node_data::empty_scalar() { + static const std::string svalue; + return svalue; +} node_data::node_data() : m_isDefined(false),