From bb264c2eb31eeda6bbbfeab53b5dff4335a9b2f2 Mon Sep 17 00:00:00 2001 From: xDec0de_ Date: Sun, 14 Jul 2024 15:49:37 +0200 Subject: [PATCH] ColorPattern: Add isHexChar(char) utility method --- .../codersky/mcutils/java/strings/pattern/ColorPattern.java | 6 +++++- .../mcutils/java/strings/pattern/color/HexColorPattern.java | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/ColorPattern.java b/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/ColorPattern.java index b01daff..c76e48d 100644 --- a/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/ColorPattern.java +++ b/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/ColorPattern.java @@ -34,5 +34,9 @@ public interface ColorPattern { * @return A new string with the pattern applied to it. */ @Nullable - String process(@Nullable final String string, boolean simple); + public String process(@Nullable final String string, final boolean simple); + + default boolean isHexChar(char ch) { + return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); + } } diff --git a/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/color/HexColorPattern.java b/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/color/HexColorPattern.java index e0994d4..c0ed755 100644 --- a/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/color/HexColorPattern.java +++ b/platforms/spigot/src/main/java/net/codersky/mcutils/java/strings/pattern/color/HexColorPattern.java @@ -65,14 +65,10 @@ public String process(@Nullable final String string, boolean simple) { private int getHexSize(String str, int start, int len, boolean simple) { int size = 0; for (int i = start; i < len && size <= 6; i++, size++) - if (!isHex(str.charAt(i))) + if (!isHexChar(str.charAt(i))) break; if (size == 6 || (simple && size == 3)) return size; return size > 3 ? 3 : 0; } - - private boolean isHex(char ch) { - return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); - } }