| 1 | package pro.verron.officestamper.experimental; | |
| 2 | ||
| 3 | import pro.verron.officestamper.core.Matcher; | |
| 4 | ||
| 5 | import java.util.ArrayList; | |
| 6 | import java.util.List; | |
| 7 | import java.util.regex.Pattern; | |
| 8 | ||
| 9 | import static java.util.Collections.emptyList; | |
| 10 | ||
| 11 | /// The ExpressionFinder class is responsible for finding expressions in a given text based on a specified pattern and | |
| 12 | /// matcher. It uses the Matcher class to determine if an expression matches the specified prefix and suffix, and the | |
| 13 | /// Expression class to represent each found expression. | |
| 14 | /// | |
| 15 | /// @param pattern the pattern to use for finding expressions | |
| 16 | /// @param matcher the matcher to use for determining if an expression matches the specified prefix and suffix | |
| 17 | public record PlaceholderFinder( | |
| 18 | Pattern pattern, Matcher matcher | |
| 19 | ) { | |
| 20 | /// Finds expressions in a given text based on a specified pattern and matcher. | |
| 21 | /// | |
| 22 | /// @param text the text to search for expressions | |
| 23 | /// | |
| 24 | /// @return a list of found expressions | |
| 25 | public List<Placeholder> find(String text) { | |
| 26 |
1
1. find : negated conditional → KILLED |
if (text.isEmpty()) return emptyList(); |
| 27 | var matcher = pattern.matcher(text); | |
| 28 | int index = 0; | |
| 29 | List<Placeholder> matches = new ArrayList<>(); | |
| 30 |
1
1. find : negated conditional → KILLED |
while (matcher.find(index)) { |
| 31 | String match = matcher.group(); | |
| 32 | matches.add(new StandardPlaceholder(this.matcher, match)); | |
| 33 | index = matcher.end(); | |
| 34 | } | |
| 35 |
1
1. find : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/PlaceholderFinder::find → KILLED |
return matches; |
| 36 | } | |
| 37 | } | |
Mutations | ||
| 26 |
1.1 |
|
| 30 |
1.1 |
|
| 35 |
1.1 |