diff options
Diffstat (limited to 'src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java')
-rw-r--r-- | src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java new file mode 100644 index 0000000..761f114 --- /dev/null +++ b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java @@ -0,0 +1,39 @@ +package makamys.neodymium.config; + +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; + +public class HumanReadableConfigElement extends ConfigElement { + + public HumanReadableConfigElement(Property prop) { + super(prop); + } + + @Override + public String getName() { + return decamelize(super.getName()); + } + + private static String decamelize(String s) { + boolean[] spaceField = new boolean[s.length()]; + + for(int i = 0; i < s.length(); i++) { + if(i > 0 && i < s.length() && !Character.isUpperCase(s.charAt(i - 1)) && Character.isUpperCase(s.charAt(i))) { + spaceField[i] = true; + } else if(i > 2 && Character.isUpperCase(s.charAt(i - 2)) && Character.isUpperCase(s.charAt(i - 1)) && !Character.isUpperCase(s.charAt(i))) { + spaceField[i - 1] = true; + } + } + + String out = ""; + for(int i = 0; i < s.length(); i++) { + if(spaceField[i]) { + out += " "; + } + out += i == 0 ? Character.toUpperCase(s.charAt(i)) : s.charAt(i); + } + + return out; + } + +} |