You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/31 16:17:25 UTC
[3/3] groovy git commit: Add DGM `startsWith(String...)` and
`endsWith(String...)`
Add DGM `startsWith(String...)` and `endsWith(String...)`
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1bd694e8
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1bd694e8
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1bd694e8
Branch: refs/heads/GROOVY_2_4_X
Commit: 1bd694e8c134dac851dfd90e83f7f2889603f2c0
Parents: 2b382c9
Author: sunlan <su...@apache.org>
Authored: Mon Jan 1 00:12:32 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Jan 1 00:16:29 2018 +0800
----------------------------------------------------------------------
.../groovy/runtime/StringGroovyMethods.java | 33 ++++++++++++++++++++
.../groovy/runtime/StringGroovyMethodsTest.java | 1 +
2 files changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/1bd694e8/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 2dd1335..e2fa5e2 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -3634,4 +3634,37 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
return unexpandLine((CharSequence) self, tabStop);
}
+ /**
+ * Tests if this string starts with any specified prefixes.
+ *
+ * @param prefixes the prefixes.
+ * @return {@code true} if this string starts with any specified prefixes.
+ * @since 2.4.14
+ */
+ public static boolean startsWith(String self, String... prefixes) {
+ for (String prefix : prefixes) {
+ if (self.startsWith(prefix)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Tests if this string ends with any specified suffixes.
+ *
+ * @param suffixes the suffixes.
+ * @return {@code true} if this string ends with any specified suffixes
+ * @since 2.4.14
+ */
+ public static boolean endsWith(String self, String... suffixes) {
+ for (String suffix : suffixes) {
+ if (self.endsWith(suffix)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/1bd694e8/src/test/org/codehaus/groovy/runtime/StringGroovyMethodsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/StringGroovyMethodsTest.java b/src/test/org/codehaus/groovy/runtime/StringGroovyMethodsTest.java
index bd0812d..af5dd0c 100644
--- a/src/test/org/codehaus/groovy/runtime/StringGroovyMethodsTest.java
+++ b/src/test/org/codehaus/groovy/runtime/StringGroovyMethodsTest.java
@@ -101,4 +101,5 @@ public class StringGroovyMethodsTest extends GroovyTestCase {
assertTrue(StringGroovyMethods.endsWith("abcd", "cd", "ef"));
assertFalse(StringGroovyMethods.endsWith("abcd", "ef", "gh"));
}
+
}