Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-08-21 19:04:13 -0400
committerPaul Pazderski2019-09-10 12:56:59 -0400
commit6b4bb0e33734ae1fb2efed9038d137d387e80658 (patch)
treea99c6b96f589f888c7827a65a373536d144d5e3f /org.eclipse.text
parent340d36aec95f8b2cf3fccdb04c63cbaf8ae9c5a8 (diff)
downloadeclipse.platform.text-6b4bb0e33734ae1fb2efed9038d137d387e80658.tar.gz
eclipse.platform.text-6b4bb0e33734ae1fb2efed9038d137d387e80658.tar.xz
eclipse.platform.text-6b4bb0e33734ae1fb2efed9038d137d387e80658.zip
Bug 550438 - MultiStringMatcher: use a Consumer to collect matches
Offer a method that reports matches via a Consumer instead of returning them in a list. Useful if there are lots of matches, since it enables the caller to store or otherwise process matches in any way it wants. Change-Id: I8b35056dae16d8e5eee67a35f2852677e6e56732 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.text/pom.xml2
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/MultiStringMatcher.java83
3 files changed, 51 insertions, 36 deletions
diff --git a/org.eclipse.text/META-INF/MANIFEST.MF b/org.eclipse.text/META-INF/MANIFEST.MF
index 0f792c4f9..8989924ee 100644
--- a/org.eclipse.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.text/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.text
-Bundle-Version: 3.9.100.qualifier
+Bundle-Version: 3.10.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/org.eclipse.text/pom.xml b/org.eclipse.text/pom.xml
index e019dabe6..4fa3e6913 100644
--- a/org.eclipse.text/pom.xml
+++ b/org.eclipse.text/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.text</groupId>
<artifactId>org.eclipse.text</artifactId>
- <version>3.9.100-SNAPSHOT</version>
+ <version>3.10.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/MultiStringMatcher.java b/org.eclipse.text/src/org/eclipse/jface/text/MultiStringMatcher.java
index a98d82d44..15cab0dda 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/MultiStringMatcher.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/MultiStringMatcher.java
@@ -18,6 +18,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -116,8 +117,8 @@ public class MultiStringMatcher {
// no search strings were added; return a specialized "matches nothing" matcher
return new MultiStringMatcher() {
@Override
- public List<Match> find(CharSequence text, int offset) {
- return new LinkedList<>();
+ public void find(CharSequence text, int offset, Consumer<Match> matches) {
+ return;
}
@Override
@@ -289,6 +290,52 @@ public class MultiStringMatcher {
}
/**
+ * Finds all occurrences of any of the search strings of the {@link MultiStringMatcher} in the
+ * given {@code text} starting at the given {@code offset}, including overlapping occurrences.
+ *
+ * @param text to search (not {@code null})
+ * @param offset to start searching at
+ * @param matches {@link Consumer} all matches are fed to
+ *
+ * @since 3.10
+ */
+ public void find(CharSequence text, int offset, Consumer<Match> matches) {
+ // Main search loop of the standard Aho-Corasick algorithm.
+ int textEnd= text.length();
+ Node node= root;
+ for (int i= offset; i < textEnd; i++) {
+ Character c= Character.valueOf(text.charAt(i));
+ Node next;
+ while ((next= node.next(c)) == null) {
+ node= node.fail;
+ }
+ node= next;
+ if (node.match != null) {
+ matches.accept(new MatchResult(node.match, i - node.depth + 1));
+ }
+ Node out= node.output;
+ while (out != null) {
+ matches.accept(new MatchResult(out.match, i - out.depth + 1));
+ out= out.output;
+ }
+ }
+ }
+
+ /**
+ * Finds all occurrences of any of the search strings of the {@link MultiStringMatcher} in the
+ * given {@code text} starting at the given {@code offset}, including overlapping occurrences.
+ *
+ * @param text to search (not {@code null})
+ * @param offset to start searching at
+ * @return a possibly empty list of matches
+ */
+ public List<Match> find(CharSequence text, int offset) {
+ List<Match> matches= new LinkedList<>();
+ find(text, offset, matches::add);
+ return matches;
+ }
+
+ /**
* Find the next occurrence of any of the search strings of the {@link MultiStringMatcher} in
* the given {@code text} starting at the given {@code offset}.
* <p>
@@ -384,38 +431,6 @@ public class MultiStringMatcher {
}
/**
- * Finds all occurrences of any of the search strings of the {@link MultiStringMatcher} in the
- * given {@code text} starting at the given {@code offset}, including overlapping occurrences.
- *
- * @param text to search (not {@code null})
- * @param offset to start searching at
- * @return a possibly empty list of matches
- */
- public List<Match> find(CharSequence text, int offset) {
- // Main search loop of the standard Aho-Corasick algorithm.
- int textEnd= text.length();
- List<Match> matches= new LinkedList<>();
- Node node= root;
- for (int i= offset; i < textEnd; i++) {
- Character c= Character.valueOf(text.charAt(i));
- Node next;
- while ((next= node.next(c)) == null) {
- node= node.fail;
- }
- node= next;
- if (node.match != null) {
- matches.add(new MatchResult(node.match, i - node.match.length() + 1));
- }
- Node out= node.output;
- while (out != null) {
- matches.add(new MatchResult(out.match, i - out.match.length() + 1));
- out= out.output;
- }
- }
- return matches;
- }
-
- /**
* Finds the leftmost longest occurrence of any of the given {@code searchStrings} in the
* {@code text} starting at the given {@code offset}.
* <p>

Back to the top