Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 3 factory mathods to wrap a matcher so that it accepts text (wh…

…itespace generally) before, after and around it
  • Loading branch information...
commit f25a8427329868bbee767b2f7a9ad70e63594b47 1 parent 8096d42
@jawher authored
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/main/java/immanix/Matchers.java
View
40 src/main/java/immanix/Matchers.java
@@ -54,4 +54,44 @@ public static EndDocumentMatcher endDoc() {
public static <T> StaxMatcher<T> untilButFinite(StaxMatcher<T> m, int giveUpBarrier) {
return new UntilButFiniteMatcher<T>(m, giveUpBarrier);
}
+
+ /**
+ * Augments a matcher so that it accepts characters (whitespace generally) before it
+ *
+ * @param m the matcher to wrap
+ * @param <T> the result type of the matcher to wrap
+ * @return the augmented matcher
+ */
+ public static <T> StaxMatcher<T> wsl(StaxMatcher<T> m) {
+ return WS_MATCHER.thenr(m);
+ }
+
+ /**
+ * Augments a matcher so that it accepts characters (whitespace generally) after it
+ *
+ * @param m the matcher to wrap
+ * @param <T> the result type of the matcher to wrap
+ * @return the augmented matcher
+ */
+ public static <T> StaxMatcher<T> wsr(StaxMatcher<T> m) {
+ return m.thenl(WS_MATCHER);
+ }
+
+ /**
+ * Augments a matcher so that it accepts characters (whitespace generally) before and after it
+ *
+ * @param m the matcher to wrap
+ * @param <T> the result type of the matcher to wrap
+ * @return the augmented matcher
+ */
+ public static <T> StaxMatcher<T> ws(StaxMatcher<T> m) {
+ return WS_MATCHER.thenr(m).thenl(WS_MATCHER);
+ }
+
+ private static final StaxMatcher<String> WS_MATCHER = new CharsMatcher() {
+ @Override
+ public String toString() {
+ return " ";
+ }
+ }.optional();
}
Please sign in to comment.
Something went wrong with that request. Please try again.