mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-26 05:51:12 +01:00
Optimize containsPlaceholders
This commit is contained in:
@@ -279,8 +279,15 @@ public final class PlaceholderAPI {
|
|||||||
* @param text String to check
|
* @param text String to check
|
||||||
* @return true if String contains any matches to the normal placeholder pattern, false otherwise
|
* @return true if String contains any matches to the normal placeholder pattern, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean containsPlaceholders(String text) {
|
public static boolean containsPlaceholders(final String text) {
|
||||||
return text != null && PLACEHOLDER_PATTERN.matcher(text).find();
|
if (text == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final int firstPercent = text.indexOf('%');
|
||||||
|
if (firstPercent == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return text.indexOf('%', firstPercent + 1) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,8 +297,15 @@ public final class PlaceholderAPI {
|
|||||||
* @param text String to check
|
* @param text String to check
|
||||||
* @return true if String contains any matches to the bracket placeholder pattern, false otherwise
|
* @return true if String contains any matches to the bracket placeholder pattern, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean containsBracketPlaceholders(String text) {
|
public static boolean containsBracketPlaceholders(final String text) {
|
||||||
return text != null && BRACKET_PLACEHOLDER_PATTERN.matcher(text).find();
|
if (text == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final int firstPercent = text.indexOf('{');
|
||||||
|
if (firstPercent == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return text.indexOf('}', firstPercent + 1) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Deprecated API ===
|
// === Deprecated API ===
|
||||||
|
|||||||
Reference in New Issue
Block a user