as the key is not always nul terminated, it'd be handy to use
a `std::string_view` when a key is expected.
before this change, we would have FTBFS if the key is a `string_view`
when looking up a node in a map:
```
/usr/include/yaml-cpp/node/detail/impl.h: In instantiation of ‘bool YAML::detail::node::equals(const T&, YAML::detail::shared_memory_holder) [with T = std::basic_string_view<char>; YAML::detail::shared_memory_holder = std::shared_ptr<YAML::detail::memory_holder>]’:
/usr/include/yaml-cpp/node/detail/impl.h:122:26: required from ‘YAML::detail::node* YAML::detail::node_data::get(const Key&, YAML::detail::shared_memory_holder) const [with Key = std::basic_string_view<char>; YAML::detail::shared_memory_holder = std::shared_ptr<YAML::detail::memory_holder>]’
/usr/include/yaml-cpp/node/detail/node_ref.h:64:55: required from ‘YAML::detail::node* YAML::detail::node_ref::get(const Key&, YAML::detail::shared_memory_holder) const [with Key = std::basic_string_view<char>; YAML::detail::shared_memory_holder = std::shared_ptr<YAML::detail::memory_holder>]’
/usr/include/yaml-cpp/node/detail/node.h:125:53: required from ‘YAML::detail::node* YAML::detail::node::get(const Key&, YAML::detail::shared_memory_holder) const [with Key = std::basic_string_view<char>; YAML::detail::shared_memory_holder = std::shared_ptr<YAML::detail::memory_holder>]’
/usr/include/yaml-cpp/node/impl.h:392:71: required from ‘const YAML::Node YAML::Node::operator[](const Key&) const [with Key = std::basic_string_view<char>]’
../../src/config/base_config.cc:20:23: required from here
/usr/include/yaml-cpp/node/detail/impl.h:93:25: error: incomplete type ‘YAML::convert<std::basic_string_view<char> >’ used in nested name specifier
93 | if (convert<T>::decode(Node(*this, pMemory), lhs)) {
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
```
after this change, a full specialization for `convert<std::string_view`
is added so that we can lookup a node using key of `std::string_view`, like
```c++
string_view key = "yet_another_key";
auto value = node[key];
```
tested with
```console
$ cmake -B build -D CMAKE_CXX_STANDARD=20 -D YAML_CPP_BUILD_TESTS=ON -G Ninja
$ cmake --build build yaml-cpp-tests
$ ctest --test-dir build --output-on-failure
```
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
* Test(CMake) set NAME and COMMAND in add_test
* (CMake) add enable_testing()
* (CMake) move cmake_dependent_option up, before using them
* (CMake) use YAML_CPP_MAIN_PROJECT in cmake_dependent_option
* (CMake) log values regarding tests
* (CMake) always find CTest, but don't enable tests
* (CMAKE)(temp) fix logging
* (actions) set YAML_CPP_BUILD_TESTS for tests
* (actions) provide YAML_CPP_BUILD_TESTS to ctest
* (actions) set -DYAML_CPP_BUILD_TESTS at build
* (actions) don't fail false
* (actions) build tests in Test step
* (actions) run tests verbose
* (CMake) remove temp logging
* (actions) split building from running tests
* (actions) ctest Debug
* (actions) ctest Debug
* Remove enable_testing
Add copying of shared library to the output directory with a test binary.
[binary] removed using of non unsigned char as argument at
'std::isspace' function that was provokes undefined behavior.
[.github/workflows/build.yml] enabled run of test at the
'windows-latest' environment.
For completeness I've implemented escaping for characters outside the
basic multilingual plane, but it doesn't get used (as there's no
EscapeAsAsciiJson emitter option implemented).
Inside of a sequence or map, `YAML::Newline` wouldn't reset the collection state, which would cause behavior like this:
```
nodeA:
k: [{i: 0},
{i:1},
]NodeB:
k: [{i: 0},
{i:1},
]
```
* partially fix clang compilation
Missing header and mistaken algorithm usage.
Also removed it name from range loops. It's not correct.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* run through clang's -Wrange-loop-analysis
Some range loops should not use references as they need to copy.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* manual range loop conversions
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Example of how someone might consume yaml-cpp with bazel:
cc_binary(
name = "example",
srcs = ["example.cc"],
deps = ["@com_github_jbeder_yaml_cpp//:yaml-cpp"],
)
Remove 2.6-isms
Remove 2.8-isms
Bump CMake minimum version to 3.4
Disable some options when used as a subdirectory
Use `CONFIGURE_DEPENDS` with `file(GLOB)` when possible
Backport CMake 3.15's MSVC_RUNTIME_LIBRARY setting.
Set all compile options as generator expressions.
Set all find-package files to be installed to the correct file.
Remove `export(PACKAGE)`, as this has been deprecated.
Remove fat binary support
Remove manual setting of iPhone settings. These should be set by parent
projects.
Remove use of ExternalProject for a local use
Conditionally remove format target unless clang-format is found
Setting CMAKE_CXX_STANDARD and CMAKE_CXX_STANDARD_REQUIRED directly is problematic when including yaml-cpp as a subproject.
The proper way is to set these per-target.
Invalid access via operator[] or as<> will now print the offending key, if possible.
For example:
a:
x: 1
y: 2
node["a"]["z"].as<int>()
will say that the key "z" was invalid.
* Add compilation flags: -Wshadow -Weffc++ -pedantic -pedantic-errors
* Delete implicit copy & move constructors & assignment operators
in classes with pointer data members.
* An exception to the above: Add default copy & move constructors &
assignment operators for the Binary class.
* Convert boolean RegEx operators to binary operators.
* Initialize all members in all classes in ctors.
* Let default ctor delegate to the converting ctor in
Binary and RegEx
* Don't change any tests except regex_test (as a result of the change
to binary operators).
Note: https://bugzilla.redhat.com/show_bug.cgi?id=1544675 makes
-Weffc++ report a false positive in "include/yaml-cpp/node/impl.h".