jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.77k forks source link

Adding support for handling YAML Merge Key (#41) - proper keys comparison for merging #1279

Open azat opened 1 month ago

azat commented 1 month ago

NOTE: this is based on https://github.com/jbeder/yaml-cpp/pull/1243, but includes a fix for proper merging (by comparing the key itself, instead of shared_ptrs, see the last patch).

Support for YAML Merge keys ( <<: [dict1, dict2] ) is added. The merge key is a specific scalar with value << (and tag !!merge) that implies that during node construction, the map (or sequence of maps) are merged into the current map. The priority rules are that each key from maps within the value associated with << are added iff the key is not yet present in the current map (and first map gets higher priority). Test cases have been added accordingly.