[TEXT-114] Add a replacement for StrSubstitutor based on interfaces: StringSubstitutor.
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/4b67dd51 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/4b67dd51 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/4b67dd51 Branch: refs/heads/master Commit: 4b67dd516dbb23b31d4b35d3f737f31de86a1cda Parents: 3e649a7 Author: Gary Gregory <garydgreg...@gmail.com> Authored: Mon Feb 12 10:22:04 2018 -0700 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Mon Feb 12 10:22:04 2018 -0700 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + .../commons/text/ExtendedMessageFormat.java | 4 +- .../java/org/apache/commons/text/StrLookup.java | 2 +- .../org/apache/commons/text/StrMatcher.java | 22 +- .../org/apache/commons/text/StrSubstitutor.java | 2663 +++++++++--------- .../apache/commons/text/StringSubstitutor.java | 1359 +++++++++ .../text/lookup/AbstractStringLookup.java | 4 - .../commons/text/lookup/StringLookup.java | 4 - .../commons/text/lookup/package-info.java | 2 +- .../text/matcher/AbstractStringMatcher.java | 256 ++ .../commons/text/matcher/StringMatcher.java | 55 + .../text/matcher/StringMatcherFactory.java | 228 ++ .../commons/text/matcher/package-info.java | 25 + .../apache/commons/text/StrSubstitutorTest.java | 1708 ++++++----- ...titutorWithInterpolatorStringLookupTest.java | 47 - .../commons/text/StringSubstitutorTest.java | 622 ++++ ...titutorWithInterpolatorStringLookupTest.java | 49 + .../commons/text/matcher/StringMatcherTest.java | 219 ++ .../matcher/StringSubstitutorGetSetTest.java | 119 + 19 files changed, 5058 insertions(+), 2331 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eedd7ac..778d77a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -49,6 +49,7 @@ The <action> type attribute can be add,update,fix,remove. <action issue="TEXT-110" type="add" dev="pschumacher">Add Automatic-Module-Name MANIFEST entry for Java 9 compatibility</action> <action issue="TEXT-70" type="fix" dev="pschumacher">Build failure with java 9-ea+159</action> <action issue="TEXT-113" type="add" dev="ggregory">Add an interpolator string lookup</action> + <action issue="TEXT-114" type="add" dev="ggregory">Add a replacement for StrSubstitutor based on interfaces: StringSubstitutor</action> </release> <release version="1.2" date="2017-12-12" description="Release 1.2"> http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java index cfe1bf4..612845f 100644 --- a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java +++ b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java @@ -27,6 +27,8 @@ import java.util.Locale.Category; import java.util.Map; import java.util.Objects; +import org.apache.commons.text.matcher.StringMatcherFactory; + /** * Extends <code>java.text.MessageFormat</code> to allow pluggable/additional formatting * options for embedded format elements. Client code should specify a registry @@ -490,7 +492,7 @@ public class ExtendedMessageFormat extends MessageFormat { int len = 0; final char[] buffer = pattern.toCharArray(); do { - len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); + len = StringMatcherFactory.INSTANCE.splitMatcher().isMatch(buffer, pos.getIndex(), 0, buffer.length); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); } http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/StrLookup.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/StrLookup.java b/src/main/java/org/apache/commons/text/StrLookup.java index 320e097..6357869 100644 --- a/src/main/java/org/apache/commons/text/StrLookup.java +++ b/src/main/java/org/apache/commons/text/StrLookup.java @@ -36,7 +36,7 @@ import org.apache.commons.text.lookup.StringLookupFactory; * * @param <V> the type of the values supported by the lookup * @since 1.0 - * @deprecated Use {@link StringLookupFactory}. + * @deprecated Use {@link StringLookupFactory}. This class will be removed in 2.0. */ @Deprecated public abstract class StrLookup<V> implements StringLookup { http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/StrMatcher.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/StrMatcher.java b/src/main/java/org/apache/commons/text/StrMatcher.java index 161d9a1..466eab4 100644 --- a/src/main/java/org/apache/commons/text/StrMatcher.java +++ b/src/main/java/org/apache/commons/text/StrMatcher.java @@ -18,6 +18,8 @@ package org.apache.commons.text; import java.util.Arrays; +import org.apache.commons.text.matcher.StringMatcherFactory; + /** * A matcher class that can be queried to determine if a character array * portion matches. @@ -26,7 +28,9 @@ import java.util.Arrays; * If these do not suffice, you can subclass and implement your own matcher. * * @since 1.0 + * @deprecated Use {@link StringMatcherFactory}. This class will be removed in 2.0. */ +@Deprecated public abstract class StrMatcher { /** @@ -223,7 +227,7 @@ public abstract class StrMatcher { } /** - * Returns the number of matching characters, zero for no match. + * Returns the number of matching characters, or zero if there is no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be @@ -245,12 +249,12 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index (exclusive) of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ public abstract int isMatch(char[] buffer, int pos, int bufferStart, int bufferEnd); /** - * Returns the number of matching characters, zero for no match. + * Returns the number of matching characters, or zero if there is no match. * <p> * This method is called to check for a match. * The parameter <code>pos</code> represents the current position to be @@ -266,7 +270,7 @@ public abstract class StrMatcher { * * @param buffer the text content to match against, do not change * @param pos the starting position for the match, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ public int isMatch(final char[] buffer, final int pos) { return isMatch(buffer, pos, 0, buffer.length); @@ -298,7 +302,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -331,7 +335,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -364,7 +368,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, int pos, final int bufferStart, final int bufferEnd) { @@ -407,7 +411,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -435,7 +439,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {