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