diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-16 14:40:09 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-16 14:42:11 -0400 |
| commit | 022773e88ceb6256b90c92599d254df94c3d3190 (patch) | |
| tree | 6581cc7b706ae76fe95c715578ef29c501bfa233 /BJC-Utils2/src/main/java/bjc | |
| parent | b570540dd42c375c6b6fe2ad5e85c160e95c58cd (diff) | |
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java | 1 | ||||
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java | 44 |
2 files changed, 25 insertions, 20 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index 0229304..77fec7e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -210,6 +210,7 @@ public class StringUtils { escapeFinder.appendReplacement(work, escapeRep); } + escapeFinder.appendTail(work); return work.toString(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java index 084bdae..206fbcd 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java @@ -21,7 +21,7 @@ public class TokenSplitter { * Thus, it will only match in places where the delimiter is, but won't * actually match the delimiter, leaving split to put it into the stream */ - private static String WITH_DELIM = "((?<=%1$s)|(?=%1$s))"; + private static String WITH_DELIM = "(?:(?<=%1$s)|(?=%1$s))"; /* * This string is a format template for the multi-delimiter matching @@ -31,7 +31,7 @@ public class TokenSplitter { * some negative lookahead/lookbehind assertions to avoid splitting a * delimiter into pieces. */ - private static String WITH_MULTI_DELIM = "((?<=%1$s+)(?!%1$s)|(?<!%1$s)(?=%1$s+))"; + private static String WITH_MULTI_DELIM = "(?:(?<=%1$s+)(?!%1$s)|(?<!%1$s)(?=%1$s+))"; /* * These represent the internal state of the splitter. @@ -57,8 +57,10 @@ public class TokenSplitter { * Split a provided string using configured delimiters, and keeping the * delimiters. * + * <p> * The splitter must be compiled first. - * + * </p> + * * @param inp * The string to split. * @@ -79,28 +81,30 @@ public class TokenSplitter { } /** - * Adds a string as a matched delimiter to split on. + * Adds one or more strings as matched delimiters to split on. * * Only works for fixed length delimiters. * - * The provided string is regex-escaped before being used. + * The provided strings are regex-escaped before being used. * - * @param delim - * The delimiter to match on. + * @param delims + * The delimiters to match on. */ - public void addDelimiter(String delim) { - String quoteDelim = Pattern.quote(delim); - String delimPat = String.format(WITH_DELIM, quoteDelim); - - if(currPatt == null) { - currPatt = new StringBuilder(); - currExclusionPatt = new StringBuilder(); - - currPatt.append("(?:" + delimPat + ")"); - currExclusionPatt.append("(?:" + quoteDelim + ")"); - } else { - currPatt.append("|(?:" + delimPat + ")"); - currExclusionPatt.append("|(?:" + quoteDelim + ")"); + public void addDelimiter(String... delims) { + for(String delim : delims) { + String quoteDelim = Pattern.quote(delim); + String delimPat = String.format(WITH_DELIM, quoteDelim); + + if(currPatt == null) { + currPatt = new StringBuilder(); + currExclusionPatt = new StringBuilder(); + + currPatt.append("(?:" + delimPat + ")"); + currExclusionPatt.append("(?:" + quoteDelim + ")"); + } else { + currPatt.append("|(?:" + delimPat + ")"); + currExclusionPatt.append("|(?:" + quoteDelim + ")"); + } } } |
