Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 3bf3b2bbf -> a8d5e864e


Fix `startsWithAny` and `endsWithAny`(parameter type should be CharSequence)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a8d5e864
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a8d5e864
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a8d5e864

Branch: refs/heads/GROOVY_2_4_X
Commit: a8d5e864ec223b9ebfc1b4ec97b032ee1f5ce58e
Parents: 3bf3b2b
Author: sunlan <[email protected]>
Authored: Wed Jan 10 18:49:43 2018 +0800
Committer: sunlan <[email protected]>
Committed: Wed Jan 10 18:49:53 2018 +0800

----------------------------------------------------------------------
 .../groovy/runtime/StringGroovyMethods.java     | 24 ++++++++++++--------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a8d5e864/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 ee34105..dd3fca6 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -3635,15 +3635,17 @@ public class StringGroovyMethods extends 
DefaultGroovyMethodsSupport {
     }
 
     /**
-     * Tests if this string starts with any specified prefixes.
+     * Tests if this CharSequence starts with any specified prefixes.
      *
      * @param   prefixes   the prefixes.
-     * @return  {@code true} if this string starts with any specified prefixes.
+     * @return  {@code true} if this CharSequence starts with any specified 
prefixes.
      * @since   2.4.14
      */
-    public static boolean startsWithAny(String self, String... prefixes) {
-        for (String prefix : prefixes) {
-            if (self.startsWith(prefix)) {
+    public static boolean startsWithAny(CharSequence self, CharSequence... 
prefixes) {
+        String str = self.toString();
+
+        for (CharSequence prefix : prefixes) {
+            if (str.startsWith(prefix.toString())) {
                 return true;
             }
         }
@@ -3652,15 +3654,17 @@ public class StringGroovyMethods extends 
DefaultGroovyMethodsSupport {
     }
 
     /**
-     * Tests if this string ends with any specified suffixes.
+     * Tests if this CharSequence ends with any specified suffixes.
      *
      * @param   suffixes   the suffixes.
-     * @return  {@code true} if this string ends with any specified suffixes
+     * @return  {@code true} if this CharSequence ends with any specified 
suffixes
      * @since   2.4.14
      */
-    public static boolean endsWithAny(String self, String... suffixes) {
-        for (String suffix : suffixes) {
-            if (self.endsWith(suffix)) {
+    public static boolean endsWithAny(CharSequence self, CharSequence... 
suffixes) {
+        String str = self.toString();
+
+        for (CharSequence suffix : suffixes) {
+            if (str.endsWith(suffix.toString())) {
                 return true;
             }
         }

Reply via email to