From e106e1f36fb04adc14f9c8a30587bf349bdcaf54 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 14 Mar 2017 14:47:07 -0400 Subject: Added ability to ignore strings to splitter --- .../java/bjc/utils/funcutils/NeoTokenSplitter.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'BJC-Utils2/src/main/java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java index 6007429..25b1e03 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java @@ -59,9 +59,10 @@ public class NeoTokenSplitter { if(compPatt == null) throw new IllegalStateException("Token splitter has not been compiled yet"); /* - * Don't split something that matches only an operator + * Don't split something that we should exclude from being split. */ if(exclusionPatt.matcher(inp).matches()) return new String[] { inp }; + return compPatt.split(inp); } @@ -116,6 +117,23 @@ public class NeoTokenSplitter { } } + /** + * Marks strings matching the pattern delim as non-splittable. + * + * @param delim + * The regex to not splitting matching strings. + */ + public void addNonMatcher(String delim) { + if(currPatt == null) { + currPatt = new StringBuilder(); + currExclusionPatt = new StringBuilder(); + + currExclusionPatt.append("(?:" + delim + ")"); + } else { + currExclusionPatt.append("|(?:" + delim + ")"); + } + } + /** * Compiles the current set of delimiters to a pattern. * -- cgit v1.2.3