From 1ad33bfe0a96b1b4a1f3c02cf2c054e8a101dfd8 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Mar 2015 20:08:15 -0400 Subject: field matcher is starting to be useful --- src/cuchaz/enigma/convert/MatchesReader.java | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/cuchaz/enigma/convert/MatchesReader.java') diff --git a/src/cuchaz/enigma/convert/MatchesReader.java b/src/cuchaz/enigma/convert/MatchesReader.java index b43535c..1dd042d 100644 --- a/src/cuchaz/enigma/convert/MatchesReader.java +++ b/src/cuchaz/enigma/convert/MatchesReader.java @@ -10,6 +10,8 @@ import java.util.List; import com.beust.jcommander.internal.Lists; import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.Type; public class MatchesReader { @@ -42,4 +44,42 @@ public class MatchesReader { } return entries; } + + public static FieldMatches readFields(File file) + throws IOException { + try (BufferedReader in = new BufferedReader(new FileReader(file))) { + FieldMatches matches = new FieldMatches(); + String line = null; + while ((line = in.readLine()) != null) { + readFieldMatch(matches, line); + } + return matches; + } + } + + private static void readFieldMatch(FieldMatches matches, String line) { + String[] parts = line.split(":", 2); + FieldEntry source = readField(parts[0]); + FieldEntry dest = readField(parts[1]); + if (source != null && dest != null) { + matches.addMatch(source, dest); + } else if (source != null) { + matches.addUnmatchedSourceField(source); + } else if (dest != null) { + matches.addUnmatchedDestField(dest); + } + } + + private static FieldEntry readField(String in) { + if (in.length() <= 0) { + return null; + } + String[] parts = in.split(" "); + assert(parts.length == 3); + return new FieldEntry( + new ClassEntry(parts[0]), + parts[1], + new Type(parts[2]) + ); + } } -- cgit v1.2.3