summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:01:35 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:01:35 -0400
commit7c4d9b7d6dba55c77fd1fd24beedcb6147d46cae (patch)
tree7878328079840b69292c3349c1b59453d0fe9494 /BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
parent4656403d47fe5636c61594886aa5bfc9cbbf8509 (diff)
Changed some of the token manipulators to not affect solo operators
The main change is that they won't handle tokens that consist only of the operator.
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java34
1 files changed, 34 insertions, 0 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
new file mode 100644
index 0000000..b7d20aa
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -0,0 +1,34 @@
+package bjc.utils.funcutils;
+
+/**
+ * Utility methods for operations on strings
+ *
+ * @author ben
+ *
+ */
+public class StringUtils {
+
+ /**
+ * Check if a string consists only of one or more matches of a regular
+ * expression
+ *
+ * @param input
+ * The string to check
+ * @param regex
+ * The regex to see if the string only contains matches of
+ * @return Whether or not the string consists only of multiple matches
+ * of the provided regex
+ */
+ public static boolean containsOnly(String input, String regex) {
+ /*
+ * This regular expression is fairly simple.
+ *
+ * First, we match the beginning of the string. Then, we start a
+ * non-capturing group whose contents are the passed in regex. That
+ * group is then matched one or more times and the pattern matches
+ * to the end of the string
+ */
+ return input.matches("\\A(?:" + regex + ")+\\Z");
+ }
+
+}