| 520 | } |
| 521 | |
| 522 | std::vector<std::string> FunctionDoc::GetArgumentTokens(const std::string& pybind_doc) |
| 523 | { |
| 524 | // First insert commas to make things easy |
| 525 | // From: |
| 526 | // "foo(arg0: float, arg1: float = 1.0, arg2: int = 1) -> cpplib.bar" |
| 527 | // To: |
| 528 | // "foo(, arg0: float, arg1: float = 1.0, arg2: int = 1) -> cpplib.bar" |
| 529 | std::string str = pybind_doc; |
| 530 | size_t parenthesis_pos = str.find("("); |
| 531 | if (parenthesis_pos == std::string::npos) |
| 532 | { |
| 533 | return {}; |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | str.replace(parenthesis_pos + 1, 0, ", "); |
| 538 | } |
| 539 | |
| 540 | // Get start positions |
| 541 | std::regex pattern("(, [A-Za-z_][A-Za-z\\d_]*:)"); |
| 542 | std::smatch res; |
| 543 | std::string::const_iterator start_iter(str.cbegin()); |
| 544 | std::vector<size_t> argument_start_positions; |
| 545 | while (std::regex_search(start_iter, str.cend(), res, pattern)) |
| 546 | { |
| 547 | size_t pos = res.position(0) + (start_iter - str.cbegin()); |
| 548 | start_iter = res.suffix().first; |
| 549 | // Now the pos include ", ", which needs to be removed |
| 550 | argument_start_positions.push_back(pos + 2); |
| 551 | } |
| 552 | |
| 553 | // Get end positions (non-inclusive) |
| 554 | // The 1st argument's end pos is 2nd argument's start pos - 2 and etc. |
| 555 | // The last argument's end pos is the location of the parenthesis before -> |
| 556 | std::vector<size_t> argument_end_positions; |
| 557 | for (size_t i = 0; i + 1 < argument_start_positions.size(); ++i) |
| 558 | { |
| 559 | argument_end_positions.push_back(argument_start_positions[i + 1] - 2); |
| 560 | } |
| 561 | std::size_t arrow_pos = str.rfind(") -> "); |
| 562 | if (arrow_pos == std::string::npos) |
| 563 | { |
| 564 | return {}; |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | argument_end_positions.push_back(arrow_pos); |
| 569 | } |
| 570 | |
| 571 | std::vector<std::string> argument_tokens; |
| 572 | for (size_t i = 0; i < argument_start_positions.size(); ++i) |
| 573 | { |
| 574 | std::string token = |
| 575 | str.substr(argument_start_positions[i], argument_end_positions[i] - argument_start_positions[i]); |
| 576 | argument_tokens.push_back(token); |
| 577 | } |
| 578 | return argument_tokens; |
| 579 | } |
nothing calls this directly
no outgoing calls
no test coverage detected