mirror of
https://github.com/RPCS3/yaml-cpp.git
synced 2026-07-25 20:55:22 -04:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a3624205e | |||
| 968e0c1f02 | |||
| b218787b98 | |||
| db0bda7087 | |||
| 6cdf363625 | |||
| d638508d33 | |||
| 90350662c9 | |||
| e0e01d53c2 | |||
| 0122697561 | |||
| bd7f8c60c8 | |||
| 82e9571213 | |||
| 0d5c57150c | |||
| eca9cfd648 | |||
| a2a113c6ff | |||
| 283d06f9f7 | |||
| b87c76a2ef | |||
| abf941b20d | |||
| b659858b19 | |||
| 2443da5224 | |||
| 54fc4dadbb | |||
| 774f25800e | |||
| ca77ef716e | |||
| ee99c4151c | |||
| d0da14404e | |||
| 45d9035a33 | |||
| b71e672caf | |||
| 5e79f5eed3 | |||
| c90c08ccc9 | |||
| 3e33bb3166 | |||
| 1698b47b65 | |||
| 0f9a586ca1 | |||
| 4fb1c4b92b | |||
| ab5f9259a4 | |||
| 124ae47600 | |||
| f996468a6a |
@@ -1 +1,2 @@
|
||||
build/
|
||||
/tags
|
||||
|
||||
+68
-66
@@ -1,38 +1,15 @@
|
||||
###
|
||||
### 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
|
||||
###
|
||||
project(YAML_CPP)
|
||||
|
||||
set(YAML_CPP_VERSION_MAJOR "0")
|
||||
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(YAML_CPP VERSION 0.6.3)
|
||||
|
||||
###
|
||||
### Project options
|
||||
@@ -41,21 +18,26 @@ enable_testing()
|
||||
option(YAML_CPP_BUILD_TESTS "Enable testing" ON)
|
||||
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
|
||||
option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
|
||||
option(YAML_CPP_INSTALL "Enable generation of install target" ON)
|
||||
|
||||
## Build options
|
||||
# --> General
|
||||
# see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
|
||||
# http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
|
||||
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
|
||||
option(YAML_BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
|
||||
|
||||
# --> Apple
|
||||
option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
|
||||
if(APPLE)
|
||||
option(YAML_APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
|
||||
endif()
|
||||
|
||||
# --> Microsoft Visual C++
|
||||
# see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
|
||||
# http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
|
||||
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)
|
||||
if(MSVC)
|
||||
option(YAML_MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
|
||||
option(YAML_MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF)
|
||||
endif()
|
||||
|
||||
###
|
||||
### Sources, headers, directories and libs
|
||||
@@ -116,9 +98,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()
|
||||
|
||||
|
||||
###
|
||||
@@ -127,14 +110,14 @@ include_directories(${YAML_CPP_SOURCE_DIR}/include)
|
||||
set(yaml_c_flags ${CMAKE_C_FLAGS})
|
||||
set(yaml_cxx_flags ${CMAKE_CXX_FLAGS})
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
if(YAML_BUILD_SHARED_LIBS)
|
||||
set(LABEL_SUFFIX "shared")
|
||||
else()
|
||||
set(LABEL_SUFFIX "static")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
if(APPLE_UNIVERSAL_BIN)
|
||||
if(YAML_APPLE_UNIVERSAL_BIN)
|
||||
set(CMAKE_OSX_ARCHITECTURES ppc;i386)
|
||||
endif()
|
||||
endif()
|
||||
@@ -145,7 +128,7 @@ if(IPHONE)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
if(YAML_BUILD_SHARED_LIBS)
|
||||
add_definitions(-D${PROJECT_NAME}_DLL) # use or build Windows DLL
|
||||
endif()
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
@@ -155,7 +138,7 @@ endif()
|
||||
|
||||
# GCC or Clang or Intel Compiler specialities
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
||||
CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
|
||||
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR
|
||||
CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
|
||||
### General stuff
|
||||
@@ -170,32 +153,27 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
#
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
|
||||
#
|
||||
set(GCC_EXTRA_OPTIONS "")
|
||||
#
|
||||
if(BUILD_SHARED_LIBS)
|
||||
if(YAML_BUILD_SHARED_LIBS)
|
||||
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} -fPIC")
|
||||
endif()
|
||||
#
|
||||
set(FLAG_TESTED "-Wextra")
|
||||
set(FLAG_TESTED "-Wextra -Wshadow -Weffc++ -pedantic -pedantic-errors")
|
||||
check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
|
||||
if(FLAG_WEXTRA)
|
||||
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
|
||||
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)
|
||||
add_custom_target(debuggable $(MAKE) clean
|
||||
add_custom_target(debuggable ${CMAKE_MAKE_PROGRAM} clean
|
||||
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Adjusting settings for debug compilation"
|
||||
VERBATIM)
|
||||
add_custom_target(releasable $(MAKE) clean
|
||||
add_custom_target(releasable ${CMAKE_MAKE_PROGRAM} clean
|
||||
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Adjusting settings for release compilation"
|
||||
VERBATIM)
|
||||
@@ -212,8 +190,8 @@ if(MSVC)
|
||||
set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC
|
||||
set(LIB_RT_OPTION "/MD")
|
||||
#
|
||||
if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
|
||||
if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
|
||||
if(NOT YAML_MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
|
||||
if(YAML_MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
|
||||
set(LIB_RT_SUFFIX "ml")
|
||||
set(LIB_RT_OPTION "/ML")
|
||||
if(NOT ${MSVC_VERSION} LESS 1400)
|
||||
@@ -243,7 +221,7 @@ if(MSVC)
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs
|
||||
|
||||
# c) Correct suffixes for static libraries
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
if(NOT YAML_BUILD_SHARED_LIBS)
|
||||
### General stuff
|
||||
set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
|
||||
endif()
|
||||
@@ -274,7 +252,24 @@ set(_INSTALL_DESTINATIONS
|
||||
###
|
||||
### Library
|
||||
###
|
||||
add_library(yaml-cpp ${library_sources})
|
||||
if(YAML_BUILD_SHARED_LIBS)
|
||||
add_library(yaml-cpp SHARED ${library_sources})
|
||||
else()
|
||||
add_library(yaml-cpp STATIC ${library_sources})
|
||||
endif()
|
||||
|
||||
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
|
||||
target_include_directories(yaml-cpp
|
||||
PUBLIC $<BUILD_INTERFACE:${YAML_CPP_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_ROOT_DIR}>
|
||||
PRIVATE $<BUILD_INTERFACE:${YAML_CPP_SOURCE_DIR}/src>)
|
||||
endif()
|
||||
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
|
||||
)
|
||||
@@ -292,7 +287,7 @@ if(IPHONE)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
if(NOT YAML_BUILD_SHARED_LIBS)
|
||||
# correct library names
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d"
|
||||
@@ -303,12 +298,14 @@ if(MSVC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
|
||||
install(
|
||||
DIRECTORY ${header_directory}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
if (YAML_CPP_INSTALL)
|
||||
install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
|
||||
install(
|
||||
DIRECTORY ${header_directory}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
export(
|
||||
TARGETS yaml-cpp
|
||||
@@ -326,6 +323,7 @@ else()
|
||||
set(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/yaml-cpp)
|
||||
endif()
|
||||
|
||||
|
||||
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_ROOT_DIR}")
|
||||
set(CONFIG_INCLUDE_DIRS "\${YAML_CPP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
|
||||
@@ -334,16 +332,19 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config-version.cmake.in
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake" @ONLY)
|
||||
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||
install(EXPORT yaml-cpp-targets DESTINATION ${INSTALL_CMAKE_DIR})
|
||||
if (YAML_CPP_INSTALL)
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||
install(EXPORT yaml-cpp-targets DESTINATION ${INSTALL_CMAKE_DIR})
|
||||
|
||||
if(UNIX)
|
||||
set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
|
||||
configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
|
||||
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
|
||||
configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
|
||||
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -351,6 +352,7 @@ endif()
|
||||
### Extras
|
||||
###
|
||||
if(YAML_CPP_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
if(YAML_CPP_BUILD_TOOLS)
|
||||
|
||||
@@ -26,7 +26,7 @@ cd build
|
||||
3. Run CMake. The basic syntax is:
|
||||
|
||||
```
|
||||
cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] ..
|
||||
cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=ON|OFF] ..
|
||||
```
|
||||
|
||||
* The `generator` is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run `cmake` (with no arguments). For example:
|
||||
@@ -34,7 +34,7 @@ cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] ..
|
||||
* On OS X, you might use "Xcode" to generate an Xcode project
|
||||
* On a UNIX-y system, simply omit the option to generate a makefile
|
||||
|
||||
* yaml-cpp defaults to building a static library, but you may build a shared library by specifying `-DBUILD_SHARED_LIBS=ON`.
|
||||
* yaml-cpp defaults to building a static library, but you may build a shared library by specifying `-DYAML_BUILD_SHARED_LIBS=ON`.
|
||||
|
||||
* For more options on customizing the build, see the [CMakeLists.txt](https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt) file.
|
||||
|
||||
|
||||
@@ -19,9 +19,13 @@ YAML_CPP_API std::vector<unsigned char> DecodeBase64(const std::string &input);
|
||||
|
||||
class YAML_CPP_API Binary {
|
||||
public:
|
||||
Binary() : m_unownedData(0), m_unownedSize(0) {}
|
||||
Binary(const unsigned char *data_, std::size_t size_)
|
||||
: m_unownedData(data_), m_unownedSize(size_) {}
|
||||
: m_data{}, m_unownedData(data_), m_unownedSize(size_) {}
|
||||
Binary() : Binary(nullptr, 0) {}
|
||||
Binary(const Binary &) = default;
|
||||
Binary(Binary &&) = default;
|
||||
Binary &operator=(const Binary &) = default;
|
||||
Binary &operator=(Binary &&) = default;
|
||||
|
||||
bool owned() const { return !m_unownedData; }
|
||||
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
|
||||
@@ -35,7 +39,7 @@ class YAML_CPP_API Binary {
|
||||
rhs.clear();
|
||||
rhs.resize(m_unownedSize);
|
||||
std::copy(m_unownedData, m_unownedData + m_unownedSize, rhs.begin());
|
||||
m_unownedData = 0;
|
||||
m_unownedData = nullptr;
|
||||
m_unownedSize = 0;
|
||||
} else {
|
||||
m_data.swap(rhs);
|
||||
@@ -62,6 +66,6 @@ class YAML_CPP_API Binary {
|
||||
const unsigned char *m_unownedData;
|
||||
std::size_t m_unownedSize;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace YAML {
|
||||
template <class T>
|
||||
class AnchorDict {
|
||||
public:
|
||||
AnchorDict() : m_data{} {}
|
||||
void Register(anchor_t anchor, T value) {
|
||||
if (anchor > m_data.size()) {
|
||||
m_data.resize(anchor);
|
||||
@@ -34,6 +35,6 @@ class AnchorDict {
|
||||
private:
|
||||
std::vector<T> m_data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -7,16 +7,18 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "yaml-cpp/binary.h"
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/emitterdef.h"
|
||||
#include "yaml-cpp/emittermanip.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
|
||||
@@ -28,10 +30,12 @@ struct _Null;
|
||||
namespace YAML {
|
||||
class EmitterState;
|
||||
|
||||
class YAML_CPP_API Emitter : private noncopyable {
|
||||
class YAML_CPP_API Emitter {
|
||||
public:
|
||||
Emitter();
|
||||
explicit Emitter(std::ostream& stream);
|
||||
Emitter(const Emitter&) = delete;
|
||||
Emitter& operator=(const Emitter&) = delete;
|
||||
~Emitter();
|
||||
|
||||
// output
|
||||
@@ -152,7 +156,28 @@ inline Emitter& Emitter::WriteStreamable(T value) {
|
||||
|
||||
std::stringstream stream;
|
||||
SetStreamablePrecision<T>(stream);
|
||||
stream << value;
|
||||
|
||||
bool special = false;
|
||||
if (std::is_floating_point<T>::value) {
|
||||
if ((std::numeric_limits<T>::has_quiet_NaN ||
|
||||
std::numeric_limits<T>::has_signaling_NaN) &&
|
||||
std::isnan(value)) {
|
||||
special = true;
|
||||
stream << ".nan";
|
||||
} else if (std::numeric_limits<T>::has_infinity) {
|
||||
if (value == std::numeric_limits<T>::infinity()) {
|
||||
special = true;
|
||||
stream << ".inf";
|
||||
} else if (value == -std::numeric_limits<T>::infinity()) {
|
||||
special = true;
|
||||
stream << "-.inf";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!special) {
|
||||
stream << value;
|
||||
}
|
||||
m_stream << stream.str();
|
||||
|
||||
StartedScalar();
|
||||
@@ -249,6 +274,6 @@ inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
|
||||
inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
|
||||
return emitter.SetLocalPrecision(precision);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -34,7 +34,12 @@ class EventHandler {
|
||||
virtual void OnMapStart(const Mark& mark, const std::string& tag,
|
||||
anchor_t anchor, EmitterStyle::value style) = 0;
|
||||
virtual void OnMapEnd() = 0;
|
||||
|
||||
virtual void OnAnchor(const Mark& /*mark*/,
|
||||
const std::string& /*anchor_name*/) {
|
||||
// empty default implementation for compatibility
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -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
|
||||
@@ -114,6 +114,35 @@ inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
||||
stream << KEY_NOT_FOUND << ": " << key;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const std::string BAD_SUBSCRIPT_WITH_KEY(
|
||||
const T&, typename disable_if<is_numeric<T>>::type* = nullptr) {
|
||||
return BAD_SUBSCRIPT;
|
||||
}
|
||||
|
||||
inline const std::string BAD_SUBSCRIPT_WITH_KEY(const std::string& key) {
|
||||
std::stringstream stream;
|
||||
stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const std::string BAD_SUBSCRIPT_WITH_KEY(
|
||||
const T& key, typename enable_if<is_numeric<T>>::type* = nullptr) {
|
||||
std::stringstream stream;
|
||||
stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
inline const std::string INVALID_NODE_WITH_KEY(const std::string& key) {
|
||||
std::stringstream stream;
|
||||
if (key.empty()) {
|
||||
return INVALID_NODE;
|
||||
}
|
||||
stream << "invalid node; first invalid key: \"" << key << "\"";
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
class YAML_CPP_API Exception : public std::runtime_error {
|
||||
@@ -131,7 +160,7 @@ class YAML_CPP_API Exception : public std::runtime_error {
|
||||
static const std::string build_what(const Mark& mark,
|
||||
const std::string& msg) {
|
||||
if (mark.is_null()) {
|
||||
return msg.c_str();
|
||||
return msg;
|
||||
}
|
||||
|
||||
std::stringstream output;
|
||||
@@ -194,8 +223,9 @@ inline TypedKeyNotFound<T> MakeTypedKeyNotFound(const Mark& mark,
|
||||
|
||||
class YAML_CPP_API InvalidNode : public RepresentationException {
|
||||
public:
|
||||
InvalidNode()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
|
||||
InvalidNode(std::string key)
|
||||
: RepresentationException(Mark::null_mark(),
|
||||
ErrorMsg::INVALID_NODE_WITH_KEY(key)) {}
|
||||
InvalidNode(const InvalidNode&) = default;
|
||||
virtual ~InvalidNode() YAML_CPP_NOEXCEPT;
|
||||
};
|
||||
@@ -224,8 +254,10 @@ class YAML_CPP_API BadDereference : public RepresentationException {
|
||||
|
||||
class YAML_CPP_API BadSubscript : public RepresentationException {
|
||||
public:
|
||||
BadSubscript()
|
||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
|
||||
template <typename Key>
|
||||
BadSubscript(const Key& key)
|
||||
: RepresentationException(Mark::null_mark(),
|
||||
ErrorMsg::BAD_SUBSCRIPT_WITH_KEY(key)) {}
|
||||
BadSubscript(const BadSubscript&) = default;
|
||||
virtual ~BadSubscript() YAML_CPP_NOEXCEPT;
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ struct convert<_Null> {
|
||||
struct convert<type> { \
|
||||
static Node encode(const type& rhs) { \
|
||||
std::stringstream stream; \
|
||||
stream.precision(std::numeric_limits<type>::digits10 + 1); \
|
||||
stream.precision(std::numeric_limits<type>::max_digits10); \
|
||||
stream << rhs; \
|
||||
return Node(stream.str()); \
|
||||
} \
|
||||
@@ -116,10 +116,11 @@ struct convert<_Null> {
|
||||
} \
|
||||
} \
|
||||
\
|
||||
if (std::numeric_limits<type>::has_quiet_NaN && \
|
||||
conversion::IsNaN(input)) { \
|
||||
rhs = std::numeric_limits<type>::quiet_NaN(); \
|
||||
return true; \
|
||||
if (std::numeric_limits<type>::has_quiet_NaN) { \
|
||||
if (conversion::IsNaN(input)) { \
|
||||
rhs = std::numeric_limits<type>::quiet_NaN(); \
|
||||
return true; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
|
||||
@@ -17,7 +17,7 @@ template <typename Key, typename Enable = void>
|
||||
struct get_idx {
|
||||
static node* get(const std::vector<node*>& /* sequence */,
|
||||
const Key& /* key */, shared_memory_holder /* pMemory */) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,12 +27,12 @@ struct get_idx<Key,
|
||||
!std::is_same<Key, bool>::value>::type> {
|
||||
static node* get(const std::vector<node*>& sequence, const Key& key,
|
||||
shared_memory_holder /* pMemory */) {
|
||||
return key < sequence.size() ? sequence[key] : 0;
|
||||
return key < sequence.size() ? sequence[key] : nullptr;
|
||||
}
|
||||
|
||||
static node* get(std::vector<node*>& 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());
|
||||
@@ -46,13 +46,44 @@ struct get_idx<Key, typename std::enable_if<std::is_signed<Key>::value>::type> {
|
||||
shared_memory_holder pMemory) {
|
||||
return key >= 0 ? get_idx<std::size_t>::get(
|
||||
sequence, static_cast<std::size_t>(key), pMemory)
|
||||
: 0;
|
||||
: nullptr;
|
||||
}
|
||||
static node* get(std::vector<node*>& sequence, const Key& key,
|
||||
shared_memory_holder pMemory) {
|
||||
return key >= 0 ? get_idx<std::size_t>::get(
|
||||
sequence, static_cast<std::size_t>(key), pMemory)
|
||||
: 0;
|
||||
: nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Enable = void>
|
||||
struct remove_idx {
|
||||
static bool remove(std::vector<node*>&, const Key&) { return false; }
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
struct remove_idx<
|
||||
Key, typename std::enable_if<std::is_unsigned<Key>::value &&
|
||||
!std::is_same<Key, bool>::value>::type> {
|
||||
|
||||
static bool remove(std::vector<node*>& sequence, const Key& key) {
|
||||
if (key >= sequence.size()) {
|
||||
return false;
|
||||
} else {
|
||||
sequence.erase(sequence.begin() + key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
struct remove_idx<Key,
|
||||
typename std::enable_if<std::is_signed<Key>::value>::type> {
|
||||
|
||||
static bool remove(std::vector<node*>& sequence, const Key& key) {
|
||||
return key >= 0 ? remove_idx<std::size_t>::remove(
|
||||
sequence, static_cast<std::size_t>(key))
|
||||
: false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,13 +109,13 @@ inline node* node_data::get(const Key& key,
|
||||
break;
|
||||
case NodeType::Undefined:
|
||||
case NodeType::Null:
|
||||
return NULL;
|
||||
return nullptr;
|
||||
case NodeType::Sequence:
|
||||
if (node* pNode = get_idx<Key>::get(m_sequence, key, pMemory))
|
||||
return pNode;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
case NodeType::Scalar:
|
||||
throw BadSubscript();
|
||||
throw BadSubscript(key);
|
||||
}
|
||||
|
||||
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
||||
@@ -93,7 +124,7 @@ inline node* node_data::get(const Key& key,
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Key>
|
||||
@@ -112,7 +143,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw BadSubscript();
|
||||
throw BadSubscript(key);
|
||||
}
|
||||
|
||||
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
||||
@@ -129,21 +160,23 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
|
||||
|
||||
template <typename Key>
|
||||
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<Key>::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 iter = m_map.begin(); iter != m_map.end(); ++iter) {
|
||||
if (iter->first->equals(key, pMemory)) {
|
||||
m_map.erase(iter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
struct iterator_value;
|
||||
|
||||
template <typename V>
|
||||
class iterator_base : public std::iterator<std::forward_iterator_tag, V,
|
||||
std::ptrdiff_t, V*, V> {
|
||||
class iterator_base {
|
||||
|
||||
private:
|
||||
template <typename>
|
||||
@@ -37,7 +37,11 @@ class iterator_base : public std::iterator<std::forward_iterator_tag, V,
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename iterator_base::value_type value_type;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = V;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = V*;
|
||||
using reference = V;
|
||||
|
||||
public:
|
||||
iterator_base() : m_iterator(), m_pMemory() {}
|
||||
@@ -86,7 +90,7 @@ class iterator_base : public std::iterator<std::forward_iterator_tag, V,
|
||||
base_type m_iterator;
|
||||
shared_memory_holder m_pMemory;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
#endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace YAML {
|
||||
namespace detail {
|
||||
class YAML_CPP_API memory {
|
||||
public:
|
||||
memory() : m_nodes{} {}
|
||||
node& create_node();
|
||||
void merge(const memory& rhs);
|
||||
|
||||
@@ -40,7 +41,7 @@ class YAML_CPP_API memory_holder {
|
||||
private:
|
||||
shared_memory m_pMemory;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/emitterstyle.h"
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/node/type.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/emitterstyle.h"
|
||||
#include "yaml-cpp/node/detail/node_ref.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/node/type.h"
|
||||
#include <set>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
class node {
|
||||
public:
|
||||
node() : m_pRef(new node_ref) {}
|
||||
node() : m_pRef(new node_ref), m_dependencies{} {}
|
||||
node(const node&) = delete;
|
||||
node& operator=(const node&) = delete;
|
||||
|
||||
@@ -163,7 +163,7 @@ class node {
|
||||
typedef std::set<node*> nodes;
|
||||
nodes m_dependencies;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -26,9 +26,9 @@ template <typename V>
|
||||
struct node_iterator_value : public std::pair<V*, V*> {
|
||||
typedef std::pair<V*, V*> kv;
|
||||
|
||||
node_iterator_value() : kv(), pNode(0) {}
|
||||
node_iterator_value() : kv(), pNode(nullptr) {}
|
||||
explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {}
|
||||
explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(0) {}
|
||||
explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(nullptr) {}
|
||||
|
||||
V& operator*() const { return *pNode; }
|
||||
V& operator->() const { return *pNode; }
|
||||
|
||||
@@ -7,18 +7,21 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include "yaml-cpp/node/detail/memory.h"
|
||||
#include "yaml-cpp/node/detail/node.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace YAML {
|
||||
inline Node::Node() : m_isValid(true), m_pNode(NULL) {}
|
||||
inline Node::Node()
|
||||
: m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {}
|
||||
|
||||
inline Node::Node(NodeType::value type)
|
||||
: m_isValid(true),
|
||||
m_invalidKey{},
|
||||
m_pMemory(new detail::memory_holder),
|
||||
m_pNode(&m_pMemory->create_node()) {
|
||||
m_pNode->set_type(type);
|
||||
@@ -27,6 +30,7 @@ inline Node::Node(NodeType::value type)
|
||||
template <typename T>
|
||||
inline Node::Node(const T& rhs)
|
||||
: m_isValid(true),
|
||||
m_invalidKey{},
|
||||
m_pMemory(new detail::memory_holder),
|
||||
m_pNode(&m_pMemory->create_node()) {
|
||||
Assign(rhs);
|
||||
@@ -34,24 +38,30 @@ inline Node::Node(const T& rhs)
|
||||
|
||||
inline Node::Node(const detail::iterator_value& rhs)
|
||||
: m_isValid(rhs.m_isValid),
|
||||
m_invalidKey(rhs.m_invalidKey),
|
||||
m_pMemory(rhs.m_pMemory),
|
||||
m_pNode(rhs.m_pNode) {}
|
||||
|
||||
inline Node::Node(const Node& rhs)
|
||||
: m_isValid(rhs.m_isValid),
|
||||
m_invalidKey(rhs.m_invalidKey),
|
||||
m_pMemory(rhs.m_pMemory),
|
||||
m_pNode(rhs.m_pNode) {}
|
||||
|
||||
inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {}
|
||||
inline Node::Node(Zombie)
|
||||
: m_isValid(false), m_invalidKey{}, m_pMemory{}, m_pNode(nullptr) {}
|
||||
|
||||
inline Node::Node(Zombie, const std::string& key)
|
||||
: m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(nullptr) {}
|
||||
|
||||
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
|
||||
: m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
|
||||
: m_isValid(true), m_invalidKey{}, m_pMemory(pMemory), m_pNode(&node) {}
|
||||
|
||||
inline Node::~Node() {}
|
||||
|
||||
inline void Node::EnsureNodeExists() const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
if (!m_pNode) {
|
||||
m_pMemory.reset(new detail::memory_holder);
|
||||
m_pNode = &m_pMemory->create_node();
|
||||
@@ -68,14 +78,14 @@ inline bool Node::IsDefined() const {
|
||||
|
||||
inline Mark Node::Mark() const {
|
||||
if (!m_isValid) {
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
}
|
||||
return m_pNode ? m_pNode->mark() : Mark::null_mark();
|
||||
}
|
||||
|
||||
inline NodeType::value Node::Type() const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
return m_pNode ? m_pNode->type() : NodeType::Null;
|
||||
}
|
||||
|
||||
@@ -142,7 +152,7 @@ struct as_if<std::string, void> {
|
||||
template <typename T>
|
||||
inline T Node::as() const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
return as_if<T, void>(*this)();
|
||||
}
|
||||
|
||||
@@ -155,32 +165,32 @@ 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;
|
||||
throw InvalidNode(m_invalidKey);
|
||||
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;
|
||||
throw InvalidNode(m_invalidKey);
|
||||
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
|
||||
}
|
||||
|
||||
inline void Node::SetTag(const std::string& tag) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->set_tag(tag);
|
||||
}
|
||||
|
||||
inline EmitterStyle::value Node::Style() const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
|
||||
}
|
||||
|
||||
inline void Node::SetStyle(EmitterStyle::value style) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->set_style(style);
|
||||
}
|
||||
@@ -188,7 +198,7 @@ inline void Node::SetStyle(EmitterStyle::value style) {
|
||||
// assignment
|
||||
inline bool Node::is(const Node& rhs) const {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
if (!m_pNode || !rhs.m_pNode)
|
||||
return false;
|
||||
return m_pNode->is(*rhs.m_pNode);
|
||||
@@ -197,14 +207,23 @@ inline bool Node::is(const Node& rhs) const {
|
||||
template <typename T>
|
||||
inline Node& Node::operator=(const T& rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode(m_invalidKey);
|
||||
if (is(rhs))
|
||||
return *this;
|
||||
AssignNode(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::reset(const YAML::Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
m_pMemory = rhs.m_pMemory;
|
||||
m_pNode = rhs.m_pNode;
|
||||
}
|
||||
@@ -212,44 +231,35 @@ inline void Node::reset(const YAML::Node& rhs) {
|
||||
template <typename T>
|
||||
inline void Node::Assign(const T& rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
AssignData(convert<T>::encode(rhs));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Node::Assign(const std::string& rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->set_scalar(rhs);
|
||||
}
|
||||
|
||||
inline void Node::Assign(const char* rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->set_scalar(rhs);
|
||||
}
|
||||
|
||||
inline void Node::Assign(char* rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->set_scalar(rhs);
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
if (is(rhs))
|
||||
return *this;
|
||||
AssignNode(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::AssignData(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
rhs.EnsureNodeExists();
|
||||
|
||||
@@ -259,7 +269,7 @@ inline void Node::AssignData(const Node& rhs) {
|
||||
|
||||
inline void Node::AssignNode(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
rhs.EnsureNodeExists();
|
||||
|
||||
if (!m_pNode) {
|
||||
@@ -276,7 +286,7 @@ inline void Node::AssignNode(const Node& rhs) {
|
||||
// size/iterator
|
||||
inline std::size_t Node::size() const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
return m_pNode ? m_pNode->size() : 0;
|
||||
}
|
||||
|
||||
@@ -309,13 +319,13 @@ inline iterator Node::end() {
|
||||
template <typename T>
|
||||
inline void Node::push_back(const T& rhs) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
push_back(Node(rhs));
|
||||
}
|
||||
|
||||
inline void Node::push_back(const Node& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
rhs.EnsureNodeExists();
|
||||
|
||||
@@ -366,18 +376,23 @@ template <typename T>
|
||||
inline typename to_value_t<T>::return_type to_value(const T& t) {
|
||||
return to_value_t<T>(t)();
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename Key>
|
||||
std::string key_to_string(const Key& key) {
|
||||
return streamable_to_string<Key, is_streamable<std::stringstream, Key>::value>().impl(key);
|
||||
}
|
||||
|
||||
// indexing
|
||||
template <typename Key>
|
||||
inline const Node Node::operator[](const Key& key) const {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
detail::node* value = static_cast<const detail::node&>(*m_pNode)
|
||||
.get(detail::to_value(key), m_pMemory);
|
||||
detail::node* value = static_cast<const detail::node&>(*m_pNode).get(
|
||||
detail::to_value(key), m_pMemory);
|
||||
if (!value) {
|
||||
return Node(ZombieNode);
|
||||
return Node(ZombieNode, key_to_string(key));
|
||||
}
|
||||
return Node(*value, m_pMemory);
|
||||
}
|
||||
@@ -385,7 +400,7 @@ inline const Node Node::operator[](const Key& key) const {
|
||||
template <typename Key>
|
||||
inline Node Node::operator[](const Key& key) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
|
||||
return Node(value, m_pMemory);
|
||||
@@ -394,28 +409,28 @@ inline Node Node::operator[](const Key& key) {
|
||||
template <typename Key>
|
||||
inline bool Node::remove(const Key& key) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
return m_pNode->remove(detail::to_value(key), m_pMemory);
|
||||
}
|
||||
|
||||
inline const Node Node::operator[](const Node& key) const {
|
||||
if (!m_isValid || !key.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
key.EnsureNodeExists();
|
||||
m_pMemory->merge(*key.m_pMemory);
|
||||
detail::node* value =
|
||||
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
|
||||
if (!value) {
|
||||
return Node(ZombieNode);
|
||||
return Node(ZombieNode, key_to_string(key));
|
||||
}
|
||||
return Node(*value, m_pMemory);
|
||||
}
|
||||
|
||||
inline Node Node::operator[](const Node& key) {
|
||||
if (!m_isValid || !key.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
key.EnsureNodeExists();
|
||||
m_pMemory->merge(*key.m_pMemory);
|
||||
@@ -425,7 +440,7 @@ inline Node Node::operator[](const Node& key) {
|
||||
|
||||
inline bool Node::remove(const Node& key) {
|
||||
if (!m_isValid || !key.m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
key.EnsureNodeExists();
|
||||
return m_pNode->remove(*key.m_pNode, m_pMemory);
|
||||
@@ -435,7 +450,7 @@ inline bool Node::remove(const Node& key) {
|
||||
template <typename Key, typename Value>
|
||||
inline void Node::force_insert(const Key& key, const Value& value) {
|
||||
if (!m_isValid)
|
||||
throw InvalidNode();
|
||||
throw InvalidNode(m_invalidKey);
|
||||
EnsureNodeExists();
|
||||
m_pNode->force_insert(detail::to_value(key), detail::to_value(value),
|
||||
m_pMemory);
|
||||
@@ -443,6 +458,6 @@ inline void Node::force_insert(const Key& key, const Value& value) {
|
||||
|
||||
// free functions
|
||||
inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); }
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/emitterstyle.h"
|
||||
@@ -116,6 +117,7 @@ class YAML_CPP_API Node {
|
||||
private:
|
||||
enum Zombie { ZombieNode };
|
||||
explicit Node(Zombie);
|
||||
explicit Node(Zombie, const std::string&);
|
||||
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
|
||||
|
||||
void EnsureNodeExists() const;
|
||||
@@ -130,6 +132,8 @@ class YAML_CPP_API Node {
|
||||
|
||||
private:
|
||||
bool m_isValid;
|
||||
// String representation of invalid key, if the node is invalid.
|
||||
std::string m_invalidKey;
|
||||
mutable detail::shared_memory_holder m_pMemory;
|
||||
mutable detail::node* m_pNode;
|
||||
};
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if defined(_MSC_VER) || \
|
||||
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
||||
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
|
||||
namespace YAML {
|
||||
// this is basically boost::noncopyable
|
||||
class YAML_CPP_API noncopyable {
|
||||
protected:
|
||||
noncopyable() {}
|
||||
~noncopyable() {}
|
||||
|
||||
private:
|
||||
noncopyable(const noncopyable&);
|
||||
const noncopyable& operator=(const noncopyable&);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
@@ -17,6 +17,10 @@ class YAML_CPP_API ostream_wrapper {
|
||||
public:
|
||||
ostream_wrapper();
|
||||
explicit ostream_wrapper(std::ostream& stream);
|
||||
ostream_wrapper(const ostream_wrapper&) = delete;
|
||||
ostream_wrapper(ostream_wrapper&&) = delete;
|
||||
ostream_wrapper& operator=(const ostream_wrapper&) = delete;
|
||||
ostream_wrapper& operator=(ostream_wrapper&&) = delete;
|
||||
~ostream_wrapper();
|
||||
|
||||
void write(const std::string& str);
|
||||
@@ -26,7 +30,7 @@ class YAML_CPP_API ostream_wrapper {
|
||||
|
||||
const char* str() const {
|
||||
if (m_pStream) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
} else {
|
||||
m_buffer[m_pos] = '\0';
|
||||
return &m_buffer[0];
|
||||
@@ -52,7 +56,7 @@ class YAML_CPP_API ostream_wrapper {
|
||||
|
||||
template <std::size_t N>
|
||||
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
|
||||
const char(&str)[N]) {
|
||||
const char (&str)[N]) {
|
||||
stream.write(str, N - 1);
|
||||
return stream;
|
||||
}
|
||||
@@ -67,6 +71,6 @@ inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
|
||||
stream.write(&ch, 1);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class EventHandler;
|
||||
@@ -24,11 +23,16 @@ struct Token;
|
||||
* A parser turns a stream of bytes into one stream of "events" per YAML
|
||||
* document in the input stream.
|
||||
*/
|
||||
class YAML_CPP_API Parser : private noncopyable {
|
||||
class YAML_CPP_API Parser {
|
||||
public:
|
||||
/** Constructs an empty parser (with no input. */
|
||||
Parser();
|
||||
|
||||
Parser(const Parser&) = delete;
|
||||
Parser(Parser&&) = delete;
|
||||
Parser& operator=(const Parser&) = delete;
|
||||
Parser& operator=(Parser&&) = delete;
|
||||
|
||||
/**
|
||||
* Constructs a parser from the given input stream. The input stream must
|
||||
* live as long as the parser.
|
||||
@@ -81,6 +85,6 @@ class YAML_CPP_API Parser : private noncopyable {
|
||||
std::unique_ptr<Scanner> m_pScanner;
|
||||
std::unique_ptr<Directives> m_pDirectives;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace YAML {
|
||||
template <typename>
|
||||
struct is_numeric {
|
||||
@@ -100,4 +105,31 @@ template <class Cond, class T = void>
|
||||
struct disable_if : public disable_if_c<Cond::value, T> {};
|
||||
}
|
||||
|
||||
template <typename S, typename T>
|
||||
struct is_streamable {
|
||||
template <typename SS, typename TT>
|
||||
static auto test(int)
|
||||
-> decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type());
|
||||
|
||||
template <typename, typename>
|
||||
static auto test(...) -> std::false_type;
|
||||
|
||||
static const bool value = decltype(test<S, T>(0))::value;
|
||||
};
|
||||
|
||||
template<typename Key, bool Streamable>
|
||||
struct streamable_to_string {
|
||||
static std::string impl(const Key& key) {
|
||||
std::stringstream ss;
|
||||
ss << key;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Key>
|
||||
struct streamable_to_string<Key, false> {
|
||||
static std::string impl(const Key&) {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
#endif // TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+9
-2
@@ -1,5 +1,7 @@
|
||||
#include "yaml-cpp/binary.h"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
namespace YAML {
|
||||
static const char encoding[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
@@ -72,19 +74,24 @@ std::vector<unsigned char> 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<unsigned>(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]);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <stack>
|
||||
#include <cassert>
|
||||
#include <stack>
|
||||
|
||||
namespace YAML {
|
||||
struct CollectionType {
|
||||
@@ -17,6 +17,7 @@ struct CollectionType {
|
||||
|
||||
class CollectionStack {
|
||||
public:
|
||||
CollectionStack() : collectionStack{} {}
|
||||
CollectionType::value GetCurCollectionType() const {
|
||||
if (collectionStack.empty())
|
||||
return CollectionType::NoCollection;
|
||||
@@ -28,12 +29,13 @@ class CollectionStack {
|
||||
}
|
||||
void PopCollectionType(CollectionType::value type) {
|
||||
assert(type == GetCurCollectionType());
|
||||
(void)type;
|
||||
collectionStack.pop();
|
||||
}
|
||||
|
||||
private:
|
||||
std::stack<CollectionType::value> collectionStack;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -11,7 +11,7 @@ void* BuildGraphOfNextDocument(Parser& parser,
|
||||
if (parser.HandleNextDocument(eventHandler)) {
|
||||
return eventHandler.RootNode();
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,15 @@ namespace YAML {
|
||||
class GraphBuilderAdapter : public EventHandler {
|
||||
public:
|
||||
GraphBuilderAdapter(GraphBuilderInterface& builder)
|
||||
: m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL) {}
|
||||
: m_builder(builder),
|
||||
m_containers{},
|
||||
m_anchors{},
|
||||
m_pRootNode(nullptr),
|
||||
m_pKeyNode(nullptr) {}
|
||||
GraphBuilderAdapter(const GraphBuilderAdapter&) = delete;
|
||||
GraphBuilderAdapter(GraphBuilderAdapter&&) = delete;
|
||||
GraphBuilderAdapter& operator=(const GraphBuilderAdapter&) = delete;
|
||||
GraphBuilderAdapter& operator=(GraphBuilderAdapter&&) = delete;
|
||||
|
||||
virtual void OnDocumentStart(const Mark& mark) { (void)mark; }
|
||||
virtual void OnDocumentEnd() {}
|
||||
@@ -50,8 +58,8 @@ class GraphBuilderAdapter : public EventHandler {
|
||||
struct ContainerFrame {
|
||||
ContainerFrame(void* pSequence)
|
||||
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {}
|
||||
ContainerFrame(void* pMap, void* pPrevKeyNode)
|
||||
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode) {}
|
||||
ContainerFrame(void* pMap, void* pPreviousKeyNode)
|
||||
: pContainer(pMap), pPrevKeyNode(pPreviousKeyNode) {}
|
||||
|
||||
void* pContainer;
|
||||
void* pPrevKeyNode;
|
||||
@@ -74,6 +82,6 @@ class GraphBuilderAdapter : public EventHandler {
|
||||
void RegisterAnchor(anchor_t anchor, void* pNode);
|
||||
void DispositionNode(void* pNode);
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- MSVC Debugger visualization hints for YAML::Node and YAML::detail::node -->
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
<Type Name="YAML::Node">
|
||||
<DisplayString Condition="!m_isValid">{{invalid}}</DisplayString>
|
||||
<DisplayString Condition="!m_pNode">{{pNode==nullptr}}</DisplayString>
|
||||
<DisplayString>{{ {*m_pNode} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Condition="m_pNode->m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Scalar" Name="scalar">m_pNode->m_pRef._Ptr->m_pData._Ptr->m_scalar</Item>
|
||||
<Item Condition="m_pNode->m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Sequence" Name="sequence">m_pNode->m_pRef._Ptr->m_pData._Ptr->m_sequence</Item>
|
||||
<Item Condition="m_pNode->m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Map" Name="map">m_pNode->m_pRef._Ptr->m_pData._Ptr->m_map</Item>
|
||||
<Item Name="[details]" >m_pNode->m_pRef._Ptr->m_pData._Ptr</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="YAML::detail::node">
|
||||
<DisplayString Condition="!m_pRef._Ptr">{{node:pRef==nullptr}}</DisplayString>
|
||||
<DisplayString Condition="!m_pRef._Ptr->m_pData._Ptr">{{node:pRef->pData==nullptr}}</DisplayString>
|
||||
<DisplayString Condition="!m_pRef._Ptr->m_pData._Ptr->m_isDefined">{{undefined}}</DisplayString>
|
||||
<DisplayString Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Scalar">{{{m_pRef._Ptr->m_pData._Ptr->m_scalar}}}</DisplayString>
|
||||
<DisplayString Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Map">{{ Map {m_pRef._Ptr->m_pData._Ptr->m_map}}}</DisplayString>
|
||||
<DisplayString Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Sequence">{{ Seq {m_pRef._Ptr->m_pData._Ptr->m_sequence}}}</DisplayString>
|
||||
<DisplayString>{{{m_pRef._Ptr->m_pData._Ptr->m_type}}}</DisplayString>
|
||||
<Expand>
|
||||
<Item Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Scalar" Name="scalar">m_pRef._Ptr->m_pData._Ptr->m_scalar</Item>
|
||||
<Item Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Sequence" Name="sequence">m_pRef._Ptr->m_pData._Ptr->m_sequence</Item>
|
||||
<Item Condition="m_pRef._Ptr->m_pData._Ptr->m_type==YAML::NodeType::Map" Name="map">m_pRef._Ptr->m_pData._Ptr->m_map</Item>
|
||||
<Item Name="[details]" >m_pRef._Ptr->m_pData._Ptr</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
</AutoVisualizer>
|
||||
@@ -0,0 +1,9 @@
|
||||
# MSVC debugger visualizer for YAML::Node
|
||||
|
||||
## How to use
|
||||
Add yaml-cpp.natvis to your Visual C++ project like any other source file. It will be included in the debug information, and improve debugger display on YAML::Node and contained types.
|
||||
|
||||
## Compatibility and Troubleshooting
|
||||
|
||||
This has been tested for MSVC 2017. It is expected to be compatible with VS 2015 and VS 2019. If you have any problems, you can open an issue here: https://github.com/peterchen-cp/yaml-cpp-natvis
|
||||
|
||||
+2
-7
@@ -1,12 +1,7 @@
|
||||
#include "directives.h"
|
||||
|
||||
namespace YAML {
|
||||
Directives::Directives() {
|
||||
// version
|
||||
version.isDefault = true;
|
||||
version.major = 1;
|
||||
version.minor = 2;
|
||||
}
|
||||
Directives::Directives() : version{true, 1, 2}, tags{} {}
|
||||
|
||||
const std::string Directives::TranslateTagHandle(
|
||||
const std::string& handle) const {
|
||||
@@ -19,4 +14,4 @@ const std::string Directives::TranslateTagHandle(
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
@@ -16,10 +16,11 @@ std::string ToString(YAML::anchor_t anchor) {
|
||||
stream << anchor;
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace YAML {
|
||||
EmitFromEvents::EmitFromEvents(Emitter& emitter) : m_emitter(emitter) {}
|
||||
EmitFromEvents::EmitFromEvents(Emitter& emitter)
|
||||
: m_emitter(emitter), m_stateStack{} {}
|
||||
|
||||
void EmitFromEvents::OnDocumentStart(const Mark&) {}
|
||||
|
||||
@@ -116,4 +117,4 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
|
||||
if (anchor)
|
||||
m_emitter << Anchor(ToString(anchor));
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+4
-6
@@ -11,7 +11,7 @@ namespace YAML {
|
||||
class Binary;
|
||||
struct _Null;
|
||||
|
||||
Emitter::Emitter() : m_pState(new EmitterState) {}
|
||||
Emitter::Emitter() : m_pState(new EmitterState), m_stream{} {}
|
||||
|
||||
Emitter::Emitter(std::ostream& stream)
|
||||
: m_pState(new EmitterState), m_stream(stream) {}
|
||||
@@ -285,10 +285,8 @@ void Emitter::PrepareTopNode(EmitterNodeType::value child) {
|
||||
if (child == EmitterNodeType::NoType)
|
||||
return;
|
||||
|
||||
if (m_pState->CurGroupChildCount() > 0 && m_stream.col() > 0) {
|
||||
if (child != EmitterNodeType::NoType)
|
||||
EmitBeginDoc();
|
||||
}
|
||||
if (m_pState->CurGroupChildCount() > 0 && m_stream.col() > 0)
|
||||
EmitBeginDoc();
|
||||
|
||||
switch (child) {
|
||||
case EmitterNodeType::NoType:
|
||||
@@ -908,4 +906,4 @@ Emitter& Emitter::Write(const Binary& binary) {
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+24
-20
@@ -6,27 +6,31 @@
|
||||
namespace YAML {
|
||||
EmitterState::EmitterState()
|
||||
: m_isGood(true),
|
||||
m_lastError{},
|
||||
// default global manipulators
|
||||
m_charset(EmitNonAscii),
|
||||
m_strFmt(Auto),
|
||||
m_boolFmt(TrueFalseBool),
|
||||
m_boolLengthFmt(LongBool),
|
||||
m_boolCaseFmt(LowerCase),
|
||||
m_intFmt(Dec),
|
||||
m_indent(2),
|
||||
m_preCommentIndent(2),
|
||||
m_postCommentIndent(1),
|
||||
m_seqFmt(Block),
|
||||
m_mapFmt(Block),
|
||||
m_mapKeyFmt(Auto),
|
||||
m_floatPrecision(std::numeric_limits<float>::max_digits10),
|
||||
m_doublePrecision(std::numeric_limits<double>::max_digits10),
|
||||
//
|
||||
m_modifiedSettings{},
|
||||
m_globalModifiedSettings{},
|
||||
m_groups{},
|
||||
m_curIndent(0),
|
||||
m_hasAnchor(false),
|
||||
m_hasTag(false),
|
||||
m_hasNonContent(false),
|
||||
m_docCount(0) {
|
||||
// set default global manipulators
|
||||
m_charset.set(EmitNonAscii);
|
||||
m_strFmt.set(Auto);
|
||||
m_boolFmt.set(TrueFalseBool);
|
||||
m_boolLengthFmt.set(LongBool);
|
||||
m_boolCaseFmt.set(LowerCase);
|
||||
m_intFmt.set(Dec);
|
||||
m_indent.set(2);
|
||||
m_preCommentIndent.set(2);
|
||||
m_postCommentIndent.set(1);
|
||||
m_seqFmt.set(Block);
|
||||
m_mapFmt.set(Block);
|
||||
m_mapKeyFmt.set(Auto);
|
||||
m_floatPrecision.set(std::numeric_limits<float>::digits10 + 1);
|
||||
m_doublePrecision.set(std::numeric_limits<double>::digits10 + 1);
|
||||
}
|
||||
m_docCount(0) {}
|
||||
|
||||
EmitterState::~EmitterState() {}
|
||||
|
||||
@@ -349,7 +353,7 @@ bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
|
||||
bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
|
||||
if (value > std::numeric_limits<float>::digits10 + 1)
|
||||
if (value > std::numeric_limits<float>::max_digits10)
|
||||
return false;
|
||||
_Set(m_floatPrecision, value, scope);
|
||||
return true;
|
||||
@@ -357,9 +361,9 @@ bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
|
||||
|
||||
bool EmitterState::SetDoublePrecision(std::size_t value,
|
||||
FmtScope::value scope) {
|
||||
if (value > std::numeric_limits<double>::digits10 + 1)
|
||||
if (value > std::numeric_limits<double>::max_digits10)
|
||||
return false;
|
||||
_Set(m_doublePrecision, value, scope);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+7
-2
@@ -145,7 +145,12 @@ class EmitterState {
|
||||
|
||||
struct Group {
|
||||
explicit Group(GroupType::value type_)
|
||||
: type(type_), indent(0), childCount(0), longKey(false) {}
|
||||
: type(type_),
|
||||
flowType{},
|
||||
indent(0),
|
||||
childCount(0),
|
||||
longKey(false),
|
||||
modifiedSettings{} {}
|
||||
|
||||
GroupType::value type;
|
||||
FlowType::value flowType;
|
||||
@@ -198,6 +203,6 @@ void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+14
-14
@@ -8,8 +8,8 @@
|
||||
#include "regeximpl.h"
|
||||
#include "stringsource.h"
|
||||
#include "yaml-cpp/binary.h" // IWYU pragma: keep
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include "yaml-cpp/ostream_wrapper.h"
|
||||
|
||||
namespace YAML {
|
||||
namespace Utils {
|
||||
@@ -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<char>(codePoint);
|
||||
} else if (codePoint < 0x7FF) {
|
||||
} else if (codePoint <= 0x7FF) {
|
||||
out << static_cast<char>(0xC0 | (codePoint >> 6))
|
||||
<< static_cast<char>(0x80 | (codePoint & 0x3F));
|
||||
} else if (codePoint < 0xFFFF) {
|
||||
} else if (codePoint <= 0xFFFF) {
|
||||
out << static_cast<char>(0xE0 | (codePoint >> 12))
|
||||
<< static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F))
|
||||
<< static_cast<char>(0x80 | (codePoint & 0x3F));
|
||||
@@ -173,12 +173,12 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
|
||||
|
||||
// then check until something is disallowed
|
||||
static const RegEx& disallowed_flow =
|
||||
Exp::EndScalarInFlow() || (Exp::BlankOrBreak() + Exp::Comment()) ||
|
||||
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() ||
|
||||
Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) |
|
||||
Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
|
||||
Exp::Tab();
|
||||
static const RegEx& disallowed_block =
|
||||
Exp::EndScalar() || (Exp::BlankOrBreak() + Exp::Comment()) ||
|
||||
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() ||
|
||||
Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) |
|
||||
Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
|
||||
Exp::Tab();
|
||||
const RegEx& disallowed =
|
||||
flowType == FlowType::Flow ? disallowed_flow : disallowed_block;
|
||||
@@ -258,7 +258,7 @@ bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
StringFormat::value ComputeStringFormat(const std::string& str,
|
||||
EMITTER_MANIP strFormat,
|
||||
@@ -382,7 +382,7 @@ bool WriteChar(ostream_wrapper& out, char ch) {
|
||||
out << "\"\\b\"";
|
||||
} else if (ch == '\\') {
|
||||
out << "\"\\\\\"";
|
||||
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
||||
} else if (0x20 <= ch && ch <= 0x7e) {
|
||||
out << "\"" << ch << "\"";
|
||||
} else {
|
||||
out << "\"";
|
||||
@@ -401,8 +401,8 @@ bool WriteComment(ostream_wrapper& out, const std::string& str,
|
||||
for (std::string::const_iterator i = str.begin();
|
||||
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
|
||||
if (codePoint == '\n') {
|
||||
out << "\n" << IndentTo(curIndent) << "#"
|
||||
<< Indentation(postCommentIndent);
|
||||
out << "\n"
|
||||
<< IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
||||
out.set_comment();
|
||||
} else {
|
||||
WriteCodePoint(out, codePoint);
|
||||
@@ -479,5 +479,5 @@ bool WriteBinary(ostream_wrapper& out, const Binary& binary) {
|
||||
false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Utils
|
||||
} // namespace YAML
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -33,15 +33,15 @@ inline const RegEx& Tab() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Blank() {
|
||||
static const RegEx e = Space() || Tab();
|
||||
static const RegEx e = Space() | Tab();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Break() {
|
||||
static const RegEx e = RegEx('\n') || RegEx("\r\n");
|
||||
static const RegEx e = RegEx('\n') | RegEx("\r\n");
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& BlankOrBreak() {
|
||||
static const RegEx e = Blank() || Break();
|
||||
static const RegEx e = Blank() | Break();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Digit() {
|
||||
@@ -49,29 +49,29 @@ inline const RegEx& Digit() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Alpha() {
|
||||
static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||
static const RegEx e = RegEx('a', 'z') | RegEx('A', 'Z');
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& AlphaNumeric() {
|
||||
static const RegEx e = Alpha() || Digit();
|
||||
static const RegEx e = Alpha() | Digit();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Word() {
|
||||
static const RegEx e = AlphaNumeric() || RegEx('-');
|
||||
static const RegEx e = AlphaNumeric() | RegEx('-');
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Hex() {
|
||||
static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
|
||||
static const RegEx e = Digit() | RegEx('A', 'F') | RegEx('a', 'f');
|
||||
return e;
|
||||
}
|
||||
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec.
|
||||
// 5.1)
|
||||
inline const RegEx& NotPrintable() {
|
||||
static const RegEx e =
|
||||
RegEx(0) ||
|
||||
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) ||
|
||||
RegEx(0x0E, 0x1F) ||
|
||||
(RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
|
||||
RegEx(0) |
|
||||
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) |
|
||||
RegEx(0x0E, 0x1F) |
|
||||
(RegEx('\xC2') + (RegEx('\x80', '\x84') | RegEx('\x86', '\x9F')));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Utf8_ByteOrderMark() {
|
||||
@@ -82,19 +82,19 @@ inline const RegEx& Utf8_ByteOrderMark() {
|
||||
// actual tags
|
||||
|
||||
inline const RegEx& DocStart() {
|
||||
static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& DocEnd() {
|
||||
static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx("...") + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& DocIndicator() {
|
||||
static const RegEx e = DocStart() || DocEnd();
|
||||
static const RegEx e = DocStart() | DocEnd();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& BlockEntry() {
|
||||
static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx('-') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Key() {
|
||||
@@ -106,11 +106,11 @@ inline const RegEx& KeyInFlow() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Value() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& ValueInFlow() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx(",}", REGEX_OR));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& ValueInJSONFlow() {
|
||||
@@ -122,20 +122,20 @@ inline const RegEx Comment() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Anchor() {
|
||||
static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
|
||||
static const RegEx e = !(RegEx("[]{},", REGEX_OR) | BlankOrBreak());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& AnchorEnd() {
|
||||
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
|
||||
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) | BlankOrBreak();
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& URI() {
|
||||
static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) ||
|
||||
static const RegEx e = Word() | RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) |
|
||||
(RegEx('%') + Hex() + Hex());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Tag() {
|
||||
static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) ||
|
||||
static const RegEx e = Word() | RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) |
|
||||
(RegEx('%') + Hex() + Hex());
|
||||
return e;
|
||||
}
|
||||
@@ -148,34 +148,34 @@ inline const RegEx& Tag() {
|
||||
// space.
|
||||
inline const RegEx& PlainScalar() {
|
||||
static const RegEx e =
|
||||
!(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) ||
|
||||
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
|
||||
!(BlankOrBreak() | RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) |
|
||||
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() | RegEx())));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& PlainScalarInFlow() {
|
||||
static const RegEx e =
|
||||
!(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) ||
|
||||
!(BlankOrBreak() | RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) |
|
||||
(RegEx("-:", REGEX_OR) + Blank()));
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EndScalar() {
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
|
||||
static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EndScalarInFlow() {
|
||||
static const RegEx e =
|
||||
(RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) ||
|
||||
(RegEx(':') + (BlankOrBreak() | RegEx() | RegEx(",]}", REGEX_OR))) |
|
||||
RegEx(",?[]{}", REGEX_OR);
|
||||
return e;
|
||||
}
|
||||
|
||||
inline const RegEx& ScanScalarEndInFlow() {
|
||||
static const RegEx e = (EndScalarInFlow() || (BlankOrBreak() + Comment()));
|
||||
static const RegEx e = (EndScalarInFlow() | (BlankOrBreak() + Comment()));
|
||||
return e;
|
||||
}
|
||||
|
||||
inline const RegEx& ScanScalarEnd() {
|
||||
static const RegEx e = EndScalar() || (BlankOrBreak() + Comment());
|
||||
static const RegEx e = EndScalar() | (BlankOrBreak() + Comment());
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& EscSingleQuote() {
|
||||
@@ -192,8 +192,8 @@ inline const RegEx& ChompIndicator() {
|
||||
return e;
|
||||
}
|
||||
inline const RegEx& Chomp() {
|
||||
static const RegEx e = (ChompIndicator() + Digit()) ||
|
||||
(Digit() + ChompIndicator()) || ChompIndicator() ||
|
||||
static const RegEx e = (ChompIndicator() + Digit()) |
|
||||
(Digit() + ChompIndicator()) | ChompIndicator() |
|
||||
Digit();
|
||||
return e;
|
||||
}
|
||||
|
||||
+24
-8
@@ -13,14 +13,22 @@
|
||||
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),
|
||||
m_mark(Mark::null_mark()),
|
||||
m_type(NodeType::Null),
|
||||
m_tag{},
|
||||
m_style(EmitterStyle::Default),
|
||||
m_seqSize(0) {}
|
||||
m_scalar{},
|
||||
m_sequence{},
|
||||
m_seqSize(0),
|
||||
m_map{},
|
||||
m_undefinedPairs{} {}
|
||||
|
||||
void node_data::mark_defined() {
|
||||
if (m_type == NodeType::Undefined)
|
||||
@@ -188,7 +196,7 @@ void node_data::insert(node& key, node& value, shared_memory_holder pMemory) {
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw BadSubscript();
|
||||
throw BadSubscript(key);
|
||||
}
|
||||
|
||||
insert_map_pair(key, value);
|
||||
@@ -197,7 +205,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 +213,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) {
|
||||
@@ -218,7 +226,7 @@ node& node_data::get(node& key, shared_memory_holder pMemory) {
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw BadSubscript();
|
||||
throw BadSubscript(key);
|
||||
}
|
||||
|
||||
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
||||
@@ -235,6 +243,14 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
|
||||
if (m_type != NodeType::Map)
|
||||
return false;
|
||||
|
||||
for (kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||
it != m_undefinedPairs.end();) {
|
||||
kv_pairs::iterator jt = std::next(it);
|
||||
if (it->first->is(key))
|
||||
m_undefinedPairs.erase(it);
|
||||
it = jt;
|
||||
}
|
||||
|
||||
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
||||
if (it->first->is(key)) {
|
||||
m_map.erase(it);
|
||||
@@ -296,5 +312,5 @@ void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
|
||||
reset_sequence();
|
||||
m_type = NodeType::Map;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace YAML
|
||||
|
||||
+8
-3
@@ -11,8 +11,13 @@ 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_stack{},
|
||||
m_anchors{},
|
||||
m_keys{},
|
||||
m_mapDepth(0) {
|
||||
m_anchors.push_back(nullptr); // since the anchors start at 1
|
||||
}
|
||||
|
||||
NodeBuilder::~NodeBuilder() {}
|
||||
@@ -127,4 +132,4 @@ void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
|
||||
m_anchors.push_back(&node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+5
-1
@@ -27,6 +27,10 @@ class Node;
|
||||
class NodeBuilder : public EventHandler {
|
||||
public:
|
||||
NodeBuilder();
|
||||
NodeBuilder(const NodeBuilder&) = delete;
|
||||
NodeBuilder(NodeBuilder&&) = delete;
|
||||
NodeBuilder& operator=(const NodeBuilder&) = delete;
|
||||
NodeBuilder& operator=(NodeBuilder&&) = delete;
|
||||
virtual ~NodeBuilder();
|
||||
|
||||
Node Root();
|
||||
@@ -65,6 +69,6 @@ class NodeBuilder : public EventHandler {
|
||||
std::vector<PushedKey> m_keys;
|
||||
std::size_t m_mapDepth;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ anchor_t NodeEvents::AliasManager::LookupAnchor(
|
||||
}
|
||||
|
||||
NodeEvents::NodeEvents(const Node& node)
|
||||
: m_pMemory(node.m_pMemory), m_root(node.m_pNode) {
|
||||
: m_pMemory(node.m_pMemory), m_root(node.m_pNode), m_refCount{} {
|
||||
if (m_root)
|
||||
Setup(*m_root);
|
||||
}
|
||||
@@ -98,4 +98,4 @@ bool NodeEvents::IsAliased(const detail::node& node) const {
|
||||
RefCount::const_iterator it = m_refCount.find(node.ref());
|
||||
return it != m_refCount.end() && it->second > 1;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+6
-2
@@ -26,13 +26,17 @@ class Node;
|
||||
class NodeEvents {
|
||||
public:
|
||||
explicit NodeEvents(const Node& node);
|
||||
NodeEvents(const NodeEvents&) = delete;
|
||||
NodeEvents(NodeEvents&&) = delete;
|
||||
NodeEvents& operator=(const NodeEvents&) = delete;
|
||||
NodeEvents& operator=(NodeEvents&&) = delete;
|
||||
|
||||
void Emit(EventHandler& handler);
|
||||
|
||||
private:
|
||||
class AliasManager {
|
||||
public:
|
||||
AliasManager() : m_curAnchor(0) {}
|
||||
AliasManager() : m_anchorByIdentity{}, m_curAnchor(0) {}
|
||||
|
||||
void RegisterReference(const detail::node& node);
|
||||
anchor_t LookupAnchor(const detail::node& node) const;
|
||||
@@ -59,6 +63,6 @@ class NodeEvents {
|
||||
typedef std::map<const detail::node_ref*, int> RefCount;
|
||||
RefCount m_refCount;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -7,14 +7,19 @@
|
||||
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),
|
||||
m_comment(false) {}
|
||||
|
||||
ostream_wrapper::ostream_wrapper(std::ostream& stream)
|
||||
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
|
||||
: m_buffer{},
|
||||
m_pStream(&stream),
|
||||
m_pos(0),
|
||||
m_row(0),
|
||||
m_col(0),
|
||||
m_comment(false) {}
|
||||
|
||||
ostream_wrapper::~ostream_wrapper() {}
|
||||
|
||||
@@ -54,4 +59,4 @@ void ostream_wrapper::update_pos(char ch) {
|
||||
m_comment = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@
|
||||
namespace YAML {
|
||||
class EventHandler;
|
||||
|
||||
Parser::Parser() {}
|
||||
Parser::Parser() : m_pScanner{}, m_pDirectives{} {}
|
||||
|
||||
Parser::Parser(std::istream& in) { Load(in); }
|
||||
Parser::Parser(std::istream& in) : Parser() { Load(in); }
|
||||
|
||||
Parser::~Parser() {}
|
||||
|
||||
@@ -126,4 +126,4 @@ void Parser::PrintTokens(std::ostream& out) {
|
||||
m_pScanner->pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+7
-5
@@ -12,15 +12,17 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
|
||||
// TODO: This class is no longer needed
|
||||
template <typename T>
|
||||
class ptr_vector : private YAML::noncopyable {
|
||||
class ptr_vector {
|
||||
public:
|
||||
ptr_vector() {}
|
||||
ptr_vector() : m_data{} {}
|
||||
ptr_vector(const ptr_vector&) = delete;
|
||||
ptr_vector(ptr_vector&&) = default;
|
||||
ptr_vector& operator=(const ptr_vector&) = delete;
|
||||
ptr_vector& operator=(ptr_vector&&) = default;
|
||||
|
||||
void clear() { m_data.clear(); }
|
||||
|
||||
@@ -38,6 +40,6 @@ class ptr_vector : private YAML::noncopyable {
|
||||
private:
|
||||
std::vector<std::unique_ptr<T>> m_data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+9
-11
@@ -2,18 +2,16 @@
|
||||
|
||||
namespace YAML {
|
||||
// constructors
|
||||
RegEx::RegEx() : m_op(REGEX_EMPTY) {}
|
||||
|
||||
RegEx::RegEx(REGEX_OP op) : m_op(op) {}
|
||||
RegEx::RegEx(REGEX_OP op) : m_op(op), m_a(0), m_z(0), m_params{} {}
|
||||
RegEx::RegEx() : RegEx(REGEX_EMPTY) {}
|
||||
|
||||
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch) {}
|
||||
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch), m_z(0), m_params{} {}
|
||||
|
||||
RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z) {}
|
||||
RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z), m_params{} {}
|
||||
|
||||
RegEx::RegEx(const std::string& str, REGEX_OP op) : m_op(op) {
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
m_params.push_back(RegEx(str[i]));
|
||||
}
|
||||
RegEx::RegEx(const std::string& str, REGEX_OP op)
|
||||
: m_op(op), m_a(0), m_z(0), m_params(str.begin(), str.end()) {}
|
||||
|
||||
// combination constructors
|
||||
RegEx operator!(const RegEx& ex) {
|
||||
@@ -22,14 +20,14 @@ RegEx operator!(const RegEx& ex) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
RegEx operator||(const RegEx& ex1, const RegEx& ex2) {
|
||||
RegEx operator|(const RegEx& ex1, const RegEx& ex2) {
|
||||
RegEx ret(REGEX_OR);
|
||||
ret.m_params.push_back(ex1);
|
||||
ret.m_params.push_back(ex2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
RegEx operator&&(const RegEx& ex1, const RegEx& ex2) {
|
||||
RegEx operator&(const RegEx& ex1, const RegEx& ex2) {
|
||||
RegEx ret(REGEX_AND);
|
||||
ret.m_params.push_back(ex1);
|
||||
ret.m_params.push_back(ex2);
|
||||
@@ -42,4 +40,4 @@ RegEx operator+(const RegEx& ex1, const RegEx& ex2) {
|
||||
ret.m_params.push_back(ex2);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+7
-6
@@ -31,14 +31,14 @@ enum REGEX_OP {
|
||||
class YAML_CPP_API RegEx {
|
||||
public:
|
||||
RegEx();
|
||||
RegEx(char ch);
|
||||
explicit RegEx(char ch);
|
||||
RegEx(char a, char z);
|
||||
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
||||
~RegEx() {}
|
||||
|
||||
friend YAML_CPP_API RegEx operator!(const RegEx& ex);
|
||||
friend YAML_CPP_API RegEx operator||(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator|(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator&(const RegEx& ex1, const RegEx& ex2);
|
||||
friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2);
|
||||
|
||||
bool Matches(char ch) const;
|
||||
@@ -53,7 +53,7 @@ class YAML_CPP_API RegEx {
|
||||
int Match(const Source& source) const;
|
||||
|
||||
private:
|
||||
RegEx(REGEX_OP op);
|
||||
explicit RegEx(REGEX_OP op);
|
||||
|
||||
template <typename Source>
|
||||
bool IsValidSource(const Source& source) const;
|
||||
@@ -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<RegEx> m_params;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#include "regeximpl.h"
|
||||
|
||||
|
||||
+9
-4
@@ -9,10 +9,15 @@
|
||||
namespace YAML {
|
||||
Scanner::Scanner(std::istream& in)
|
||||
: INPUT(in),
|
||||
m_tokens{},
|
||||
m_startedStream(false),
|
||||
m_endedStream(false),
|
||||
m_simpleKeyAllowed(false),
|
||||
m_canBeJSONFlow(false) {}
|
||||
m_canBeJSONFlow(false),
|
||||
m_simpleKeys{},
|
||||
m_indents{},
|
||||
m_indentRefs{},
|
||||
m_flows{} {}
|
||||
|
||||
Scanner::~Scanner() {}
|
||||
|
||||
@@ -282,7 +287,7 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column,
|
||||
IndentMarker::INDENT_TYPE type) {
|
||||
// are we in flow?
|
||||
if (InFlowContext()) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IndentMarker> pIndent(new IndentMarker(column, type));
|
||||
@@ -291,12 +296,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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
|
||||
case FOLD_FLOW:
|
||||
if (nextEmptyLine) {
|
||||
scalar += "\n";
|
||||
} else if (!emptyLine && !nextEmptyLine && !escapedNewline) {
|
||||
} else if (!emptyLine && !escapedNewline) {
|
||||
scalar += " ";
|
||||
}
|
||||
break;
|
||||
|
||||
+2
-2
@@ -338,7 +338,7 @@ void Scanner::ScanQuotedScalar() {
|
||||
|
||||
// setup the scanning parameters
|
||||
ScanScalarParams params;
|
||||
RegEx end = (single ? RegEx(quote) && !Exp::EscSingleQuote() : RegEx(quote));
|
||||
RegEx end = (single ? RegEx(quote) & !Exp::EscSingleQuote() : RegEx(quote));
|
||||
params.end = &end;
|
||||
params.eatEnd = true;
|
||||
params.escape = (single ? '\'' : '\\');
|
||||
@@ -434,4 +434,4 @@ void Scanner::ScanBlockScalar() {
|
||||
token.value = scalar;
|
||||
m_tokens.push(token);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+16
-8
@@ -8,8 +8,8 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class SettingChangeBase;
|
||||
@@ -18,6 +18,7 @@ template <typename T>
|
||||
class Setting {
|
||||
public:
|
||||
Setting() : m_value() {}
|
||||
Setting(const T& value) : m_value() { set(value); }
|
||||
|
||||
const T get() const { return m_value; }
|
||||
std::unique_ptr<SettingChangeBase> set(const T& value);
|
||||
@@ -36,10 +37,14 @@ class SettingChangeBase {
|
||||
template <typename T>
|
||||
class SettingChange : public SettingChangeBase {
|
||||
public:
|
||||
SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) {
|
||||
// copy old setting to save its state
|
||||
m_oldSetting = *pSetting;
|
||||
}
|
||||
SettingChange(Setting<T>* pSetting)
|
||||
: m_pCurSetting(pSetting),
|
||||
m_oldSetting(*pSetting) // copy old setting to save its state
|
||||
{}
|
||||
SettingChange(const SettingChange&) = delete;
|
||||
SettingChange(SettingChange&&) = delete;
|
||||
SettingChange& operator=(const SettingChange&) = delete;
|
||||
SettingChange& operator=(SettingChange&&) = delete;
|
||||
|
||||
virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
|
||||
|
||||
@@ -55,9 +60,12 @@ inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
|
||||
return pChange;
|
||||
}
|
||||
|
||||
class SettingChanges : private noncopyable {
|
||||
class SettingChanges {
|
||||
public:
|
||||
SettingChanges() {}
|
||||
SettingChanges() : m_settingChanges{} {}
|
||||
SettingChanges(const SettingChanges&) = delete;
|
||||
SettingChanges(SettingChanges&&) = default;
|
||||
SettingChanges& operator=(const SettingChanges&) = delete;
|
||||
~SettingChanges() { clear(); }
|
||||
|
||||
void clear() {
|
||||
@@ -90,6 +98,6 @@ class SettingChanges : private noncopyable {
|
||||
typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes;
|
||||
setting_changes m_settingChanges;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+17
-9
@@ -18,6 +18,7 @@ SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives)
|
||||
: m_scanner(scanner),
|
||||
m_directives(directives),
|
||||
m_pCollectionStack(new CollectionStack),
|
||||
m_anchors{},
|
||||
m_curAnchor(0) {}
|
||||
|
||||
SingleDocParser::~SingleDocParser() {}
|
||||
@@ -71,8 +72,12 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
|
||||
}
|
||||
|
||||
std::string tag;
|
||||
std::string anchor_name;
|
||||
anchor_t anchor;
|
||||
ParseProperties(tag, anchor);
|
||||
ParseProperties(tag, anchor, anchor_name);
|
||||
|
||||
if (!anchor_name.empty())
|
||||
eventHandler.OnAnchor(mark, anchor_name);
|
||||
|
||||
const Token& token = m_scanner.peek();
|
||||
|
||||
@@ -166,10 +171,10 @@ void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
|
||||
|
||||
// check for null
|
||||
if (!m_scanner.empty()) {
|
||||
const Token& token = m_scanner.peek();
|
||||
if (token.type == Token::BLOCK_ENTRY ||
|
||||
token.type == Token::BLOCK_SEQ_END) {
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
const Token& nextToken = m_scanner.peek();
|
||||
if (nextToken.type == Token::BLOCK_ENTRY ||
|
||||
nextToken.type == Token::BLOCK_SEQ_END) {
|
||||
eventHandler.OnNull(nextToken.mark, NullAnchor);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -356,8 +361,10 @@ void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler) {
|
||||
|
||||
// ParseProperties
|
||||
// . Grabs any tag or anchor tokens and deals with them.
|
||||
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
|
||||
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor,
|
||||
std::string& anchor_name) {
|
||||
tag.clear();
|
||||
anchor_name.clear();
|
||||
anchor = NullAnchor;
|
||||
|
||||
while (1) {
|
||||
@@ -369,7 +376,7 @@ void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
|
||||
ParseTag(tag);
|
||||
break;
|
||||
case Token::ANCHOR:
|
||||
ParseAnchor(anchor);
|
||||
ParseAnchor(anchor, anchor_name);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -387,11 +394,12 @@ void SingleDocParser::ParseTag(std::string& tag) {
|
||||
m_scanner.pop();
|
||||
}
|
||||
|
||||
void SingleDocParser::ParseAnchor(anchor_t& anchor) {
|
||||
void SingleDocParser::ParseAnchor(anchor_t& anchor, std::string& anchor_name) {
|
||||
Token& token = m_scanner.peek();
|
||||
if (anchor)
|
||||
throw ParserException(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
|
||||
|
||||
anchor_name = token.value;
|
||||
anchor = RegisterAnchor(token.value);
|
||||
m_scanner.pop();
|
||||
}
|
||||
@@ -411,4 +419,4 @@ anchor_t SingleDocParser::LookupAnchor(const Mark& mark,
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "yaml-cpp/anchor.h"
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
namespace YAML {
|
||||
class CollectionStack;
|
||||
@@ -23,9 +22,13 @@ struct Directives;
|
||||
struct Mark;
|
||||
struct Token;
|
||||
|
||||
class SingleDocParser : private noncopyable {
|
||||
class SingleDocParser {
|
||||
public:
|
||||
SingleDocParser(Scanner& scanner, const Directives& directives);
|
||||
SingleDocParser(const SingleDocParser&) = delete;
|
||||
SingleDocParser(SingleDocParser&&) = delete;
|
||||
SingleDocParser& operator=(const SingleDocParser&) = delete;
|
||||
SingleDocParser& operator=(SingleDocParser&&) = delete;
|
||||
~SingleDocParser();
|
||||
|
||||
void HandleDocument(EventHandler& eventHandler);
|
||||
@@ -43,9 +46,10 @@ class SingleDocParser : private noncopyable {
|
||||
void HandleCompactMap(EventHandler& eventHandler);
|
||||
void HandleCompactMapWithNoKey(EventHandler& eventHandler);
|
||||
|
||||
void ParseProperties(std::string& tag, anchor_t& anchor);
|
||||
void ParseProperties(std::string& tag, anchor_t& anchor,
|
||||
std::string& anchor_name);
|
||||
void ParseTag(std::string& tag);
|
||||
void ParseAnchor(anchor_t& anchor);
|
||||
void ParseAnchor(anchor_t& anchor, std::string& anchor_name);
|
||||
|
||||
anchor_t RegisterAnchor(const std::string& name);
|
||||
anchor_t LookupAnchor(const Mark& mark, const std::string& name) const;
|
||||
@@ -60,6 +64,6 @@ class SingleDocParser : private noncopyable {
|
||||
|
||||
anchor_t m_curAnchor;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+13
-19
@@ -111,24 +111,15 @@ static UtfIntroState s_introTransitions[][uictMax] = {
|
||||
|
||||
static char s_introUngetCount[][uictMax] = {
|
||||
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
|
||||
{0, 1, 1, 0, 0, 0, 0, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 3, 0, 3, 3, 3},
|
||||
{4, 4, 4, 4, 4, 0, 4, 4},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{2, 2, 2, 2, 2, 0, 2, 2},
|
||||
{2, 2, 2, 2, 0, 2, 2, 2},
|
||||
{0, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{0, 3, 3, 3, 3, 3, 3, 3},
|
||||
{4, 4, 4, 4, 4, 4, 4, 4},
|
||||
{2, 0, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 0, 3, 3, 3, 3, 3},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 1, 1, 0, 0, 0, 0, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 3, 0, 3, 3, 3}, {4, 4, 4, 4, 4, 0, 4, 4},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{2, 2, 2, 2, 2, 0, 2, 2}, {2, 2, 2, 2, 0, 2, 2, 2},
|
||||
{0, 1, 1, 1, 1, 1, 1, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{0, 2, 2, 2, 2, 2, 2, 2}, {0, 3, 3, 3, 3, 3, 3, 3},
|
||||
{4, 4, 4, 4, 4, 4, 4, 4}, {2, 0, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 0, 3, 3, 3, 3, 3}, {1, 1, 1, 1, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
|
||||
@@ -192,6 +183,9 @@ inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) {
|
||||
|
||||
Stream::Stream(std::istream& input)
|
||||
: m_input(input),
|
||||
m_mark{},
|
||||
m_charSet{},
|
||||
m_readahead{},
|
||||
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
|
||||
m_nPrefetchedAvailable(0),
|
||||
m_nPrefetchedUsed(0) {
|
||||
@@ -445,4 +439,4 @@ void Stream::StreamInUtf32() const {
|
||||
|
||||
QueueUnicodeCodepoint(m_readahead, ch);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+6
-3
@@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "yaml-cpp/mark.h"
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
@@ -17,11 +16,15 @@
|
||||
#include <string>
|
||||
|
||||
namespace YAML {
|
||||
class Stream : private noncopyable {
|
||||
class Stream {
|
||||
public:
|
||||
friend class StreamCharSource;
|
||||
|
||||
Stream(std::istream& input);
|
||||
Stream(const Stream&) = delete;
|
||||
Stream(Stream&&) = delete;
|
||||
Stream& operator=(const Stream&) = delete;
|
||||
Stream& operator=(Stream&&) = delete;
|
||||
~Stream();
|
||||
|
||||
operator bool() const;
|
||||
@@ -71,6 +74,6 @@ inline bool Stream::ReadAheadTo(size_t i) const {
|
||||
return true;
|
||||
return _ReadAheadTo(i);
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace YAML {
|
||||
@@ -16,6 +15,9 @@ class StreamCharSource {
|
||||
StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {}
|
||||
StreamCharSource(const StreamCharSource& source)
|
||||
: m_offset(source.m_offset), m_stream(source.m_stream) {}
|
||||
StreamCharSource(StreamCharSource&&) = default;
|
||||
StreamCharSource& operator=(const StreamCharSource&) = delete;
|
||||
StreamCharSource& operator=(StreamCharSource&&) = delete;
|
||||
~StreamCharSource() {}
|
||||
|
||||
operator bool() const;
|
||||
@@ -27,8 +29,6 @@ class StreamCharSource {
|
||||
private:
|
||||
std::size_t m_offset;
|
||||
const Stream& m_stream;
|
||||
|
||||
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
|
||||
};
|
||||
|
||||
inline StreamCharSource::operator bool() const {
|
||||
@@ -43,6 +43,6 @@ inline const StreamCharSource StreamCharSource::operator+(int i) const {
|
||||
source.m_offset = 0;
|
||||
return source;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+3
-2
@@ -6,7 +6,8 @@
|
||||
#include "token.h"
|
||||
|
||||
namespace YAML {
|
||||
Tag::Tag(const Token& token) : type(static_cast<TYPE>(token.data)) {
|
||||
Tag::Tag(const Token& token)
|
||||
: type(static_cast<TYPE>(token.data)), handle{}, value{} {
|
||||
switch (type) {
|
||||
case VERBATIM:
|
||||
value = token.value;
|
||||
@@ -46,4 +47,4 @@ const std::string Tag::Translate(const Directives& directives) {
|
||||
}
|
||||
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+7
-6
@@ -14,10 +14,11 @@
|
||||
|
||||
namespace YAML {
|
||||
const std::string TokenNames[] = {
|
||||
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START", "BLOCK_MAP_START",
|
||||
"BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY", "FLOW_SEQ_START",
|
||||
"FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END", "FLOW_MAP_COMPACT",
|
||||
"FLOW_ENTRY", "KEY", "VALUE", "ANCHOR", "ALIAS", "TAG", "SCALAR"};
|
||||
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
|
||||
"BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
|
||||
"FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
|
||||
"FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
|
||||
"ANCHOR", "ALIAS", "TAG", "SCALAR"};
|
||||
|
||||
struct Token {
|
||||
// enums
|
||||
@@ -48,7 +49,7 @@ struct Token {
|
||||
|
||||
// data
|
||||
Token(TYPE type_, const Mark& mark_)
|
||||
: status(VALID), type(type_), mark(mark_), data(0) {}
|
||||
: status(VALID), type(type_), mark(mark_), value{}, params{}, data(0) {}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
|
||||
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||
@@ -64,6 +65,6 @@ struct Token {
|
||||
std::vector<std::string> params;
|
||||
int data;
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
+47
-22
@@ -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=<INSTALL_DIR>
|
||||
-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)
|
||||
@@ -30,15 +43,27 @@ 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
|
||||
${test_sources}
|
||||
${test_headers}
|
||||
${test_sources}
|
||||
${test_headers}
|
||||
)
|
||||
|
||||
set_target_properties(run-tests PROPERTIES
|
||||
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
target_link_libraries(run-tests yaml-cpp gmock)
|
||||
|
||||
add_dependencies(run-tests googletest_project)
|
||||
|
||||
set_target_properties(run-tests PROPERTIES
|
||||
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
|
||||
)
|
||||
target_link_libraries(run-tests
|
||||
yaml-cpp
|
||||
gmock
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests)
|
||||
|
||||
@@ -35,10 +35,12 @@ def doc_end(implicit=False):
|
||||
|
||||
def scalar(value, tag='', anchor='', anchor_id=0):
|
||||
emit = []
|
||||
handle = []
|
||||
if tag:
|
||||
emit += ['VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['Anchor("%s")' % encode(anchor)]
|
||||
handle += ['OnAnchor(_, "%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
@@ -47,39 +49,46 @@ def scalar(value, tag='', anchor='', anchor_id=0):
|
||||
else:
|
||||
out_tag = '!'
|
||||
emit += ['"%s"' % encode(value)]
|
||||
return {'emit': emit, 'handle': 'OnScalar(_, "%s", %s, "%s")' % (out_tag, anchor_id, encode(value))}
|
||||
handle += ['OnScalar(_, "%s", %s, "%s")' % (out_tag, anchor_id, encode(value))]
|
||||
return {'emit': emit, 'handle': handle}
|
||||
|
||||
def comment(value):
|
||||
return {'emit': 'Comment("%s")' % value, 'handle': ''}
|
||||
|
||||
def seq_start(tag='', anchor='', anchor_id=0, style='_'):
|
||||
emit = []
|
||||
handle = []
|
||||
if tag:
|
||||
emit += ['VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['Anchor("%s")' % encode(anchor)]
|
||||
handle += ['OnAnchor(_, "%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
out_tag = '?'
|
||||
emit += ['BeginSeq']
|
||||
return {'emit': emit, 'handle': 'OnSequenceStart(_, "%s", %s, %s)' % (out_tag, anchor_id, style)}
|
||||
handle += ['OnSequenceStart(_, "%s", %s, %s)' % (out_tag, anchor_id, style)]
|
||||
return {'emit': emit, 'handle': handle}
|
||||
|
||||
def seq_end():
|
||||
return {'emit': 'EndSeq', 'handle': 'OnSequenceEnd()'}
|
||||
|
||||
def map_start(tag='', anchor='', anchor_id=0, style='_'):
|
||||
emit = []
|
||||
handle = []
|
||||
if tag:
|
||||
emit += ['VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['Anchor("%s")' % encode(anchor)]
|
||||
handle += ['OnAnchor(_, "%s")' % encode(anchor)]
|
||||
if tag:
|
||||
out_tag = encode(tag)
|
||||
else:
|
||||
out_tag = '?'
|
||||
emit += ['BeginMap']
|
||||
return {'emit': emit, 'handle': 'OnMapStart(_, "%s", %s, %s)' % (out_tag, anchor_id, style)}
|
||||
handle += ['OnMapStart(_, "%s", %s, %s)' % (out_tag, anchor_id, style)]
|
||||
return {'emit': emit, 'handle': handle}
|
||||
|
||||
def map_end():
|
||||
return {'emit': 'EndMap', 'handle': 'OnMapEnd()'}
|
||||
@@ -202,7 +211,10 @@ def create_emitter_tests(out):
|
||||
out.writeln('')
|
||||
for event in test['events']:
|
||||
handle = event['handle']
|
||||
if handle:
|
||||
if isinstance(handle, list):
|
||||
for e in handle:
|
||||
out.writeln('EXPECT_CALL(handler, %s);' % e)
|
||||
elif handle:
|
||||
out.writeln('EXPECT_CALL(handler, %s);' % handle)
|
||||
out.writeln('Parse(out.c_str());')
|
||||
out.writeln('')
|
||||
|
||||
@@ -253,8 +253,9 @@ TEST_F(EmitterTest, ScalarFormat) {
|
||||
out << DoubleQuoted << "explicit double-quoted scalar";
|
||||
out << "auto-detected\ndouble-quoted scalar";
|
||||
out << "a non-\"auto-detected\" double-quoted scalar";
|
||||
out << Literal << "literal scalar\nthat may span\nmany, many\nlines "
|
||||
"and have \"whatever\" crazy\tsymbols that we like";
|
||||
out << Literal
|
||||
<< "literal scalar\nthat may span\nmany, many\nlines "
|
||||
"and have \"whatever\" crazy\tsymbols that we like";
|
||||
out << EndSeq;
|
||||
|
||||
ExpectEmit(
|
||||
@@ -526,9 +527,10 @@ TEST_F(EmitterTest, SimpleComment) {
|
||||
|
||||
TEST_F(EmitterTest, MultiLineComment) {
|
||||
out << BeginSeq;
|
||||
out << "item 1" << Comment(
|
||||
"really really long\ncomment that couldn't "
|
||||
"possibly\nfit on one line");
|
||||
out << "item 1"
|
||||
<< Comment(
|
||||
"really really long\ncomment that couldn't "
|
||||
"possibly\nfit on one line");
|
||||
out << "item 2";
|
||||
out << EndSeq;
|
||||
|
||||
@@ -901,18 +903,18 @@ TEST_F(EmitterTest, SingleChar) {
|
||||
|
||||
TEST_F(EmitterTest, DefaultPrecision) {
|
||||
out << BeginSeq;
|
||||
out << 1.234f;
|
||||
out << 3.14159265358979;
|
||||
out << 1.3125f;
|
||||
out << 1.23455810546875;
|
||||
out << EndSeq;
|
||||
ExpectEmit("- 1.234\n- 3.14159265358979");
|
||||
ExpectEmit("- 1.3125\n- 1.23455810546875");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, SetPrecision) {
|
||||
out << BeginSeq;
|
||||
out << FloatPrecision(3) << 1.234f;
|
||||
out << DoublePrecision(6) << 3.14159265358979;
|
||||
out << FloatPrecision(3) << 1.3125f;
|
||||
out << DoublePrecision(6) << 1.23455810546875;
|
||||
out << EndSeq;
|
||||
ExpectEmit("- 1.23\n- 3.14159");
|
||||
ExpectEmit("- 1.31\n- 1.23456");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, DashInBlockContext) {
|
||||
@@ -984,6 +986,45 @@ TEST_F(EmitterTest, ValueOfBackslash) {
|
||||
ExpectEmit("foo: \"\\\\\"");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, Infinity) {
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "foo" << YAML::Value
|
||||
<< std::numeric_limits<float>::infinity();
|
||||
out << YAML::Key << "bar" << YAML::Value
|
||||
<< std::numeric_limits<double>::infinity();
|
||||
out << YAML::EndMap;
|
||||
|
||||
ExpectEmit(
|
||||
"foo: .inf\n"
|
||||
"bar: .inf");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, NegInfinity) {
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "foo" << YAML::Value
|
||||
<< -std::numeric_limits<float>::infinity();
|
||||
out << YAML::Key << "bar" << YAML::Value
|
||||
<< -std::numeric_limits<double>::infinity();
|
||||
out << YAML::EndMap;
|
||||
|
||||
ExpectEmit(
|
||||
"foo: -.inf\n"
|
||||
"bar: -.inf");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, NaN) {
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "foo" << YAML::Value
|
||||
<< std::numeric_limits<float>::quiet_NaN();
|
||||
out << YAML::Key << "bar" << YAML::Value
|
||||
<< std::numeric_limits<double>::quiet_NaN();
|
||||
out << YAML::EndMap;
|
||||
|
||||
ExpectEmit(
|
||||
"foo: .nan\n"
|
||||
"bar: .nan");
|
||||
}
|
||||
|
||||
class EmitterErrorTest : public ::testing::Test {
|
||||
protected:
|
||||
void ExpectEmitError(const std::string& expectedError) {
|
||||
@@ -1034,5 +1075,5 @@ TEST_F(EmitterErrorTest, InvalidAlias) {
|
||||
|
||||
ExpectEmitError(ErrorMsg::INVALID_ALIAS);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace YAML
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define EXPECT_THROW_EXCEPTION(exception_type, statement, message) \
|
||||
ASSERT_THROW(statement, exception_type); \
|
||||
try { \
|
||||
statement; \
|
||||
} catch (const exception_type& e) { \
|
||||
EXPECT_EQ(e.msg, message); \
|
||||
}
|
||||
|
||||
namespace YAML {
|
||||
namespace {
|
||||
|
||||
TEST(ErrorMessageTest, BadSubscriptErrorMessage) {
|
||||
const char *example_yaml = "first:\n"
|
||||
" second: 1\n"
|
||||
" third: 2\n";
|
||||
|
||||
Node doc = Load(example_yaml);
|
||||
|
||||
// Test that printable key is part of error message
|
||||
EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"]["fourth"],
|
||||
"operator[] call on a scalar (key: \"fourth\")");
|
||||
|
||||
EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"][37],
|
||||
"operator[] call on a scalar (key: \"37\")");
|
||||
|
||||
|
||||
// Non-printable key is not included in error message
|
||||
EXPECT_THROW_EXCEPTION(YAML::BadSubscript,
|
||||
doc["first"]["second"][std::vector<int>()],
|
||||
"operator[] call on a scalar");
|
||||
|
||||
EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"][Node()],
|
||||
"operator[] call on a scalar");
|
||||
}
|
||||
|
||||
TEST(ErrorMessageTest, Ex9_1_InvalidNodeErrorMessage) {
|
||||
const char *example_yaml = "first:\n"
|
||||
" second: 1\n"
|
||||
" third: 2\n";
|
||||
|
||||
const Node doc = Load(example_yaml);
|
||||
|
||||
// Test that printable key is part of error message
|
||||
EXPECT_THROW_EXCEPTION(YAML::InvalidNode, doc["first"]["fourth"].as<int>(),
|
||||
"invalid node; first invalid key: \"fourth\"");
|
||||
|
||||
EXPECT_THROW_EXCEPTION(YAML::InvalidNode, doc["first"][37].as<int>(),
|
||||
"invalid node; first invalid key: \"37\"");
|
||||
|
||||
// Non-printable key is not included in error message
|
||||
EXPECT_THROW_EXCEPTION(YAML::InvalidNode,
|
||||
doc["first"][std::vector<int>()].as<int>(),
|
||||
"invalid node; this may result from using a map "
|
||||
"iterator as a sequence iterator, or vice-versa");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -199,6 +199,7 @@ TEST_F(HandlerSpecTest, Ex2_10_SimpleAnchor) {
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
|
||||
EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "SS"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 1, "Sammy Sosa"));
|
||||
EXPECT_CALL(handler, OnSequenceEnd());
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "rbi"));
|
||||
@@ -376,6 +377,7 @@ TEST_F(HandlerSpecTest, Ex2_24_GlobalTags) {
|
||||
EXPECT_CALL(handler, OnMapStart(_, "tag:clarkevans.com,2002:circle", 0,
|
||||
EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "center"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "ORIGIN"));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 1, EmitterStyle::Flow));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "x"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "73"));
|
||||
@@ -456,6 +458,7 @@ TEST_F(HandlerSpecTest, Ex2_27_Invoice) {
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "date"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-01-23"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "bill-to"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "id001"));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 1, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "given"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chris"));
|
||||
@@ -616,6 +619,7 @@ TEST_F(HandlerSpecTest, Ex5_6_NodePropertyIndicators) {
|
||||
EXPECT_CALL(handler, OnDocumentStart(_));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "anchored"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "anchor"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "!local", 1, "value"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "alias"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 1));
|
||||
@@ -909,8 +913,10 @@ TEST_F(HandlerSpecTest, Ex6_22_GlobalTagPrefix) {
|
||||
TEST_F(HandlerSpecTest, Ex6_23_NodeProperties) {
|
||||
EXPECT_CALL(handler, OnDocumentStart(_));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "a1"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 1, "foo"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "bar"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "a2"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 2, "baz"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 1));
|
||||
EXPECT_CALL(handler, OnMapEnd());
|
||||
@@ -972,6 +978,7 @@ TEST_F(HandlerSpecTest, Ex6_29_NodeAnchors) {
|
||||
EXPECT_CALL(handler, OnDocumentStart(_));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "First occurrence"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "anchor"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 1, "Value"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Second occurrence"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 1));
|
||||
@@ -984,10 +991,12 @@ TEST_F(HandlerSpecTest, Ex7_1_AliasNodes) {
|
||||
EXPECT_CALL(handler, OnDocumentStart(_));
|
||||
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "First occurrence"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "anchor"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 1, "Foo"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Second occurrence"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 1));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Override anchor"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "anchor"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 2, "Bar"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "?", 0, "Reuse anchor"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 2));
|
||||
@@ -1307,6 +1316,7 @@ TEST_F(HandlerSpecTest, Ex7_24_FlowNodes) {
|
||||
EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
|
||||
EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "a"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "!", 0, "b"));
|
||||
EXPECT_CALL(handler, OnAnchor(_, "anchor"));
|
||||
EXPECT_CALL(handler, OnScalar(_, "!", 1, "c"));
|
||||
EXPECT_CALL(handler, OnAlias(_, 1));
|
||||
EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, ""));
|
||||
@@ -1607,5 +1617,5 @@ TEST_F(HandlerSpecTest, Ex8_22_BlockCollectionNodes) {
|
||||
EXPECT_CALL(handler, OnDocumentEnd());
|
||||
Parse(ex8_22);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace YAML
|
||||
|
||||
@@ -55,6 +55,26 @@ TEST(LoadNodeTest, Binary) {
|
||||
node[1].as<Binary>());
|
||||
}
|
||||
|
||||
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<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),
|
||||
node["binaryText"].as<Binary>());
|
||||
}
|
||||
|
||||
TEST(LoadNodeTest, IterateSequence) {
|
||||
Node node = Load("[1, 3, 5, 7]");
|
||||
int seq[] = {1, 3, 5, 7};
|
||||
|
||||
@@ -22,5 +22,6 @@ class MockEventHandler : public EventHandler {
|
||||
MOCK_METHOD4(OnMapStart, void(const Mark&, const std::string&, anchor_t,
|
||||
EmitterStyle::value));
|
||||
MOCK_METHOD0(OnMapEnd, void());
|
||||
MOCK_METHOD2(OnAnchor, void(const Mark&, const std::string&));
|
||||
};
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
+90
-42
@@ -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<std::string>());
|
||||
EXPECT_EQ("c", node[1].as<std::string>());
|
||||
}
|
||||
|
||||
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<std::string>());
|
||||
EXPECT_EQ("b", node[1].as<std::string>());
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -349,7 +391,13 @@ TEST(NodeTest, AutoBoolConversion) {
|
||||
EXPECT_TRUE(!!node["foo"]);
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecision) {
|
||||
TEST(NodeTest, FloatingPrecisionFloat) {
|
||||
const float x = 0.123456789;
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<float>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionDouble) {
|
||||
const double x = 0.123456789;
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<double>());
|
||||
@@ -410,108 +458,108 @@ class NodeEmitterTest : public ::testing::Test {
|
||||
TEST_F(NodeEmitterTest, SimpleFlowSeqNode) {
|
||||
Node node;
|
||||
node.SetStyle(EmitterStyle::Flow);
|
||||
node.push_back(1.01);
|
||||
node.push_back(2.01);
|
||||
node.push_back(3.01);
|
||||
node.push_back(1.5);
|
||||
node.push_back(2.25);
|
||||
node.push_back(3.125);
|
||||
|
||||
ExpectOutput("[1.01, 2.01, 3.01]", node);
|
||||
ExpectOutput("[1.5, 2.25, 3.125]", node);
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, NestFlowSeqNode) {
|
||||
Node node, cell0, cell1;
|
||||
|
||||
cell0.push_back(1.01);
|
||||
cell0.push_back(2.01);
|
||||
cell0.push_back(3.01);
|
||||
cell0.push_back(1.5);
|
||||
cell0.push_back(2.25);
|
||||
cell0.push_back(3.125);
|
||||
|
||||
cell1.push_back(4.01);
|
||||
cell1.push_back(5.01);
|
||||
cell1.push_back(6.01);
|
||||
cell1.push_back(4.5);
|
||||
cell1.push_back(5.25);
|
||||
cell1.push_back(6.125);
|
||||
|
||||
node.SetStyle(EmitterStyle::Flow);
|
||||
node.push_back(cell0);
|
||||
node.push_back(cell1);
|
||||
|
||||
ExpectOutput("[[1.01, 2.01, 3.01], [4.01, 5.01, 6.01]]", node);
|
||||
ExpectOutput("[[1.5, 2.25, 3.125], [4.5, 5.25, 6.125]]", node);
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, MixBlockFlowSeqNode) {
|
||||
Node node, cell0, cell1;
|
||||
|
||||
cell0.SetStyle(EmitterStyle::Flow);
|
||||
cell0.push_back(1.01);
|
||||
cell0.push_back(2.01);
|
||||
cell0.push_back(3.01);
|
||||
cell0.push_back(1.5);
|
||||
cell0.push_back(2.25);
|
||||
cell0.push_back(3.125);
|
||||
|
||||
cell1.push_back(4.01);
|
||||
cell1.push_back(5.01);
|
||||
cell1.push_back(6.01);
|
||||
cell1.push_back(4.5);
|
||||
cell1.push_back(5.25);
|
||||
cell1.push_back(6.125);
|
||||
|
||||
node.SetStyle(EmitterStyle::Block);
|
||||
node.push_back(cell0);
|
||||
node.push_back(cell1);
|
||||
|
||||
ExpectOutput("- [1.01, 2.01, 3.01]\n-\n - 4.01\n - 5.01\n - 6.01", node);
|
||||
ExpectOutput("- [1.5, 2.25, 3.125]\n-\n - 4.5\n - 5.25\n - 6.125", node);
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, NestBlockFlowMapListNode) {
|
||||
Node node, mapNode, blockNode;
|
||||
|
||||
node.push_back(1.01);
|
||||
node.push_back(2.01);
|
||||
node.push_back(3.01);
|
||||
node.push_back(1.5);
|
||||
node.push_back(2.25);
|
||||
node.push_back(3.125);
|
||||
|
||||
mapNode.SetStyle(EmitterStyle::Flow);
|
||||
mapNode["position"] = node;
|
||||
|
||||
blockNode.push_back(1.01);
|
||||
blockNode.push_back(1.0625);
|
||||
blockNode.push_back(mapNode);
|
||||
|
||||
ExpectOutput("- 1.01\n- {position: [1.01, 2.01, 3.01]}", blockNode);
|
||||
ExpectOutput("- 1.0625\n- {position: [1.5, 2.25, 3.125]}", blockNode);
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, NestBlockMixMapListNode) {
|
||||
Node node, mapNode, blockNode;
|
||||
|
||||
node.push_back(1.01);
|
||||
node.push_back(2.01);
|
||||
node.push_back(3.01);
|
||||
node.push_back(1.5);
|
||||
node.push_back(2.25);
|
||||
node.push_back(3.125);
|
||||
|
||||
mapNode.SetStyle(EmitterStyle::Flow);
|
||||
mapNode["position"] = node;
|
||||
|
||||
blockNode["scalar"] = 1.01;
|
||||
blockNode["scalar"] = 1.0625;
|
||||
blockNode["object"] = mapNode;
|
||||
|
||||
ExpectAnyOutput(blockNode,
|
||||
"scalar: 1.01\nobject: {position: [1.01, 2.01, 3.01]}",
|
||||
"object: {position: [1.01, 2.01, 3.01]}\nscalar: 1.01");
|
||||
"scalar: 1.0625\nobject: {position: [1.5, 2.25, 3.125]}",
|
||||
"object: {position: [1.5, 2.25, 3.125]}\nscalar: 1.5");
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, NestBlockMapListNode) {
|
||||
Node node, mapNode;
|
||||
|
||||
node.push_back(1.01);
|
||||
node.push_back(2.01);
|
||||
node.push_back(3.01);
|
||||
node.push_back(1.5);
|
||||
node.push_back(2.25);
|
||||
node.push_back(3.125);
|
||||
|
||||
mapNode.SetStyle(EmitterStyle::Block);
|
||||
mapNode["position"] = node;
|
||||
|
||||
ExpectOutput("position:\n - 1.01\n - 2.01\n - 3.01", mapNode);
|
||||
ExpectOutput("position:\n - 1.5\n - 2.25\n - 3.125", mapNode);
|
||||
}
|
||||
|
||||
TEST_F(NodeEmitterTest, NestFlowMapListNode) {
|
||||
Node node, mapNode;
|
||||
|
||||
node.push_back(1.01);
|
||||
node.push_back(2.01);
|
||||
node.push_back(3.01);
|
||||
node.push_back(1.5);
|
||||
node.push_back(2.25);
|
||||
node.push_back(3.125);
|
||||
|
||||
mapNode.SetStyle(EmitterStyle::Flow);
|
||||
mapNode["position"] = node;
|
||||
|
||||
ExpectOutput("{position: [1.01, 2.01, 3.01]}", mapNode);
|
||||
ExpectOutput("{position: [1.5, 2.25, 3.125]}", mapNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "regex_yaml.h"
|
||||
#include "stream.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using YAML::RegEx;
|
||||
using YAML::Stream;
|
||||
@@ -106,8 +106,8 @@ TEST(RegExTest, OperatorOr) {
|
||||
for (int j = i + 1; j < 128; ++j) {
|
||||
auto iStr = std::string(1, char(i));
|
||||
auto jStr = std::string(1, char(j));
|
||||
RegEx ex1 = RegEx(iStr) || RegEx(jStr);
|
||||
RegEx ex2 = RegEx(jStr) || RegEx(iStr);
|
||||
RegEx ex1 = RegEx(iStr) | RegEx(jStr);
|
||||
RegEx ex2 = RegEx(jStr) | RegEx(iStr);
|
||||
|
||||
for (int k = MIN_CHAR; k < 128; ++k) {
|
||||
auto str = std::string(1, char(k));
|
||||
@@ -128,8 +128,8 @@ TEST(RegExTest, OperatorOr) {
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorOrShortCircuits) {
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) || RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) || RegEx(std::string("aaaa"));
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) | RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) | RegEx(std::string("aaaa"));
|
||||
|
||||
EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
|
||||
EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
|
||||
@@ -139,13 +139,13 @@ TEST(RegExTest, OperatorOrShortCircuits) {
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorAnd) {
|
||||
RegEx emptySet = RegEx('a') && RegEx();
|
||||
RegEx emptySet = RegEx('a') & RegEx();
|
||||
EXPECT_FALSE(emptySet.Matches(std::string("a")));
|
||||
}
|
||||
|
||||
TEST(RegExTest, OperatorAndShortCircuits) {
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) && RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) && RegEx(std::string("aaaa"));
|
||||
RegEx ex1 = RegEx(std::string("aaaa")) & RegEx(std::string("aa"));
|
||||
RegEx ex2 = RegEx(std::string("aa")) & RegEx(std::string("aaaa"));
|
||||
|
||||
EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
|
||||
EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
|
||||
@@ -174,4 +174,4 @@ TEST(RegExTest, StringOr) {
|
||||
|
||||
EXPECT_EQ(1, ex.Match(str));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
+15
-3
@@ -1,14 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
add_sources(parse.cpp)
|
||||
add_executable(parse parse.cpp)
|
||||
set_target_properties(parse PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
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)
|
||||
set_target_properties(sandbox PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
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)
|
||||
set_target_properties(read PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
target_link_libraries(read yaml-cpp)
|
||||
set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user