diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:06:04 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:06:04 -0400 |
| commit | 942c4e3d28e0eef3efc50160ad3562f7fa1b3695 (patch) | |
| tree | 4b5dc4e36dc71ec8145cf455dcefc80ac1850156 /src/main/java/bjc/everge/ControlledString.java | |
| parent | c6fced7b8d5ec1a6a37471d5edf17bb7e088cc9c (diff) | |
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
Diffstat (limited to 'src/main/java/bjc/everge/ControlledString.java')
| -rw-r--r-- | src/main/java/bjc/everge/ControlledString.java | 42 |
1 files changed, 41 insertions, 1 deletions
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; } |
