diff options
| author | BuildTools <james.jenour@protonmail.com> | 2021-01-30 18:22:49 +0800 |
|---|---|---|
| committer | BuildTools <james.jenour@protonmail.com> | 2021-01-30 18:22:49 +0800 |
| commit | 3290259e39e9816fd92afa85710de01a6ddfa3b9 (patch) | |
| tree | e105bcfccfbc38f091848a94667dd612271eed7c /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | |
| parent | 659a0e4981640802058d9eef35fec16fab82c5f2 (diff) | |
| download | notenoughupdates-3290259e39e9816fd92afa85710de01a6ddfa3b9.tar.gz notenoughupdates-3290259e39e9816fd92afa85710de01a6ddfa3b9.tar.bz2 notenoughupdates-3290259e39e9816fd92afa85710de01a6ddfa3b9.zip | |
PRE13.2
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.java | 42 |
1 files changed, 42 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 e40edd4f..f452b406 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -228,6 +228,48 @@ public class Utils { : shortNumberFormat(d, iteration+1)); } + public static String trimIgnoreColour(String str) { + return trimIgnoreColourStart(trimIgnoreColourEnd(str)); + } + + public static String trimIgnoreColourStart(String str) { + str = str.trim(); + boolean colourCodeLast = false; + StringBuilder colours = new StringBuilder(); + for(int i=0; i<str.length(); i++) { + char c = str.charAt(i); + if(colourCodeLast) { + colours.append('\u00a7').append(c); + colourCodeLast = false; + continue; + } + if(c == '\u00A7') { + colourCodeLast = true; + } else if(c != ' ') { + return colours.append(str.substring(i)).toString(); + } + } + + return ""; + } + + public static String trimIgnoreColourEnd(String str) { + str = str.trim(); + for(int i=str.length()-1; i>=0; i--) { + char c = str.charAt(i); + if(c == ' ') { + continue; + } else if(i > 0 && str.charAt(i-1) == '\u00a7') { + i--; + continue; + } + + return str.substring(0, i+1); + } + + return ""; + } + public static void drawItemStackLinear(ItemStack stack, int x, int y) { if(stack == null)return; |
