Function sample_tags

Synopsis

#include <samples/quickstart.cpp>

void sample_tags()

Description

deal with YAML type tags

Mentioned in

Source

Lines 3213-3283 in samples/quickstart.cpp. Line 71 in samples/quickstart.cpp.

void sample_tags()
{
    std::string unresolved = R"(--- !!map
a: 0
b: 1
--- !map
? a
: b
--- !!seq
- a
- b
--- !!str
a
 b
...
--- !!str a b
...
--- !!str a b
--- !!str
a: b
--- !!str a: b
---
!!str a: b
---
!!str a
 b
---
!!set
? a
? b
--- !!set
? a
---
[!!int 0, !!str 0]
)";
    std::string resolved = R"(--- !!map
a: 0
b: 1
--- !map
a: b
--- !!seq
- a
- b
--- !!str a b
--- !!str a b
--- !!str a b
--- !!str 'a: b'
--- !!str 'a: b'
---
!!str a: b
--- !!str a b
--- !!set
a: ~
b: ~
--- !!set
a: ~
---
- !!int 0
- !!str 0
)";
    auto tree = ryml::parse(ryml::to_csubstr(unresolved));
    CHECK(ryml::emitrs<std::string>(tree) == resolved);
    auto stream = tree.rootref();
    CHECK(stream.is_stream());
    CHECK(stream.num_children() == 13);
    for(auto node : stream.children())
    {
        CHECK(node.is_doc());
    }
    CHECK(stream[11].val_tag() == "!!set");
}





Add Discussion as Guest

Log in