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

Method fix_repeating_arguments

docopt_private.h:395–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393 }
394
395 inline void BranchPattern::fix_repeating_arguments()
396 {
397 std::vector<PatternList> either = transform(children());
398 for(auto const& group : either) {
399 // use multiset to help identify duplicate entries
400 std::unordered_multiset<std::shared_ptr<Pattern>, PatternHasher> group_set {group.begin(), group.end()};
401 for(auto const& e : group_set) {
402 if (group_set.count(e) == 1)
403 continue;
404
405 LeafPattern* leaf = dynamic_cast<LeafPattern*>(e.get());
406 if (!leaf) continue;
407
408 bool ensureList = false;
409 bool ensureInt = false;
410
411 if (dynamic_cast<Command*>(leaf)) {
412 ensureInt = true;
413 } else if (dynamic_cast<Argument*>(leaf)) {
414 ensureList = true;
415 } else if (Option* o = dynamic_cast<Option*>(leaf)) {
416 if (o->argCount()) {
417 ensureList = true;
418 } else {
419 ensureInt = true;
420 }
421 }
422
423 if (ensureList) {
424 std::vector<std::string> newValue;
425 if (leaf->getValue().isString()) {
426 newValue = split(leaf->getValue().asString());
427 }
428 if (!leaf->getValue().isStringList()) {
429 leaf->setValue(value{newValue});
430 }
431 } else if (ensureInt) {
432 leaf->setValue(value{0});
433 }
434 }
435 }
436 }
437
438 inline bool LeafPattern::match(PatternList& left, std::vector<std::shared_ptr<LeafPattern>>& collected) const
439 {

Callers

nothing calls this directly

Calls 6

transformFunction · 0.85
splitFunction · 0.85
argCountMethod · 0.80
isStringMethod · 0.80
isStringListMethod · 0.80
setValueMethod · 0.80

Tested by

no test coverage detected