13
0
geforkt von Mirrors/Paper

Use region matching instead of sub-strings. Addresses BUKKIT-5275

By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2014-01-04 12:50:19 -06:00
Ursprung a323c9fd8c
Commit 32f2dca3ed

Datei anzeigen

@ -21,7 +21,7 @@ public class StringUtil {
* @throws IllegalArgumentException if originals contains a null element. * @throws IllegalArgumentException if originals contains a null element.
* <b>Note: the collection may be modified before this is thrown</b> * <b>Note: the collection may be modified before this is thrown</b>
*/ */
public static <T extends Collection<String>> T copyPartialMatches(final String token, final Iterable<String> originals, final T collection) throws UnsupportedOperationException, IllegalArgumentException { public static <T extends Collection<? super String>> T copyPartialMatches(final String token, final Iterable<String> originals, final T collection) throws UnsupportedOperationException, IllegalArgumentException {
Validate.notNull(token, "Search token cannot be null"); Validate.notNull(token, "Search token cannot be null");
Validate.notNull(collection, "Collection cannot be null"); Validate.notNull(collection, "Collection cannot be null");
Validate.notNull(originals, "Originals cannot be null"); Validate.notNull(originals, "Originals cannot be null");
@ -36,7 +36,7 @@ public class StringUtil {
} }
/** /**
* This method uses a substring to check case-insensitive equality. This * This method uses a region to check case-insensitive equality. This
* means the internal array does not need to be copied like a * means the internal array does not need to be copied like a
* toLowerCase() call would. * toLowerCase() call would.
* *
@ -52,6 +52,6 @@ public class StringUtil {
if (string.length() < prefix.length()) { if (string.length() < prefix.length()) {
return false; return false;
} }
return string.substring(0, prefix.length()).equalsIgnoreCase(prefix); return string.regionMatches(true, 0, prefix, 0, prefix.length());
} }
} }