(MachineInput input, int n, DeliverFunc deliver)
| 533 | |
| 534 | // Find matches in input. |
| 535 | private void allMatches(MachineInput input, int n, DeliverFunc deliver) { |
| 536 | int end = input.endPos(); |
| 537 | if (n < 0) { |
| 538 | n = end + 1; |
| 539 | } |
| 540 | for (int pos = 0, i = 0, prevMatchEnd = -1; i < n && pos <= end; ) { |
| 541 | int[] matches = doExecute(input, pos, UNANCHORED, prog.numCap); |
| 542 | if (matches == null || matches.length == 0) { |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | boolean accept = true; |
| 547 | if (matches[1] == pos) { |
| 548 | // We've found an empty match. |
| 549 | if (matches[0] == prevMatchEnd) { |
| 550 | // We don't allow an empty match right |
| 551 | // after a previous match, so ignore it. |
| 552 | accept = false; |
| 553 | } |
| 554 | int r = input.step(pos); |
| 555 | if (r < 0) { // EOF |
| 556 | pos = end + 1; |
| 557 | } else { |
| 558 | pos += r & 0x7; |
| 559 | } |
| 560 | } else { |
| 561 | pos = matches[1]; |
| 562 | } |
| 563 | prevMatchEnd = matches[1]; |
| 564 | |
| 565 | if (accept) { |
| 566 | deliver.deliver(pad(matches)); |
| 567 | i++; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | // Legacy Go-style interface; preserved (package-private) for better |
| 573 | // test coverage. |
no test coverage detected