From 90bb38ef08f0173ddfa9abb8b4ca2542f10af04a Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Fri, 4 Mar 2022 17:52:54 +0200 Subject: Rewrote escaped unicode parsing in properties --- .../citresewn/pack/format/PropertiesGroupAdapter.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java index c0b3da6..7a8d2d4 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java @@ -1,11 +1,9 @@ package shcm.shsupercm.fabric.citresewn.pack.format; import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; import java.io.*; import java.nio.charset.StandardCharsets; -import java.util.Properties; public class PropertiesGroupAdapter extends PropertyGroup { public static final String EXTENSION = ".properties"; @@ -44,6 +42,8 @@ public class PropertiesGroupAdapter extends PropertyGroup { line = line.substring(0, line.length() - 1) + "\\n" + nextLine; } + line = line.stripTrailing(); + StringBuilder builder = new StringBuilder(); String key = null, keyMetadata = null; @@ -59,18 +59,12 @@ public class PropertiesGroupAdapter extends PropertyGroup { case 'f' -> '\f'; case 't' -> '\t'; case 'u' -> { - if (i + 4 >= line.length()) - yield c; - - //todo implement manually - java.util.Properties properties = new Properties(); - properties.load(new StringReader("k=\\u" + line.charAt(i + 1) + line.charAt(i + 2) + line.charAt(i + 3) + line.charAt(i + 4))); - String k = properties.getProperty("k"); - if (k.length() == 1) { + try { i += 4; - yield k.charAt(0); + yield (char) Integer.parseInt(line.substring(i - 3, i + 1), 16); + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { + throw new IOException("Malformatted escaped unicode character"); } - yield c; } default -> c; -- cgit