diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index f141133f..fd69d8c3 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -52,32 +52,6 @@ jobs: working-directory: ${{github.workspace}}/build run: ctest -C ${{matrix.build_type}} --output-on-failure -j ${{env.JOBS}} - xcode_for_macos11: - timeout-minutes: 10 - runs-on: macos-11 - strategy: - matrix: - xcode: [ '11.7', '12.4', '12.5.1', '13.0', '13.1', '13.2.1' ] - build_type: [ Debug, Release ] - env: - DEVELOPER_DIR: /Applications/Xcode_${{matrix.xcode}}.app/Contents/Developer - JOBS: 2 - - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DFK_YAML_BUILD_TEST=ON - - - name: Build - run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -j ${{env.JOBS}} - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest -C ${{matrix.build_type}} --output-on-failure -j ${{env.JOBS}} - xcode_for_macos12: timeout-minutes: 10 runs-on: macos-12 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 44a7a0f9..0702a9d7 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -269,3 +269,32 @@ jobs: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -j ${{env.JOBS}} cd ${{github.workspace}}/build ctest -C ${{matrix.build_type}} --output-on-failure -j ${{env.JOBS}} + + ci_test_icpx: + runs-on: ubuntu-latest + strategy: + matrix: + build_type: [ Debug, Release ] + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Intel oneAPI Base Toolkit + run: | # from the official document: https://www.intel.com/content/www/us/en/docs/oneapi/installation-guide-linux/2024-1/apt.html + wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null + echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list + sudo apt-get update + sudo apt-get install -y intel-basekit + + - name: Configure CMake + run: | + source /opt/intel/oneapi/setvars.sh + cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DFK_YAML_BUILD_TEST=ON + + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -j ${{env.JOBS}} + + - name: Test + run: ctest --test-dir ${{github.workspace}}/build -C ${{matrix.build_type}} --output-on-failure -j ${{env.JOBS}} diff --git a/.reuse/dep5 b/.reuse/dep5 deleted file mode 100644 index 2e54326c..00000000 --- a/.reuse/dep5 +++ /dev/null @@ -1,17 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: fkYAML -Upstream-Contact: Kensuke Fukutani -Source: https://github.com/fktn-k/fkYAML - -Files: * -Copyright: 2023 Kensuke Fukutani -License: MIT - -Files: thirdparty/imapdl/* -Copyright: 2017 Georg Sauthoff - 2022, Alexander Stohr, ZF Friedrichshafen AG -License: GPL-3.0-only - -Files: tool/amalgamation/* -Copyright: 2012 Erik Edlund -License: BSD-3-Clause diff --git a/.reuse/templates/fkYAML.commented.jinja2 b/.reuse/templates/fkYAML.commented.jinja2 index eb5d5a9a..d65ce0d3 100644 --- a/.reuse/templates/fkYAML.commented.jinja2 +++ b/.reuse/templates/fkYAML.commented.jinja2 @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// {% for copyright_line in copyright_lines %} diff --git a/.reuse/templates/fkYAML_support.jinja2 b/.reuse/templates/fkYAML_support.jinja2 index eeef04fe..a63371db 100644 --- a/.reuse/templates/fkYAML_support.jinja2 +++ b/.reuse/templates/fkYAML_support.jinja2 @@ -1,6 +1,6 @@ _______ __ __ __ _____ __ __ __ | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -| __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +| __| _ < \_ _/| ___ | _ | |___ version 0.3.10 |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML {% for copyright_line in copyright_lines %} diff --git a/CHANGELOG.md b/CHANGELOG.md index b24a7352..7321c772 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [v0.3.10](https://github.com/fktn-k/fkYAML/releases/tag/v0.3.10) (2024-08-18) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.3.9...v0.3.10) + +- \#366 Fix node-to-float conversion error if node's value is \<= 0 [\#371](https://github.com/fktn-k/fkYAML/pull/371) ([fktn-k](https://github.com/fktn-k)) +- Apply node properties for the root node [\#370](https://github.com/fktn-k/fkYAML/pull/370) ([fktn-k](https://github.com/fktn-k)) +- \#368 Fix line advancement after node props [\#369](https://github.com/fktn-k/fkYAML/pull/369) ([fktn-k](https://github.com/fktn-k)) +- Allow trailing comma in flow mapping/sequence [\#365](https://github.com/fktn-k/fkYAML/pull/365) ([fktn-k](https://github.com/fktn-k)) +- Fix bug in serializing alias keys [\#364](https://github.com/fktn-k/fkYAML/pull/364) ([fktn-k](https://github.com/fktn-k)) +- Detect missing the end of directives markers \(---\) [\#361](https://github.com/fktn-k/fkYAML/pull/361) ([fktn-k](https://github.com/fktn-k)) + +- update configs for reuse v4 [\#372](https://github.com/fktn-k/fkYAML/pull/372) ([fktn-k](https://github.com/fktn-k)) +- Remove CI jobs running with macOS 11 [\#367](https://github.com/fktn-k/fkYAML/pull/367) ([fktn-k](https://github.com/fktn-k)) +- Support serializing multiple YAML docs [\#363](https://github.com/fktn-k/fkYAML/pull/363) ([fktn-k](https://github.com/fktn-k)) +- Support parssing multiple YAML documents [\#362](https://github.com/fktn-k/fkYAML/pull/362) ([fktn-k](https://github.com/fktn-k)) +- Support Intel icpx compiler [\#360](https://github.com/fktn-k/fkYAML/pull/360) ([fktn-k](https://github.com/fktn-k)) + ## [v0.3.9](https://github.com/fktn-k/fkYAML/releases/tag/v0.3.9) (2024-06-12) [Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.3.8...v0.3.9) diff --git a/CMakeLists.txt b/CMakeLists.txt index 415395be..860f0db7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.8) project( fkYAML - VERSION 0.3.9 + VERSION 0.3.10 LANGUAGES CXX) ############################################################# diff --git a/Makefile b/Makefile index 7fd4fb65..3a545de6 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TOOL_SRCS = $(shell find tool -type f -name '*.cpp' | sort) # target version definition TARGET_MAJOR_VERSION := 0 TARGET_MINOR_VERSION := 3 -TARGET_PATCH_VERSION := 9 +TARGET_PATCH_VERSION := 10 TARGET_VERSION_FULL := $(TARGET_MAJOR_VERSION).$(TARGET_MINOR_VERSION).$(TARGET_PATCH_VERSION) VERSION_MACRO_FILE := include/fkYAML/detail/macros/version_macros.hpp @@ -126,14 +126,14 @@ update-version-macros: update-project-version: $(shell sed -i 's/VERSION [0-9]\+\.[0-9]\+\.[0-9]\+/VERSION $(TARGET_VERSION_FULL)/' CMakeLists.txt) -# pre-requisites: pipx, reuse +# pre-requisites: pipx, reuse(>=v4.0.0, confirmed with v4.0.3) reuse: update-reuse-templates pipx run reuse annotate $(SRCS) --template fkYAML \ --copyright "Kensuke Fukutani " --copyright-style spdx \ - --license MIT --year "2023-2024" --style c + --license MIT --year "2023-2024" --style cppsingle pipx run reuse annotate $(TEST_SRCS) $(EXAMPLE_SRCS) $(TOOL_SRCS) --template fkYAML_support \ --copyright "Kensuke Fukutani " --copyright-style spdx \ - --license MIT --year "2023-2024" --style c + --license MIT --year "2023-2024" --style cppsingle pipx run reuse lint update-sources: reuse update-version-macros diff --git a/README.md b/README.md index 168d6b2b..612e4ff9 100644 --- a/README.md +++ b/README.md @@ -106,10 +106,6 @@ Currently, the following compilers are known to work and used in GitHub Actions | Compiler | Operating System | | -------------------------- | -------------------------------------------------------------------------------------------------------------- | -| AppleClang 11.0.3.11030032 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 12.0.0.12000032 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 12.0.5.12050022 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 13.0.0.13000029 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | | AppleClang 13.0.0.13000029 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | | AppleClang 13.1.6.13160021 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | | AppleClang 14.0.0.14000029 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | @@ -148,6 +144,7 @@ Currently, the following compilers are known to work and used in GitHub Actions | GCC 12.3.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | GCC 13.3.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | GCC 14.1.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | +| IntelLLVM 2024.1.2 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | MinGW-64 8.1.0 | [Windows Server 2019](https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md) | | MinGW-64 12.2.0 | [Windows Server 2022](https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md) | | Visual Studio 16 2019 | [Windows Server 2019](https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md) | diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 00000000..c8d72e59 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,22 @@ +version = 1 +SPDX-PackageName = "fkYAML" +SPDX-PackageSupplier = "Kensuke Fukutani " +SPDX-PackageDownloadLocation = "https://github.com/fktn-k/fkYAML" + +[[annotations]] +path = "**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2023 Kensuke Fukutani " +SPDX-License-Identifier = "MIT" + +[[annotations]] +path = "thirdparty/imapdl/**" +precedence = "aggregate" +SPDX-FileCopyrightText = ["2017 Georg Sauthoff ", "2022, Alexander Stohr, ZF Friedrichshafen AG"] +SPDX-License-Identifier = "GPL-3.0-only" + +[[annotations]] +path = "tool/amalgamation/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2012 Erik Edlund " +SPDX-License-Identifier = "BSD-3-Clause" diff --git a/docs/examples/CMakeLists.txt b/docs/examples/CMakeLists.txt index 668c80d2..72042c2e 100644 --- a/docs/examples/CMakeLists.txt +++ b/docs/examples/CMakeLists.txt @@ -50,6 +50,7 @@ foreach(EX_SRC_FILE ${EX_SRC_FILES}) TARGET ${EX_SRC_FILE_BASE} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/input.yaml $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/input_multi.yaml $ COMMAND $ > ${CMAKE_CURRENT_SOURCE_DIR}/${EX_SRC_FILE_BASE}.output ) endforeach() diff --git a/docs/examples/ex_basic_node_add_anchor_name.cpp b/docs/examples/ex_basic_node_add_anchor_name.cpp index b1d49249..15f9b622 100644 --- a/docs/examples/ex_basic_node_add_anchor_name.cpp +++ b/docs/examples/ex_basic_node_add_anchor_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_add_tag_name.cpp b/docs/examples/ex_basic_node_add_tag_name.cpp index 214bdbf8..3d11d56e 100644 --- a/docs/examples/ex_basic_node_add_tag_name.cpp +++ b/docs/examples/ex_basic_node_add_tag_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_alias_of.cpp b/docs/examples/ex_basic_node_alias_of.cpp index 81544e0f..e081d9e4 100644 --- a/docs/examples/ex_basic_node_alias_of.cpp +++ b/docs/examples/ex_basic_node_alias_of.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_at_basic_node.cpp b/docs/examples/ex_basic_node_at_basic_node.cpp index 1ed0c486..5fb7070e 100644 --- a/docs/examples/ex_basic_node_at_basic_node.cpp +++ b/docs/examples/ex_basic_node_at_basic_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_at_compatible_type.cpp b/docs/examples/ex_basic_node_at_compatible_type.cpp index 3b964725..69f115b1 100644 --- a/docs/examples/ex_basic_node_at_compatible_type.cpp +++ b/docs/examples/ex_basic_node_at_compatible_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_begin.cpp b/docs/examples/ex_basic_node_begin.cpp index bd4ec1d8..5cb4c4e2 100644 --- a/docs/examples/ex_basic_node_begin.cpp +++ b/docs/examples/ex_basic_node_begin.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_boolean_type.cpp b/docs/examples/ex_basic_node_boolean_type.cpp index 9cabb055..fcbe5fd2 100644 --- a/docs/examples/ex_basic_node_boolean_type.cpp +++ b/docs/examples/ex_basic_node_boolean_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_const_iterator.cpp b/docs/examples/ex_basic_node_const_iterator.cpp index dd8261de..68a4771a 100644 --- a/docs/examples/ex_basic_node_const_iterator.cpp +++ b/docs/examples/ex_basic_node_const_iterator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_1.cpp b/docs/examples/ex_basic_node_constructor_1.cpp index 46626b0f..42dfe9d4 100644 --- a/docs/examples/ex_basic_node_constructor_1.cpp +++ b/docs/examples/ex_basic_node_constructor_1.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_2.cpp b/docs/examples/ex_basic_node_constructor_2.cpp index 8b9e3827..6691a742 100644 --- a/docs/examples/ex_basic_node_constructor_2.cpp +++ b/docs/examples/ex_basic_node_constructor_2.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_3.cpp b/docs/examples/ex_basic_node_constructor_3.cpp index 13fd2554..bd651963 100644 --- a/docs/examples/ex_basic_node_constructor_3.cpp +++ b/docs/examples/ex_basic_node_constructor_3.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_4.cpp b/docs/examples/ex_basic_node_constructor_4.cpp index 13fd2554..bd651963 100644 --- a/docs/examples/ex_basic_node_constructor_4.cpp +++ b/docs/examples/ex_basic_node_constructor_4.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_5.cpp b/docs/examples/ex_basic_node_constructor_5.cpp index 48818c4b..03dfed50 100644 --- a/docs/examples/ex_basic_node_constructor_5.cpp +++ b/docs/examples/ex_basic_node_constructor_5.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_6.cpp b/docs/examples/ex_basic_node_constructor_6.cpp index f06bf97e..31fb3a1a 100644 --- a/docs/examples/ex_basic_node_constructor_6.cpp +++ b/docs/examples/ex_basic_node_constructor_6.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_constructor_7.cpp b/docs/examples/ex_basic_node_constructor_7.cpp index 472ef659..63b3305c 100644 --- a/docs/examples/ex_basic_node_constructor_7.cpp +++ b/docs/examples/ex_basic_node_constructor_7.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_contains.cpp b/docs/examples/ex_basic_node_contains.cpp index 7857aa0a..8b2a3fa9 100644 --- a/docs/examples/ex_basic_node_contains.cpp +++ b/docs/examples/ex_basic_node_contains.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_copy_assignment_operator.cpp b/docs/examples/ex_basic_node_copy_assignment_operator.cpp index daeb1d50..72658f73 100644 --- a/docs/examples/ex_basic_node_copy_assignment_operator.cpp +++ b/docs/examples/ex_basic_node_copy_assignment_operator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_deserialize_char_array.cpp b/docs/examples/ex_basic_node_deserialize_char_array.cpp index 7d6ee72d..6cd732d6 100644 --- a/docs/examples/ex_basic_node_deserialize_char_array.cpp +++ b/docs/examples/ex_basic_node_deserialize_char_array.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_deserialize_docs_char_array.cpp b/docs/examples/ex_basic_node_deserialize_docs_char_array.cpp new file mode 100644 index 00000000..d7228d64 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_char_array.cpp @@ -0,0 +1,43 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include + +int main() { + // deserialize a YAML string. + char input[] = R"( + %YAML 1.2 + --- + foo: true + bar: 123 + baz: 3.14 + ... + %TAG ! tag:test.com,2000: + --- + null: one + false: 456 + TRUE: 1.414 + )"; + std::vector docs = fkyaml::node::deserialize_docs(input); + + // check the deserialization result. + std::cout << docs[0]["foo"].get_value() << std::endl; + std::cout << docs[0]["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << docs[0]["baz"].get_value() << std::endl; + + std::cout << std::endl; + + std::cout << docs[1][nullptr].get_value_ref() << std::endl; + std::cout << docs[1][false].get_value() << std::endl; + std::cout << std::setprecision(4) << docs[1][true].get_value() << std::endl; + + return 0; +} diff --git a/docs/examples/ex_basic_node_deserialize_docs_char_array.output b/docs/examples/ex_basic_node_deserialize_docs_char_array.output new file mode 100644 index 00000000..ec6ba187 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_char_array.output @@ -0,0 +1,7 @@ +1 +123 +3.14 + +one +456 +1.414 diff --git a/docs/examples/ex_basic_node_deserialize_docs_file_pointer.cpp b/docs/examples/ex_basic_node_deserialize_docs_file_pointer.cpp new file mode 100644 index 00000000..3f765fb7 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_file_pointer.cpp @@ -0,0 +1,38 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include +#include + +int main() { + // deserialize a YAML string. + FILE* p_file = std::fopen("input_multi.yaml", "r"); + if (!p_file) { + // You must not pass a null FILE pointer. + return -1; + } + std::vector docs = fkyaml::node::deserialize_docs(p_file); + + std::fclose(p_file); + + // check the deserialization result. + std::cout << docs[0]["foo"].get_value() << std::endl; + std::cout << docs[0]["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << docs[0]["baz"].get_value() << std::endl; + + std::cout << std::endl; + + std::cout << docs[1][nullptr].get_value_ref() << std::endl; + std::cout << docs[1][false].get_value() << std::endl; + std::cout << std::setprecision(4) << docs[1][true].get_value() << std::endl; + + return 0; +} diff --git a/docs/examples/ex_basic_node_deserialize_docs_file_pointer.output b/docs/examples/ex_basic_node_deserialize_docs_file_pointer.output new file mode 100644 index 00000000..ec6ba187 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_file_pointer.output @@ -0,0 +1,7 @@ +1 +123 +3.14 + +one +456 +1.414 diff --git a/docs/examples/ex_basic_node_deserialize_docs_iterators.cpp b/docs/examples/ex_basic_node_deserialize_docs_iterators.cpp new file mode 100644 index 00000000..6f076fc0 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_iterators.cpp @@ -0,0 +1,45 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include +#include +#include + +int main() { + // deserialize a YAML string. + char input[] = R"( + %YAML 1.2 + --- + foo: true + bar: 123 + baz: 3.14 + ... + %TAG ! tag:test.com,2000: + --- + null: one + false: 456 + TRUE: 1.414 + )"; + std::vector docs = fkyaml::node::deserialize_docs(std::begin(input), std::end(input)); + + // check the deserialization result. + std::cout << docs[0]["foo"].get_value() << std::endl; + std::cout << docs[0]["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << docs[0]["baz"].get_value() << std::endl; + + std::cout << std::endl; + + std::cout << docs[1][nullptr].get_value_ref() << std::endl; + std::cout << docs[1][false].get_value() << std::endl; + std::cout << std::setprecision(4) << docs[1][true].get_value() << std::endl; + + return 0; +} diff --git a/docs/examples/ex_basic_node_deserialize_docs_iterators.output b/docs/examples/ex_basic_node_deserialize_docs_iterators.output new file mode 100644 index 00000000..ec6ba187 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_iterators.output @@ -0,0 +1,7 @@ +1 +123 +3.14 + +one +456 +1.414 diff --git a/docs/examples/ex_basic_node_deserialize_docs_string.cpp b/docs/examples/ex_basic_node_deserialize_docs_string.cpp new file mode 100644 index 00000000..00f1e1f4 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_string.cpp @@ -0,0 +1,44 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include +#include + +int main() { + // deserialize a YAML string. + std::string s = R"( + %YAML 1.2 + --- + foo: true + bar: 123 + baz: 3.14 + ... + %TAG ! tag:test.com,2000: + --- + null: one + false: 456 + TRUE: 1.414 + )"; + std::vector docs = fkyaml::node::deserialize_docs(s); + + // check the deserialization result. + std::cout << docs[0]["foo"].get_value() << std::endl; + std::cout << docs[0]["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << docs[0]["baz"].get_value() << std::endl; + + std::cout << std::endl; + + std::cout << docs[1][nullptr].get_value_ref() << std::endl; + std::cout << docs[1][false].get_value() << std::endl; + std::cout << std::setprecision(4) << docs[1][true].get_value() << std::endl; + + return 0; +} diff --git a/docs/examples/ex_basic_node_deserialize_docs_string.output b/docs/examples/ex_basic_node_deserialize_docs_string.output new file mode 100644 index 00000000..ec6ba187 --- /dev/null +++ b/docs/examples/ex_basic_node_deserialize_docs_string.output @@ -0,0 +1,7 @@ +1 +123 +3.14 + +one +456 +1.414 diff --git a/docs/examples/ex_basic_node_deserialize_file_pointer.cpp b/docs/examples/ex_basic_node_deserialize_file_pointer.cpp index 1790a254..e010244c 100644 --- a/docs/examples/ex_basic_node_deserialize_file_pointer.cpp +++ b/docs/examples/ex_basic_node_deserialize_file_pointer.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -21,6 +21,8 @@ int main() { } fkyaml::node n = fkyaml::node::deserialize(p_file); + std::fclose(p_file); + // check the deserialization result. std::cout << n["foo"].get_value() << std::endl; std::cout << n["bar"].get_value() << std::endl; diff --git a/docs/examples/ex_basic_node_deserialize_iterators.cpp b/docs/examples/ex_basic_node_deserialize_iterators.cpp index f3bd62e7..231c4bca 100644 --- a/docs/examples/ex_basic_node_deserialize_iterators.cpp +++ b/docs/examples/ex_basic_node_deserialize_iterators.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_deserialize_string.cpp b/docs/examples/ex_basic_node_deserialize_string.cpp index c7ad27ea..ae7e5e38 100644 --- a/docs/examples/ex_basic_node_deserialize_string.cpp +++ b/docs/examples/ex_basic_node_deserialize_string.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_empty.cpp b/docs/examples/ex_basic_node_empty.cpp index cd99a0e4..f3437e7f 100644 --- a/docs/examples/ex_basic_node_empty.cpp +++ b/docs/examples/ex_basic_node_empty.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_end.cpp b/docs/examples/ex_basic_node_end.cpp index ae4a5e4b..a05f59a3 100644 --- a/docs/examples/ex_basic_node_end.cpp +++ b/docs/examples/ex_basic_node_end.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_extraction_operator.cpp b/docs/examples/ex_basic_node_extraction_operator.cpp index 96a56a96..06635d07 100644 --- a/docs/examples/ex_basic_node_extraction_operator.cpp +++ b/docs/examples/ex_basic_node_extraction_operator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_float_number_type.cpp b/docs/examples/ex_basic_node_float_number_type.cpp index fd6f0c7e..d341a0f0 100644 --- a/docs/examples/ex_basic_node_float_number_type.cpp +++ b/docs/examples/ex_basic_node_float_number_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_get_anchor_name.cpp b/docs/examples/ex_basic_node_get_anchor_name.cpp index f6a5fadc..bd0423b6 100644 --- a/docs/examples/ex_basic_node_get_anchor_name.cpp +++ b/docs/examples/ex_basic_node_get_anchor_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_get_tag_name.cpp b/docs/examples/ex_basic_node_get_tag_name.cpp index bd5644cb..2d316350 100644 --- a/docs/examples/ex_basic_node_get_tag_name.cpp +++ b/docs/examples/ex_basic_node_get_tag_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_get_value.cpp b/docs/examples/ex_basic_node_get_value.cpp index 055a41fb..fbfd75bb 100644 --- a/docs/examples/ex_basic_node_get_value.cpp +++ b/docs/examples/ex_basic_node_get_value.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_get_value_ref.cpp b/docs/examples/ex_basic_node_get_value_ref.cpp index b09a8bef..c5c29d60 100644 --- a/docs/examples/ex_basic_node_get_value_ref.cpp +++ b/docs/examples/ex_basic_node_get_value_ref.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_get_yaml_version.cpp b/docs/examples/ex_basic_node_get_yaml_version.cpp index 0385c4c6..40a9d1c6 100644 --- a/docs/examples/ex_basic_node_get_yaml_version.cpp +++ b/docs/examples/ex_basic_node_get_yaml_version.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_has_anchor_name.cpp b/docs/examples/ex_basic_node_has_anchor_name.cpp index ef27ee67..ca8614fc 100644 --- a/docs/examples/ex_basic_node_has_anchor_name.cpp +++ b/docs/examples/ex_basic_node_has_anchor_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_has_tag_name.cpp b/docs/examples/ex_basic_node_has_tag_name.cpp index 9c541625..24daec7f 100644 --- a/docs/examples/ex_basic_node_has_tag_name.cpp +++ b/docs/examples/ex_basic_node_has_tag_name.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_insertion_operator.cpp b/docs/examples/ex_basic_node_insertion_operator.cpp index 7181018a..00e9610f 100644 --- a/docs/examples/ex_basic_node_insertion_operator.cpp +++ b/docs/examples/ex_basic_node_insertion_operator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_integer_type.cpp b/docs/examples/ex_basic_node_integer_type.cpp index 9303a1a9..199e60a6 100644 --- a/docs/examples/ex_basic_node_integer_type.cpp +++ b/docs/examples/ex_basic_node_integer_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_alias.cpp b/docs/examples/ex_basic_node_is_alias.cpp index e7b8e650..64e97382 100644 --- a/docs/examples/ex_basic_node_is_alias.cpp +++ b/docs/examples/ex_basic_node_is_alias.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_anchor.cpp b/docs/examples/ex_basic_node_is_anchor.cpp index 800f33f4..30720253 100644 --- a/docs/examples/ex_basic_node_is_anchor.cpp +++ b/docs/examples/ex_basic_node_is_anchor.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_boolean.cpp b/docs/examples/ex_basic_node_is_boolean.cpp index 98fc11a1..460b0592 100644 --- a/docs/examples/ex_basic_node_is_boolean.cpp +++ b/docs/examples/ex_basic_node_is_boolean.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_float_number.cpp b/docs/examples/ex_basic_node_is_float_number.cpp index 08d91562..ef762602 100644 --- a/docs/examples/ex_basic_node_is_float_number.cpp +++ b/docs/examples/ex_basic_node_is_float_number.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_integer.cpp b/docs/examples/ex_basic_node_is_integer.cpp index f428ca5e..7394972b 100644 --- a/docs/examples/ex_basic_node_is_integer.cpp +++ b/docs/examples/ex_basic_node_is_integer.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_mapping.cpp b/docs/examples/ex_basic_node_is_mapping.cpp index e4f23fc0..334a3d8b 100644 --- a/docs/examples/ex_basic_node_is_mapping.cpp +++ b/docs/examples/ex_basic_node_is_mapping.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_null.cpp b/docs/examples/ex_basic_node_is_null.cpp index 7e20b803..7aeddf41 100644 --- a/docs/examples/ex_basic_node_is_null.cpp +++ b/docs/examples/ex_basic_node_is_null.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_scalar.cpp b/docs/examples/ex_basic_node_is_scalar.cpp index 27aeab81..107653e4 100644 --- a/docs/examples/ex_basic_node_is_scalar.cpp +++ b/docs/examples/ex_basic_node_is_scalar.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_sequence.cpp b/docs/examples/ex_basic_node_is_sequence.cpp index 33d334d8..5319d4df 100644 --- a/docs/examples/ex_basic_node_is_sequence.cpp +++ b/docs/examples/ex_basic_node_is_sequence.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_is_string.cpp b/docs/examples/ex_basic_node_is_string.cpp index 6e23a92e..7a5416ac 100644 --- a/docs/examples/ex_basic_node_is_string.cpp +++ b/docs/examples/ex_basic_node_is_string.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_iterator.cpp b/docs/examples/ex_basic_node_iterator.cpp index 771efc2f..03652468 100644 --- a/docs/examples/ex_basic_node_iterator.cpp +++ b/docs/examples/ex_basic_node_iterator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_mapping.cpp b/docs/examples/ex_basic_node_mapping.cpp index 37301370..be2b5ba0 100644 --- a/docs/examples/ex_basic_node_mapping.cpp +++ b/docs/examples/ex_basic_node_mapping.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_mapping_type.cpp b/docs/examples/ex_basic_node_mapping_type.cpp index 2ab619a5..f7535d6b 100644 --- a/docs/examples/ex_basic_node_mapping_type.cpp +++ b/docs/examples/ex_basic_node_mapping_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_node.cpp b/docs/examples/ex_basic_node_node.cpp index b545e7ca..94649a57 100644 --- a/docs/examples/ex_basic_node_node.cpp +++ b/docs/examples/ex_basic_node_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_node_t.cpp b/docs/examples/ex_basic_node_node_t.cpp index 10b25112..595af0ee 100644 --- a/docs/examples/ex_basic_node_node_t.cpp +++ b/docs/examples/ex_basic_node_node_t.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_eq.cpp b/docs/examples/ex_basic_node_operator_eq.cpp index fd965218..08f44ac8 100644 --- a/docs/examples/ex_basic_node_operator_eq.cpp +++ b/docs/examples/ex_basic_node_operator_eq.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_ge.cpp b/docs/examples/ex_basic_node_operator_ge.cpp index 55284ce8..d5fed415 100644 --- a/docs/examples/ex_basic_node_operator_ge.cpp +++ b/docs/examples/ex_basic_node_operator_ge.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_gt.cpp b/docs/examples/ex_basic_node_operator_gt.cpp index 4d281a66..1e809ae9 100644 --- a/docs/examples/ex_basic_node_operator_gt.cpp +++ b/docs/examples/ex_basic_node_operator_gt.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_le.cpp b/docs/examples/ex_basic_node_operator_le.cpp index 10c443d9..33b1b54e 100644 --- a/docs/examples/ex_basic_node_operator_le.cpp +++ b/docs/examples/ex_basic_node_operator_le.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_lt.cpp b/docs/examples/ex_basic_node_operator_lt.cpp index 85b1b0ad..beb3a66e 100644 --- a/docs/examples/ex_basic_node_operator_lt.cpp +++ b/docs/examples/ex_basic_node_operator_lt.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_operator_ne.cpp b/docs/examples/ex_basic_node_operator_ne.cpp index 360b0f25..9833e3f6 100644 --- a/docs/examples/ex_basic_node_operator_ne.cpp +++ b/docs/examples/ex_basic_node_operator_ne.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_sequence.cpp b/docs/examples/ex_basic_node_sequence.cpp index 74c886c9..bed1adce 100644 --- a/docs/examples/ex_basic_node_sequence.cpp +++ b/docs/examples/ex_basic_node_sequence.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_sequence_type.cpp b/docs/examples/ex_basic_node_sequence_type.cpp index 71e71461..deab3598 100644 --- a/docs/examples/ex_basic_node_sequence_type.cpp +++ b/docs/examples/ex_basic_node_sequence_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_serialize.cpp b/docs/examples/ex_basic_node_serialize.cpp index 452562fc..aabd7704 100644 --- a/docs/examples/ex_basic_node_serialize.cpp +++ b/docs/examples/ex_basic_node_serialize.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_serialize_docs.cpp b/docs/examples/ex_basic_node_serialize_docs.cpp new file mode 100644 index 00000000..da887bde --- /dev/null +++ b/docs/examples/ex_basic_node_serialize_docs.cpp @@ -0,0 +1,33 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include + +int main() { + // create a basic_node object. + fkyaml::node n1 = { + {"foo", true}, + {"bar", {1, 2, 3}}, + {"baz", {{"qux", 3.14}, {"corge", nullptr}}}, + {{{true, 123}}, false}, + {{1.23, 4.56, 7.89}, 123456789}}; + // set tags to some nodes. + n1["foo"].add_tag_name("!!bool"); + n1["bar"][1].add_tag_name("!"); + // set an anchor name to a node. + n1["baz"].add_anchor_name("anchor"); + + // create another one. + fkyaml::node n2 = {"foo", 123, true}; + + // serialize the basic_node objects into a string. + std::cout << fkyaml::node::serialize_docs({n1, n2}) << std::endl; + + return 0; +} diff --git a/docs/examples/ex_basic_node_serialize_docs.output b/docs/examples/ex_basic_node_serialize_docs.output new file mode 100644 index 00000000..187c9994 --- /dev/null +++ b/docs/examples/ex_basic_node_serialize_docs.output @@ -0,0 +1,19 @@ +? - 1.23 + - 4.56 + - 7.89 +: 123456789 +? true: 123 +: false +bar: + - 1 + - ! 2 + - 3 +baz: &anchor + corge: null + qux: 3.14 +foo: !!bool true +... +- foo +- 123 +- true + diff --git a/docs/examples/ex_basic_node_set_yaml_version.cpp b/docs/examples/ex_basic_node_set_yaml_version.cpp index 4c0e2b17..2382caf4 100644 --- a/docs/examples/ex_basic_node_set_yaml_version.cpp +++ b/docs/examples/ex_basic_node_set_yaml_version.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_size.cpp b/docs/examples/ex_basic_node_size.cpp index 48462f2e..caab8f87 100644 --- a/docs/examples/ex_basic_node_size.cpp +++ b/docs/examples/ex_basic_node_size.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_string_type.cpp b/docs/examples/ex_basic_node_string_type.cpp index 6c05136b..ab6c3a53 100644 --- a/docs/examples/ex_basic_node_string_type.cpp +++ b/docs/examples/ex_basic_node_string_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_subscript_operator_basic_node.cpp b/docs/examples/ex_basic_node_subscript_operator_basic_node.cpp index 031dc9f5..6906ce53 100644 --- a/docs/examples/ex_basic_node_subscript_operator_basic_node.cpp +++ b/docs/examples/ex_basic_node_subscript_operator_basic_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_subscript_operator_compatible_type.cpp b/docs/examples/ex_basic_node_subscript_operator_compatible_type.cpp index b7456781..3593f1c4 100644 --- a/docs/examples/ex_basic_node_subscript_operator_compatible_type.cpp +++ b/docs/examples/ex_basic_node_subscript_operator_compatible_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_swap_member.cpp b/docs/examples/ex_basic_node_swap_member.cpp index 549db87f..21844383 100644 --- a/docs/examples/ex_basic_node_swap_member.cpp +++ b/docs/examples/ex_basic_node_swap_member.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_swap_std.cpp b/docs/examples/ex_basic_node_swap_std.cpp index 202ae284..95edfa7d 100644 --- a/docs/examples/ex_basic_node_swap_std.cpp +++ b/docs/examples/ex_basic_node_swap_std.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_type.cpp b/docs/examples/ex_basic_node_type.cpp index 10b25112..595af0ee 100644 --- a/docs/examples/ex_basic_node_type.cpp +++ b/docs/examples/ex_basic_node_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_value_converter_type.cpp b/docs/examples/ex_basic_node_value_converter_type.cpp index b86754dc..f537869d 100644 --- a/docs/examples/ex_basic_node_value_converter_type.cpp +++ b/docs/examples/ex_basic_node_value_converter_type.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_basic_node_yaml_version_t.cpp b/docs/examples/ex_basic_node_yaml_version_t.cpp index 3680ed63..99330ae5 100644 --- a/docs/examples/ex_basic_node_yaml_version_t.cpp +++ b/docs/examples/ex_basic_node_yaml_version_t.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_exception_constructor_msg.cpp b/docs/examples/ex_exception_constructor_msg.cpp index a46e68b5..116efc6e 100644 --- a/docs/examples/ex_exception_constructor_msg.cpp +++ b/docs/examples/ex_exception_constructor_msg.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_exception_constructor_noarg.cpp b/docs/examples/ex_exception_constructor_noarg.cpp index 27699989..d4cceb30 100644 --- a/docs/examples/ex_exception_constructor_noarg.cpp +++ b/docs/examples/ex_exception_constructor_noarg.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_exception_what.cpp b/docs/examples/ex_exception_what.cpp index 6568b3e5..cd7ca2f5 100644 --- a/docs/examples/ex_exception_what.cpp +++ b/docs/examples/ex_exception_what.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_macros_versions.cpp b/docs/examples/ex_macros_versions.cpp index 5cdc7157..33039bba 100644 --- a/docs/examples/ex_macros_versions.cpp +++ b/docs/examples/ex_macros_versions.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_macros_versions.output b/docs/examples/ex_macros_versions.output index 5cd5213b..ac960c4a 100644 --- a/docs/examples/ex_macros_versions.output +++ b/docs/examples/ex_macros_versions.output @@ -1 +1 @@ -fkYAML version 0.3.8 +fkYAML version 0.3.9 diff --git a/docs/examples/ex_node_value_converter_from_node.cpp b/docs/examples/ex_node_value_converter_from_node.cpp index aa4d2750..5d93789a 100644 --- a/docs/examples/ex_node_value_converter_from_node.cpp +++ b/docs/examples/ex_node_value_converter_from_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_node_value_converter_to_node.cpp b/docs/examples/ex_node_value_converter_to_node.cpp index a02dc784..ff510e3d 100644 --- a/docs/examples/ex_node_value_converter_to_node.cpp +++ b/docs/examples/ex_node_value_converter_to_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_operator_literal_yaml.cpp b/docs/examples/ex_operator_literal_yaml.cpp index e3644f40..6132fd01 100644 --- a/docs/examples/ex_operator_literal_yaml.cpp +++ b/docs/examples/ex_operator_literal_yaml.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_at.cpp b/docs/examples/ex_ordered_map_at.cpp index 822acd11..b81644bc 100644 --- a/docs/examples/ex_ordered_map_at.cpp +++ b/docs/examples/ex_ordered_map_at.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_constructor_initializer_list.cpp b/docs/examples/ex_ordered_map_constructor_initializer_list.cpp index c5a3e6c1..93eabbc7 100644 --- a/docs/examples/ex_ordered_map_constructor_initializer_list.cpp +++ b/docs/examples/ex_ordered_map_constructor_initializer_list.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_constructor_noarg.cpp b/docs/examples/ex_ordered_map_constructor_noarg.cpp index 410a562c..bc9b059e 100644 --- a/docs/examples/ex_ordered_map_constructor_noarg.cpp +++ b/docs/examples/ex_ordered_map_constructor_noarg.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_emplace.cpp b/docs/examples/ex_ordered_map_emplace.cpp index 873c3d15..79cd73fc 100644 --- a/docs/examples/ex_ordered_map_emplace.cpp +++ b/docs/examples/ex_ordered_map_emplace.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_find.cpp b/docs/examples/ex_ordered_map_find.cpp index 7532a2e0..b958c90d 100644 --- a/docs/examples/ex_ordered_map_find.cpp +++ b/docs/examples/ex_ordered_map_find.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/ex_ordered_map_subscript_operator.cpp b/docs/examples/ex_ordered_map_subscript_operator.cpp index 05e878c1..d3e8c41c 100644 --- a/docs/examples/ex_ordered_map_subscript_operator.cpp +++ b/docs/examples/ex_ordered_map_subscript_operator.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/input_multi.yaml b/docs/examples/input_multi.yaml new file mode 100644 index 00000000..fb311e2a --- /dev/null +++ b/docs/examples/input_multi.yaml @@ -0,0 +1,11 @@ +%YAML 1.2 +--- +foo: true +bar: 123 +baz: 3.14 +... +%TAG ! tag:test.com,2000: +--- +null: one +false: 456 +TRUE: 1.414 diff --git a/docs/examples/tutorial_1.cpp b/docs/examples/tutorial_1.cpp index fc55c775..4d3b9eb2 100644 --- a/docs/examples/tutorial_1.cpp +++ b/docs/examples/tutorial_1.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/tutorial_2.cpp b/docs/examples/tutorial_2.cpp index 683de941..0623d3f0 100644 --- a/docs/examples/tutorial_2.cpp +++ b/docs/examples/tutorial_2.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/tutorial_3.cpp b/docs/examples/tutorial_3.cpp index 87430779..02ce7c8e 100644 --- a/docs/examples/tutorial_3.cpp +++ b/docs/examples/tutorial_3.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/examples/tutorial_4.cpp b/docs/examples/tutorial_4.cpp index 977befbb..339438a4 100644 --- a/docs/examples/tutorial_4.cpp +++ b/docs/examples/tutorial_4.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/docs/mkdocs/docs/api/basic_node/deserialize.md b/docs/mkdocs/docs/api/basic_node/deserialize.md index 3d85cd6d..599a644e 100644 --- a/docs/mkdocs/docs/api/basic_node/deserialize.md +++ b/docs/mkdocs/docs/api/basic_node/deserialize.md @@ -10,8 +10,11 @@ template static basic_node deserialize(ItrType&& begin, ItrType&& end); // (2) ``` -Deserializes from compatible input sources. -Throws a [`fkyaml::exception`](../exception/index.md) if the deserialization process detects an error from the input sources. +Deserializes from compatible inputs. +Note that this function deserializes only the first YAML document in the given input and ignore the rest. +Use this function when the input consists of a single YAML document or only the first one needs to be deserialized. +Otherwise, use the [`deserialize_docs()`](deserialize_docs.md) function instead. +Throws a [`fkyaml::exception`](../exception/index.md) if the deserialization process detects an error from the input. !!! note "Supported Unicode Encodings" @@ -136,4 +139,5 @@ The resulting `basic_node` object deserialized from the pair of iterators. ### **See Also** * [basic_node](index.md) +* [deserialize_docs](deserialize_docs.md) * [get_value](get_value.md) diff --git a/docs/mkdocs/docs/api/basic_node/deserialize_docs.md b/docs/mkdocs/docs/api/basic_node/deserialize_docs.md new file mode 100644 index 00000000..d47a8cb0 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/deserialize_docs.md @@ -0,0 +1,144 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::deserialize_docs + +```cpp +template +static std::vector deserialize_docs(InputType&& input); // (1) + +template +static std::vector deserialize_docs(ItrType&& begin, ItrType&& end); // (2) +``` + +Deserializes from compatible inputs. +Unlike the [`deserialize()`](deserialize.md) function, this function deserializes all YAML documents in the input into [`fkyaml::basic_node`](index.md) objects. +Prefer this function when your input may contain more than one YAML documents and all of them must be processed. +Otherwise, use the [`deserialize()`](deserialize.md) function which is optimized for processing single YAML documents. + +Throws a [`fkyaml::exception`](../exception/index.md) if the deserialization process detects an error from the input. + +!!! note "Supported Unicode Encodings" + + fkYAML supports UTF-8, UTF-16 and UTF-32 encodings for input characters. + As the YAML specification shows [(here)](https://yaml.org/spec/1.2.2/#52-character-encodings), all input streams must begin with either a byte order mark(BOM) or an ASCII character, which will allow the encoding to be deduced by the pattern of the first few bytes of the input sequence. + If an input fails to meet the above requirement, the input is interpreted as a UTF-8 encoded character sequence starting without a BOM. + If a stream with `char` as a character type is used (including FILE pointers), the encoding will be automatically detected in the deserialization process, while an array/container of `char16_t` and `char32_t` denotes that its contents are encoded in the UTF-16BE/LE and UTF-32BE/LE format, respectively. + Furthermore, a byte order mark (BOM) can be put only at the beginning of an input sequence. + The deserialization process internally converts input characters into the UTF-8 encoded ones if they are encoded in the UTF-16 or UTF-32 format. + +!!! note "Supported newline codes" + + fkYAML supports LF (Unix style) and CR+LF (Windows style) as line break formats. + Inside the deserialization processes, however, fkYAML normalizes them into line feeds (LF, `0x0A`) just as described in the YAML specification (see the ["5.4. Line Break Characters"](https://yaml.org/spec/1.2.2/#54-line-break-characters) section). + Currently, there is no way to restore the original line break style in the serialization processes. + +## Overload (1) + +```cpp +template +static std::vector deserialize_docs(InputType&& input); +``` + +### **Template Parameters** + +***`InputType`*** +: Type of a compatible input, for instance: + + * an `std::istream` object + * a `FILE` pointer (must not be `nullptr`) + * a C-style array of characters (`char`, `char16_t` or `char32_t`. See the "Supported Unicode Encodings" above.) + * char[N], char16_t[N], or char32_t[N] (N is the size of an array) + * a container `obj` with which `begin(obj)` and `end(obj)` produces a valid pair of iterators + * std::basic_string, std::array, std::string_view (with C++17 or better) and the likes. + +### **Parameters** + +***`input`*** [in] +: An input source in the YAML format. + +### **Return Value** + +The resulting `basic_node` objects deserialized from the input source. + +## Overload (2) + +```cpp +template +static std::vector deserialize_docs(ItrType&& begin, ItrType&& end); +``` + +### **Template Parameters** + +***`ItrType`*** +: Type of a compatible iterator, for instance: + + * a pair of iterators such as return values of `std::string::begin()` and `std::string::end()` + * a pair of pointers such as `ptr` and `ptr + len` + +### **Parameters** + +***`begin`*** [in] +: An iterator to the first element of an input sequence + +***`end`*** [in] +: An iterator to the past-the-last element of an input sequence + +### **Return Value** + +The resulting `basic_node` objects deserialized from the pair of iterators. + +## Examples + +???+ Example "Example (a character array)" + + ```cpp + --8<-- "examples/ex_basic_node_deserialize_docs_char_array.cpp:9" + ``` + + output: + ```bash + --8<-- "examples/ex_basic_node_deserialize_docs_char_array.output" + ``` + +???+ Example "Example (a std::string object)" + + ```cpp + --8<-- "examples/ex_basic_node_deserialize_docs_string.cpp:9" + ``` + + output: + ```bash + --8<-- "examples/ex_basic_node_deserialize_docs_string.output" + ``` + +???+ Example "Example (a FILE pointer)" + + ```yaml title="input_multi.yaml" + --8<-- "examples/input_multi.yaml" + ``` + + ```cpp + --8<-- "examples/ex_basic_node_deserialize_docs_file_pointer.cpp:9" + ``` + + output: + ```bash + --8<-- "examples/ex_basic_node_deserialize_docs_file_pointer.output" + ``` + +???+ Example "Example (a pair of iterators)" + + ```cpp + --8<-- "examples/ex_basic_node_deserialize_docs_iterators.cpp:9" + ``` + + output: + ```bash + --8<-- "examples/ex_basic_node_deserialize_docs_iterators.output" + ``` + +### **See Also** + +* [basic_node](index.md) +* [deserialize](deserialize.md) +* [get_value](get_value.md) diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md index df4e820e..ce896c11 100644 --- a/docs/mkdocs/docs/api/basic_node/index.md +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -74,14 +74,16 @@ This class provides features to handle YAML nodes. | [is_string](is_string.md) | checks if a basic_node has a string node value. | ### Conversions -| Name | | Description | -| ------------------------------------ | -------- | ------------------------------------------------------------------ | -| [deserialize](deserialize.md) | (static) | deserializes a YAML formatted string into a basic_node. | -| [operator>>](extraction_operator.md) | | deserializes an input stream into a basic_node. | -| [serialize](serialize.md) | (static) | serializes a basic_node into a YAML formatted string. | -| [operator<<](insertion_operator.md) | | serializes a basic_node into an output stream. | -| [get_value](get_value.md) | | converts a basic_node into a target native data type. | -| [get_value_ref](get_value_ref.md) | | converts a basic_node into reference to a target native data type. | +| Name | | Description | +| --------------------------------------- | -------- | ------------------------------------------------------------------ | +| [deserialize](deserialize.md) | (static) | deserializes the first YAML document into a basic_node. | +| [deserialize_docs](deserialize_docs.md) | (static) | deserializes all YAML documents into basic_node objects. | +| [operator>>](extraction_operator.md) | | deserializes an input stream into a basic_node. | +| [serialize](serialize.md) | (static) | serializes a basic_node into a YAML formatted string. | +| [serialize_docs](serialize_docs.md) | (static) | serializes basic_node objects into a YAML formatted string. | +| [operator<<](insertion_operator.md) | | serializes a basic_node into an output stream. | +| [get_value](get_value.md) | | converts a basic_node into a target native data type. | +| [get_value_ref](get_value_ref.md) | | converts a basic_node into reference to a target native data type. | ### Iterators | Name | Description | diff --git a/docs/mkdocs/docs/api/basic_node/serialize.md b/docs/mkdocs/docs/api/basic_node/serialize.md index 051dc503..1861ef62 100644 --- a/docs/mkdocs/docs/api/basic_node/serialize.md +++ b/docs/mkdocs/docs/api/basic_node/serialize.md @@ -8,8 +8,8 @@ static std::string serialize(const basic_node& node); Serializes YAML node values recursively. Currently, the serialization of mappings and sequences only supports block styles. -That means that, even if a deserialized source input contains container nodes written in flow styles, the serialization processes force them to be emitted in block styles. -Moreover, fkYAML unconditionally uses LFs as the line break format in serialization outputs and there is currently no way to change it to use CR+LFs. +That means that, even if a deserialized source input contains container nodes written in flow styles, this function forces them to be emitted in block styles. +Moreover, fkYAML unconditionally uses LFs as the line break format in serialization outputs, and there is currently no way to change it to use CR+LFs instead. This function serializes the given `node` parameter in the following format. ```yaml diff --git a/docs/mkdocs/docs/api/basic_node/serialize_docs.md b/docs/mkdocs/docs/api/basic_node/serialize_docs.md new file mode 100644 index 00000000..39cc43be --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/serialize_docs.md @@ -0,0 +1,48 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::serialize_docs + +```cpp +static std::string serialize_docs(const std::vector& docs); +``` + +Serializes YAML documents into a string. +This function serializes the given `docs` parameter with the separation line (...) between YAML documents. +Regarding the serialization of each document, see the documentation for the [`serialize()`](serialize.md) function which this function calls internally. +Just as the [`serialize()`](serialize.md) function does, fkYAML unconditionally uses LFs as the line break format in serialization outputs, and there is currently no way to change it to use CR+LFs instead. + +```yaml + +... + +# the last document end marker (...) is omitted since it's redundant. +``` + +### **Parameters** + +***`docs`*** [in] +: `basic_node` objects to be serialized. + +### **Return Value** + +The resulting string object from the serialization of the `docs` object. + +???+ Example + + ```cpp + --8<-- "examples/ex_basic_node_serialize_docs.cpp:9" + ``` + + output: + ```bash + --8<-- "examples/ex_basic_node_serialize_docs.output" + ``` + +### **See Also** + +* [basic_node](index.md) +* [add_anchor_name](add_anchor_name.md) +* [add_tag_name](add_tag_name.md) +* [deserialize](deserialize.md) +* [operator<<](insertion_operator.md) +* [operator"" _yaml](../operator_literal_yaml.md) diff --git a/docs/mkdocs/docs/home/releases.md b/docs/mkdocs/docs/home/releases.md index 0a67bf31..b37aa201 100644 --- a/docs/mkdocs/docs/home/releases.md +++ b/docs/mkdocs/docs/home/releases.md @@ -1,5 +1,52 @@ # Releases +## [v0.3.10](https://github.com/fktn-k/fkYAML/releases/tag/v0.3.10) (2024-08-18) + +!!! abstract "Release Packages" + + * [fkYAML.zip](https://github.com/fktn-k/fkYAML/releases/download/v0.3.10/fkYAML.zip) + * [fkYAML.tgz](https://github.com/fktn-k/fkYAML/releases/download/v0.3.10/fkYAML.tgz) + * [fkYAML_single_header.zip](https://github.com/fktn-k/fkYAML/releases/download/v0.3.10/fkYAML_single_header.zip) + * [fkYAML_single_header.tgz](https://github.com/fktn-k/fkYAML/releases/download/v0.3.10/fkYAML_single_header.tgz) + * [node.hpp](https://github.com/fktn-k/fkYAML/releases/download/v0.3.10/node.hpp) (single header) + +### Summary + +This release adds the new support for deserializing/serializing multiple YAML documents by adding new APIs ([`fkyaml::node::deserialize_docs()`](https://fktn-k.github.io/fkYAML/api/basic_node/deserialize_docs/) and [`fkyaml::node::serialize_docs()`](https://fktn-k.github.io/fkYAML/api/basic_node/serialize_docs/) respectively). You can still call the existing APIs for deserializing/serializing a single YAML document. See the linked API document pages for details. +In addition, from this version on, Intel icpx compiler is supported and used in the CI processes. Some compiler flags are added in building the unit testing app, but no compiler specific swiches are required for the library itself. +Moreover, because the GitHub Actions runner image for macOS11 has been deprecated, the CI jobs which uses the runner image and some compiler support which depend on the runner image have been removed. +For other changes like bug fixes, see descriptions in each related issues and PRs. + +### What's Changed + +#### :sparkles: New Features + +- Support Intel icpx compiler by [fktn-k](https://github.com/fktn-k) in [\#360](https://github.com/fktn-k/fkYAML/pull/360) +- Support parssing multiple YAML documents by [fktn-k](https://github.com/fktn-k) in [\#362](https://github.com/fktn-k/fkYAML/pull/362) +- Support serializing multiple YAML docs by [fktn-k](https://github.com/fktn-k) in [\#363](https://github.com/fktn-k/fkYAML/pull/363) + +#### :bug: Bug Fixes + +- Detect missing the end of directives markers (---) by [fktn-k](https://github.com/fktn-k) in [\#361](https://github.com/fktn-k/fkYAML/pull/361) +- Fix bug in serializing alias keys by [fktn-k](https://github.com/fktn-k) in [\#364](https://github.com/fktn-k/fkYAML/pull/364) +- Allow trailing comma in flow mapping/sequence by [fktn-k](https://github.com/fktn-k) in [\#365](https://github.com/fktn-k/fkYAML/pull/365) +- \#368 Fix line advancement after node props by [fktn-k](https://github.com/fktn-k) in [\#369](https://github.com/fktn-k/fkYAML/pull/369), reported by [alienczf](https://github.com/alienczf) in [\#368](https://github.com/fktn-k/fkYAML/issues/368) +- Apply node properties for the root node by [fktn-k](https://github.com/fktn-k) in [\#370](https://github.com/fktn-k/fkYAML/pull/370) +- \#366 Fix node-to-float conversion error if node's value is \<= 0 by [fktn-k](https://github.com/fktn-k) in [\#371](https://github.com/fktn-k/fkYAML/pull/371), reported by [ARessegetesStery](https://github.com/ARessegetesStery) in [\#366](https://github.com/fktn-k/fkYAML/issues/366) + +#### :robot: CI + +- Remove CI jobs running with macOS 11 by [fktn-k](https://github.com/fktn-k) in [\#367](https://github.com/fktn-k/fkYAML/pull/367) + + + +- update configs for reuse v4 by [fktn-k](https://github.com/fktn-k) in [\#372](https://github.com/fktn-k/fkYAML/pull/372) + + +**Full Changelog**: https://github.com/fktn-k/fkYAML/compare/v0.3.9...v0.3.10 + +--- + ## **fkYAML version 0.3.9** !!! abstract "Release Packages" diff --git a/docs/mkdocs/docs/home/supported_compilers.md b/docs/mkdocs/docs/home/supported_compilers.md index 652dbc24..7a873635 100644 --- a/docs/mkdocs/docs/home/supported_compilers.md +++ b/docs/mkdocs/docs/home/supported_compilers.md @@ -4,10 +4,6 @@ Currently, the following compilers are known to work and used in GitHub Actions | Compiler | Operating System | | -------------------------- | -------------------------------------------------------------------------------------------------------------- | -| AppleClang 11.0.3.11030032 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 12.0.0.12000032 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 12.0.5.12050022 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | -| AppleClang 13.0.0.13000029 | [macOS 11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md) | | AppleClang 13.0.0.13000029 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | | AppleClang 13.1.6.13160021 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | | AppleClang 14.0.0.14000029 | [macOS 12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md) | @@ -46,6 +42,7 @@ Currently, the following compilers are known to work and used in GitHub Actions | GCC 12.3.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | GCC 13.3.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | GCC 14.1.0 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | +| IntelLLVM 2024.1.2 | [Ubuntu 22.04](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md) | | MinGW-64 8.1.0 | [Windows Server 2019](https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md) | | MinGW-64 12.2.0 | [Windows Server 2022](https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md) | | Visual Studio 16 2019 | [Windows Server 2019](https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md) | diff --git a/docs/mkdocs/docs/tutorials/cmake_integration.md b/docs/mkdocs/docs/tutorials/cmake_integration.md index a97021e3..77232433 100644 --- a/docs/mkdocs/docs/tutorials/cmake_integration.md +++ b/docs/mkdocs/docs/tutorials/cmake_integration.md @@ -57,7 +57,7 @@ Since CMake v3.11, [`FetchContent`](https://cmake.org/cmake/help/latest/module/F FetchContent_Declare( fkYAML GIT_REPOSITORY https://github.com/fktn-k/fkYAML.git - GIT_TAG v0.3.9 + GIT_TAG v0.3.10 ) FetchContent_MakeAvailable(fkYAML) diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index ac2064d5..82960ce1 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -56,10 +56,6 @@ markdown_extensions: - pymdownx.inlinehilite - pymdownx.magiclink - pymdownx.superfences: - # custom_fences: - # - name: mermaid - # class: mermaid - # format: !!python/name:pymdownx.superfences.fence_code_format - pymdownx.tabbed: alternate_style: true - pymdownx.tilde @@ -114,6 +110,7 @@ nav: - const_iterator: api/basic_node/const_iterator.md - contains: api/basic_node/contains.md - deserialize: api/basic_node/deserialize.md + - deserialize_docs: api/basic_node/deserialize_docs.md - empty: api/basic_node/empty.md - end: api/basic_node/end.md - float_number_type: api/basic_node/float_number_type.md @@ -143,6 +140,7 @@ nav: - sequence_type: api/basic_node/sequence_type.md - sequence: api/basic_node/sequence.md - serialize: api/basic_node/serialize.md + - serialize_docs: api/basic_node/serialize_docs.md - set_yaml_version: api/basic_node/set_yaml_version.md - size: api/basic_node/size.md - string_type: api/basic_node/string_type.md diff --git a/fkYAML.natvis b/fkYAML.natvis index f5fb405d..8b3c0fda 100644 --- a/fkYAML.natvis +++ b/fkYAML.natvis @@ -4,26 +4,26 @@ - - - {*(m_node_value.p_sequence)} - {*(m_node_value.p_mapping)} - nullptr - {m_node_value.boolean} - {m_node_value.integer} - {m_node_value.float_val} - {*(m_node_value.p_string)} + + + {*(m_node_value.p_sequence)} + {*(m_node_value.p_mapping)} + nullptr + {m_node_value.boolean} + {m_node_value.integer} + {m_node_value.float_val} + {*(m_node_value.p_string)} - + *(m_node_value.p_sequence),view(simple) - + *(m_node_value.p_mapping),view(simple) - + {second} second diff --git a/include/fkYAML/detail/assert.hpp b/include/fkYAML/detail/assert.hpp index 26fb945b..344200b1 100644 --- a/include/fkYAML/detail/assert.hpp +++ b/include/fkYAML/detail/assert.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/conversions/from_node.hpp b/include/fkYAML/detail/conversions/from_node.hpp index 1e353003..98059672 100644 --- a/include/fkYAML/detail/conversions/from_node.hpp +++ b/include/fkYAML/detail/conversions/from_node.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -198,7 +198,7 @@ inline void from_node(const BasicNodeType& n, FloatType& f) { } auto tmp_float = n.template get_value_ref(); - if (tmp_float < std::numeric_limits::min()) { + if (tmp_float < std::numeric_limits::lowest()) { throw exception("Floating point value underflow detected."); } if (std::numeric_limits::max() < tmp_float) { diff --git a/include/fkYAML/detail/conversions/from_string.hpp b/include/fkYAML/detail/conversions/from_string.hpp index 3a551fd6..f8d9398c 100644 --- a/include/fkYAML/detail/conversions/from_string.hpp +++ b/include/fkYAML/detail/conversions/from_string.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/conversions/to_node.hpp b/include/fkYAML/detail/conversions/to_node.hpp index 577e5795..c31daa83 100644 --- a/include/fkYAML/detail/conversions/to_node.hpp +++ b/include/fkYAML/detail/conversions/to_node.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/conversions/to_string.hpp b/include/fkYAML/detail/conversions/to_string.hpp index d11ea10f..09079f32 100644 --- a/include/fkYAML/detail/conversions/to_string.hpp +++ b/include/fkYAML/detail/conversions/to_string.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/document_metainfo.hpp b/include/fkYAML/detail/document_metainfo.hpp index c624fffa..1b60e8bc 100644 --- a/include/fkYAML/detail/document_metainfo.hpp +++ b/include/fkYAML/detail/document_metainfo.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/encodings/encode_detector.hpp b/include/fkYAML/detail/encodings/encode_detector.hpp index ef1f790e..f2154434 100644 --- a/include/fkYAML/detail/encodings/encode_detector.hpp +++ b/include/fkYAML/detail/encodings/encode_detector.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/encodings/uri_encoding.hpp b/include/fkYAML/detail/encodings/uri_encoding.hpp index 0eb1ed18..b4f8a3ba 100644 --- a/include/fkYAML/detail/encodings/uri_encoding.hpp +++ b/include/fkYAML/detail/encodings/uri_encoding.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/encodings/utf_encode_t.hpp b/include/fkYAML/detail/encodings/utf_encode_t.hpp index 51663f0f..50aa4855 100644 --- a/include/fkYAML/detail/encodings/utf_encode_t.hpp +++ b/include/fkYAML/detail/encodings/utf_encode_t.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/encodings/utf_encodings.hpp b/include/fkYAML/detail/encodings/utf_encodings.hpp index 40c5d44d..c393505a 100644 --- a/include/fkYAML/detail/encodings/utf_encodings.hpp +++ b/include/fkYAML/detail/encodings/utf_encodings.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/encodings/yaml_escaper.hpp b/include/fkYAML/detail/encodings/yaml_escaper.hpp index 3766aacd..5a32cbdc 100644 --- a/include/fkYAML/detail/encodings/yaml_escaper.hpp +++ b/include/fkYAML/detail/encodings/yaml_escaper.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 607fe1b0..222bf875 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,19 @@ class basic_deserializer { p_node(_p_node) { } + ~parse_context() { + switch (state) { + case context_state_t::BLOCK_MAPPING_EXPLICIT_KEY: + case context_state_t::FLOW_SEQUENCE_KEY: + case context_state_t::FLOW_MAPPING_KEY: + delete p_node; + p_node = nullptr; + break; + default: + break; + } + } + /// The current line. (count from zero) uint32_t line {0}; /// The indentation width in the current line. (count from zero) @@ -90,17 +104,55 @@ class basic_deserializer { node_type* p_node {nullptr}; }; + /// @brief Definitions of state types for expected flow token hints. + enum class flow_token_state_t { + NEEDS_VALUE_OR_SUFFIX, //!< Either value or flow suffix (`]` or `}`) + NEEDS_SEPARATOR_OR_SUFFIX, //!< Either separator (`,`) or flow suffix (`]` or `}`) + }; + public: /// @brief Construct a new basic_deserializer object. basic_deserializer() = default; public: - /// @brief Deserialize a YAML-formatted source string into a YAML node. - /// @param input_adapter An adapter object for the input source buffer. - /// @return node_type A root YAML node object deserialized from the source string. + /// @brief Deserialize a single YAML document into a YAML node. + /// @note + /// If the input consists of multiple YAML documents, this function only parses the first. + /// If the input may have multiple YAML documents all of which must be parsed into nodes, + /// prefer the `deserialize_docs()` function. + /// @tparam InputAdapterType The type of an input adapter object. + /// @param input_adapter An input adapter object for the input source buffer. + /// @return node_type A root YAML node deserialized from the source string. template ::value, int> = 0> node_type deserialize(InputAdapterType&& input_adapter) { + lexical_token_t type {lexical_token_t::END_OF_BUFFER}; lexer_type lexer(std::forward(input_adapter)); + return deserialize_document(lexer, type); + } + + /// @brief Deserialize multiple YAML documents into YAML nodes. + /// @tparam InputAdapterType The type of an adapter object. + /// @param input_adapter An input adapter object for the input source buffer. + /// @return std::vector Root YAML nodes for deserialized YAML documents. + template ::value, int> = 0> + std::vector deserialize_docs(InputAdapterType&& input_adapter) { + lexer_type lexer(std::forward(input_adapter)); + std::vector nodes {}; + lexical_token_t type {lexical_token_t::END_OF_BUFFER}; + + do { + nodes.emplace_back(deserialize_document(lexer, type)); + } while (type != lexical_token_t::END_OF_BUFFER); + + return nodes; + } + +private: + /// @brief Deserialize a YAML document into a YAML node. + /// @param lexer The lexical analyzer to be used. + /// @param last_type The variable to store the last lexical token type. + /// @return node_type A root YAML node deserialized from the YAML document. + node_type deserialize_document(lexer_type& lexer, lexical_token_t& last_type) { lexical_token_t type {lexical_token_t::END_OF_BUFFER}; node_type root; @@ -109,10 +161,20 @@ class basic_deserializer { // parse directives first. deserialize_directives(lexer, type); + // parse node properties for root node if any + uint32_t line = lexer.get_lines_processed(); + uint32_t indent = lexer.get_last_token_begin_pos(); + bool found_props = deserialize_node_properties(lexer, type, line, indent); + switch (type) { case lexical_token_t::SEQUENCE_BLOCK_PREFIX: { root = node_type::sequence(); apply_directive_set(root); + if (found_props) { + // If node properties are found before the block sequence entry prefix, the properties belong to the + // root sequence node. + apply_node_properties(root); + } parse_context context( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::BLOCK_SEQUENCE, &root); m_context_stack.emplace_back(std::move(context)); @@ -123,6 +185,7 @@ class basic_deserializer { ++m_flow_context_depth; root = node_type::sequence(); apply_directive_set(root); + apply_node_properties(root); m_context_stack.emplace_back( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::FLOW_SEQUENCE, &root); type = lexer.get_next_token(); @@ -131,6 +194,7 @@ class basic_deserializer { ++m_flow_context_depth; root = node_type::mapping(); apply_directive_set(root); + apply_node_properties(root); m_context_stack.emplace_back( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::FLOW_MAPPING, &root); type = lexer.get_next_token(); @@ -138,6 +202,11 @@ class basic_deserializer { default: { root = node_type::mapping(); apply_directive_set(root); + if (found_props && line < lexer.get_lines_processed()) { + // If node properties and a followed node are on the different line, the properties belong to the root + // node. + apply_node_properties(root); + } parse_context context( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::BLOCK_MAPPING, &root); m_context_stack.emplace_back(std::move(context)); @@ -148,23 +217,27 @@ class basic_deserializer { mp_current_node = &root; // parse YAML nodes recursively - deserialize_node(lexer, type); + deserialize_node(lexer, type, last_type); + FK_YAML_ASSERT(last_type == lexical_token_t::END_OF_BUFFER || last_type == lexical_token_t::END_OF_DOCUMENT); // reset parameters for the next call. mp_current_node = nullptr; mp_meta.reset(); m_needs_tag_impl = false; m_needs_anchor_impl = false; + m_flow_context_depth = 0; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; m_context_stack.clear(); return root; } -private: /// @brief Deserializes the YAML directives if specified. /// @param lexer The lexical analyzer to be used. /// @param last_type The variable to store the last lexical token type. void deserialize_directives(lexer_type& lexer, lexical_token_t& last_type) { + bool lacks_end_of_directives_marker = false; + for (;;) { lexical_token_t type = lexer.get_next_token(); @@ -179,6 +252,7 @@ class basic_deserializer { mp_meta->version = convert_yaml_version(lexer.get_yaml_version()); mp_meta->is_version_specified = true; + lacks_end_of_directives_marker = true; break; case lexical_token_t::TAG_DIRECTIVE: { const std::string& tag_handle = lexer.get_tag_handle(); @@ -192,6 +266,7 @@ class basic_deserializer { lexer.get_last_token_begin_pos()); } mp_meta->primary_handle_prefix = lexer.get_tag_prefix(); + lacks_end_of_directives_marker = true; break; } case 2: { @@ -203,6 +278,7 @@ class basic_deserializer { lexer.get_last_token_begin_pos()); } mp_meta->secondary_handle_prefix = lexer.get_tag_prefix(); + lacks_end_of_directives_marker = true; break; } default: { @@ -214,6 +290,7 @@ class basic_deserializer { lexer.get_lines_processed(), lexer.get_last_token_begin_pos()); } + lacks_end_of_directives_marker = true; break; } } @@ -223,9 +300,15 @@ class basic_deserializer { // TODO: should output a warning log. Currently just ignore this case. break; case lexical_token_t::END_OF_DIRECTIVES: - // Ignore this directives end marker so the caller will get the beginning token of the contents. + lacks_end_of_directives_marker = false; break; default: + if (lacks_end_of_directives_marker) { + throw parse_error( + "The end of directives marker (---) is missing after directives.", + lexer.get_lines_processed(), + lexer.get_last_token_begin_pos()); + } // end the parsing of directives if the other tokens are found. last_type = type; return; @@ -236,16 +319,13 @@ class basic_deserializer { /// @brief Deserializes the YAML nodes recursively. /// @param lexer The lexical analyzer to be used. /// @param first_type The first lexical token type. - void deserialize_node(lexer_type& lexer, lexical_token_t first_type) { + void deserialize_node(lexer_type& lexer, lexical_token_t first_type, lexical_token_t& last_type) { lexical_token_t type = first_type; uint32_t line = lexer.get_lines_processed(); uint32_t indent = lexer.get_last_token_begin_pos(); do { switch (type) { - case lexical_token_t::END_OF_BUFFER: - // This handles an empty input. - break; case lexical_token_t::EXPLICIT_KEY_PREFIX: { uint32_t pop_num = 0; if (indent == 0) { @@ -350,7 +430,7 @@ class basic_deserializer { if (line > old_line) { if (m_needs_tag_impl) { tag_t tag_type = tag_resolver_type::resolve_tag(m_tag_name, mp_meta); - if (tag_type == tag_t::MAPPING) { + if (tag_type == tag_t::MAPPING || tag_type == tag_t::CUSTOM_TAG) { // set YAML node properties here to distinguish them from those for the first key node // as shown in the following snippet: // @@ -363,6 +443,7 @@ class basic_deserializer { *mp_current_node = node_type::mapping(); apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); continue; } } @@ -376,7 +457,40 @@ class basic_deserializer { cur_context.line = line; cur_context.indent = indent; cur_context.state = context_state_t::BLOCK_SEQUENCE; - break; + + type = lexer.get_next_token(); + line = lexer.get_lines_processed(); + indent = lexer.get_last_token_begin_pos(); + + bool has_props = deserialize_node_properties(lexer, type, line, indent); + if (has_props) { + uint32_t line_after_props = lexer.get_lines_processed(); + if (line == line_after_props) { + // Skip updating the current indent to avoid stacking a wrong indentation. + // + // ```yaml + // &foo bar: baz + // ^ + // the correct indent width for the "bar" node key. + // ``` + continue; + } + + // if node properties and the followed node are on different lines (i.e., the properties are + // for a container node), the application and the line advancement must happen here. + // Otherwise, a false indent error will be emitted. See + // https://github.com/fktn-k/fkYAML/issues/368 for more details. + line = line_after_props; + indent = lexer.get_last_token_begin_pos(); + mp_current_node->template get_value_ref().emplace_back( + node_type::mapping()); + mp_current_node = &mp_current_node->template get_value_ref().back(); + m_context_stack.emplace_back( + line_after_props, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + apply_node_properties(*mp_current_node); + } + + continue; } // defer checking the existence of a key separator after the following scalar until the next @@ -390,14 +504,12 @@ class basic_deserializer { m_context_stack.pop_back(); } - node_type* key_node = m_context_stack.back().p_node; + node_type key_node = std::move(*m_context_stack.back().p_node); m_context_stack.pop_back(); - m_context_stack.back().p_node->template get_value_ref().emplace(*key_node, node_type()); - mp_current_node = &(m_context_stack.back().p_node->operator[](*key_node)); + m_context_stack.back().p_node->template get_value_ref().emplace(key_node, node_type()); + mp_current_node = &(m_context_stack.back().p_node->operator[](std::move(key_node))); m_context_stack.emplace_back( line, indent, context_state_t::BLOCK_MAPPING_EXPLICIT_VALUE, mp_current_node); - delete key_node; - key_node = nullptr; if (type == lexical_token_t::SEQUENCE_BLOCK_PREFIX) { *mp_current_node = node_type::sequence(); @@ -417,13 +529,15 @@ class basic_deserializer { case lexical_token_t::ANCHOR_PREFIX: case lexical_token_t::TAG_PREFIX: deserialize_node_properties(lexer, type, line, indent); - // Skip updating the current indent to avoid stacking a wrong indentation. + // Note that node properties for block sequences as a mapping value are processed when a + // `lexical_token_t::KEY_SEPARATOR` token is processed. // - // &foo bar: baz - // ^ - // the correct indent width for the "bar" node key. - + // ```yaml + // &foo bar: baz + // ^ + // the correct indent width for the "bar" node key. + // ``` continue; case lexical_token_t::SEQUENCE_BLOCK_PREFIX: { bool is_further_nested = m_context_stack.back().indent < indent; @@ -482,6 +596,9 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } + else if (m_flow_token_state == flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { + throw parse_error("Flow sequence begininng is found without separated with a comma.", line, indent); + } ++m_flow_context_depth; @@ -512,20 +629,12 @@ class basic_deserializer { apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); - type = lexer.get_next_token(); - if (type == lexical_token_t::SEQUENCE_FLOW_END) { - // enable the flag for the next loop for the empty flow sequence. - m_needs_value_separator_or_suffix = true; - } - line = lexer.get_lines_processed(); - indent = lexer.get_last_token_begin_pos(); - continue; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + break; case lexical_token_t::SEQUENCE_FLOW_END: { - if (!m_needs_value_separator_or_suffix) { - throw parse_error("invalid flow sequence ending is found.", line, indent); + if (m_flow_context_depth == 0) { + throw parse_error("Flow sequence ending is found outside the flow context.", line, indent); } - m_needs_value_separator_or_suffix = false; - --m_flow_context_depth; // find the corresponding flow sequence beginning. @@ -544,12 +653,13 @@ class basic_deserializer { bool is_valid = itr != m_context_stack.rend(); if (!is_valid) { - throw parse_error("invalid flow sequence ending is found.", line, indent); + throw parse_error("No corresponding flow sequence beginning is found.", line, indent); } // keep the last state for later processing. parse_context& last_context = m_context_stack.back(); mp_current_node = last_context.p_node; + last_context.p_node = nullptr; indent = last_context.indent; context_state_t state = last_context.state; m_context_stack.pop_back(); @@ -560,6 +670,7 @@ class basic_deserializer { node_type key_node = std::move(*mp_current_node); delete mp_current_node; mp_current_node = m_context_stack.back().p_node; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; add_new_key(std::move(key_node), line, indent); break; @@ -570,7 +681,10 @@ class basic_deserializer { node_type key_node = node_type::mapping(); apply_directive_set(key_node); mp_current_node->swap(key_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + add_new_key(std::move(key_node), line, indent); } else { @@ -578,7 +692,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } @@ -624,6 +738,9 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } + else if (m_flow_token_state == flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { + throw parse_error("Flow mapping begininng is found without separated with a comma.", line, indent); + } ++m_flow_context_depth; @@ -654,20 +771,15 @@ class basic_deserializer { apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); - type = lexer.get_next_token(); - if (type == lexical_token_t::MAPPING_FLOW_END) { - // enable the flag for the next loop for the empty flow mapping. - m_needs_value_separator_or_suffix = true; - } line = lexer.get_lines_processed(); indent = lexer.get_last_token_begin_pos(); - continue; + + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + break; case lexical_token_t::MAPPING_FLOW_END: { - if (!m_needs_value_separator_or_suffix) { - throw parse_error("invalid flow mapping ending is found.", line, indent); + if (m_flow_context_depth == 0) { + throw parse_error("Flow mapping ending is found outside the flow context.", line, indent); } - m_needs_value_separator_or_suffix = false; - --m_flow_context_depth; // find the corresponding flow mapping beginning. @@ -686,12 +798,13 @@ class basic_deserializer { bool is_valid = itr != m_context_stack.rend(); if (!is_valid) { - throw parse_error("invalid flow mapping ending is found.", line, indent); + throw parse_error("No corresponding flow mapping beginning is found.", line, indent); } // keep the last state for later processing. parse_context& last_context = m_context_stack.back(); mp_current_node = last_context.p_node; + last_context.p_node = nullptr; indent = last_context.indent; context_state_t state = last_context.state; m_context_stack.pop_back(); @@ -702,6 +815,7 @@ class basic_deserializer { node_type key_node = std::move(*mp_current_node); delete mp_current_node; mp_current_node = m_context_stack.back().p_node; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; add_new_key(std::move(key_node), line, indent); break; @@ -710,8 +824,12 @@ class basic_deserializer { type = lexer.get_next_token(); if (type == lexical_token_t::KEY_SEPARATOR) { node_type key_node = node_type::mapping(); + apply_directive_set(key_node); mp_current_node->swap(key_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + add_new_key(std::move(key_node), line, indent); } else { @@ -719,7 +837,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } @@ -729,10 +847,10 @@ class basic_deserializer { } case lexical_token_t::VALUE_SEPARATOR: FK_YAML_ASSERT(m_flow_context_depth > 0); - if (!m_needs_value_separator_or_suffix) { + if (m_flow_token_state != flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { throw parse_error("invalid value separator is found.", line, indent); } - m_needs_value_separator_or_suffix = false; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; break; case lexical_token_t::ALIAS_PREFIX: case lexical_token_t::NULL_VALUE: @@ -747,15 +865,21 @@ class basic_deserializer { break; } case lexical_token_t::END_OF_DIRECTIVES: + throw parse_error("invalid end-of-directives marker (---) found in the contents.", line, indent); + case lexical_token_t::END_OF_BUFFER: + // This handles an empty input. case lexical_token_t::END_OF_DOCUMENT: // TODO: This token should be handled to support multiple documents. - break; + last_type = type; + return; } type = lexer.get_next_token(); indent = lexer.get_last_token_begin_pos(); line = lexer.get_lines_processed(); } while (type != lexical_token_t::END_OF_BUFFER); + + last_type = type; } /// @brief Deserializes YAML node properties (anchor and/or tag names) if they exist @@ -841,17 +965,8 @@ class basic_deserializer { else if (indent < m_context_stack.back().indent) { auto target_itr = std::find_if(m_context_stack.rbegin(), m_context_stack.rend(), [indent](const parse_context& c) { - if (indent != c.indent) { - return false; - } - - switch (c.state) { - case context_state_t::BLOCK_MAPPING: - case context_state_t::MAPPING_VALUE: - return true; - default: - return false; - } + // the target node is a block mapping key node with the same indentation. + return (indent == c.indent) && (c.state == context_state_t::BLOCK_MAPPING); }); bool is_indent_valid = (target_itr != m_context_stack.rend()); if (!is_indent_valid) { @@ -868,8 +983,8 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } - else if (m_needs_value_separator_or_suffix) { - throw parse_error("flow mapping entry is found without separated with a comma.", line, indent); + else if (m_flow_token_state != flow_token_state_t::NEEDS_VALUE_OR_SUFFIX) { + throw parse_error("Flow mapping entry is found without separated with a comma.", line, indent); } if (mp_current_node->is_sequence()) { @@ -894,10 +1009,10 @@ class basic_deserializer { void assign_node_value(node_type&& node_value, const uint32_t line, const uint32_t indent) { if (mp_current_node->is_sequence()) { if (m_flow_context_depth > 0) { - if (m_needs_value_separator_or_suffix) { + if (m_flow_token_state != flow_token_state_t::NEEDS_VALUE_OR_SUFFIX) { throw parse_error("flow sequence entry is found without separated with a comma.", line, indent); } - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } mp_current_node->template get_value_ref().emplace_back(std::move(node_value)); @@ -911,7 +1026,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } } @@ -1107,8 +1222,8 @@ class basic_deserializer { bool m_needs_anchor_impl {false}; /// A flag to determine the need for a corresponding node with the last YAML tag. bool m_needs_tag_impl {false}; - /// A flag to determine the need for a value separator or a flow suffix to be follow. - bool m_needs_value_separator_or_suffix {false}; + /// A flag to determine the need for a value separator or a flow suffix to follow. + flow_token_state_t m_flow_token_state {flow_token_state_t::NEEDS_VALUE_OR_SUFFIX}; /// The last YAML anchor name. string_type m_anchor_name {}; /// The last tag name. diff --git a/include/fkYAML/detail/input/input_adapter.hpp b/include/fkYAML/detail/input/input_adapter.hpp index 9aab6b16..d05a1466 100644 --- a/include/fkYAML/detail/input/input_adapter.hpp +++ b/include/fkYAML/detail/input/input_adapter.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/lexical_analyzer.hpp b/include/fkYAML/detail/input/lexical_analyzer.hpp index ac5717f5..eb269a48 100644 --- a/include/fkYAML/detail/input/lexical_analyzer.hpp +++ b/include/fkYAML/detail/input/lexical_analyzer.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/position_tracker.hpp b/include/fkYAML/detail/input/position_tracker.hpp index 312a3ee0..09c3628d 100644 --- a/include/fkYAML/detail/input/position_tracker.hpp +++ b/include/fkYAML/detail/input/position_tracker.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/scalar_scanner.hpp b/include/fkYAML/detail/input/scalar_scanner.hpp index b2db5d19..fe0bb134 100644 --- a/include/fkYAML/detail/input/scalar_scanner.hpp +++ b/include/fkYAML/detail/input/scalar_scanner.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/tag_resolver.hpp b/include/fkYAML/detail/input/tag_resolver.hpp index 8d9778c3..e1545dd3 100644 --- a/include/fkYAML/detail/input/tag_resolver.hpp +++ b/include/fkYAML/detail/input/tag_resolver.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/input/tag_t.hpp b/include/fkYAML/detail/input/tag_t.hpp index 0a1e2aa1..5fd6c6f4 100644 --- a/include/fkYAML/detail/input/tag_t.hpp +++ b/include/fkYAML/detail/input/tag_t.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/iterator.hpp b/include/fkYAML/detail/iterator.hpp index 7d7f709f..d6582417 100644 --- a/include/fkYAML/detail/iterator.hpp +++ b/include/fkYAML/detail/iterator.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/macros/cpp_config_macros.hpp b/include/fkYAML/detail/macros/cpp_config_macros.hpp index 9f7a71f8..6c69874e 100644 --- a/include/fkYAML/detail/macros/cpp_config_macros.hpp +++ b/include/fkYAML/detail/macros/cpp_config_macros.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/macros/version_macros.hpp b/include/fkYAML/detail/macros/version_macros.hpp index 36526643..9aeaab8c 100644 --- a/include/fkYAML/detail/macros/version_macros.hpp +++ b/include/fkYAML/detail/macros/version_macros.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -10,7 +10,7 @@ // Check version definitions if already defined. #if defined(FK_YAML_MAJOR_VERSION) && defined(FK_YAML_MINOR_VERSION) && defined(FK_YAML_PATCH_VERSION) -#if FK_YAML_MAJOR_VERSION != 0 || FK_YAML_MINOR_VERSION != 3 || FK_YAML_PATCH_VERSION != 9 +#if FK_YAML_MAJOR_VERSION != 0 || FK_YAML_MINOR_VERSION != 3 || FK_YAML_PATCH_VERSION != 10 #warning Already included a different version of the fkYAML library! #else // define macros to skip defining macros down below. @@ -22,7 +22,7 @@ #define FK_YAML_MAJOR_VERSION 0 #define FK_YAML_MINOR_VERSION 3 -#define FK_YAML_PATCH_VERSION 9 +#define FK_YAML_PATCH_VERSION 10 #define FK_YAML_NAMESPACE_VERSION_CONCAT_IMPL(major, minor, patch) v##major##_##minor##_##patch diff --git a/include/fkYAML/detail/meta/detect.hpp b/include/fkYAML/detail/meta/detect.hpp index f6dc14e3..82d22980 100644 --- a/include/fkYAML/detail/meta/detect.hpp +++ b/include/fkYAML/detail/meta/detect.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/meta/input_adapter_traits.hpp b/include/fkYAML/detail/meta/input_adapter_traits.hpp index a94d6f5a..5747fc59 100644 --- a/include/fkYAML/detail/meta/input_adapter_traits.hpp +++ b/include/fkYAML/detail/meta/input_adapter_traits.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/meta/node_traits.hpp b/include/fkYAML/detail/meta/node_traits.hpp index 709c95fa..172913a9 100644 --- a/include/fkYAML/detail/meta/node_traits.hpp +++ b/include/fkYAML/detail/meta/node_traits.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/meta/stl_supplement.hpp b/include/fkYAML/detail/meta/stl_supplement.hpp index 5286fc04..dbfc3a6e 100644 --- a/include/fkYAML/detail/meta/stl_supplement.hpp +++ b/include/fkYAML/detail/meta/stl_supplement.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/meta/type_traits.hpp b/include/fkYAML/detail/meta/type_traits.hpp index 1d2d43e5..0bcd9bac 100644 --- a/include/fkYAML/detail/meta/type_traits.hpp +++ b/include/fkYAML/detail/meta/type_traits.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/node_property.hpp b/include/fkYAML/detail/node_property.hpp index f17d98e2..44812b81 100644 --- a/include/fkYAML/detail/node_property.hpp +++ b/include/fkYAML/detail/node_property.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp index 98316bda..624bdd6f 100644 --- a/include/fkYAML/detail/node_ref_storage.hpp +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/output/serializer.hpp b/include/fkYAML/detail/output/serializer.hpp index 44b05d5e..985177c6 100644 --- a/include/fkYAML/detail/output/serializer.hpp +++ b/include/fkYAML/detail/output/serializer.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -42,16 +42,48 @@ class basic_serializer { /// @return std::string A serialization result of the given Node value. std::string serialize(const BasicNodeType& node) { std::string str {}; - serialize_directives(node, str); - serialize_node(node, 0, str); + serialize_document(node, str); + return str; + } // LCOV_EXCL_LINE + + std::string serialize_docs(const std::vector& docs) { + std::string str {}; + + uint32_t size = static_cast(docs.size()); + for (uint32_t i = 0; i < size; i++) { + serialize_document(docs[i], str); + if (i + 1 < size) { + // Append the end-of-document marker for the next document. + str += "...\n"; + } + } + return str; } // LCOV_EXCL_LINE private: + void serialize_document(const BasicNodeType& node, std::string& str) { + bool dirs_serialized = serialize_directives(node, str); + + // the root node cannot be an alias node. + bool root_has_props = node.is_anchor() || node.has_tag_name(); + + if (root_has_props) { + if (dirs_serialized) { + str.back() = ' '; // replace the last LF with a white space + } + bool is_anchor_appended = try_append_anchor(node, false, str); + try_append_tag(node, is_anchor_appended, str); + str += "\n"; + } + serialize_node(node, 0, str); + } + /// @brief Serialize the directives if any is applied to the node. /// @param node The targe node. /// @param str A string to hold serialization result. - void serialize_directives(const BasicNodeType& node, std::string& str) { + /// @return bool true if any directive is serialized, false otherwise. + bool serialize_directives(const BasicNodeType& node, std::string& str) { const auto& p_meta = node.mp_meta; bool needs_directive_end = false; @@ -96,6 +128,8 @@ class basic_serializer { if (needs_directive_end) { str += "---\n"; } + + return needs_directive_end; } /// @brief Recursively serialize each Node object. @@ -135,7 +169,11 @@ class basic_serializer { insert_indentation(cur_indent, str); bool is_appended = try_append_alias(itr.key(), false, str); - if (!is_appended) { + if (is_appended) { + // The trailing white space is necessary since anchor names can contain a colon (:) at its end. + str += " "; + } + else { bool is_anchor_appended = try_append_anchor(itr.key(), false, str); bool is_tag_appended = try_append_tag(itr.key(), is_anchor_appended, str); if (is_anchor_appended || is_tag_appended) { diff --git a/include/fkYAML/detail/string_formatter.hpp b/include/fkYAML/detail/string_formatter.hpp index 16527166..e08724d4 100644 --- a/include/fkYAML/detail/string_formatter.hpp +++ b/include/fkYAML/detail/string_formatter.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/types/lexical_token_t.hpp b/include/fkYAML/detail/types/lexical_token_t.hpp index 7976e80c..07661ace 100644 --- a/include/fkYAML/detail/types/lexical_token_t.hpp +++ b/include/fkYAML/detail/types/lexical_token_t.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/types/node_t.hpp b/include/fkYAML/detail/types/node_t.hpp index 8b8aacef..7e300258 100644 --- a/include/fkYAML/detail/types/node_t.hpp +++ b/include/fkYAML/detail/types/node_t.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/detail/types/yaml_version_t.hpp b/include/fkYAML/detail/types/yaml_version_t.hpp index 43a5e4d9..e9e0fd9e 100644 --- a/include/fkYAML/detail/types/yaml_version_t.hpp +++ b/include/fkYAML/detail/types/yaml_version_t.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/exception.hpp b/include/fkYAML/exception.hpp index 2b44a7e0..db381916 100644 --- a/include/fkYAML/exception.hpp +++ b/include/fkYAML/exception.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index b40604ba..3b180667 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -401,7 +401,7 @@ class basic_node { } public: - /// @brief Deserialize an input source into a basic_node object. + /// @brief Deserialize the first YAML document in the input into a basic_node object. /// @tparam InputType Type of a compatible input. /// @param[in] input An input source in the YAML format. /// @return The resulting basic_node object deserialized from the input source. @@ -411,7 +411,7 @@ class basic_node { return deserializer_type().deserialize(detail::input_adapter(std::forward(input))); } - /// @brief Deserialize input iterators into a basic_node object. + /// @brief Deserialize the first YAML document in the input ranged by the iterators into a basic_node object. /// @tparam ItrType Type of a compatible iterator. /// @param[in] begin An iterator to the first element of an input sequence. /// @param[in] end An iterator to the past-the-last element of an input sequence. @@ -423,14 +423,44 @@ class basic_node { detail::input_adapter(std::forward(begin), std::forward(end))); } + /// @brief Deserialize all YAML documents in the input into basic_node objects. + /// @tparam InputType Type of a compatible input. + /// @param[in] input An input source in the YAML format. + /// @return The resulting basic_node objects deserialized from the input. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize_docs/ + template + static std::vector deserialize_docs(InputType&& input) { + return deserializer_type().deserialize_docs(detail::input_adapter(std::forward(input))); + } + + /// @brief Deserialize all YAML documents in the input ranged by the iterators into basic_node objects. + /// @tparam ItrType Type of a compatible iterator. + /// @param[in] begin An iterator to the first element of an input sequence. + /// @param[in] end An iterator to the past-the-last element of an input sequence. + /// @return The resulting basic_node objects deserialized from the pair of iterators. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize_docs/ + template + static std::vector deserialize_docs(ItrType&& begin, ItrType&& end) { + return deserializer_type().deserialize_docs( + detail::input_adapter(std::forward(begin), std::forward(end))); + } + /// @brief Serialize a basic_node object into a string. /// @param[in] node A basic_node object to be serialized. - /// @return The resulting string object from the serialization of the node object. + /// @return The resulting string object from the serialization of the given node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize/ static std::string serialize(const basic_node& node) { return serializer_type().serialize(node); } + /// @brief Serialize basic_node objects into a string. + /// @param docs basic_node objects to be serialized. + /// @return The resulting string object from the serialization of the given nodes. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize_docs/ + static std::string serialize_docs(const std::vector& docs) { + return serializer_type().serialize_docs(docs); + } + /// @brief A factory method for sequence basic_node objects without sequence_type objects. /// @return A YAML sequence node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ diff --git a/include/fkYAML/node_value_converter.hpp b/include/fkYAML/node_value_converter.hpp index e9ccc958..21391b77 100644 --- a/include/fkYAML/node_value_converter.hpp +++ b/include/fkYAML/node_value_converter.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/include/fkYAML/ordered_map.hpp b/include/fkYAML/ordered_map.hpp index b6d9d6b2..cd31af0c 100644 --- a/include/fkYAML/ordered_map.hpp +++ b/include/fkYAML/ordered_map.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/single_include/fkYAML/node.hpp b/single_include/fkYAML/node.hpp index bec30513..cdb2df73 100644 --- a/single_include/fkYAML/node.hpp +++ b/single_include/fkYAML/node.hpp @@ -1,6 +1,6 @@ /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -24,7 +24,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -34,7 +34,7 @@ // Check version definitions if already defined. #if defined(FK_YAML_MAJOR_VERSION) && defined(FK_YAML_MINOR_VERSION) && defined(FK_YAML_PATCH_VERSION) -#if FK_YAML_MAJOR_VERSION != 0 || FK_YAML_MINOR_VERSION != 3 || FK_YAML_PATCH_VERSION != 9 +#if FK_YAML_MAJOR_VERSION != 0 || FK_YAML_MINOR_VERSION != 3 || FK_YAML_PATCH_VERSION != 10 #warning Already included a different version of the fkYAML library! #else // define macros to skip defining macros down below. @@ -46,7 +46,7 @@ #define FK_YAML_MAJOR_VERSION 0 #define FK_YAML_MINOR_VERSION 3 -#define FK_YAML_PATCH_VERSION 9 +#define FK_YAML_PATCH_VERSION 10 #define FK_YAML_NAMESPACE_VERSION_CONCAT_IMPL(major, minor, patch) v##major##_##minor##_##patch @@ -74,7 +74,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -138,7 +138,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -164,7 +164,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -183,7 +183,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -199,7 +199,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -217,7 +217,7 @@ // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -465,7 +465,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -777,7 +777,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -832,7 +832,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -847,6 +847,7 @@ FK_YAML_DETAIL_NAMESPACE_END #include #include #include +#include // #include @@ -855,7 +856,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -881,7 +882,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -907,7 +908,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -928,7 +929,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -977,7 +978,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -1415,7 +1416,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -1545,7 +1546,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -1838,7 +1839,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -2189,7 +2190,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -2210,7 +2211,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -2487,7 +2488,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -2508,7 +2509,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -3984,7 +3985,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -4008,7 +4009,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -4212,7 +4213,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -4309,6 +4310,19 @@ class basic_deserializer { p_node(_p_node) { } + ~parse_context() { + switch (state) { + case context_state_t::BLOCK_MAPPING_EXPLICIT_KEY: + case context_state_t::FLOW_SEQUENCE_KEY: + case context_state_t::FLOW_MAPPING_KEY: + delete p_node; + p_node = nullptr; + break; + default: + break; + } + } + /// The current line. (count from zero) uint32_t line {0}; /// The indentation width in the current line. (count from zero) @@ -4319,17 +4333,55 @@ class basic_deserializer { node_type* p_node {nullptr}; }; + /// @brief Definitions of state types for expected flow token hints. + enum class flow_token_state_t { + NEEDS_VALUE_OR_SUFFIX, //!< Either value or flow suffix (`]` or `}`) + NEEDS_SEPARATOR_OR_SUFFIX, //!< Either separator (`,`) or flow suffix (`]` or `}`) + }; + public: /// @brief Construct a new basic_deserializer object. basic_deserializer() = default; public: - /// @brief Deserialize a YAML-formatted source string into a YAML node. - /// @param input_adapter An adapter object for the input source buffer. - /// @return node_type A root YAML node object deserialized from the source string. + /// @brief Deserialize a single YAML document into a YAML node. + /// @note + /// If the input consists of multiple YAML documents, this function only parses the first. + /// If the input may have multiple YAML documents all of which must be parsed into nodes, + /// prefer the `deserialize_docs()` function. + /// @tparam InputAdapterType The type of an input adapter object. + /// @param input_adapter An input adapter object for the input source buffer. + /// @return node_type A root YAML node deserialized from the source string. template ::value, int> = 0> node_type deserialize(InputAdapterType&& input_adapter) { + lexical_token_t type {lexical_token_t::END_OF_BUFFER}; + lexer_type lexer(std::forward(input_adapter)); + return deserialize_document(lexer, type); + } + + /// @brief Deserialize multiple YAML documents into YAML nodes. + /// @tparam InputAdapterType The type of an adapter object. + /// @param input_adapter An input adapter object for the input source buffer. + /// @return std::vector Root YAML nodes for deserialized YAML documents. + template ::value, int> = 0> + std::vector deserialize_docs(InputAdapterType&& input_adapter) { lexer_type lexer(std::forward(input_adapter)); + std::vector nodes {}; + lexical_token_t type {lexical_token_t::END_OF_BUFFER}; + + do { + nodes.emplace_back(deserialize_document(lexer, type)); + } while (type != lexical_token_t::END_OF_BUFFER); + + return nodes; + } + +private: + /// @brief Deserialize a YAML document into a YAML node. + /// @param lexer The lexical analyzer to be used. + /// @param last_type The variable to store the last lexical token type. + /// @return node_type A root YAML node deserialized from the YAML document. + node_type deserialize_document(lexer_type& lexer, lexical_token_t& last_type) { lexical_token_t type {lexical_token_t::END_OF_BUFFER}; node_type root; @@ -4338,10 +4390,20 @@ class basic_deserializer { // parse directives first. deserialize_directives(lexer, type); + // parse node properties for root node if any + uint32_t line = lexer.get_lines_processed(); + uint32_t indent = lexer.get_last_token_begin_pos(); + bool found_props = deserialize_node_properties(lexer, type, line, indent); + switch (type) { case lexical_token_t::SEQUENCE_BLOCK_PREFIX: { root = node_type::sequence(); apply_directive_set(root); + if (found_props) { + // If node properties are found before the block sequence entry prefix, the properties belong to the + // root sequence node. + apply_node_properties(root); + } parse_context context( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::BLOCK_SEQUENCE, &root); m_context_stack.emplace_back(std::move(context)); @@ -4352,6 +4414,7 @@ class basic_deserializer { ++m_flow_context_depth; root = node_type::sequence(); apply_directive_set(root); + apply_node_properties(root); m_context_stack.emplace_back( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::FLOW_SEQUENCE, &root); type = lexer.get_next_token(); @@ -4360,6 +4423,7 @@ class basic_deserializer { ++m_flow_context_depth; root = node_type::mapping(); apply_directive_set(root); + apply_node_properties(root); m_context_stack.emplace_back( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::FLOW_MAPPING, &root); type = lexer.get_next_token(); @@ -4367,6 +4431,11 @@ class basic_deserializer { default: { root = node_type::mapping(); apply_directive_set(root); + if (found_props && line < lexer.get_lines_processed()) { + // If node properties and a followed node are on the different line, the properties belong to the root + // node. + apply_node_properties(root); + } parse_context context( lexer.get_lines_processed(), lexer.get_last_token_begin_pos(), context_state_t::BLOCK_MAPPING, &root); m_context_stack.emplace_back(std::move(context)); @@ -4377,23 +4446,27 @@ class basic_deserializer { mp_current_node = &root; // parse YAML nodes recursively - deserialize_node(lexer, type); + deserialize_node(lexer, type, last_type); + FK_YAML_ASSERT(last_type == lexical_token_t::END_OF_BUFFER || last_type == lexical_token_t::END_OF_DOCUMENT); // reset parameters for the next call. mp_current_node = nullptr; mp_meta.reset(); m_needs_tag_impl = false; m_needs_anchor_impl = false; + m_flow_context_depth = 0; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; m_context_stack.clear(); return root; } -private: /// @brief Deserializes the YAML directives if specified. /// @param lexer The lexical analyzer to be used. /// @param last_type The variable to store the last lexical token type. void deserialize_directives(lexer_type& lexer, lexical_token_t& last_type) { + bool lacks_end_of_directives_marker = false; + for (;;) { lexical_token_t type = lexer.get_next_token(); @@ -4408,6 +4481,7 @@ class basic_deserializer { mp_meta->version = convert_yaml_version(lexer.get_yaml_version()); mp_meta->is_version_specified = true; + lacks_end_of_directives_marker = true; break; case lexical_token_t::TAG_DIRECTIVE: { const std::string& tag_handle = lexer.get_tag_handle(); @@ -4421,6 +4495,7 @@ class basic_deserializer { lexer.get_last_token_begin_pos()); } mp_meta->primary_handle_prefix = lexer.get_tag_prefix(); + lacks_end_of_directives_marker = true; break; } case 2: { @@ -4432,6 +4507,7 @@ class basic_deserializer { lexer.get_last_token_begin_pos()); } mp_meta->secondary_handle_prefix = lexer.get_tag_prefix(); + lacks_end_of_directives_marker = true; break; } default: { @@ -4443,6 +4519,7 @@ class basic_deserializer { lexer.get_lines_processed(), lexer.get_last_token_begin_pos()); } + lacks_end_of_directives_marker = true; break; } } @@ -4452,9 +4529,15 @@ class basic_deserializer { // TODO: should output a warning log. Currently just ignore this case. break; case lexical_token_t::END_OF_DIRECTIVES: - // Ignore this directives end marker so the caller will get the beginning token of the contents. + lacks_end_of_directives_marker = false; break; default: + if (lacks_end_of_directives_marker) { + throw parse_error( + "The end of directives marker (---) is missing after directives.", + lexer.get_lines_processed(), + lexer.get_last_token_begin_pos()); + } // end the parsing of directives if the other tokens are found. last_type = type; return; @@ -4465,16 +4548,13 @@ class basic_deserializer { /// @brief Deserializes the YAML nodes recursively. /// @param lexer The lexical analyzer to be used. /// @param first_type The first lexical token type. - void deserialize_node(lexer_type& lexer, lexical_token_t first_type) { + void deserialize_node(lexer_type& lexer, lexical_token_t first_type, lexical_token_t& last_type) { lexical_token_t type = first_type; uint32_t line = lexer.get_lines_processed(); uint32_t indent = lexer.get_last_token_begin_pos(); do { switch (type) { - case lexical_token_t::END_OF_BUFFER: - // This handles an empty input. - break; case lexical_token_t::EXPLICIT_KEY_PREFIX: { uint32_t pop_num = 0; if (indent == 0) { @@ -4579,7 +4659,7 @@ class basic_deserializer { if (line > old_line) { if (m_needs_tag_impl) { tag_t tag_type = tag_resolver_type::resolve_tag(m_tag_name, mp_meta); - if (tag_type == tag_t::MAPPING) { + if (tag_type == tag_t::MAPPING || tag_type == tag_t::CUSTOM_TAG) { // set YAML node properties here to distinguish them from those for the first key node // as shown in the following snippet: // @@ -4592,6 +4672,7 @@ class basic_deserializer { *mp_current_node = node_type::mapping(); apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); continue; } } @@ -4605,7 +4686,40 @@ class basic_deserializer { cur_context.line = line; cur_context.indent = indent; cur_context.state = context_state_t::BLOCK_SEQUENCE; - break; + + type = lexer.get_next_token(); + line = lexer.get_lines_processed(); + indent = lexer.get_last_token_begin_pos(); + + bool has_props = deserialize_node_properties(lexer, type, line, indent); + if (has_props) { + uint32_t line_after_props = lexer.get_lines_processed(); + if (line == line_after_props) { + // Skip updating the current indent to avoid stacking a wrong indentation. + // + // ```yaml + // &foo bar: baz + // ^ + // the correct indent width for the "bar" node key. + // ``` + continue; + } + + // if node properties and the followed node are on different lines (i.e., the properties are + // for a container node), the application and the line advancement must happen here. + // Otherwise, a false indent error will be emitted. See + // https://github.com/fktn-k/fkYAML/issues/368 for more details. + line = line_after_props; + indent = lexer.get_last_token_begin_pos(); + mp_current_node->template get_value_ref().emplace_back( + node_type::mapping()); + mp_current_node = &mp_current_node->template get_value_ref().back(); + m_context_stack.emplace_back( + line_after_props, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + apply_node_properties(*mp_current_node); + } + + continue; } // defer checking the existence of a key separator after the following scalar until the next @@ -4619,14 +4733,12 @@ class basic_deserializer { m_context_stack.pop_back(); } - node_type* key_node = m_context_stack.back().p_node; + node_type key_node = std::move(*m_context_stack.back().p_node); m_context_stack.pop_back(); - m_context_stack.back().p_node->template get_value_ref().emplace(*key_node, node_type()); - mp_current_node = &(m_context_stack.back().p_node->operator[](*key_node)); + m_context_stack.back().p_node->template get_value_ref().emplace(key_node, node_type()); + mp_current_node = &(m_context_stack.back().p_node->operator[](std::move(key_node))); m_context_stack.emplace_back( line, indent, context_state_t::BLOCK_MAPPING_EXPLICIT_VALUE, mp_current_node); - delete key_node; - key_node = nullptr; if (type == lexical_token_t::SEQUENCE_BLOCK_PREFIX) { *mp_current_node = node_type::sequence(); @@ -4646,13 +4758,15 @@ class basic_deserializer { case lexical_token_t::ANCHOR_PREFIX: case lexical_token_t::TAG_PREFIX: deserialize_node_properties(lexer, type, line, indent); - // Skip updating the current indent to avoid stacking a wrong indentation. + // Note that node properties for block sequences as a mapping value are processed when a + // `lexical_token_t::KEY_SEPARATOR` token is processed. // - // &foo bar: baz - // ^ - // the correct indent width for the "bar" node key. - + // ```yaml + // &foo bar: baz + // ^ + // the correct indent width for the "bar" node key. + // ``` continue; case lexical_token_t::SEQUENCE_BLOCK_PREFIX: { bool is_further_nested = m_context_stack.back().indent < indent; @@ -4711,6 +4825,9 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } + else if (m_flow_token_state == flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { + throw parse_error("Flow sequence begininng is found without separated with a comma.", line, indent); + } ++m_flow_context_depth; @@ -4741,20 +4858,12 @@ class basic_deserializer { apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); - type = lexer.get_next_token(); - if (type == lexical_token_t::SEQUENCE_FLOW_END) { - // enable the flag for the next loop for the empty flow sequence. - m_needs_value_separator_or_suffix = true; - } - line = lexer.get_lines_processed(); - indent = lexer.get_last_token_begin_pos(); - continue; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + break; case lexical_token_t::SEQUENCE_FLOW_END: { - if (!m_needs_value_separator_or_suffix) { - throw parse_error("invalid flow sequence ending is found.", line, indent); + if (m_flow_context_depth == 0) { + throw parse_error("Flow sequence ending is found outside the flow context.", line, indent); } - m_needs_value_separator_or_suffix = false; - --m_flow_context_depth; // find the corresponding flow sequence beginning. @@ -4773,12 +4882,13 @@ class basic_deserializer { bool is_valid = itr != m_context_stack.rend(); if (!is_valid) { - throw parse_error("invalid flow sequence ending is found.", line, indent); + throw parse_error("No corresponding flow sequence beginning is found.", line, indent); } // keep the last state for later processing. parse_context& last_context = m_context_stack.back(); mp_current_node = last_context.p_node; + last_context.p_node = nullptr; indent = last_context.indent; context_state_t state = last_context.state; m_context_stack.pop_back(); @@ -4789,6 +4899,7 @@ class basic_deserializer { node_type key_node = std::move(*mp_current_node); delete mp_current_node; mp_current_node = m_context_stack.back().p_node; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; add_new_key(std::move(key_node), line, indent); break; @@ -4799,7 +4910,10 @@ class basic_deserializer { node_type key_node = node_type::mapping(); apply_directive_set(key_node); mp_current_node->swap(key_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + add_new_key(std::move(key_node), line, indent); } else { @@ -4807,7 +4921,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } @@ -4853,6 +4967,9 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } + else if (m_flow_token_state == flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { + throw parse_error("Flow mapping begininng is found without separated with a comma.", line, indent); + } ++m_flow_context_depth; @@ -4883,20 +5000,15 @@ class basic_deserializer { apply_directive_set(*mp_current_node); apply_node_properties(*mp_current_node); - type = lexer.get_next_token(); - if (type == lexical_token_t::MAPPING_FLOW_END) { - // enable the flag for the next loop for the empty flow mapping. - m_needs_value_separator_or_suffix = true; - } line = lexer.get_lines_processed(); indent = lexer.get_last_token_begin_pos(); - continue; + + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + break; case lexical_token_t::MAPPING_FLOW_END: { - if (!m_needs_value_separator_or_suffix) { - throw parse_error("invalid flow mapping ending is found.", line, indent); + if (m_flow_context_depth == 0) { + throw parse_error("Flow mapping ending is found outside the flow context.", line, indent); } - m_needs_value_separator_or_suffix = false; - --m_flow_context_depth; // find the corresponding flow mapping beginning. @@ -4915,12 +5027,13 @@ class basic_deserializer { bool is_valid = itr != m_context_stack.rend(); if (!is_valid) { - throw parse_error("invalid flow mapping ending is found.", line, indent); + throw parse_error("No corresponding flow mapping beginning is found.", line, indent); } // keep the last state for later processing. parse_context& last_context = m_context_stack.back(); mp_current_node = last_context.p_node; + last_context.p_node = nullptr; indent = last_context.indent; context_state_t state = last_context.state; m_context_stack.pop_back(); @@ -4931,6 +5044,7 @@ class basic_deserializer { node_type key_node = std::move(*mp_current_node); delete mp_current_node; mp_current_node = m_context_stack.back().p_node; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; add_new_key(std::move(key_node), line, indent); break; @@ -4939,8 +5053,12 @@ class basic_deserializer { type = lexer.get_next_token(); if (type == lexical_token_t::KEY_SEPARATOR) { node_type key_node = node_type::mapping(); + apply_directive_set(key_node); mp_current_node->swap(key_node); + m_context_stack.emplace_back(line, indent, context_state_t::BLOCK_MAPPING, mp_current_node); + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; + add_new_key(std::move(key_node), line, indent); } else { @@ -4948,7 +5066,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } @@ -4958,10 +5076,10 @@ class basic_deserializer { } case lexical_token_t::VALUE_SEPARATOR: FK_YAML_ASSERT(m_flow_context_depth > 0); - if (!m_needs_value_separator_or_suffix) { + if (m_flow_token_state != flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX) { throw parse_error("invalid value separator is found.", line, indent); } - m_needs_value_separator_or_suffix = false; + m_flow_token_state = flow_token_state_t::NEEDS_VALUE_OR_SUFFIX; break; case lexical_token_t::ALIAS_PREFIX: case lexical_token_t::NULL_VALUE: @@ -4976,15 +5094,21 @@ class basic_deserializer { break; } case lexical_token_t::END_OF_DIRECTIVES: + throw parse_error("invalid end-of-directives marker (---) found in the contents.", line, indent); + case lexical_token_t::END_OF_BUFFER: + // This handles an empty input. case lexical_token_t::END_OF_DOCUMENT: // TODO: This token should be handled to support multiple documents. - break; + last_type = type; + return; } type = lexer.get_next_token(); indent = lexer.get_last_token_begin_pos(); line = lexer.get_lines_processed(); } while (type != lexical_token_t::END_OF_BUFFER); + + last_type = type; } /// @brief Deserializes YAML node properties (anchor and/or tag names) if they exist @@ -5070,17 +5194,8 @@ class basic_deserializer { else if (indent < m_context_stack.back().indent) { auto target_itr = std::find_if(m_context_stack.rbegin(), m_context_stack.rend(), [indent](const parse_context& c) { - if (indent != c.indent) { - return false; - } - - switch (c.state) { - case context_state_t::BLOCK_MAPPING: - case context_state_t::MAPPING_VALUE: - return true; - default: - return false; - } + // the target node is a block mapping key node with the same indentation. + return (indent == c.indent) && (c.state == context_state_t::BLOCK_MAPPING); }); bool is_indent_valid = (target_itr != m_context_stack.rend()); if (!is_indent_valid) { @@ -5097,8 +5212,8 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; } } - else if (m_needs_value_separator_or_suffix) { - throw parse_error("flow mapping entry is found without separated with a comma.", line, indent); + else if (m_flow_token_state != flow_token_state_t::NEEDS_VALUE_OR_SUFFIX) { + throw parse_error("Flow mapping entry is found without separated with a comma.", line, indent); } if (mp_current_node->is_sequence()) { @@ -5123,10 +5238,10 @@ class basic_deserializer { void assign_node_value(node_type&& node_value, const uint32_t line, const uint32_t indent) { if (mp_current_node->is_sequence()) { if (m_flow_context_depth > 0) { - if (m_needs_value_separator_or_suffix) { + if (m_flow_token_state != flow_token_state_t::NEEDS_VALUE_OR_SUFFIX) { throw parse_error("flow sequence entry is found without separated with a comma.", line, indent); } - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } mp_current_node->template get_value_ref().emplace_back(std::move(node_value)); @@ -5140,7 +5255,7 @@ class basic_deserializer { mp_current_node = m_context_stack.back().p_node; if (m_flow_context_depth > 0) { - m_needs_value_separator_or_suffix = true; + m_flow_token_state = flow_token_state_t::NEEDS_SEPARATOR_OR_SUFFIX; } } } @@ -5336,8 +5451,8 @@ class basic_deserializer { bool m_needs_anchor_impl {false}; /// A flag to determine the need for a corresponding node with the last YAML tag. bool m_needs_tag_impl {false}; - /// A flag to determine the need for a value separator or a flow suffix to be follow. - bool m_needs_value_separator_or_suffix {false}; + /// A flag to determine the need for a value separator or a flow suffix to follow. + flow_token_state_t m_flow_token_state {flow_token_state_t::NEEDS_VALUE_OR_SUFFIX}; /// The last YAML anchor name. string_type m_anchor_name {}; /// The last tag name. @@ -5351,7 +5466,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -5376,7 +5491,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -5395,7 +5510,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -6573,7 +6688,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -6980,7 +7095,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -7073,7 +7188,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -7093,7 +7208,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -7214,16 +7329,48 @@ class basic_serializer { /// @return std::string A serialization result of the given Node value. std::string serialize(const BasicNodeType& node) { std::string str {}; - serialize_directives(node, str); - serialize_node(node, 0, str); + serialize_document(node, str); + return str; + } // LCOV_EXCL_LINE + + std::string serialize_docs(const std::vector& docs) { + std::string str {}; + + uint32_t size = static_cast(docs.size()); + for (uint32_t i = 0; i < size; i++) { + serialize_document(docs[i], str); + if (i + 1 < size) { + // Append the end-of-document marker for the next document. + str += "...\n"; + } + } + return str; } // LCOV_EXCL_LINE private: + void serialize_document(const BasicNodeType& node, std::string& str) { + bool dirs_serialized = serialize_directives(node, str); + + // the root node cannot be an alias node. + bool root_has_props = node.is_anchor() || node.has_tag_name(); + + if (root_has_props) { + if (dirs_serialized) { + str.back() = ' '; // replace the last LF with a white space + } + bool is_anchor_appended = try_append_anchor(node, false, str); + try_append_tag(node, is_anchor_appended, str); + str += "\n"; + } + serialize_node(node, 0, str); + } + /// @brief Serialize the directives if any is applied to the node. /// @param node The targe node. /// @param str A string to hold serialization result. - void serialize_directives(const BasicNodeType& node, std::string& str) { + /// @return bool true if any directive is serialized, false otherwise. + bool serialize_directives(const BasicNodeType& node, std::string& str) { const auto& p_meta = node.mp_meta; bool needs_directive_end = false; @@ -7268,6 +7415,8 @@ class basic_serializer { if (needs_directive_end) { str += "---\n"; } + + return needs_directive_end; } /// @brief Recursively serialize each Node object. @@ -7307,7 +7456,11 @@ class basic_serializer { insert_indentation(cur_indent, str); bool is_appended = try_append_alias(itr.key(), false, str); - if (!is_appended) { + if (is_appended) { + // The trailing white space is necessary since anchor names can contain a colon (:) at its end. + str += " "; + } + else { bool is_anchor_appended = try_append_anchor(itr.key(), false, str); bool is_tag_appended = try_append_tag(itr.key(), is_anchor_appended, str); if (is_anchor_appended || is_tag_appended) { @@ -7496,7 +7649,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -7514,7 +7667,7 @@ FK_YAML_DETAIL_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -7718,7 +7871,7 @@ inline void from_node(const BasicNodeType& n, FloatType& f) { } auto tmp_float = n.template get_value_ref(); - if (tmp_float < std::numeric_limits::min()) { + if (tmp_float < std::numeric_limits::lowest()) { throw exception("Floating point value underflow detected."); } if (std::numeric_limits::max() < tmp_float) { @@ -7804,7 +7957,7 @@ FK_YAML_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -8192,7 +8345,7 @@ FK_YAML_NAMESPACE_END // #include /// _______ __ __ __ _____ __ __ __ /// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library -/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 /// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML /// /// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -8734,7 +8887,7 @@ class basic_node { } public: - /// @brief Deserialize an input source into a basic_node object. + /// @brief Deserialize the first YAML document in the input into a basic_node object. /// @tparam InputType Type of a compatible input. /// @param[in] input An input source in the YAML format. /// @return The resulting basic_node object deserialized from the input source. @@ -8744,7 +8897,7 @@ class basic_node { return deserializer_type().deserialize(detail::input_adapter(std::forward(input))); } - /// @brief Deserialize input iterators into a basic_node object. + /// @brief Deserialize the first YAML document in the input ranged by the iterators into a basic_node object. /// @tparam ItrType Type of a compatible iterator. /// @param[in] begin An iterator to the first element of an input sequence. /// @param[in] end An iterator to the past-the-last element of an input sequence. @@ -8756,14 +8909,44 @@ class basic_node { detail::input_adapter(std::forward(begin), std::forward(end))); } + /// @brief Deserialize all YAML documents in the input into basic_node objects. + /// @tparam InputType Type of a compatible input. + /// @param[in] input An input source in the YAML format. + /// @return The resulting basic_node objects deserialized from the input. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize_docs/ + template + static std::vector deserialize_docs(InputType&& input) { + return deserializer_type().deserialize_docs(detail::input_adapter(std::forward(input))); + } + + /// @brief Deserialize all YAML documents in the input ranged by the iterators into basic_node objects. + /// @tparam ItrType Type of a compatible iterator. + /// @param[in] begin An iterator to the first element of an input sequence. + /// @param[in] end An iterator to the past-the-last element of an input sequence. + /// @return The resulting basic_node objects deserialized from the pair of iterators. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize_docs/ + template + static std::vector deserialize_docs(ItrType&& begin, ItrType&& end) { + return deserializer_type().deserialize_docs( + detail::input_adapter(std::forward(begin), std::forward(end))); + } + /// @brief Serialize a basic_node object into a string. /// @param[in] node A basic_node object to be serialized. - /// @return The resulting string object from the serialization of the node object. + /// @return The resulting string object from the serialization of the given node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize/ static std::string serialize(const basic_node& node) { return serializer_type().serialize(node); } + /// @brief Serialize basic_node objects into a string. + /// @param docs basic_node objects to be serialized. + /// @return The resulting string object from the serialization of the given nodes. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize_docs/ + static std::string serialize_docs(const std::vector& docs) { + return serializer_type().serialize_docs(docs); + } + /// @brief A factory method for sequence basic_node objects without sequence_type objects. /// @return A YAML sequence node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ diff --git a/test/cmake_add_subdirectory_test/project/main.cpp b/test/cmake_add_subdirectory_test/project/main.cpp index 0a54a896..80a7c651 100644 --- a/test/cmake_add_subdirectory_test/project/main.cpp +++ b/test/cmake_add_subdirectory_test/project/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/cmake_fetch_content_test/project/CMakeLists.txt b/test/cmake_fetch_content_test/project/CMakeLists.txt index a706efb3..f28498f9 100644 --- a/test/cmake_fetch_content_test/project/CMakeLists.txt +++ b/test/cmake_fetch_content_test/project/CMakeLists.txt @@ -6,7 +6,7 @@ include(FetchContent) FetchContent_Declare( fkYAML GIT_REPOSITORY https://github.com/fktn-k/fkYAML.git - GIT_TAG v0.3.9) + GIT_TAG v0.3.10) FetchContent_MakeAvailable(fkYAML) add_executable( diff --git a/test/cmake_fetch_content_test/project/main.cpp b/test/cmake_fetch_content_test/project/main.cpp index 0a54a896..80a7c651 100644 --- a/test/cmake_fetch_content_test/project/main.cpp +++ b/test/cmake_fetch_content_test/project/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/cmake_find_package_test/project/main.cpp b/test/cmake_find_package_test/project/main.cpp index 0a54a896..80a7c651 100644 --- a/test/cmake_find_package_test/project/main.cpp +++ b/test/cmake_find_package_test/project/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/cmake_target_include_directories_test/project/main.cpp b/test/cmake_target_include_directories_test/project/main.cpp index 0a54a896..80a7c651 100644 --- a/test/cmake_target_include_directories_test/project/main.cpp +++ b/test/cmake_target_include_directories_test/project/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 734a4114..8d122890 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -123,6 +123,24 @@ target_compile_options( -Wall -Wextra -Werror -pedantic -Wno-c++98-compat -Wno-c++98-compat-pedantic > + # IntelLLVM + $<$: + # IntelLLVM warns the usage of nans and infinities due to its over-estimation. + # fkYAML, however, uses them as YAML node values, not as calculation. + # To disable too aggressive warnings, `-fp-model=precise` is used in the test as a workaround. + -fp-model=precise + $<$:-O0 -g> + $<$:-O2> + > +) + +target_link_options( + unit_test_config + INTERFACE + $<$: + $<$:-O0 -g> + $<$:-O2> + > ) # additional compile options for Clang Sanitizers. diff --git a/test/unit_test/main.cpp b/test/unit_test/main.cpp index ee4f319e..fba12d83 100644 --- a/test/unit_test/main.cpp +++ b/test/unit_test/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_custom_from_node.cpp b/test/unit_test/test_custom_from_node.cpp index de46764b..997b8d4e 100644 --- a/test/unit_test/test_custom_from_node.cpp +++ b/test/unit_test/test_custom_from_node.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_deserializer_class.cpp b/test/unit_test/test_deserializer_class.cpp index 260bfa8b..98486883 100644 --- a/test/unit_test/test_deserializer_class.cpp +++ b/test/unit_test/test_deserializer_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -540,9 +540,11 @@ TEST_CASE("Deserializer_BlockMapping") { } SECTION("nested block mapping") { - REQUIRE_NOTHROW( - root = - deserializer.deserialize(fkyaml::detail::input_adapter("test:\n bool: true\n foo: bar\n pi: 3.14"))); + std::string input = "test:\n" + " bool: true\n" + " foo: bar\n" + " pi: 3.14"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); REQUIRE(root.is_mapping()); REQUIRE_NOTHROW(root.size()); @@ -1386,7 +1388,7 @@ TEST_CASE("Deserializer_FlowSequence") { } SECTION("lack the beginning of a flow sequence") { - auto input = GENERATE(std::string("test: {]}"), std::string("test: {foo: bar]}")); + auto input = GENERATE(std::string("test: {]}"), std::string("test: {foo: bar]}"), std::string("test: bar ]")); REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); } @@ -1412,12 +1414,12 @@ TEST_CASE("Deserializer_FlowSequence") { std::string input = "[\n" " [\n" " \"a\",\n" - " \"b\"\n" + " \"b\",\n" " ],\n" " [\n" " 123,\n" - " true\n" - " ]\n" + " true,\n" + " ],\n" "]"; REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); @@ -1453,12 +1455,12 @@ TEST_CASE("Deserializer_FlowSequence") { std::string input = "[\n" " {\n" " true: 1.23,\n" - " null: 123\n" + " null: 123,\n" " },\n" " {\n" " \"a\": foo,\n" - " \"b\": bar\n" - " }\n" + " \"b\": bar,\n" + " },\n" "]"; REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); @@ -1498,9 +1500,9 @@ TEST_CASE("Deserializer_FlowSequence") { auto input = GENERATE( std::string("[123 true, 3.14]"), std::string("[123, true 3.14]"), - std::string("[123 [true, 3.14]]"), + // std::string("[123 [true, 3.14]]"), std::string("[123, [true 3.14]]"), - std::string("[123 {foo: true, bar: 3.14}]"), + // std::string("[123 {foo: true, bar: 3.14}]"), std::string("[123, {foo: true bar: 3.14}]")); REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); } @@ -1529,8 +1531,8 @@ TEST_CASE("Deserializer_FlowMapping") { fkyaml::node root; SECTION("simple flow mapping") { - REQUIRE_NOTHROW( - root = deserializer.deserialize(fkyaml::detail::input_adapter("test: { bool: true, foo: bar, pi: 3.14 }"))); + std::string input = "test: { bool: true, foo: bar, pi: 3.14 }"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); REQUIRE(root.is_mapping()); REQUIRE_NOTHROW(root.size()); @@ -1582,7 +1584,7 @@ TEST_CASE("Deserializer_FlowMapping") { } SECTION("lack the beginning of a flow mapping") { - auto input = GENERATE(std::string("test: [}]"), std::string("test: [true}]")); + auto input = GENERATE(std::string("test: [}]"), std::string("test: [true}]"), std::string("test: foo }")); REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); } @@ -1659,12 +1661,12 @@ TEST_CASE("Deserializer_FlowMapping") { std::string input = "{\n" " \"a\": [\n" " \"a\",\n" - " \"b\"\n" + " \"b\",\n" " ],\n" " \"b\": [\n" " 123,\n" - " true\n" - " ]\n" + " true,\n" + " ],\n" "}"; REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); @@ -1702,12 +1704,12 @@ TEST_CASE("Deserializer_FlowMapping") { std::string input = "{\n" " \"a\": {\n" " true: 1.23,\n" - " null: 123\n" + " null: 123,\n" " },\n" " \"b\": {\n" " \"a\": foo,\n" - " \"b\": bar\n" - " }\n" + " \"b\": bar,\n" + " },\n" "}"; REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); @@ -1814,10 +1816,10 @@ TEST_CASE("Deserializer_FlowMapping") { auto input = GENERATE( std::string("{foo: 123 bar: true, baz: 3.14}"), std::string("{foo: 123, bar: true baz: 3.14}"), - std::string("{foo: 123 child: {bar: true, baz: 3.14}}"), - std::string("{foo: 123, child: {bar: true baz: 3.14}}"), - std::string("{foo: 123 child: [bar: true, baz: 3.14]}"), - std::string("{foo: 123, child: [bar: true baz: 3.14]}")); + std::string("{foo: 123 {bar: true, baz: 3.14}: child}"), + std::string("{foo: 123, {bar: true baz: 3.14}: child}"), + std::string("{foo: 123 [bar: true, baz: 3.14]: child}"), + std::string("{foo: 123, [bar: true baz: 3.14]: child}")); REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); } @@ -1921,6 +1923,11 @@ TEST_CASE("Deserializer_YAMLVerDirective") { REQUIRE_THROWS_AS( deserializer.deserialize(fkyaml::detail::input_adapter("%YAML 1.1\n%YAML 1.2\n")), fkyaml::parse_error); } + + SECTION("lacks the end of directives marker after YAML directive") { + REQUIRE_THROWS_AS( + deserializer.deserialize(fkyaml::detail::input_adapter("%YAML 1.2\nfoo: bar")), fkyaml::parse_error); + } } TEST_CASE("Deserializer_TagDirective") { @@ -2010,6 +2017,12 @@ TEST_CASE("Deserializer_TagDirective") { "foo: bar"; REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); } + + SECTION("lacks the end of directives marker after TAG directive") { + std::string input = "%TAG ! tag:test.com,2000:\n" + "foo: bar"; + REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); + } } TEST_CASE("Deserializer_InvalidDirective") { @@ -2273,6 +2286,80 @@ TEST_CASE("Deserializer_Anchor") { REQUIRE(test_1_node.get_value() == 123); } + SECTION("anchor for the root block mapping node") { + std::string input = "&anchor\n" + "foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor for the root block sequence node") { + std::string input = "&anchor\n" + "- foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor for the root flow mapping node") { + std::string input = "&anchor {foo: bar}"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor for the root flow sequence node") { + std::string input = "&anchor [{foo: bar}]"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + SECTION("multiple anchors specified") { auto input = GENERATE(std::string("foo: &anchor &anchor2\n bar: baz"), std::string("&anchor &anchor2 foo: bar")); @@ -2479,6 +2566,76 @@ TEST_CASE("Deserializer_Tag") { REQUIRE(root_0_node.get_value_ref() == "bar"); } + SECTION("tag for the root block mapping node") { + std::string input = "!!map\n" + "foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!map"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("tag for the root block sequence node") { + std::string input = "!!seq\n" + "- foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!seq"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + + SECTION("tag for the root flow mapping node") { + std::string input = "!!map {foo: bar}"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!map"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("tag for the root flow sequence node") { + std::string input = "!!seq [{foo: bar}]"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!seq"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + SECTION("multiple tags specified") { auto input = GENERATE(std::string("foo: !!map !!map\n bar: baz"), std::string("!!str !!bool true: 123")); REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); @@ -2515,8 +2672,151 @@ TEST_CASE("Deserializer_NodeProperties") { } SECTION("alias node with tag") { - REQUIRE_THROWS_AS( - deserializer.deserialize(fkyaml::detail::input_adapter("&anchor foo: !!str *anchor")), fkyaml::parse_error); + std::string input = "&anchor foo: !!str *anchor"; + REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); + } + + SECTION("parse anchored child block mapping as a block sequence entry") { + std::string input = "values:\n" + "- &anchor !XXX\n" + " source: !YYY\n" + " name: foo\n" + " include: false"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("values")); + + fkyaml::node& values_node = root["values"]; + REQUIRE(values_node.is_sequence()); + REQUIRE(values_node.size() == 1); + + fkyaml::node& values_0_node = values_node[0]; + REQUIRE(values_0_node.is_mapping()); + REQUIRE(values_0_node.size() == 2); + REQUIRE(values_0_node.contains("source")); + REQUIRE(values_0_node.contains("include")); + REQUIRE(values_0_node.has_anchor_name()); + REQUIRE(values_0_node.get_anchor_name() == "anchor"); + REQUIRE(values_0_node.has_tag_name()); + REQUIRE(values_0_node.get_tag_name() == "!XXX"); + + fkyaml::node& values_0_source_node = values_0_node["source"]; + REQUIRE(values_0_source_node.is_mapping()); + REQUIRE(values_0_source_node.size() == 1); + REQUIRE(values_0_source_node.contains("name")); + REQUIRE(values_0_source_node.has_tag_name()); + REQUIRE(values_0_source_node.get_tag_name() == "!YYY"); + + fkyaml::node& values_0_source_name_node = values_0_source_node["name"]; + REQUIRE(values_0_source_name_node.is_string()); + REQUIRE(values_0_source_name_node.get_value_ref() == "foo"); + + fkyaml::node& values_0_include_node = values_0_node["include"]; + REQUIRE(values_0_include_node.is_boolean()); + REQUIRE(values_0_include_node.get_value() == false); + } + + SECTION("anchor and tag for the root block mapping node") { + std::string input = "&anchor !!map\n" + "foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!map"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor and tag for the root block sequence node") { + std::string input = "&anchor !!seq\n" + "- foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!seq"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor and tag for the root flow mapping node") { + std::string input = "&anchor !!map {foo: bar}"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!map"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor and tag for the root flow sequence node") { + std::string input = "&anchor !!seq [{foo: bar}]"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_sequence()); + REQUIRE(root.size() == 1); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!seq"); + + fkyaml::node& root_0_node = root[0]; + REQUIRE(root_0_node.is_mapping()); + REQUIRE(root_0_node.size() == 1); + REQUIRE(root_0_node.contains("foo")); + + fkyaml::node& root_0_foo_node = root_0_node["foo"]; + REQUIRE(root_0_foo_node.is_string()); + REQUIRE(root_0_foo_node.get_value_ref() == "bar"); + } + + SECTION("anchor and tag for the root block mapping node with the end-of-directives marker") { + std::string input = "--- &anchor !!map\n" + "foo: bar"; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + REQUIRE(root.is_anchor()); + REQUIRE(root.has_anchor_name()); + REQUIRE(root.get_anchor_name() == "anchor"); + REQUIRE(root.has_tag_name()); + REQUIRE(root.get_tag_name() == "!!map"); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); } } @@ -2529,13 +2829,85 @@ TEST_CASE("Deserializer_DocumentWithMarkers") { fkyaml::detail::basic_deserializer deserializer; fkyaml::node root; - REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter("%YAML 1.2\n---\nfoo: one\n..."))); - REQUIRE(root.is_mapping()); - REQUIRE(root.size() == 1); - REQUIRE(root.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_2); - REQUIRE(root.contains("foo")); + SECTION("valid YAML document") { + std::string input = "%YAML 1.2\n" + "---\n" + "foo: one\n" + "..."; + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_2); + REQUIRE(root.contains("foo")); - fkyaml::node& foo_node = root["foo"]; - REQUIRE(foo_node.is_string()); - REQUIRE(foo_node.get_value_ref() == "one"); + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "one"); + } + + SECTION("invalid end-of-directives marker") { + std::string input = "foo: bar\n" + "---\n" + "123: false\n" + "..."; + REQUIRE_THROWS_AS(deserializer.deserialize(fkyaml::detail::input_adapter(input)), fkyaml::parse_error); + } +} + +TEST_CASE("Deserializer_MultipleDocuments") { + fkyaml::detail::basic_deserializer deserializer; + fkyaml::node root; + std::vector docs; + + std::string input = "%YAML 1.1\n" + "---\n" + "foo: 123\n" + "...\n" + "%TAG ! tag:com.example,2024:\n" + "---\n" + "- !foo bar\n" + "- 3.14\n" + "- Null"; + + SECTION("parse only the first document") { + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(input))); + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 1); + REQUIRE(root.contains("foo")); + + fkyaml::node& foo_node = root["foo"]; + REQUIRE(foo_node.is_integer()); + REQUIRE(foo_node.get_value() == 123); + } + + SECTION("parse all documents") { + REQUIRE_NOTHROW(docs = deserializer.deserialize_docs(fkyaml::detail::input_adapter(input))); + REQUIRE(docs.size() == 2); + + fkyaml::node& root0 = docs[0]; + REQUIRE(root0.is_mapping()); + REQUIRE(root0.size() == 1); + REQUIRE(root0.contains("foo")); + + fkyaml::node& foo_node = root0["foo"]; + REQUIRE(foo_node.is_integer()); + REQUIRE(foo_node.get_value() == 123); + + fkyaml::node& root1 = docs[1]; + REQUIRE(root1.is_sequence()); + REQUIRE(root1.size() == 3); + + fkyaml::node& seq0 = root1[0]; + REQUIRE(seq0.has_tag_name()); + REQUIRE(seq0.get_tag_name() == "!foo"); + REQUIRE(seq0.is_string()); + REQUIRE(seq0.get_value_ref() == "bar"); + + fkyaml::node& seq1 = root1[1]; + REQUIRE(seq1.is_float_number()); + REQUIRE(seq1.get_value() == 3.14); + + fkyaml::node& seq2 = root1[2]; + REQUIRE(seq2.is_null()); + } } diff --git a/test/unit_test/test_encode_detector.cpp b/test/unit_test/test_encode_detector.cpp index b663fcac..5926d4a0 100644 --- a/test/unit_test/test_encode_detector.cpp +++ b/test/unit_test/test_encode_detector.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_exception_class.cpp b/test/unit_test/test_exception_class.cpp index 971e592e..1fec9394 100644 --- a/test/unit_test/test_exception_class.cpp +++ b/test/unit_test/test_exception_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_from_string.cpp b/test/unit_test/test_from_string.cpp index 8ea8ba32..65884485 100644 --- a/test/unit_test/test_from_string.cpp +++ b/test/unit_test/test_from_string.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 8c508c05..5b737225 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -1682,6 +1682,8 @@ TEST_CASE("InputAdapter_FillBuffer_UTF8NewlineCodeNormalization") { std::string buffer {}; input_adapter.fill_buffer(buffer); + + std::fclose(p_file); } SECTION("stream_input_adapter") { @@ -1774,6 +1776,8 @@ TEST_CASE("InputAdapter_FillBuffer_UTF16BENewlineCodeNormalization") { REQUIRE(buffer[7] == 't'); REQUIRE(buffer[8] == 'a'); REQUIRE(buffer[9] == '\n'); + + std::fclose(p_file); } SECTION("stream_input_adapter") { @@ -1879,6 +1883,8 @@ TEST_CASE("InputAdapter_FillBuffer_UTF32BENewlineCodeNormalization") { REQUIRE(buffer[7] == 't'); REQUIRE(buffer[8] == 'a'); REQUIRE(buffer[9] == '\n'); + + std::fclose(p_file); } SECTION("stream_input_adapter") { diff --git a/test/unit_test/test_iterator_class.cpp b/test/unit_test/test_iterator_class.cpp index 631785fb..b0c5ec6d 100644 --- a/test/unit_test/test_iterator_class.cpp +++ b/test/unit_test/test_iterator_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_lexical_analyzer_class.cpp b/test/unit_test/test_lexical_analyzer_class.cpp index b8ab5a0d..f8893404 100644 --- a/test/unit_test/test_lexical_analyzer_class.cpp +++ b/test/unit_test/test_lexical_analyzer_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 2cc22472..240180ee 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -371,7 +371,7 @@ TEST_CASE("Node_CopyAssignmentOperator") { } // -// test cases for serialization/deserialization features +// test cases for deserialization // TEST_CASE("Node_Deserialize") { @@ -393,17 +393,46 @@ TEST_CASE("Node_Deserialize") { REQUIRE(node["foo"].get_value_ref() == "bar"); } -TEST_CASE("Node_Serialize") { - fkyaml::node node = fkyaml::node::deserialize("foo: bar"); - REQUIRE(fkyaml::node::serialize(node) == "foo: bar\n"); -} - -TEST_CASE("Node_InsertionOperator") { - fkyaml::node node = {{"foo", 123}, {"bar", nullptr}, {"baz", true}}; +TEST_CASE("Node_DeserializeDocs") { + char source[] = "foo: bar\n" + "...\n" + "- true\n" + "- 3.14\n" + "- Null"; std::stringstream ss; - ss << node; + ss << source; - REQUIRE(ss.str() == "bar: null\nbaz: true\nfoo: 123\n"); + std::vector docs = GENERATE_REF( + fkyaml::node::deserialize_docs("foo: bar\n" + "...\n" + "- true\n" + "- 3.14\n" + "- Null"), + fkyaml::node::deserialize_docs(source), + fkyaml::node::deserialize_docs(&source[0], &source[33]), + fkyaml::node::deserialize_docs(std::string(source)), + fkyaml::node::deserialize_docs(ss)); + + REQUIRE(docs.size() == 2); + fkyaml::node& root0 = docs[0]; + REQUIRE(root0.is_mapping()); + REQUIRE(root0.size() == 1); + REQUIRE(root0.contains("foo")); + fkyaml::node& foo_node = root0["foo"]; + REQUIRE(foo_node.is_string()); + REQUIRE(foo_node.get_value_ref() == "bar"); + + fkyaml::node& root1 = docs[1]; + REQUIRE(root1.is_sequence()); + REQUIRE(root1.size() == 3); + fkyaml::node& seq0 = root1[0]; + REQUIRE(seq0.is_boolean()); + REQUIRE(seq0.get_value() == true); + fkyaml::node& seq1 = root1[1]; + REQUIRE(seq1.is_float_number()); + REQUIRE(seq1.get_value() == 3.14); + fkyaml::node& seq2 = root1[2]; + REQUIRE(seq2.is_null()); } TEST_CASE("Node_ExtractionOperator") { @@ -540,6 +569,30 @@ TEST_CASE("Node_UserDefinedLiteralYaml") { } } +// +// test cases for serialization +// + +TEST_CASE("Node_Serialize") { + fkyaml::node node = fkyaml::node::deserialize("foo: bar"); + REQUIRE(fkyaml::node::serialize(node) == "foo: bar\n"); +} + +TEST_CASE("Node_SerializeDocs") { + std::vector docs = fkyaml::node::deserialize_docs("foo: bar\n" + "...\n" + "123: true"); + REQUIRE(fkyaml::node::serialize_docs(docs) == "foo: bar\n...\n123: true\n"); +} + +TEST_CASE("Node_InsertionOperator") { + fkyaml::node node = {{"foo", 123}, {"bar", nullptr}, {"baz", true}}; + std::stringstream ss; + ss << node; + + REQUIRE(ss.str() == "bar: null\nbaz: true\nfoo: 123\n"); +} + // // test cases for factory methods // @@ -2363,12 +2416,26 @@ TEST_CASE("Node_GetValue") { SECTION("float number node value") { fkyaml::node node(3.14); - SECTION("float number values") { + SECTION("positive float number values") { REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); } + SECTION("zero float number values") { + node = 0.0; + REQUIRE(std::abs(node.get_value() - 0.0) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - 0.0) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - 0.0) < std::numeric_limits::epsilon()); + } + + SECTION("negative float number values") { + node = -3.14; + REQUIRE(std::abs(node.get_value() - (-3.14)) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - (-3.14)) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - (-3.14)) < std::numeric_limits::epsilon()); + } + SECTION("non-float-number values") { REQUIRE_THROWS_AS(node.get_value(), fkyaml::type_error); REQUIRE_THROWS_AS(node.get_value(), fkyaml::type_error); @@ -2385,7 +2452,7 @@ TEST_CASE("Node_GetValue") { } SECTION("underflowable float number type") { - fkyaml::node negative_float_node(std::numeric_limits::min()); + fkyaml::node negative_float_node(std::numeric_limits::lowest()); REQUIRE_THROWS_AS(negative_float_node.get_value(), fkyaml::exception); } diff --git a/test/unit_test/test_node_ref_storage_class.cpp b/test/unit_test/test_node_ref_storage_class.cpp index 1f9fd2bd..09eb4681 100644 --- a/test/unit_test/test_node_ref_storage_class.cpp +++ b/test/unit_test/test_node_ref_storage_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_ordered_map_class.cpp b/test/unit_test/test_ordered_map_class.cpp index e6560934..5cd0008a 100644 --- a/test/unit_test/test_ordered_map_class.cpp +++ b/test/unit_test/test_ordered_map_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_position_tracker_class.cpp b/test/unit_test/test_position_tracker_class.cpp index fb8a677b..e80651fc 100644 --- a/test/unit_test/test_position_tracker_class.cpp +++ b/test/unit_test/test_position_tracker_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_scalar_scanner_class.cpp b/test/unit_test/test_scalar_scanner_class.cpp index 23ff72e8..c30e43e5 100644 --- a/test/unit_test/test_scalar_scanner_class.cpp +++ b/test/unit_test/test_scalar_scanner_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index f51851bf..66bcbb6b 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani @@ -127,8 +127,10 @@ TEST_CASE("Serializer_AnchorNode") { fkyaml::node key = "baz"; key.add_anchor_name("C"); node.get_value_ref().emplace(key, "qux"); + node.add_anchor_name("anchor"); - std::string expected = "null: &A\n" + std::string expected = "&anchor\n" + "null: &A\n" " - true\n" " - bar\n" " - &B 3.14\n" @@ -156,7 +158,7 @@ TEST_CASE("Serializer_AliasNode") { " - bar\n" " - *A\n" "true: *A\n" - "*A: 3.14\n" + "*A : 3.14\n" "foo: &A 123\n"; fkyaml::detail::basic_serializer serializer; @@ -187,7 +189,10 @@ TEST_CASE("Serializer_TaggedNode") { mapping.emplace("map", map_node); mapping.emplace("seq", seq_node); - std::string expected = "!!null null: ! 3.14\n" + root.add_tag_name("!!map"); + + std::string expected = "!!map\n" + "!!null null: ! 3.14\n" "! true: !!int 123\n" "!!str foo: !!null null\n" "map: !!map\n" @@ -200,6 +205,20 @@ TEST_CASE("Serializer_TaggedNode") { REQUIRE(serializer.serialize(root) == expected); } +TEST_CASE("Serializer_RootNodeWithDirectivesAndNodeProperties") { + fkyaml::node root; + fkyaml::detail::basic_deserializer deserializer; + + std::string expected = "%YAML 1.2\n" + "--- &anchor !!map\n" + "foo: bar\n"; + + REQUIRE_NOTHROW(root = deserializer.deserialize(fkyaml::detail::input_adapter(expected))); + + fkyaml::detail::basic_serializer serializer; + REQUIRE(serializer.serialize(root) == expected); +} + TEST_CASE("Serializer_NodesWithDirectives") { fkyaml::node root; fkyaml::detail::basic_deserializer deserializer; @@ -251,3 +270,31 @@ TEST_CASE("Serializer_NodesWithDirectives") { REQUIRE(serializer.serialize(root) == expected); } } + +TEST_CASE("Serializer_MultipleDocuments") { + std::vector docs; + fkyaml::detail::basic_deserializer deserializer; + fkyaml::detail::basic_serializer serializer; + + SECTION("bare documents") { + std::string expected = "foo: bar\n" + "...\n" + "123: true\n"; + + REQUIRE_NOTHROW(docs = deserializer.deserialize_docs(fkyaml::detail::input_adapter(expected))); + REQUIRE(serializer.serialize_docs(docs) == expected); + } + + SECTION("with directives") { + std::string expected = "%YAML 1.2\n" + "---\n" + "foo: !!str bar\n" + "...\n" + "%TAG !t! !test-\n" + "---\n" + "test: !t!result success\n"; + + REQUIRE_NOTHROW(docs = deserializer.deserialize_docs(fkyaml::detail::input_adapter(expected))); + REQUIRE(serializer.serialize_docs(docs) == expected); + } +} diff --git a/test/unit_test/test_string_formatter.cpp b/test/unit_test/test_string_formatter.cpp index acabf23f..a8ff240d 100644 --- a/test/unit_test/test_string_formatter.cpp +++ b/test/unit_test/test_string_formatter.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_tag_resolver_class.cpp b/test/unit_test/test_tag_resolver_class.cpp index ded478d4..f7f153f3 100644 --- a/test/unit_test/test_tag_resolver_class.cpp +++ b/test/unit_test/test_tag_resolver_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_uri_encoding_class.cpp b/test/unit_test/test_uri_encoding_class.cpp index 278fcea9..fdb80030 100644 --- a/test/unit_test/test_uri_encoding_class.cpp +++ b/test/unit_test/test_uri_encoding_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_utf_encodings.cpp b/test/unit_test/test_utf_encodings.cpp index c4b486fe..efc83b81 100644 --- a/test/unit_test/test_utf_encodings.cpp +++ b/test/unit_test/test_utf_encodings.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/test/unit_test/test_yaml_escaper_class.cpp b/test/unit_test/test_yaml_escaper_class.cpp index 76f88902..d1379034 100644 --- a/test/unit_test/test_yaml_escaper_class.cpp +++ b/test/unit_test/test_yaml_escaper_class.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/tool/benchmark/main.cpp b/tool/benchmark/main.cpp index 411c7f81..e58760a4 100644 --- a/tool/benchmark/main.cpp +++ b/tool/benchmark/main.cpp @@ -1,6 +1,6 @@ // _______ __ __ __ _____ __ __ __ // | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) -// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9 +// | __| _ < \_ _/| ___ | _ | |___ version 0.3.10 // |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML // // SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani diff --git a/tool/natvis_generator/params.json b/tool/natvis_generator/params.json index e5604d86..df1e65ef 100644 --- a/tool/natvis_generator/params.json +++ b/tool/natvis_generator/params.json @@ -1 +1 @@ -{ "version": "0.3.9" } +{ "version": "0.3.10" } diff --git a/tool/natvis_generator/requirements.txt b/tool/natvis_generator/requirements.txt index 9dc0d71f..8a9acaa0 100644 --- a/tool/natvis_generator/requirements.txt +++ b/tool/natvis_generator/requirements.txt @@ -1 +1 @@ -Jinja2==3.1.2. +Jinja2==3.1.4