diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-01-05 11:29:00 -0400 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-01-05 11:29:00 -0400 |
| commit | 11bcfd3632668d57d4df07760121fc6ebda044f3 (patch) | |
| tree | 824f848cad1cf973007d0d874d6c1ffe8d55681c /src/main/java/tlIItools/ReplPair.java | |
| parent | 98c5fd3f7c3cfc8dea8908d04b8d694a53fa1aeb (diff) | |
Split AffixLister
This splits AffixLister into a separate file for each class that it once
contained.
Diffstat (limited to 'src/main/java/tlIItools/ReplPair.java')
| -rw-r--r-- | src/main/java/tlIItools/ReplPair.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/tlIItools/ReplPair.java b/src/main/java/tlIItools/ReplPair.java new file mode 100644 index 00000000..41d483b3 --- /dev/null +++ b/src/main/java/tlIItools/ReplPair.java @@ -0,0 +1,77 @@ +package tlIItools; + +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<ReplPair> 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<ReplPair> readList(List<ReplPair> 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; + } +} |
