MCPcopy Create free account
hub / github.com/docopt/docopt.cpp / parse_defaults

Function parse_defaults

docopt.cpp:526–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

524}
525
526std::vector<Option> parse_defaults(std::string const& doc) {
527 // This pattern is a delimiter by which we split the options.
528 // The delimiter is a new line followed by a whitespace(s) followed by one or two hyphens.
529 static std::regex const re_delimiter{
530 "(?:^|\\n)[ \\t]*" // a new line with leading whitespace
531 "(?=-{1,2})" // [split happens here] (positive lookahead) ... and followed by one or two hyphes
532 };
533
534 std::vector<Option> defaults;
535 for (auto s : parse_section("options:", doc)) {
536 s.erase(s.begin(), s.begin() + static_cast<std::ptrdiff_t>(s.find(':')) + 1); // get rid of "options:"
537
538 for (const auto& opt : regex_split(s, re_delimiter)) {
539 if (starts_with(opt, "-")) {
540 defaults.emplace_back(Option::parse(opt));
541 }
542 }
543 }
544
545 return defaults;
546}
547
548static bool isOptionSet(PatternList const& options, std::string const& opt1, std::string const& opt2 = "") {
549 return std::any_of(options.begin(), options.end(), [&](std::shared_ptr<Pattern const> const& opt) -> bool {

Callers 1

create_pattern_treeFunction · 0.85

Calls 3

parse_sectionFunction · 0.85
regex_splitFunction · 0.85
starts_withFunction · 0.85

Tested by

no test coverage detected