Function sample_parse_reuse_parser


#include <samples/quickstart.cpp>

void sample_parse_reuse_parser()


reuse an existing parser

Demonstrates reuse of an existing parser. Doing this is recommended when multiple files are parsed.

Mentioned in


Lines 1492-1517 in samples/quickstart.cpp. Line 54 in samples/quickstart.cpp.

void sample_parse_reuse_parser()
    ryml::Parser parser;

    // it is also advised to reserve the parser depth
    // to the expected depth of the data tree:
    parser.reserve_stack(10); // uses small storage optimization defaulting to 16 depth,
                              // so this instruction is a no-op, and the stack will located
                              // in the parser object.
    parser.reserve_stack(20); // But this will cause an allocation because it is above 16.

    auto champagnes = parser.parse("champagnes.yml", "[Dom Perignon, Gosset Grande Reserve, Ruinart Blanc de Blancs, Jacquesson 742]");
    CHECK(ryml::emitrs<std::string>(champagnes) == R"(- Dom Perignon
- Gosset Grande Reserve
- Ruinart Blanc de Blancs
- Jacquesson 742

    auto beers = parser.parse("beers.yml", "[Rochefort 10, Busch, Leffe Rituel, Kasteel Donker]");
    CHECK(ryml::emitrs<std::string>(beers) == R"(- Rochefort 10
- Busch
- Leffe Rituel
- Kasteel Donker


Add Discussion as Guest

Log in