From 942c4e3d28e0eef3efc50160ad3562f7fa1b3695 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 25 Jun 2019 20:06:04 -0400 Subject: Add parsing support to ControlledString ControlledString now has support for parsing out control strings. Need to come up with something so that ReplPair can use it as is, instead of having its own implementation; plus, there are a few other interesting things I can think of that could be added to ControlledString * named arguments to controls is one * multiple named arguments * store controls in controlled string by name instead of as ordinals --- src/main/java/bjc/everge/ControlledString.java | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/main/java/bjc/everge') diff --git a/src/main/java/bjc/everge/ControlledString.java b/src/main/java/bjc/everge/ControlledString.java index f6e9f07..21aac6f 100644 --- a/src/main/java/bjc/everge/ControlledString.java +++ b/src/main/java/bjc/everge/ControlledString.java @@ -130,7 +130,47 @@ public class ControlledString { */ public static ControlledString parse(String lne, String contInd, String contSep, String contArg, String contEsc) { - ControlledString cs = new ControlledString(lne); + if (!lne.startsWith(contInd)) { + return new ControlledString(lne); + } + + String tmp = lne.substring(2); + + String[] bits = StringUtils.escapeSplit(contEsc, contInd, lne); + + if (bits.length < 2) { + String msg = "Did not find control terminator (%s) where it should be"; + msg = String.format(msg, contInd); + + throw new IllegalArgumentException(msg); + } + + ControlledString cs = new ControlledString(bits[0]); + + bits = StringUtils.escapeSplit(contEsc, contSep, bits[1]); + + cs.controls = new Control[bits.length]; + + for (int i = 0; i < bits.length; i++) { + String bit = bits[i]; + + String[] bots = StringUtils.escapeSplit(contEsc, contArg, 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