### Start Benchmark Explorer Server Source: https://github.com/biojppm/rapidyaml/blob/master/proj/c4proj/bm-xp/README.md Run this command in the project directory to start the HTTP server for the Benchmark Explorer. This server is used to explore benchmarks. ```shell python bm.py serve . ``` -------------------------------- ### Add Quickstart Test Instances Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Calls the ryml_add_quickstart_test function to define various quickstart tests with different arguments and configurations. ```cmake ryml_add_quickstart_test(ryml-test-quickstart noargs LOCK) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart quiet ARGS --quiet LOCK) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-help ARGS --help) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-quiet ARGS --quiet) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-zero ARGS -e 0 -a 0) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-stdin STDIN ARGS -) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-stdin2 STDIN ARGS stdin) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-noretry ARGS -n) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-noretry-fail WILL_FAIL ARGS -n -e 0) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-file ARGS ${CMAKE_CURRENT_LIST_DIR}/../bm/cases/appveyor.yml) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-too_many WILL_FAIL ARGS a b c) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-missing_events WILL_FAIL ARGS -e) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-missing_arena WILL_FAIL ARGS -a) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-bad_events WILL_FAIL ARGS -e bad) ``` ```cmake ryml_add_quickstart_test(ryml-test-quickstart-ints ints-bad_arena WILL_FAIL ARGS -a bad) ``` -------------------------------- ### Define Executable for Quickstart Tests Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Defines an executable for quickstart tests without linking against the main library. Used for sample C++ files. ```cmake ryml_add_test_exe_no_lib(ryml-test-quickstart SOURCES ../samples/quickstart.cpp) ``` ```cmake ryml_add_test_exe_no_lib(ryml-test-quickstart-ints SOURCES ../samples/quickstart-ints.cpp) ``` -------------------------------- ### Build and Run Commands Source: https://github.com/biojppm/rapidyaml/blob/master/doc/sphinx_try_quickstart.md Commands to configure, build, and run the RapidYAML quickstart project using CMake. ```bash # configure the project cmake -S . -B build # build and run cmake --build build --target ryml-quickstart -j # optionally, open in your IDE cmake --open build ``` -------------------------------- ### Add Quickstart Test Function Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt A CMake function to add quickstart tests, handling arguments, stdin, locking, and potential failures. It supports Valgrind for memory checking. ```cmake function(ryml_add_quickstart_test targetname suffix) set(testname ${targetname}-${suffix}) cmake_parse_arguments("" "STDIN;LOCK;WILL_FAIL" "" "ARGS" ${ARGN}) ryml_get_target_exe(${targetname} exe) # c4_add_test() cannot be used with multiple tests from the same # exe, so we use explicit add_test()+valgrind. Also, use # RESOURCE_LOCK to prevent the tests from running simultaneously, # because they write/read to the same file. if(NOT _STDIN) add_test(NAME ${testname} COMMAND ${CMAKE_COMMAND} -E env ${exe} ${_ARGS}) else() if(NOT UNIX) return() endif() add_test(NAME ${testname} COMMAND ${CMAKE_COMMAND} -E env echo "foo: bar" | ${exe} ${_ARGS}) endif() if(_LOCK) set(lockid ${targetname}-lock) set_tests_properties(${testname} PROPERTIES RESOURCE_LOCK ${lockid}) endif() if(_WILL_FAIL) set_tests_properties(${testname} PROPERTIES WILL_FAIL TRUE) endif() if(RYML_VALGRIND) separate_arguments(_vg_opts UNIX_COMMAND "${RYML_VALGRIND_OPTIONS}") add_test(NAME ${testname}-valgrind COMMAND valgrind ${_vg_opts} $ ${_ARGS} COMMAND_EXPAND_LISTS) if(_LOCK) set_tests_properties(${testname}-valgrind PROPERTIES RESOURCE_LOCK ${lockid}) endif() if(_WILL_FAIL) set_tests_properties(${testname}-valgrind PROPERTIES WILL_FAIL TRUE) endif() endif() endfunction() ``` -------------------------------- ### YAML Parsing with Tags Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Provides examples of YAML structures involving tags for maps and sequences, demonstrating fixes in parsing these constructs. ```yaml --- !!map { k: !!seq [ a, !!str b], j: !!seq [ a, !!str b] --- !!seq [ !!map { !!str k: v}, !!map { !!str ? k: v} ] --- !!map !!str foo: !!map # there was a parse error with the multiple tags !!int 1: !!float 20.0 !!int 3: !!float 40.0 --- !!seq - !!map !!str k1: v1 !!str k2: v2 !!str k3: v3 ``` -------------------------------- ### Install Manifest Generation Source: https://github.com/biojppm/rapidyaml/blob/master/CMakeLists.txt Generates and writes an installation manifest file. This is useful for tracking installed files for later uninstallation. ```cmake install(CODE " string(REPLACE "${CMAKE_INSTALL_PREFIX}/" "" ryml_manifest "${CMAKE_INSTALL_MANIFEST_FILES}") list(APPEND ryml_manifest share/ryml/MANIFEST.txt) list(SORT ryml_manifest) string(REPLACE ";" "\n" ryml_manifest "${ryml_manifest}") file(WRITE ${CMAKE_BINARY_DIR}/MANIFEST.txt "${ryml_manifest}") ") install(FILES "${CMAKE_BINARY_DIR}/MANIFEST.txt" DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ryml) ``` -------------------------------- ### Setup Testing with Google Test Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Initializes the testing framework, specifically Google Test, for the project. ```cmake c4_setup_testing(GTEST) ``` -------------------------------- ### Install RapidYAML Target Source: https://github.com/biojppm/rapidyaml/blob/master/CMakeLists.txt Installs the 'ryml' target and its exports based on the RYML_INSTALL option. Handles dependencies for exports differently depending on whether RYML_STANDALONE or RYML_SYSTEM_C4CORE is enabled. ```cmake if(RYML_INSTALL) c4_install_target(ryml) if(RYML_STANDALONE OR RYML_SYSTEM_C4CORE) c4_install_exports() else() c4_install_exports(DEPENDENCIES c4core) endif() c4_pack_project() endif() ``` -------------------------------- ### Setup Test Target Properties Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Configures compile flags, definitions, and position-independent code for test targets. ```cmake function(ryml_setup_test_target_props target_name) c4_target_compile_flags(${target_name} PUBLIC GCC -Wno-useless-cast) if(RYML_DBG) target_compile_definitions(${target_name} PUBLIC RYML_DBG) endif() if(DEFINED RYML_DEFAULT_CALLBACKS) if(NOT RYML_DEFAULT_CALLBACKS) target_compile_definitions(${target_name} PUBLIC RYML_NO_DEFAULT_CALLBACKS) endif() endif() if(RYML_SAVE_TEST_YAML) target_compile_definitions(${target_name} PUBLIC RYML_SAVE_TEST_YAML) endif() get_target_property(target_type ${target_name} TYPE) if(target_type STREQUAL "SHARED_LIBRARY") set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif () endfunction() ``` -------------------------------- ### Create Executable and Link Libraries Source: https://github.com/biojppm/rapidyaml/blob/master/samples/ints_only/CMakeLists.txt Defines an executable 'ryml-quickstart-ints' that links against the 'ryml-ints' library and includes additional utility source files. This setup allows the executable to use the specialized integer parsing library. ```cmake # now create the executable and link with that library. Also, the # library does not need the ints utils, but the exe does, so we add # the util source files directly to the executable. add_executable(ryml-quickstart-ints ../quickstart-ints.cpp ${RAPIDYAML_DIR}/src_extra/c4/yml/extra/ints_utils.hpp ${RAPIDYAML_DIR}/src_extra/c4/yml/extra/ints_utils.cpp ) target_link_libraries(ryml-quickstart-ints ryml-ints) ``` -------------------------------- ### Find and Execute clang-tidy Setup Source: https://github.com/biojppm/rapidyaml/blob/master/CMakeLists.txt Finds the clang-tidy executable using `find_program`. If found, it calls the `ryml_setup_clang_tidy` function to configure the clang-tidy custom target for the project. ```cmake find_program(CLANG_TIDY clang-tidy) if(CLANG_TIDY) ryml_setup_clang_tidy(${CMAKE_CURRENT_LIST_DIR}) endif() ``` -------------------------------- ### Block Literal Indentation Example (YAML) Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.3.0.md Illustrates how block literal indentation is now interpreted relative to the current indentation level. ```yaml foo: - | child0 - |2 child2 # indentation is 4, not 2 ``` -------------------------------- ### Define Custom Target to Run Executable Source: https://github.com/biojppm/rapidyaml/blob/master/samples/ints_only/CMakeLists.txt Creates a custom CMake target named 'run' that executes the 'ryml-quickstart-ints' executable. This provides a convenient way to build and run the example. ```cmake add_custom_target(run COMMAND $ DEPENDS ryml-quickstart-ints COMMENT "running $" ) ``` -------------------------------- ### YAML Anchors and References Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Illustrates a complex YAML structure involving anchors and references, specifically `{&a a: &b b, *b: *a}`, and the fix in resolving such nodes. ```yaml {&a a: &b b, *b: *a} ``` -------------------------------- ### YAML map scalar parsing example Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Illustrates a parsing issue with map scalars containing a colon and starting on a new line, contrasted with a correctly parsed example. ```yaml --- # failed to parse: description: foo:bar --- # but this was ok: description: foo:bar --- ``` -------------------------------- ### Example of type predicate API usage Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Demonstrates the correct usage of type predicates after API cleanup, showing how to use `Tree::is_map()` and `NodeRef::is_map()`. ```c++ Tree t = parse("{foo: bar}"); size_t map_id = t.root_id(); NodeRef map = t.rootref(); t.get(map_id)->is_map(); // compile error: no longer exists assert(t.is_map(map_id)); // OK assert(map.is_map()); // OK ``` -------------------------------- ### YAML Indentation Fix for Explicit Keys Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.8.0.md This example demonstrates the correct indentation for explicit keys in YAML output, which was previously not handled correctly. ```yaml fixed: ? explicit key : value previously: ? explicit key : value # this was not indented ``` -------------------------------- ### C++ Key Reference Flag Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Shows how map inheritance nodes like `<<: *anchor` now correctly have the KEYREF flag set in their type before Tree::resolve() is called. ```c++ Tree tree = parse("{map: &anchor {foo: bar}, copy: {<<: *anchor}}"); assert(tree["copy"]["<<"].is_key_ref()); // previously this did not hold assert(tree["copy"]["<<"].is_val_ref()); // ... but this did ``` -------------------------------- ### Parsing Benchmark Example Source: https://github.com/biojppm/rapidyaml/blob/master/doc/sphinx_is_it_rapid.md This C++ code snippet is part of a parsing benchmark for rapidyaml. It demonstrates how to use rapidyaml for parsing YAML/JSON buffers and compares its performance against other libraries. ```cpp #include #include int main(int argc, char** argv) { // ... benchmark setup ... // parse YAML buffer ryml::Tree tree = ryml::parse_in_place(buffer); // ... benchmark assertions ... return 0; } ``` -------------------------------- ### Control Wrapping with Max Columns (C++) Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Shows how to control the wrapping of flow multiline style (`FLOW_MLN`) using `EmitOptions::max_cols()`. This example sets the maximum columns to 8. ```cpp auto maxcols8 = c4::yml::EmitOptions{}.max_cols(8); CHECK(c4::yml::emitrs_yaml(tree, maxcols8), "[ 0,1,2, 3,4,5, 6 ] "); ``` -------------------------------- ### Add Uninstall Target Source: https://github.com/biojppm/rapidyaml/blob/master/CMakeLists.txt Creates a custom target 'ryml-uninstall' that executes an uninstall script. This allows for a clean removal of installed files. ```cmake add_custom_target(ryml-uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/proj/uninstall.cmake" ) ``` -------------------------------- ### Create File and Add Event Tool Test Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt A helper function to create a YAML file and then add an event tool test case for it. Simplifies test setup. ```cmake function(ryml_add_event_tool_test name expect_success args contents) ryml_create_file(${name}.yml "${contents}" ${events_dir} file basename) ryml_add_event_tool_test_(${name} ${expect_success} "${args}" ${basename}) endfunction() ``` -------------------------------- ### YAML Tabs within Tokens Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Shows various YAML tokens (scalars, maps, sequences) containing tabs, indicating correct parsing. ```yaml --- scalar # test case K54U --- {} # test case Q5MG --- # test case DC7X a: b seq: - a c: d #X ``` -------------------------------- ### Invalid Block Containers After Document Open Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Catches invalid block container starts (e.g., map, sequence, alias) immediately following a document start token ('---'). ```yaml --- a: b # invalid --- - a # invalid --- ? a # invalid ``` -------------------------------- ### YAML Document Start/Begin Tokens in Flow Containers Fix Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.12.0.md Enforces correct indentation rules for document start ('---') and begin ('...') tokens when they appear within flow sequences and quoted scalars. ```yaml [ --- --- --- , ... ... , ... , # etc ] --- " --- ... " --- ' --- ... ' ``` -------------------------------- ### Direct Use of sync.py Script Source: https://github.com/biojppm/rapidyaml/blob/master/ext/README.md The `Makefile` targets are wrappers around the `sync.py` script. This script can be used directly for synchronization tasks. Refer to the makefile commands or run `sync.py --help` for usage examples. ```shell sync.py --help ``` -------------------------------- ### Block Literal Indentation (YAML) Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md This example shows how block literal indentation is now interpreted relative to the current indentation level, not as an absolute level. ```yaml foo: - | child0 - |2 child2 # indentation is 4, not 2 ``` -------------------------------- ### Invalid Plain Scalars Starting with Comma Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Rejects plain scalars that begin with a comma (`,`) in block mode, as this is an invalid YAML construct. ```yaml all invalid: - , foo - ,foo - , ``` -------------------------------- ### C++ Type Predicate API Cleanup Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Demonstrates the updated C++ API for type predicates on nodes. Type predicates are now accessed through Tree or NodeRef, not NodeData directly. ```c++ Tree t = parse("{foo: bar}"); size_t map_id = t.root_id(); NodeRef map = t.rootref(); t.get(map_id)->is_map(); // compile error: no longer exists assert(t.is_map(map_id)); // OK assert(map.is_map()); // OK ``` -------------------------------- ### Sequence Member Map Parsing Fix (YAML) Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Fixes an issue where sequence members that are maps would not parse correctly if they did not start with a key. ```yaml ``` -------------------------------- ### Invalid Block Containers After In-Block Open Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Detects invalid block container starts within an existing block, such as a sequence or map, where they are not permitted. ```yaml a: - b # invalid a: ? b # invalid ``` -------------------------------- ### YAML Map Scalar Parsing Fix Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.6.0.md Addresses an issue where map scalars containing a colon and starting on a new line were incorrectly parsed. This example shows the problematic input and the expected behavior. ```yaml --- # failed to parse: description: foo:bar --- # but this was ok: description: foo:bar ``` -------------------------------- ### Ensure Filtering of Multiline Quoted Scalars Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md This example ensures that multiline quoted scalars, both double and single-quoted, are correctly filtered and parsed. It covers various scenarios including scalars within sequences and mappings. ```yaml # all scalars now correctly parsed as "quoted string", # both for double and single quotes --- "quoted string" ---"quoted string" --- - "quoted string" --- - "quoted string" --- "quoted string": "quoted string" --- "quoted string": "quoted string" ``` -------------------------------- ### YAML Plain Scalars Starting with Comma Fix Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.12.0.md Corrects parsing of plain scalars that incorrectly start with a comma, which is not allowed in standard YAML. ```yaml all invalid: - , foo - ,foo - , ``` -------------------------------- ### Fix Filtering of Tab Characters in Quoted Scalars Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Demonstrates the fix for filtering tab characters within quoted scalars, ensuring they are correctly interpreted as line feeds or spaces. Includes examples for both double and single quotes. ```yaml --- # test case 5GBF "Empty line as a line feed" # now correctly parsed as "Empty line\nas a line feed" --- # test case PRH3 ' 1st non-empty 2nd non-empty 3rd non-empty ' # now correctly parsed as " 1st non-empty\n2nd non-empty 3rd non-empty " ``` -------------------------------- ### Configure and Compile JavaScript Tests with Emcmake Source: https://github.com/biojppm/rapidyaml/blob/master/doc/sphinx_other_languages.md Use this command to set up, compile, and run tests for the JavaScript+WebAssembly port of RapidYAML using emcmake. ```bash git clone https://github.com/biojppm/rapidyaml cd rapidyaml emcmake cmake -S . -B build/emscripten \ -D RYML_DEV=ON \ -D RYML_BUILD_TESTS=ON \ -D RYML_BUILD_BENCHMARKS=OFF \ -D RYML_TEST_SUITE=OFF \ -D RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS=ON \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' cmake --build build/emscripten --target ryml-test-run -j ``` -------------------------------- ### Build and Run RapidYAML Project Source: https://github.com/biojppm/rapidyaml/blob/master/doc/index.md Commands to configure, build, and run a C++ project that uses RapidYAML. Assumes a CMake build system and the provided CMakeLists.txt. ```bash # configure the project cmake -S . -B build # build and run cmake --build build --target ryml-quickstart -j # optionally, open in your IDE cmake --open build ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/biojppm/rapidyaml/blob/master/samples/singleheaderlib/CMakeLists.txt This snippet defines the main executable target 'ryml-quickstart' and links it against the 'ryml' library. It also defines a preprocessor macro for single-header library usage. ```cmake add_executable(ryml-quickstart ../quickstart.cpp) target_link_libraries(ryml-quickstart PRIVATE ryml) target_compile_definitions(ryml-quickstart PUBLIC -DRYML_SINGLE_HEADER_LIB) ``` -------------------------------- ### Get rapidyaml Events Executable Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Retrieves the path to the rapidyaml events executable and stores it in the RYML_TGT_EVENTS variable. ```cmake ryml_get_target_exe(ryml-yaml-events RYML_TGT_EVENTS) ``` -------------------------------- ### Get Target Executable Path Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Determines the full path to a target executable, considering cross-compilation environments. ```cmake function(ryml_get_target_exe target_name target_file) if(CMAKE_CROSSCOMPILING) set(tgt ${CMAKE_CROSSCOMPILING_EMULATOR} $) else() set(tgt $) endif() set(${target_file} ${tgt} PARENT_SCOPE) endfunction() ``` -------------------------------- ### YAML Emission of Scalars Starting with Special Characters Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Shows how scalars that begin with characters like `*`, `&`, or `<<` are now correctly quoted during emission. ```yaml # Fix [#151](https://github.com/biojppm/rapidyaml/issues/151): scalars beginning with `*` or `&` or `<<` are now correctly quoted when emitting ([PR #156](https://github.com/biojppm/rapidyaml/pull/156)). ``` -------------------------------- ### CMakeLists.txt for RapidYAML Project Source: https://github.com/biojppm/rapidyaml/blob/master/doc/sphinx_try_quickstart.md This CMakeLists.txt file configures a C++ project to use RapidYAML. It fetches the library from GitHub and links it to a sample executable. ```cmake cmake_minimum_required(VERSION 3.13) project(my-quickstart LANGUAGES CXX) include(FetchContent) FetchContent_Declare(ryml GIT_REPOSITORY https://github.com/biojppm/rapidyaml.git GIT_TAG v0.15.2 ) FetchContent_MakeAvailable(ryml) add_executable(my-quickstart ${ryml_SOURCE_DIR}/samples/quickstart.cpp) target_link_libraries(my-quickstart ryml::ryml) add_custom_target(run my-quickstart COMMAND $ DEPENDS my-quickstart) ``` -------------------------------- ### Tree Construction and Empty Check Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.11.0.md Demonstrates the change in default Tree construction. A default-constructed Tree is now non-empty. To create an empty tree, a capacity of zero must be explicitly provided. ```cpp // breaking change: default-constructed tree is now non-empty Tree tree; assert(!tree.empty()); // MODIFIED! was empty on previous version id_type root = tree.root_id(); // OK. default-constructed tree is now non-empty // to create an empty tree (as happened before): Tree tree(0); // pass capacity of zero assert(tree.empty()); // as expected // but watchout, this is no longer possible: //id_type root = tree.root_id(); // ERROR: cannot get root of empty tree. ``` -------------------------------- ### YAML Double-Quoted Scalar with Tab Example Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Illustrates a double-quoted scalar containing a tab character, showing correct parsing of the tab. ```yaml "This has a\ttab" # is now correctly parsed as "This has atab" ``` -------------------------------- ### Define Test Library (_testlib) Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Creates a static library for testing purposes, including various test-related source files and linking against ryml, c4fs, and gtest. It also sets up test target properties and adds c4core development dependencies. ```cmake c4_add_library(ryml-_testlib LIBRARY_TYPE STATIC SOURCES test_lib/callbacks_tester.hpp test_lib/test_case_node.hpp test_lib/test_case_node.cpp test_lib/test_case.hpp test_lib/test_case.cpp test_lib/test_engine.hpp test_lib/test_engine.cpp test_lib/test_events_ints_helpers.hpp test_lib/test_events_ints_helpers.cpp test_lib/test_save.cpp INC_DIRS ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/../src_extra LIBS ryml c4fs gtest FOLDER test) ryml_setup_test_target_props(ryml-_testlib) ryml_add_c4core_dev_to_target(ryml-_testlib) ``` -------------------------------- ### Fetch RapidYAML using FetchContent Source: https://github.com/biojppm/rapidyaml/blob/master/samples/fetch_content/CMakeLists.txt Declares and makes available the RapidYAML library from a Git repository. Ensure the repository URL and branch name are correctly set. ```cmake cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(ryml-quickstart LANGUAGES CXX) set(RYML_REPO_URL https://github.com/biojppm/rapidyaml CACHE STRING "") set(RYML_BRANCH_NAME master CACHE STRING "") message(STATUS "FetchContent from repo: ${RYML_REPO_URL}") message(STATUS "FetchContent from branch: ${RYML_BRANCH_NAME}") include(FetchContent) FetchContent_Declare(ryml GIT_REPOSITORY ${RYML_REPO_URL} GIT_TAG ${RYML_BRANCH_NAME} ) FetchContent_MakeAvailable(ryml) ``` -------------------------------- ### Fix Leading Colon in Flow Map Keys (YAML) Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.5.0.md Demonstrates the corrected parsing of YAML flow maps where keys can now start with a colon. ```yaml :foo: # parse error on the leading colon :bar: a # parse error on the leading colon :barbar: b # was ok :barbarbar: c # was ok foo: # was ok bar: a # was ok :barbar: b # was ok :barbarbar: c # was ol ``` -------------------------------- ### Build Executable and Link Library Source: https://github.com/biojppm/rapidyaml/blob/master/samples/add_subdirectory/CMakeLists.txt Create an executable target and link it against the RapidYAML library. This is a standard CMake practice for building applications that depend on libraries. ```cmake add_executable(ryml-quickstart ../quickstart.cpp) target_link_libraries(ryml-quickstart ryml::ryml) ``` -------------------------------- ### YAML Parsing Implicit Scalars with Tags Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.2.1.md Examples of YAML parsing where implicit scalars are present alongside tags, demonstrating fixes for these cases. ```yaml - &a # test case PW8X - a - &a : a b: &b - &c : &a - ? &d - ? &e : &a ``` -------------------------------- ### Base64 Serialization in C++ Source: https://github.com/biojppm/rapidyaml/blob/master/doc/doxy_changelog.md Demonstrates how to use the improved base64 serialization facilities in RapidYAML for decoding strings and obtaining buffer size requirements. ```c++ std::string decoded; tree["node"] >> fmt::base64(decoded); // now possible // also can now obtain the size explicitly: substr buf = ...; size_t required = 0; tree["node"] >> fmt::base64(buf, &required); ``` -------------------------------- ### Define Test Main Library (_testmain) Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Creates an OBJECT library for the test main entry point, containing test_main.cpp and test_main.hpp, and linking against the ryml library. ```cmake c4_add_library(ryml-_testmain LIBRARY_TYPE OBJECT SOURCES test_lib/test_main.cpp test_lib/test_main.hpp LIBS ryml FOLDER test ) ``` -------------------------------- ### Amalgamate Script Help Source: https://github.com/biojppm/rapidyaml/blob/master/doc/sphinx_using.md Use this command to see the available options for the amalgamation script, which allows customization of the single-header file. ```console python3 tools/amalgamate.py -h ``` -------------------------------- ### Sequence Member Map Parsing Fix (YAML) Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.3.0.md Shows a YAML structure where sequence members are maps starting without a key, which is now parsed correctly. ```yaml # previously this resulted in a parse error - - : empty key - - : another empty key ``` -------------------------------- ### Configure Fuzzing Directories Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Sets up lists of directories for different fuzzing test types based on the RYML_FUZZ_TEST_INDIVIDUAL build option. This allows for selective inclusion of fuzzing test cases. ```cmake if(RYML_FUZZ_TEST_INDIVIDUAL) set(srlz_dirs srlz_fails) set(json_dirs json_fails) set(yaml_dirs yaml_fails ${json_dirs}) else() set(srlz_dirs srlz_fails srlz_merged) set(json_dirs json_fails json_merged json_rapidyamldump) set(yaml_dirs yaml_fails yaml_merged yaml_rapidyamldump yaml_test_suite ${json_dirs}) endif() ``` -------------------------------- ### Configure Runtime Output Directory Source: https://github.com/biojppm/rapidyaml/blob/master/samples/add_subdirectory/CMakeLists.txt When building a shared library, this setting places the executable in the same directory as the library's DLL. This simplifies deployment and execution by keeping related files together. ```cmake set_target_properties(ryml-quickstart PROPERTIES RUNTIME_OUTPUT_DIRECTORY $) ``` -------------------------------- ### Create Test File Function Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Defines a function to create a file with specified content in a subdirectory within the build directory. It outputs the full filename and the base filename. ```cmake function(ryml_create_file name contents subdir fileout basenameout) set(dir ${CMAKE_CURRENT_BINARY_DIR}/${subdir}) if(NOT EXISTS ${dir}) file(MAKE_DIRECTORY ${dir}) endif() set(filename ${dir}/${name}) file(WRITE "${filename}" "${contents} ") set("${fileout}" "${filename}" PARENT_SCOPE) set("${basenameout}" "${name}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Windows DLL Copy for Executable Source: https://github.com/biojppm/rapidyaml/blob/master/samples/custom_c4core/CMakeLists.txt On Windows, this custom command ensures that necessary DLLs (RapidYAML and c4core) are copied to the executable's directory after the build. This is important for runtime loading. ```cmake if(WIN32) function(maybe_copy_dll_to_exe_dir exe lib) if(TARGET ${lib}) get_target_property(type ${lib} TYPE) if((type STREQUAL SHARED_LIBRARY) OR (type STREQUAL MODULE_LIBRARY)) add_custom_command(TARGET ${exe} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $) endif() endif() endfunction() maybe_copy_dll_to_exe_dir(ryml-quickstart ryml::ryml) maybe_copy_dll_to_exe_dir(ryml-quickstart c4core::c4core) endif() ``` -------------------------------- ### YAML Parse Error Fix for Block Scalars Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.14.0.md Fixes a parsing error where whitespace after block scalar indicators (`|` or `>`) caused issues. This example shows the problematic YAML structure. ```yaml space after: >\space tag after: >\t ``` -------------------------------- ### Link RapidYAML to Executable Source: https://github.com/biojppm/rapidyaml/blob/master/samples/find_package/CMakeLists.txt Add an executable and link it against the RapidYAML library using its namespace. ```cmake add_executable(ryml-quickstart ../quickstart.cpp) target_link_libraries(ryml-quickstart PRIVATE ryml::ryml) # note the namespace! ``` -------------------------------- ### Configure Custom c4core Fetch Source: https://github.com/biojppm/rapidyaml/blob/master/samples/custom_c4core/CMakeLists.txt Sets up CMake to fetch a specific version of c4core from a Git repository. Ensure C4CORE_REPO and C4CORE_TAG are set to your desired repository and branch/tag. ```cmake cmake_minimum_required(VERSION 3.12) project(ryml-quickstart DESCRIPTION "Shows how to use a custom c4core version different from ryml's c4core submodule" LANGUAGES CXX) include(../../ext/c4core/cmake/c4Project.cmake) c4_project(VERSION 0.1.0 STANDALONE AUTHOR "Joao Paulo Magalhaes ") set(C4CORE_REPO https://github.com/biojppm/c4core CACHE STRING "") set(C4CORE_TAG master CACHE STRING "") include(FetchContent) message(STATUS "fetch c4core from repo: ${C4CORE_REPO}") message(STATUS "fetch c4core from tag: ${C4CORE_TAG}") FetchContent_Declare(c4core GIT_REPOSITORY ${C4CORE_REPO} GIT_TAG ${C4CORE_TAG} ) FetchContent_MakeAvailable(c4core) ``` -------------------------------- ### Fix JSON Emitter Leading Zero Scalar Quoting (JSON) Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.5.0.md JSON emitter now quotes scalars that start with a zero (e.g., "048") to ensure they are treated as strings. ```json // JSON emitter now quotes scalars with leading zero, eg "048". ``` -------------------------------- ### Fix Container Key Parsing in YAML Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.11.1.md This example demonstrates a YAML structure with explicit keys that previously caused parsing errors. The fix ensures correct parsing of such corner cases. ```yaml ? ? # was causing a parse error ? # popping was also causing a parse error --- ? [a: b]: x : y ``` -------------------------------- ### Base64 Serialization with RapidYAML Source: https://github.com/biojppm/rapidyaml/blob/master/changelog/0.14.0.md Demonstrates improved base64 serialization facilities in RapidYAML. It shows how to decode a base64 string directly into a C++ string and how to explicitly obtain the required buffer size for decoding. ```c++ std::string decoded; tree["node"] >> fmt::base64(decoded); // now works! // also can now obtain the size explicitly: substr buf = ...; size_t required = 0; tree["node"] >> fmt::base64(buf, &required); ``` -------------------------------- ### Add Test Executable Without Library Dependency Source: https://github.com/biojppm/rapidyaml/blob/master/test/CMakeLists.txt Creates a test executable, links it against the 'ryml' library, and sets up its properties. ```cmake function(ryml_add_test_exe_no_lib name) c4_add_executable(${name} LIBS ryml FOLDER test ${ARGN}) ryml_setup_test_target_props(${name}) ryml_maybe_dump_test_yaml(${name}) add_dependencies(ryml-test-build ${name}) endfunction() ```