Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 4a0bd40ee -> 8bcbb688f
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/8bcbb688 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8bcbb688 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8bcbb688 Branch: refs/heads/GROOVY_2_5_X Commit: 8bcbb688f45a825ba97f9f86e0364f1221c7be2d Parents: 4a0bd40 Author: sunlan <[email protected]> Authored: Wed Jan 10 18:47:48 2018 +0800 Committer: sunlan <[email protected]> Committed: Wed Jan 10 18:48:55 2018 +0800 ---------------------------------------------------------------------- .../groovy/runtime/StringGroovyMethods.java | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/8bcbb688/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; } }
