From 98c5fd3f7c3cfc8dea8908d04b8d694a53fa1aeb Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Sat, 5 Jan 2019 11:10:28 -0400 Subject: Split AffixLister pt. 1 --- src/main/java/ReplPair.java | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/ReplPair.java (limited to 'src/main/java/ReplPair.java') diff --git a/src/main/java/ReplPair.java b/src/main/java/ReplPair.java new file mode 100644 index 00000000..474f7c93 --- /dev/null +++ b/src/main/java/ReplPair.java @@ -0,0 +1,75 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * String pairs for replacements. + * + * @author Ben Culkin + */ +public class ReplPair { + /** + * The string to look for. + */ + public String find; + /** + * The string to replace it with. + */ + public String replace; + + /** + * Create a new blank replacement pair. + */ + public ReplPair() { + + } + + /** + * Create a new replacement pair. + * + * @param f + * The string to find. + * @param r + * The string to replace. + */ + public ReplPair(String f, String r) { + find = f; + replace = r; + } + + /** + * Read a list of replacement pairs from an input source. + * + * @param scn + * The source to read the replacements from. + */ + public static List readList(Scanner scn) { + return ReplPair.readList(new ArrayList<>(), scn); + } + + /** + * Read a list of replacement pairs from an input source, adding them to + * an existing list. + * + * @param detals + * The list to add the replacements to. + * @param scn + * The source to read the replacements from. + */ + public static List readList(List detals, Scanner scn) { + while (scn.hasNextLine()) { + String name = scn.nextLine().trim(); + if (name.equals("")) continue; + if (name.startsWith("#")) continue; + + String body; + do { + body = scn.nextLine().trim(); + } while (body.startsWith("#")); + + detals.add(new ReplPair(name, body)); + } + + return detals; + } +} -- cgit v1.2.3