get a group capture's string pointer and size specified by %[ARG] as arg, if any
| 564 | |
| 565 | // get a group capture's string pointer and size specified by %[ARG] as arg, if any |
| 566 | std::pair<const char*,size_t> Output::capture(reflex::AbstractMatcher *matcher, const char *arg) |
| 567 | { |
| 568 | if (arg != NULL) |
| 569 | { |
| 570 | while (true) |
| 571 | { |
| 572 | const char *bar = strchr(arg, '|'); |
| 573 | const char *end = strchr(arg, ']'); |
| 574 | |
| 575 | if (end == NULL) |
| 576 | break; |
| 577 | |
| 578 | if (bar == NULL || bar > end) |
| 579 | bar = end; |
| 580 | |
| 581 | if (isdigit(static_cast<unsigned char>(*arg))) |
| 582 | { |
| 583 | size_t index = strtoul(arg, NULL, 10); |
| 584 | |
| 585 | if (index == 0 || *bar == ']') |
| 586 | return (*matcher)[index]; |
| 587 | |
| 588 | std::pair<size_t,const char*> id = matcher->group_id(); |
| 589 | |
| 590 | while (id.first != 0 && id.first != index) |
| 591 | id = matcher->group_next_id(); |
| 592 | |
| 593 | if (id.first == index) |
| 594 | return (*matcher)[index]; |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | std::pair<size_t,const char*> id = matcher->group_id(); |
| 599 | |
| 600 | while (id.first != 0 |
| 601 | && (id.second == NULL || strncmp(id.second, arg, bar - arg) != 0 || id.second[bar - arg] != '\0')) |
| 602 | id = matcher->group_next_id(); |
| 603 | |
| 604 | if (id.first != 0) |
| 605 | return (*matcher)[id.first]; |
| 606 | } |
| 607 | |
| 608 | if (*bar == ']') |
| 609 | break; |
| 610 | |
| 611 | arg = bar + 1; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return std::pair<const char*,size_t>(NULL, 0); |
| 616 | } |
| 617 | |
| 618 | // output format with option --format-begin and --format-end |
| 619 | void Output::format(const char *format, size_t matches) |
nothing calls this directly
no test coverage detected