Skip to content

Commit

Permalink
ColorPattern: Add isHexChar(char) utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Jul 14, 2024
1 parent 035556d commit bb264c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit bb264c2

Please sign in to comment.