aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
diff options
context:
space:
mode:
authorCraftyOldMiner <85420839+CraftyOldMiner@users.noreply.github.com>2022-03-07 21:44:17 -0600
committerGitHub <noreply@github.com>2022-03-07 22:44:17 -0500
commit73fad7064fb47d9d79ccdb3bab5988df1b9eea6f (patch)
tree8b192d2304de3823339f238653e6d55dcfdfd04a /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
parent8b630cb7c39e73346d43b1e083b62b30fc3cde8f (diff)
downloadnotenoughupdates-73fad7064fb47d9d79ccdb3bab5988df1b9eea6f.tar.gz
notenoughupdates-73fad7064fb47d9d79ccdb3bab5988df1b9eea6f.tar.bz2
notenoughupdates-73fad7064fb47d9d79ccdb3bab5988df1b9eea6f.zip
Wishing Compass Solver, Metal Detector Solver improvements, add /neudiag, other misc changes (#90)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
index 9b5f62e3..dc88da2f 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -301,6 +301,40 @@ public class Utils {
return "";
}
+ public static String trimWhitespaceAndFormatCodes(String str) {
+ int startIndex = indexOfFirstNonWhitespaceNonFormatCode(str);
+ int endIndex = lastIndexOfNonWhitespaceNonFormatCode(str);
+ if (startIndex == -1 || endIndex == -1) return "";
+ return str.substring(startIndex, endIndex+1);
+ }
+
+ private static int indexOfFirstNonWhitespaceNonFormatCode(String str) {
+ int len = str.length();
+ for (int i = 0; i < len; i++) {
+ char ch = str.charAt(i);
+ if (Character.isWhitespace(ch)) {
+ continue;
+ } else if (ch == '\u00a7') {
+ i++;
+ continue;
+ }
+ return i;
+ }
+ return -1;
+ }
+
+ private static int lastIndexOfNonWhitespaceNonFormatCode(String str) {
+ for (int i = str.length() - 1; i >= 0; i--) {
+ char ch = str.charAt(i);
+ if (Character.isWhitespace(ch) || ch == '\u00a7' || (i > 0 && str.charAt(i - 1) == '\u00a7')) {
+ continue;
+ }
+ return i;
+ }
+
+ return -1;
+ }
+
public static List<String> getRawTooltip(ItemStack stack) {
List<String> list = Lists.newArrayList();
String s = stack.getDisplayName();