MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / parseArguments

Method parseArguments

src/attributes.cpp:1652–1716  ·  view source on GitHub ↗

Parse arguments from function signature. This is tricky because commas are used to delimit arguments but are also valid inside template type qualifiers.

Source from the content-addressed store, hash-verified

1650 // are used to delimit arguments but are also valid inside template type
1651 // qualifiers.
1652 std::vector<std::string> SourceFileAttributesParser::parseArguments(
1653 const std::string& argText) {
1654
1655 int templateCount = 0;
1656 int parenCount = 0;
1657 std::string currentArg;
1658 std::vector<std::string> args;
1659 char quote = 0;
1660 bool escaped = false;
1661 typedef std::string::const_iterator it_t;
1662 for (it_t it = argText.begin(); it != argText.end(); ++it) {
1663
1664 // Store current character
1665 char ch = *it;
1666
1667 // Ignore quoted strings and character values in single quotes
1668 if ( ! quote && (ch == '"' || ch == '\''))
1669 quote = ch;
1670 else if (quote && ch == quote && ! escaped)
1671 quote = 0;
1672
1673 // Escaped character inside quotes
1674 if (escaped)
1675 escaped = false;
1676 else if (quote && ch == '\\')
1677 escaped = true;
1678
1679 // Detect end of argument declaration
1680 if ( ! quote &&
1681 (ch == ',') &&
1682 (templateCount == 0) &&
1683 (parenCount == 0)) {
1684 args.push_back(currentArg);
1685 currentArg.clear();
1686 continue;
1687 }
1688
1689 // Append current character if not a space at start
1690 if ( ! currentArg.empty() || ch != ' ')
1691 currentArg.push_back(ch);
1692
1693 // Count use of potentially enclosed brackets
1694 if ( ! quote) {
1695 switch(ch) {
1696 case '<':
1697 templateCount++;
1698 break;
1699 case '>':
1700 templateCount--;
1701 break;
1702 case '(': // #nocov start
1703 parenCount++;
1704 break;
1705 case ')':
1706 parenCount--;
1707 break; // #nocov end
1708 }
1709 }

Callers

nothing calls this directly

Calls 4

beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected