From e760e590104a177a26badb616ac400fef815c679 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 24 Jun 2019 20:43:15 -0400 Subject: Part I of factoring out controls This is part one of factoring out controls and control parsing so that we aren't doing it in three different places. Two main things before this is done: 1. Finish up the parsing in ControlledString 2. Actually replace the old implementations in ReplPair --- src/main/java/bjc/everge/ReplPair.java | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/main/java/bjc/everge/ReplPair.java') diff --git a/src/main/java/bjc/everge/ReplPair.java b/src/main/java/bjc/everge/ReplPair.java index 2d2e115..904b1fa 100644 --- a/src/main/java/bjc/everge/ReplPair.java +++ b/src/main/java/bjc/everge/ReplPair.java @@ -761,4 +761,54 @@ public class ReplPair implements Comparable, UnaryOperator { return; } + + private static ControlledString getControls(String lne, List errs, + ReplOpts ropts, IntHolder lno, IntHolder pno, String type) { + if (!lne.startsWith("//")) { + return new ControlledString(lne); + } + + String tmp = lne.substring(2); + + String[] bits = StringUtils.escapeSplit("|", "//", lne); + + if (bits.length < 2) { + String msg = "Did not find control terminator (//) in %s where it should be"; + msg = String.format(msg, type); + + ReplError re = new ReplError(lno, pno, msg, lne); + errs.add(re); + + return null; + } + + ControlledString cs = new ControlledString(bits[0]); + + bits = StringUtils.escapeSplit("|", ";", bits[1]); + + cs.controls = new Control[bits.length]; + + for (int i = 0; i < bits.length; i++) { + String bit = bits[i]; + + String[] bots = StringUtils.escapeSplit("|", "/", bit); + + Control cont = new Control(bots[0]); + + if (cont.name.length() > 1) { + cont.name = cont.name.toUpperCase(); + } + + if (bots.length > 1) { + cont.args = new String[bots.length - 1]; + for (int j = 1; j < bots.length; j++) { + cont.args[j - 1] = bots[j]; + } + } + + cs.controls[i] = cont; + } + + return cs; + } } -- cgit v1.2.3