Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 6293c3e66 -> 324919ac2


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

(cherry picked from commit c800bb0)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 324919ac25e75826b385ebfa474258f08665cbdb
Parents: 6293c3e
Author: sunlan <[email protected]>
Authored: Wed Jan 10 18:47:48 2018 +0800
Committer: sunlan <[email protected]>
Committed: Wed Jan 10 18:48:21 2018 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/324919ac/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index ba8f1bc..8d87e40 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -3799,15 +3799,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;
             }
         }
@@ -3816,15 +3818,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