From ffdeed6d39f651bc6ffb75ecf9b8134798041f82 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 9 Sep 2019 20:13:50 -0400 Subject: Upgrade version to 0.2 --- docs/jacoco-ut/bjc.everge/BadReplParse.html | 1 + docs/jacoco-ut/bjc.everge/BadReplParse.java.html | 89 +++ .../bjc.everge/ControlledString$Control.html | 2 +- .../bjc.everge/ControlledString$ParseStrings.html | 2 +- docs/jacoco-ut/bjc.everge/ControlledString.html | 2 +- .../bjc.everge/ControlledString.java.html | 185 ++--- docs/jacoco-ut/bjc.everge/Everge$InputStatus.html | 2 +- docs/jacoco-ut/bjc.everge/Everge.html | 2 +- docs/jacoco-ut/bjc.everge/Everge.java.html | 453 ++++++------ docs/jacoco-ut/bjc.everge/IntHolder.html | 2 +- docs/jacoco-ut/bjc.everge/IntHolder.java.html | 10 +- docs/jacoco-ut/bjc.everge/ReplError.html | 2 +- docs/jacoco-ut/bjc.everge/ReplError.java.html | 27 +- docs/jacoco-ut/bjc.everge/ReplOpts.html | 2 +- docs/jacoco-ut/bjc.everge/ReplOpts.java.html | 54 +- docs/jacoco-ut/bjc.everge/ReplPair.html | 2 +- docs/jacoco-ut/bjc.everge/ReplPair.java.html | 764 +++++++++++---------- docs/jacoco-ut/bjc.everge/ReplParseException.html | 1 - .../bjc.everge/ReplParseException.java.html | 63 -- docs/jacoco-ut/bjc.everge/ReplSet.html | 2 +- docs/jacoco-ut/bjc.everge/ReplSet.java.html | 63 +- docs/jacoco-ut/bjc.everge/StringUtils.html | 2 +- docs/jacoco-ut/bjc.everge/StringUtils.java.html | 242 ++++--- docs/jacoco-ut/bjc.everge/index.html | 2 +- docs/jacoco-ut/bjc.everge/index.source.html | 2 +- 25 files changed, 1042 insertions(+), 936 deletions(-) create mode 100644 docs/jacoco-ut/bjc.everge/BadReplParse.html create mode 100644 docs/jacoco-ut/bjc.everge/BadReplParse.java.html delete mode 100644 docs/jacoco-ut/bjc.everge/ReplParseException.html delete mode 100644 docs/jacoco-ut/bjc.everge/ReplParseException.java.html (limited to 'docs/jacoco-ut/bjc.everge') diff --git a/docs/jacoco-ut/bjc.everge/BadReplParse.html b/docs/jacoco-ut/bjc.everge/BadReplParse.html new file mode 100644 index 0000000..967e289 --- /dev/null +++ b/docs/jacoco-ut/bjc.everge/BadReplParse.html @@ -0,0 +1 @@ +BadReplParse

BadReplParse

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total59 of 12853%6 of 1250%710112724
toString()280%20%224411
toPrintString()246272%4660%4651801
BadReplParse(String)70%n/a112211
BadReplParse(String, List)7100%n/a010301
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/BadReplParse.java.html b/docs/jacoco-ut/bjc.everge/BadReplParse.java.html new file mode 100644 index 0000000..4859e42 --- /dev/null +++ b/docs/jacoco-ut/bjc.everge/BadReplParse.java.html @@ -0,0 +1,89 @@ +BadReplParse.java

BadReplParse.java

package bjc.everge;
+
+import java.util.ArrayList;
+import java.util.List;
+/**
+ * Exception thrown when ReplPair parsing fails
+ * @author bjculkin
+ *
+ */
+public class BadReplParse extends RuntimeException {
+	/**
+	 * Serialization ID.
+	 */
+	private static final long serialVersionUID = 4752304282380556849L;
+	/**
+	 * The errors that were encountered during parsing.
+	 */
+	public List<ReplError> errs;
+
+	/**
+	 * Create a new exception for ReplPair parsing failing.
+	 * 
+	 * @param msg 
+	 * 	The message for the exception.
+	 */
+	public BadReplParse(String msg) {
+		this(msg, new ArrayList<>());
+	}
+
+	/**
+	 * Create a new exception for ReplPair parsing failing.
+	 * 
+	 * @param msg
+	 * 	The message for the exception.
+	 * @param errs
+	 * 	The list of errors encountered while parsing.
+	 */
+	public BadReplParse(String msg, List<ReplError> errs) {
+		super(msg);
+
+		this.errs = errs;
+	}
+
+	@Override
+	public String toString() {
+		String errString;
+		if (errs.size() == 0) errString = "An error";
+		else                  errString = "Errors";
+
+		return String.format("%s occured parsing replacement pairs: %s\n%s",
+				errString, getMessage(), errs);
+	}
+
+	/**
+	 * Convert the exception to a printable format.
+	 * 
+	 * @return The exception as a printable format.
+	 */
+	public String toPrintString() {
+		StringBuilder errString = new StringBuilder("[ERROR] ");
+
+		if (errs.size() == 0) {
+			errString.append("No specific errors");
+		} else if (errs.size() == 1) {
+			errString.append("An error");
+		} else {
+			errString.append(errs.size());
+			errString.append(" errors");
+		}
+
+		errString.append(" occured parsing replacement pairs:");
+		if (!getMessage().equals("")) {
+			errString.append(" ");
+			errString.append(getMessage());
+		}
+
+		if (errs.size() > 0) {
+			errString.append("\n\t");
+
+			for (ReplError err : errs) {
+				errString.append(err.toPrintString("\t"));
+				errString.append("\n\t");
+			}
+		}
+
+		return errString.toString().trim();
+	}
+}
+
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ControlledString$Control.html b/docs/jacoco-ut/bjc.everge/ControlledString$Control.html index e9f1cbe..c08658b 100644 --- a/docs/jacoco-ut/bjc.everge/ControlledString$Control.html +++ b/docs/jacoco-ut/bjc.everge/ControlledString$Control.html @@ -1 +1 @@ -ControlledString.Control

ControlledString.Control

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total132 of 23343%22 of 4450%2031214639
toString()480%60%448811
get(int)371224%2250%235801
hashCode()270%20%225511
equals(Object)176479%122062%111711401
ControlledString.Control()30%n/a112211
ControlledString.Control(String, String[])9100%n/a010401
ControlledString.Control(String)6100%n/a010301
C(String, String[])6100%n/a010101
count()4100%n/a010101
\ No newline at end of file +ControlledString.Control

ControlledString.Control

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total132 of 23343%22 of 4450%2031214639
toString()480%60%448811
get(int)371224%2250%235801
hashCode()270%20%225511
equals(Object)176479%122062%111711401
ControlledString.Control()30%n/a112211
ControlledString.Control(String, String[])9100%n/a010401
ControlledString.Control(String)6100%n/a010301
C(String, String[])6100%n/a010101
count()4100%n/a010101
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ControlledString$ParseStrings.html b/docs/jacoco-ut/bjc.everge/ControlledString$ParseStrings.html index 15d59e9..980fe3f 100644 --- a/docs/jacoco-ut/bjc.everge/ControlledString$ParseStrings.html +++ b/docs/jacoco-ut/bjc.everge/ControlledString$ParseStrings.html @@ -1 +1 @@ -ControlledString.ParseStrings

ControlledString.ParseStrings

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total8 of 2365%0 of 0n/a121712
PS(String, String, String, String)80%n/a111111
ControlledString.ParseStrings(String, String, String, String)15100%n/a010601
\ No newline at end of file +ControlledString.ParseStrings

ControlledString.ParseStrings

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total8 of 2365%0 of 0n/a121712
PS(String, String, String, String)80%n/a111111
ControlledString.ParseStrings(String, String, String, String)15100%n/a010601
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ControlledString.html b/docs/jacoco-ut/bjc.everge/ControlledString.html index 8b72ed6..9a5f89d 100644 --- a/docs/jacoco-ut/bjc.everge/ControlledString.html +++ b/docs/jacoco-ut/bjc.everge/ControlledString.html @@ -1 +1 @@ -ControlledString

ControlledString

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total74 of 22266%3 of 1883%516174437
toString()410%20%227711
parse(String, ControlledString.ParseStrings)1712688%11392%1832401
ControlledString(String, ControlledString.Control[])90%n/a114411
ControlledString()70%n/a113311
ControlledString(String)10100%n/a010401
hasControls()8100%2100%020101
count()4100%n/a010101
\ No newline at end of file +ControlledString

ControlledString

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total74 of 21866%3 of 1883%516174337
toString()410%20%227711
parse(String, ControlledString.ParseStrings)1712287%11392%1832301
ControlledString(String, ControlledString.Control[])90%n/a114411
ControlledString()70%n/a113311
ControlledString(String)10100%n/a010401
hasControls()8100%2100%020101
count()4100%n/a010101
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ControlledString.java.html b/docs/jacoco-ut/bjc.everge/ControlledString.java.html index 63c0b44..9beba2e 100644 --- a/docs/jacoco-ut/bjc.everge/ControlledString.java.html +++ b/docs/jacoco-ut/bjc.everge/ControlledString.java.html @@ -63,72 +63,78 @@ public class ControlledString { return args.length; } + /** + * Get an argument from the control. + * + * @param i The index of the argument to get. + * @return The argument at that position. + */ public String get(int i) { - if (i < 0) { - String msg = String.format("Control argument index must be greater than 0 (was %d)", i); + if (i < 0) { + String msg = String.format("Control argument index must be greater than 0 (was %d)", i); - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException(msg); } - if (i > args.length) { - String msg = String.format("Control argument index must be less than %d (was %d)", - args.length, i); + if (i > args.length) { + String msg = String.format("Control argument index must be less than %d (was %d)", + args.length, i); - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException(msg); } - return args[i]; + return args[i]; } @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(name); + StringBuilder sb = new StringBuilder(); + sb.append(name); - if (args != null && args.length > 0) { - sb.append("/"); + if (args != null && args.length > 0) { + sb.append("/"); - for (String arg : args) { - sb.append(arg); - sb.append(";"); + for (String arg : args) { + sb.append(arg); + sb.append(";"); } } - return sb.toString(); + return sb.toString(); } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(args); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(args); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; } @Override public boolean equals(Object obj) { - if (this == obj) { return true; } - if (obj == null) { return false; } - if (getClass() != obj.getClass()) { return false; } + if (this == obj) { return true; } + if (obj == null) { return false; } + if (getClass() != obj.getClass()) { return false; } - Control other = (Control) obj; + Control other = (Control) obj; - if (name == null) { - if (other.name != null) { return false; } - } else if (!name.equals(other.name)) { return false; } + if (name == null) { + if (other.name != null) { return false; } + } else if (!name.equals(other.name)) { return false; } - boolean isArged = args != null && args.length > 0; - boolean oIsArged = other.args != null && other.args.length > 0; + boolean isArged = args != null && args.length > 0; + boolean oIsArged = other.args != null && other.args.length > 0; - if (isArged && !oIsArged) { return false; } - if (!isArged && oIsArged) { return false; } + if (isArged && !oIsArged) { return false; } + if (!isArged && oIsArged) { return false; } - if (isArged && oIsArged) { - return Arrays.equals(args, other.args); + if (isArged && oIsArged) { + return Arrays.equals(args, other.args); } - return true; + return true; } /** @@ -141,7 +147,7 @@ public class ControlledString { * @return A control with the right parameters. */ public static Control C(String nam, String... ars) { - return new Control(nam, ars); + return new Control(nam, ars); } } @@ -183,12 +189,12 @@ public class ControlledString { * @param contEsc * The control escape. */ - public ParseStrings(String contInd, String contSep, String contArg, String contEsc) { - this.contInd = contInd; - this.contSep = contSep; - this.contArg = contArg; - this.contEsc = contEsc; - } + public ParseStrings(String contInd, String contSep, String contArg, String contEsc) { + this.contInd = contInd; + this.contSep = contSep; + this.contArg = contArg; + this.contEsc = contEsc; + } /** * Convenient static constructor. @@ -204,7 +210,7 @@ public class ControlledString { * @return A new set of control strings. */ public static ParseStrings PS(String contInd, String contSep, String contArg, String contEsc) { - return new ParseStrings(contInd, contSep, contArg, contEsc); + return new ParseStrings(contInd, contSep, contArg, contEsc); } } @@ -221,9 +227,9 @@ public class ControlledString { /** * Create a new blank controlled string. */ - public ControlledString() { - controls = new Control[0]; - } + public ControlledString() { + controls = new Control[0]; + } /** * Create a new controlled string without any controls. @@ -231,11 +237,11 @@ public class ControlledString { * @param strung * The string to use. */ - public ControlledString(String strung) { - strang = strung; + public ControlledString(String strung) { + strang = strung; - controls = new Control[0]; - } + controls = new Control[0]; + } /** * Create a new controlled string. @@ -245,11 +251,11 @@ public class ControlledString { * @param controls * The controls that apply to the string. */ - public ControlledString(String strung, Control... controls) { - strang = strung; + public ControlledString(String strung, Control... controls) { + strang = strung; - this.controls = controls; - } + this.controls = controls; + } /** * Check if the string has controls. @@ -257,7 +263,7 @@ public class ControlledString { * @return Whether or not the string has controls. */ public boolean hasControls() { - return controls.length > 0; + return controls.length > 0; } /** @@ -266,7 +272,7 @@ public class ControlledString { * @return The number of controls for this string. */ public int count() { - return controls.length; + return controls.length; } /** @@ -276,71 +282,70 @@ public class ControlledString { * * @param lne * The string to parse from. - * @param parameterObject TODO + * @param strangs + * The object to read the strings from * @return A parsed control string. */ - public static ControlledString parse(String lne, ParseStrings parameterObject) + public static ControlledString parse(String lne, ParseStrings strangs) { - if (!lne.startsWith(parameterObject.contInd)) { - return new ControlledString(lne); + if (!lne.startsWith(strangs.contInd)) { + return new ControlledString(lne); } - String tmp = lne.substring(2); - - String[] bits = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contInd, lne); + String[] bits = StringUtils.escapeSplit(strangs.contEsc, strangs.contInd, lne); - if (bits.length < 2) { - String msg = "Did not find control terminator (%s) where it should be"; - msg = String.format(msg, parameterObject.contInd); + if (bits.length < 2) { + String msg = "Did not find control terminator (%s) where it should be"; + msg = String.format(msg, strangs.contInd); - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException(msg); } - ControlledString cs = new ControlledString(bits[0]); - if (bits.length > 2) cs.strang = bits[2]; + ControlledString cs = new ControlledString(bits[0]); + if (bits.length > 2) cs.strang = bits[2]; - bits = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contSep, bits[1]); + bits = StringUtils.escapeSplit(strangs.contEsc, strangs.contSep, bits[1]); - cs.controls = new Control[bits.length]; + cs.controls = new Control[bits.length]; - for (int i = 0; i < bits.length; i++) { - String bit = bits[i]; + for (int i = 0; i < bits.length; i++) { + String bit = bits[i]; - String[] bots = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contArg, bit); + String[] bots = StringUtils.escapeSplit(strangs.contEsc, strangs.contArg, bit); - Control cont = new Control(bots[0]); + Control cont = new Control(bots[0]); - if (cont.name.length() > 1) { - cont.name = cont.name.toUpperCase(); + 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]; + 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; + cs.controls[i] = cont; } - return cs; + return cs; } @Override public String toString() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - sb.append("//"); + sb.append("//"); - for (Control cont : controls) { - sb.append(cont); + for (Control cont : controls) { + sb.append(cont); } - sb.append("//"); - sb.append(strang); + sb.append("//"); + sb.append(strang); - return sb.toString(); + return sb.toString(); } } \ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/Everge$InputStatus.html b/docs/jacoco-ut/bjc.everge/Everge$InputStatus.html index 3595e45..047e9e3 100644 --- a/docs/jacoco-ut/bjc.everge/Everge$InputStatus.html +++ b/docs/jacoco-ut/bjc.everge/Everge$InputStatus.html @@ -1 +1 @@ -Everge.InputStatus

Everge.InputStatus

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total0 of 34100%0 of 0n/a010401
static {...}34100%n/a010401
\ No newline at end of file +Everge.InputStatus

Everge.InputStatus

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total0 of 34100%0 of 0n/a010401
static {...}34100%n/a010401
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/Everge.html b/docs/jacoco-ut/bjc.everge/Everge.html index d9253fe..7524fd9 100644 --- a/docs/jacoco-ut/bjc.everge/Everge.html +++ b/docs/jacoco-ut/bjc.everge/Everge.html @@ -1 +1 @@ -Everge

Everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total534 of 85337%54 of 8334%415512419928
processArgs(List, String[])34211224%331226%25298811601
processInputFile(List, String)1334023%11321%78223301
processArgs(String[])280%40%337711
processInputFile(String)151346%3125%233701
main(String[])90%n/a113311
loadQueue(String[])77691%21083%2711301
Everge()41100%n/a0101101
processString(String)37100%1375%130901
\ No newline at end of file +Everge

Everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total538 of 85737%54 of 8334%415512419928
processArgs(List, String[])34611224%331226%25298811601
processInputFile(List, String)1334023%11321%78223301
processArgs(String[])280%40%337711
processInputFile(String)151346%3125%233701
main(String[])90%n/a113311
loadQueue(String[])77691%21083%2711301
Everge()41100%n/a0101101
processString(String)37100%1375%130901
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/Everge.java.html b/docs/jacoco-ut/bjc.everge/Everge.java.html index 8416daa..82fd293 100644 --- a/docs/jacoco-ut/bjc.everge/Everge.java.html +++ b/docs/jacoco-ut/bjc.everge/Everge.java.html @@ -1,84 +1,77 @@ Everge.java

Everge.java

package bjc.everge;
 
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.*;
 
 import java.nio.charset.Charset;
 
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.nio.file.*;
 
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Scanner;
+import java.util.*;
 
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.*;
 
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
+import java.util.regex.*;
 
 /**
  * Everge front-end application.
  *
  * @author Ben Culkin
  */
-public class Everge {
+public class Everge {
 	/**
 	 * Details how we handle our input.
 	 */
-	public static enum InputStatus {
+	public static enum InputStatus {
 		/**
 		 * Process the input as a single string.
 		 */
-		ALL,
+		ALL,
 		/**
 		 * Process the input line-by-line.
 		 */
-		LINE,
+		LINE,
 		/**
 		 * Process the input, splitting it around occurances of a regex.
 		 */
-		REGEX;
+		REGEX;
 	}
 
 	// Options for doing repl-pairs
-	private ReplOpts ropts = new ReplOpts();
+	private ReplOpts ropts = new ReplOpts();
 
 	// Loaded repl-pairs
-	private List<ReplPair> lrp = new ArrayList<>();
+	private List<ReplPair> lrp = new ArrayList<>();
 
 	// Input status
-	private InputStatus inputStat = InputStatus.ALL;
+	private InputStatus inputStat = InputStatus.ALL;
 
 	// Are we processing CLI args? (haven't seen a -- yet)
-	private boolean doingArgs = true;
+	private boolean doingArgs = true;
 
 	// Should an NL be printed after each replace?
-	private boolean printNL = true;
+	private boolean printNL = true;
 
 	// Verbosity level
-	private int verbosity = 0;
+	private int verbosity = 0;
 
 	// The pattern to use for REGEX input mode
 	private String pattern;
 
 	// The queue of arguments to process
-	private Deque<String> argQue = new LinkedList<>();
+	private Deque<String> argQue = new LinkedList<>();
 
 	// Used to prevent inter-mixing argument alterations with input processing.
-	private ReadWriteLock argLock = new ReentrantReadWriteLock();
+	private ReadWriteLock argLock = new ReentrantReadWriteLock();
 
 	// Input/output streams
-	public PrintStream outStream = System.out;
-	public PrintStream errStream = System.err;
+	/**
+	 * Stream to use for normal output.
+	 */
+	public PrintStream outStream = System.out;
+	/**
+	 * Stream to use for error output.
+	 */
+	public PrintStream errStream = System.err;
 
 	/**
 	 * Main method for front end,
@@ -87,10 +80,10 @@ import java.util.regex.PatternSyntaxException;
 	 * 		The CLI arguments.
 	 */
 	public static void main(String[] args) {
-		Everge evg = new Everge();
+		Everge evg = new Everge();
 
-		evg.processArgs(args);
-	}
+		evg.processArgs(args);
+	}
 
 	/**
 	 * Process one or more command line arguments.
@@ -100,16 +93,16 @@ import java.util.regex.PatternSyntaxException;
 	 * @return Whether we processed succesfully or not.
 	 */
 	public boolean processArgs(String... args) {
-		List<String> errs = new ArrayList<>();
+		List<String> errs = new ArrayList<>();
 
-		boolean stat = processArgs(errs, args);
-		if (!stat) {
-			for (String err : errs) {
-				errStream.println(err);
-			}
+		boolean stat = processArgs(errs, args);
+		if (!stat) {
+			for (String err : errs) {
+				errStream.println(err);
+			}
 		}
 
-		return stat;
+		return stat;
 	}
 
 	/**
@@ -122,185 +115,185 @@ import java.util.regex.PatternSyntaxException;
 	 * @return Whether we processed succesfully or not.
 	 */
 	public boolean processArgs(List<String> errs, String... args) {
-		argLock.writeLock().lock();
+		argLock.writeLock().lock();
 
-		boolean retStat = true;
+		boolean retStat = true;
 
 		try {
-			loadQueue(args);
+			loadQueue(args);
 
 			// Process CLI args
-			while(argQue.size() > 0) {
-				String arg = argQue.pop();
+			while(argQue.size() > 0) {
+				String arg = argQue.pop();
 
-				if (arg.equals("--")) {
-					doingArgs = false;
-					continue;
+				if (arg.equals("--")) {
+					doingArgs = false;
+					continue;
 				}
 
 				// Process an argument
-				if (doingArgs && arg.startsWith("-")) {
-					String argName = arg;
-					String argBody = "";
+				if (doingArgs && arg.startsWith("-")) {
+					String argName = arg;
+					String argBody = "";
 
 					// Process arguments to arguments 
-					int idx = arg.indexOf("=");
-					if (idx != -1) {
-						argName = arg.substring(0, idx);
-						argBody = arg.substring(idx + 1);
+					int idx = arg.indexOf("=");
+					if (idx != -1) {
+						argName = arg.substring(0, idx);
+						argBody = arg.substring(idx + 1);
 					}
 
-					switch (argName) {
+					switch (argName) {
 					case "-n":
 					case "--newline":
-						printNL = true;
-						break;
+						printNL = true;
+						break;
 					case "-N":
 					case "--no-newline":
-						printNL = false;
-						break;
+						printNL = false;
+						break;
 					case "-v":
 					case "--verbose":
-						verbosity += 1;
-						break;
+						verbosity += 1;
+						break;
 					case "-q":
 					case "--quiet":
-						verbosity -= 1;
-						break;
+						verbosity -= 1;
+						break;
 					case "--verbosity":
-						if (argQue.size() < 1) {
-							errs.add("[ERROR] No parameter to --verbosity");
-							retStat = false;
-							break;
+						if (argQue.size() < 1) {
+							errs.add("[ERROR] No parameter to --verbosity");
+							retStat = false;
+							break;
 						}
-						argBody = argQue.pop();
-						break;
+						argBody = argQue.pop();
+						break;
 					case "-V":
 						try {
-							verbosity = Integer.parseInt(argBody);
-						} catch (NumberFormatException nfex) {
-							String msg = String.format("[ERROR] Invalid verbosity: '%s' is not an integer",
+							verbosity = Integer.parseInt(argBody);
+						} catch (NumberFormatException nfex) {
+							String msg = String.format("[ERROR] Invalid verbosity: '%s' is not an integer",
 									argBody);
-							errs.add(msg);
-							retStat = false;
-						}
-						break;
+							errs.add(msg);
+							retStat = false;
+						}
+						break;
 					case "--pattern":
-						if (argQue.size() < 1) {
-							errs.add("[ERROR] No parameter to --pattern");
-							retStat = false;
-							break;
+						if (argQue.size() < 1) {
+							errs.add("[ERROR] No parameter to --pattern");
+							retStat = false;
+							break;
 						}
-						argBody = argQue.pop();
+						argBody = argQue.pop();
 					case "-p":
 						try {
-							pattern = argBody;
-
-							Pattern.compile(argBody);
-						} catch (PatternSyntaxException psex) {
-							String msg = String.format("[ERROR] Pattern '%s' is invalid: %s",
-									pattern, psex.getMessage());
-							errs.add(msg);
-							retStat = false;
-						}
-						break;
+							pattern = argBody;
+
+							Pattern.compile(argBody);
+						} catch (PatternSyntaxException psex) {
+							String msg = String.format("[ERROR] Pattern '%s' is invalid: %s",
+									pattern, psex.getMessage());
+							errs.add(msg);
+							retStat = false;
+						}
+						break;
 					case "--file":
-						if (argQue.size() < 1) {
-							errs.add("[ERROR] No argument to --file");
-							retStat = false;
-							break;
+						if (argQue.size() < 1) {
+							errs.add("[ERROR] No argument to --file");
+							retStat = false;
+							break;
 						}
-						argBody = argQue.pop();
+						argBody = argQue.pop();
 					case "-f":
-						try (FileInputStream fis = new FileInputStream(argBody);
-								Scanner scn = new Scanner(fis)) {
-							List<ReplError> ferrs = new ArrayList<>();
+						try (FileInputStream fis = new FileInputStream(argBody);
+								Scanner scn = new Scanner(fis)) {
+							List<ReplError> ferrs = new ArrayList<>();
 
-							lrp = ReplPair.readList(lrp, scn, ferrs, ropts);
+							lrp = ReplPair.readList(lrp, scn, ferrs, ropts);
 
-							if (ferrs.size() > 0) {
-								StringBuilder sb = new StringBuilder();
+							if (ferrs.size() > 0) {
+								StringBuilder sb = new StringBuilder();
 								
-								String errString = "an error";
-								if (ferrs.size() > 1) errString = String.format("%d errors");
+								String errString = "an error";
+								if (ferrs.size() > 1) errString = String.format("%d errors");
 
 								{
-									String msg = String.format(
-											"[ERROR] Encountered errors parsing data file'%s'\n",
-											argBody);
-									sb.append(msg);
+									String msg = String.format(
+											"[ERROR] Encountered %s parsing data file'%s'\n",
+											errString, argBody);
+									sb.append(msg);
 								}
 
-								for (ReplError err : ferrs) {
-									sb.append(String.format("\t%s\n", err));
-								}
+								for (ReplError err : ferrs) {
+									sb.append(String.format("\t%s\n", err));
+								}
 
-								errs.add(sb.toString());
-								retStat = false;
+								errs.add(sb.toString());
+								retStat = false;
 							}
-						} catch (FileNotFoundException fnfex) {
-							String msg = String.format("[ERROR] Could not open data file '%s' for input",
+						} catch (FileNotFoundException fnfex) {
+							String msg = String.format("[ERROR] Could not open data file '%s' for input",
 									argBody);
-							errs.add(msg);
-							retStat = false;
-						} catch (IOException ioex) {
-							String msg = String.format("[ERROR] Unknown I/O error reading data file '%s': %s",
-									argBody, ioex.getMessage());
-							errs.add(msg);
-							retStat = false;
-						}
-						break;
+							errs.add(msg);
+							retStat = false;
+						} catch (IOException ioex) {
+							String msg = String.format("[ERROR] Unknown I/O error reading data file '%s': %s",
+									argBody, ioex.getMessage());
+							errs.add(msg);
+							retStat = false;
+						}
+						break;
 					case "--arg-file":
-						if (argQue.size() < 1) {
-							errs.add("[ERROR] No argument to --arg-file");
-							break;
+						if (argQue.size() < 1) {
+							errs.add("[ERROR] No argument to --arg-file");
+							break;
 						}
-						argBody = argQue.pop();
+						argBody = argQue.pop();
 					case "-F":
-						try (FileInputStream fis = new FileInputStream(argBody);
-								Scanner scn = new Scanner(fis)) {
-							List<String> sl = new ArrayList<>();
-
-							while (scn.hasNextLine()) {
-								String ln = scn.nextLine().trim();
-
-								if (ln.equals(""))      continue;
-								if (ln.startsWith("#")) continue;
-
-								sl.add(ln);
-							}
-
-							processArgs(sl.toArray(new String[0]));
-						} catch (FileNotFoundException fnfex) {
-							String msg = String.format("[ERROR] Could not open argument file '%s' for input", argBody);
-							errs.add(msg);
-							retStat = false;
-						} catch (IOException ioex) {
-							String msg = String.format("[ERROR] Unknown I/O error reading input file '%s': %s",
-									argBody, ioex.getMessage());
-							errs.add(msg);
-							retStat = false;
-						}
-						break;
+						try (FileInputStream fis = new FileInputStream(argBody);
+								Scanner scn = new Scanner(fis)) {
+							List<String> sl = new ArrayList<>();
+
+							while (scn.hasNextLine()) {
+								String ln = scn.nextLine().trim();
+
+								if (ln.equals(""))      continue;
+								if (ln.startsWith("#")) continue;
+
+								sl.add(ln);
+							}
+
+							processArgs(sl.toArray(new String[0]));
+						} catch (FileNotFoundException fnfex) {
+							String msg = String.format("[ERROR] Could not open argument file '%s' for input", argBody);
+							errs.add(msg);
+							retStat = false;
+						} catch (IOException ioex) {
+							String msg = String.format("[ERROR] Unknown I/O error reading input file '%s': %s",
+									argBody, ioex.getMessage());
+							errs.add(msg);
+							retStat = false;
+						}
+						break;
 					default:
 						{
-							String msg = String.format("[ERROR] Unrecognised CLI argument name '%s'\n", argName);
-							errs.add(msg);
-							retStat = false;
+							String msg = String.format("[ERROR] Unrecognised CLI argument name '%s'\n", argName);
+							errs.add(msg);
+							retStat = false;
 						}
 					}
-				} else {
+				} else {
 					// Strip off an escaped initial dash
-					if (arg.startsWith("\\-")) arg = arg.substring(1);
+					if (arg.startsWith("\\-")) arg = arg.substring(1);
 
-					processInputFile(arg);
+					processInputFile(arg);
 				}
-			}
+			}
 		} finally {
-			argLock.writeLock().unlock();
+			argLock.writeLock().unlock();
 		}
 
-		return retStat;
+		return retStat;
 	}
 
 	/**
@@ -311,16 +304,16 @@ import java.util.regex.PatternSyntaxException;
 	 * @return Whether we processed succesfully or not.
 	 */
 	public boolean processInputFile(String fle) {
-		List<String> errs = new ArrayList<>();
+		List<String> errs = new ArrayList<>();
 
-		boolean stat = processInputFile(errs, fle);
-		if (!stat) {
-			for (String err : errs) {
-				errStream.println(err);
-			}
+		boolean stat = processInputFile(errs, fle);
+		if (!stat) {
+			for (String err : errs) {
+				errStream.println(err);
+			}
 		}
 
-		return stat;
+		return stat;
 	}
 
 	/**
@@ -333,58 +326,58 @@ import java.util.regex.PatternSyntaxException;
 	 * @return Whether we processed succesfully or not.
 	 */
 	public boolean processInputFile(List<String> errs, String fle) {
-		argLock.readLock().lock();
+		argLock.readLock().lock();
 
 		// Read in and do replacements on a file
 		try {
-			if (verbosity > 2) {
-				errStream.printf("[TRACE] Reading file (%s) in mode (%s)\n", fle, inputStat);
+			if (verbosity > 2) {
+				errStream.printf("[TRACE] Reading file (%s) in mode (%s)\n", fle, inputStat);
 			}
 
-			if (inputStat == InputStatus.ALL) {
-				Path pth = Paths.get(fle);
+			if (inputStat == InputStatus.ALL) {
+				Path pth = Paths.get(fle);
 
-				if (!Files.isReadable(pth)) {
-					String msg = String.format("[ERROR] File '%s' is not readable\n", fle);
-					errs.add(msg);
-					return false;
-				} else {
-					byte[] inp = Files.readAllBytes(pth);
+				if (!Files.isReadable(pth)) {
+					String msg = String.format("[ERROR] File '%s' is not readable\n", fle);
+					errs.add(msg);
+					return false;
+				}
 
-					String strang = new String(inp, Charset.forName("UTF-8"));
+				byte[] inp = Files.readAllBytes(pth);
 
-					processString(strang);
-				}
-			} else if (inputStat == InputStatus.LINE) {
-				try (FileInputStream fis = new FileInputStream(fle); Scanner scn = new Scanner(fis)) {
-					while(scn.hasNextLine()) {
-						processString(scn.nextLine());
+				String strang = new String(inp, Charset.forName("UTF-8"));
+
+				processString(strang);
+			} else if (inputStat == InputStatus.LINE) {
+				try (FileInputStream fis = new FileInputStream(fle); Scanner scn = new Scanner(fis)) {
+					while(scn.hasNextLine()) {
+						processString(scn.nextLine());
 					}
-				}
-			} else if (inputStat == InputStatus.REGEX) {
-				try (FileInputStream fis = new FileInputStream(fle); Scanner scn = new Scanner(fis)) {
-					scn.useDelimiter(pattern);
+				}
+			} else if (inputStat == InputStatus.REGEX) {
+				try (FileInputStream fis = new FileInputStream(fle); Scanner scn = new Scanner(fis)) {
+					scn.useDelimiter(pattern);
 
-					while(scn.hasNext()) {
-						processString(scn.next());
+					while(scn.hasNext()) {
+						processString(scn.next());
 					}
-				}
+				}
 			} else {
-				String msg = String.format("[INTERNAL-ERROR] Input status '%s' is not yet implemented\n",
+				String msg = String.format("[INTERNAL-ERROR] Input status '%s' is not yet implemented\n",
 						inputStat);
-				errs.add(msg);
-				return false;
+				errs.add(msg);
+				return false;
 			}
-		} catch (IOException ioex) {
-			String msg = String.format("[ERROR] Unknown I/O related error for file '%s'\n\tError was %s",
-					fle, ioex.getMessage());
-			errs.add(msg);
-			return false;
+		} catch (IOException ioex) {
+			String msg = String.format("[ERROR] Unknown I/O related error for file '%s'\n\tError was %s",
+					fle, ioex.getMessage());
+			errs.add(msg);
+			return false;
 		} finally {
-			argLock.readLock().unlock();
+			argLock.readLock().unlock();
 		}
 
-		return true;
+		return true;
 	}
 
 	/**
@@ -394,43 +387,43 @@ import java.util.regex.PatternSyntaxException;
 	 * 		The input string to process.
 	 */
 	public void processString(String inp) {
-		argLock.readLock().lock();
+		argLock.readLock().lock();
 
 		try {
-			String strang = inp;
+			String strang = inp;
 
-			for (ReplPair rp : lrp) {
-				strang = rp.apply(strang);
-			}
+			for (ReplPair rp : lrp) {
+				strang = rp.apply(strang);
+			}
 
-			outStream.print(strang);
-			if (printNL) outStream.println();
+			outStream.print(strang);
+			if (printNL) outStream.println();
 		} finally {
-			argLock.readLock().unlock();
+			argLock.readLock().unlock();
 		}
-	}
+	}
 
 	// Load arguments into the argument queue.
 	private void loadQueue(String... args) {
-		boolean doArgs = true;
-		for (String arg : args) {
-			if (arg.equals("--")) doArgs = false;
+		boolean doArgs = true;
+		for (String arg : args) {
+			if (arg.equals("--")) doArgs = false;
 
 			// Handle things like -nNv correctly
-			if (doArgs) {
-				if (arg.startsWith("-") && !arg.startsWith("--")) {
-					char[] car = arg.substring(1).toCharArray();
-					for (char c : car) {
-						String argstr = String.format("-%c", c);
-						argQue.add(argstr);
+			if (doArgs) {
+				if (arg.startsWith("-") && !arg.startsWith("--")) {
+					char[] car = arg.substring(1).toCharArray();
+					for (char c : car) {
+						String argstr = String.format("-%c", c);
+						argQue.add(argstr);
 					}
-				} else {
-					argQue.add(arg);
+				} else {
+					argQue.add(arg);
 				}
 			} else {
-				argQue.add(arg);
+				argQue.add(arg);
 			}
 		}
-	}
+	}
 }
 
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/IntHolder.html b/docs/jacoco-ut/bjc.everge/IntHolder.html index 7ef6a96..13bb140 100644 --- a/docs/jacoco-ut/bjc.everge/IntHolder.html +++ b/docs/jacoco-ut/bjc.everge/IntHolder.html @@ -1 +1 @@ -IntHolder

IntHolder

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total10 of 3268%0 of 0n/a2651226
IntHolder(int)60%n/a113311
set(int)40%n/a112211
incr(int)9100%n/a010201
IntHolder()6100%n/a010301
incr()4100%n/a010101
get()3100%n/a010101
\ No newline at end of file +IntHolder

IntHolder

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total10 of 3268%0 of 0n/a2651226
IntHolder(int)60%n/a113311
set(int)40%n/a112211
incr(int)9100%n/a010201
IntHolder()6100%n/a010301
incr()4100%n/a010101
get()3100%n/a010101
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/IntHolder.java.html b/docs/jacoco-ut/bjc.everge/IntHolder.java.html index 746a71a..db6e5b4 100644 --- a/docs/jacoco-ut/bjc.everge/IntHolder.java.html +++ b/docs/jacoco-ut/bjc.everge/IntHolder.java.html @@ -60,8 +60,14 @@ public class IntHolder { return val; } + /** + * Set the value. + * + * @param i + * The value to set it to. + */ public void set(int i) { - val = i; - } + val = i; + } } \ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplError.html b/docs/jacoco-ut/bjc.everge/ReplError.html index 5fe14b6..012b0c4 100644 --- a/docs/jacoco-ut/bjc.everge/ReplError.html +++ b/docs/jacoco-ut/bjc.everge/ReplError.html @@ -1 +1 @@ -ReplError

ReplError

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total57 of 13256%5 of 837%5951825
toString()500%40%334411
toPrintString()40%n/a111111
toPrintString(String)35194%1375%130501
ReplError(int, int, String, String)15100%n/a010601
ReplError(IntHolder, IntHolder, String, String)9100%n/a010201
\ No newline at end of file +ReplError

ReplError

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total72 of 13245%7 of 812%6971825
toString()500%40%334411
toPrintString(String)183666%3125%232501
toPrintString()40%n/a111111
ReplError(int, int, String, String)15100%n/a010601
ReplError(IntHolder, IntHolder, String, String)9100%n/a010201
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplError.java.html b/docs/jacoco-ut/bjc.everge/ReplError.java.html index 1e0ba81..7c92b1c 100644 --- a/docs/jacoco-ut/bjc.everge/ReplError.java.html +++ b/docs/jacoco-ut/bjc.everge/ReplError.java.html @@ -7,7 +7,7 @@ */ public class ReplError { /** - * The line the error occured on. + * The line the error occurred on. */ public int line; /** @@ -70,18 +70,31 @@ public class ReplError { return String.format("line %d, pair %d:%s\n\t%s", line, numPairs, msg, errString); } + /** + * Convert the error to a printable string. + * + * @return The error as a printable string. + */ public String toPrintString() { - return toPrintString(""); + return toPrintString(""); } + /** + * Convert the error to a printable string, with a custom header. + * + * @param hdr + * The text to include in the header. + * + * @return The error as a printable string. + */ public String toPrintString(String hdr) { String errString; - if (txt == null) errString = "No associated line"; - else if (txt.equals("")) errString = "Text of line was empty"; - else errString = "Text of line was: " + txt; + if (txt == null) errString = "No associated line"; + else if (txt.equals("")) errString = "Text of line was empty"; + else errString = "Text of line was: " + txt; - return String.format("[ERROR] line %d, pair %d: %s\n%s\tContext: %s", - line, numPairs, msg, hdr, errString); + return String.format("[ERROR] line %d, pair %d: %s\n%s\tContext: %s", + line, numPairs, msg, hdr, errString); } } \ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplOpts.html b/docs/jacoco-ut/bjc.everge/ReplOpts.html index 9d884f8..aa18045 100644 --- a/docs/jacoco-ut/bjc.everge/ReplOpts.html +++ b/docs/jacoco-ut/bjc.everge/ReplOpts.html @@ -1 +1 @@ -ReplOpts

ReplOpts

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total147 of 17716%30 of 300%1718223223
hashCode()770%100%66101011
equals(Object)700%200%1111121211
ReplOpts()30100%n/a0101001
\ No newline at end of file +ReplOpts

ReplOpts

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total147 of 17716%30 of 300%1718223223
hashCode()770%100%66101011
equals(Object)700%200%1111121211
ReplOpts()30100%n/a0101001
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplOpts.java.html b/docs/jacoco-ut/bjc.everge/ReplOpts.java.html index 8e3e829..c8b5767 100644 --- a/docs/jacoco-ut/bjc.everge/ReplOpts.java.html +++ b/docs/jacoco-ut/bjc.everge/ReplOpts.java.html @@ -43,35 +43,41 @@ import java.io.PrintStream; */ public boolean isPerf = false; - public PrintStream outStream = System.out; - public PrintStream errStream = System.err; + /** + * The stream to print normal output on. + */ + public PrintStream outStream = System.out; + /** + * The stream to print error output on. + */ + public PrintStream errStream = System.err; @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (defMulti ? 1231 : 1237); - result = prime * result + defPrior; - result = prime * result + defStage; - result = prime * result + ((defStatus == null) ? 0 : defStatus.hashCode()); - result = prime * result + (isDebug ? 1231 : 1237); - result = prime * result + (isPerf ? 1231 : 1237); - result = prime * result + (isTrace ? 1231 : 1237); - return result; + final int prime = 31; + int result = 1; + result = prime * result + (defMulti ? 1231 : 1237); + result = prime * result + defPrior; + result = prime * result + defStage; + result = prime * result + ((defStatus == null) ? 0 : defStatus.hashCode()); + result = prime * result + (isDebug ? 1231 : 1237); + result = prime * result + (isPerf ? 1231 : 1237); + result = prime * result + (isTrace ? 1231 : 1237); + return result; } @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - ReplOpts other = (ReplOpts) obj; - if (defMulti != other.defMulti) return false; - if (defPrior != other.defPrior) return false; - if (defStage != other.defStage) return false; - if (defStatus != other.defStatus) return false; - if (isDebug != other.isDebug) return false; - if (isPerf != other.isPerf) return false; - if (isTrace != other.isTrace) return false; - return true; + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + ReplOpts other = (ReplOpts) obj; + if (defMulti != other.defMulti) return false; + if (defPrior != other.defPrior) return false; + if (defStage != other.defStage) return false; + if (defStatus != other.defStatus) return false; + if (isDebug != other.isDebug) return false; + if (isPerf != other.isPerf) return false; + if (isTrace != other.isTrace) return false; + return true; } } \ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplPair.html b/docs/jacoco-ut/bjc.everge/ReplPair.html index e7404ea..f5189e8 100644 --- a/docs/jacoco-ut/bjc.everge/ReplPair.html +++ b/docs/jacoco-ut/bjc.everge/ReplPair.html @@ -1 +1 @@ -ReplPair

ReplPair

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total940 of 1,77547%99 of 20451%83133161355218
readGlobal(String, Scanner, List, ReplOpts, IntHolder, IntHolder)3028722%241233%2127699001
readList(List, Scanner, List, ReplOpts)25437559%295163%24422611601
readName(String, Scanner, List, ReplPair, ReplOpts, IntHolder, IntHolder)2149630%141450%1219456901
hashCode()590%60%448811
readMultiLine(String, Scanner, ReplOpts, List, String, IntHolder)378469%81260%61122001
equals(Object)315262%171139%141531601
getControls(String, List, ReplOpts, IntHolder, IntHolder, String)261027%n/a016701
toString()103376%1150%120301
ReplPair(String, String, String)70%n/a112211
readList(List, Scanner)20100%2100%020501
ReplPair(String, String, int, String)18100%n/a010701
compareTo(ReplPair)17100%2100%020201
readList(Scanner)8100%n/a010201
readList(List, Scanner, List)8100%n/a010101
ReplPair()7100%n/a010201
ReplPair(String, String, int)7100%n/a010201
apply(String)7100%n/a010101
ReplPair(String, String)6100%n/a010201
\ No newline at end of file +ReplPair

ReplPair

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total987 of 1,85046%100 of 21152%84137169371218
readGlobal(String, Scanner, List, ReplOpts, IntHolder, IntHolder)3028722%241233%2127699001
readName(String, Scanner, List, ReplPair, ReplOpts, IntHolder, IntHolder)26111430%151651%1321538301
readList(List, Scanner, List, ReplOpts)25437559%295163%24422611601
hashCode()590%60%448811
readMultiLine(String, Scanner, ReplOpts, List, String, IntHolder)378469%81260%61122001
equals(Object)315262%171139%141531601
getControls(String, List, ReplOpts, IntHolder, IntHolder, String)261027%n/a016701
toString()103376%1150%120301
ReplPair(String, String, String)70%n/a112211
readList(List, Scanner)20100%2100%020501
ReplPair(String, String, int, String)18100%n/a010701
apply(String)17100%4100%030301
compareTo(ReplPair)17100%2100%020201
readList(Scanner)8100%n/a010201
readList(List, Scanner, List)8100%n/a010101
ReplPair()7100%n/a010201
ReplPair(String, String, int)7100%n/a010201
ReplPair(String, String)6100%n/a010201
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplPair.java.html b/docs/jacoco-ut/bjc.everge/ReplPair.java.html index 9701d27..eea7307 100644 --- a/docs/jacoco-ut/bjc.everge/ReplPair.java.html +++ b/docs/jacoco-ut/bjc.everge/ReplPair.java.html @@ -1,13 +1,10 @@ ReplPair.java

ReplPair.java

package bjc.everge;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Scanner;
+import java.util.*;
+import java.util.function.*;
+import java.util.regex.*;
 
-import java.util.function.UnaryOperator;
-
-import bjc.everge.ControlledString.Control;
-import bjc.everge.ControlledString.ParseStrings;
+import bjc.everge.ControlledString.*;
 
 /**
  * String pairs for replacements.
@@ -22,7 +19,7 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	private int stage;
 
 	// Status of this pair with regards to doing staging stuff
-	private StageStatus stat = StageStatus.BOTH;
+	private StageStatus stat = StageStatus.BOTH;
 
 	/**
 	 * The priority for this replacement.
@@ -36,6 +33,14 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 */
 	public String name;
 
+	/**
+	 * The guard for this replacement.
+	 *
+	 * The guard of the replacement is a regex that has to match before the pair will be considered.
+	 * Defaults to being blank.
+	 */
+	public String guard;
+
 	/**
 	 * The string to look for.
 	 */
@@ -50,8 +55,8 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * Create a new blank replacement pair.
 	 */
 	public ReplPair() {
-		this("", "", 1, null);
-	}
+		this("", "", 1, null);
+	}
 
 	/**
 	 * Create a new replacement pair with a priority of 1.
@@ -62,8 +67,8 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The string to replace.
 	 */
 	public ReplPair(String f, String r) {
-		this(f, r, 1);
-	}
+		this(f, r, 1);
+	}
 
 	/**
 	 * Create a new named replacement pair with a priority of 1.
@@ -76,8 +81,8 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The name of the replacement pair.
 	 */
 	public ReplPair(String f, String r, String n) {
-		this(f, r, 1, n);
-	}
+		this(f, r, 1, n);
+	}
 
 	/**
 	 * Create a new replacement pair with a set priority.
@@ -90,8 +95,8 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The priority for the replacement.
 	 */
 	public ReplPair(String f, String r, int p) {
-		this(f, r, p, f);
-	}
+		this(f, r, p, f);
+	}
 
 	/**
 	 * Create a new replacement pair with a set priority and name.
@@ -105,14 +110,14 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * @param p
 	 * 	The priority for the replacement.
 	 */
-	public ReplPair(String f, String r, int p, String n) {
-		find    = f;
-		replace = r;
+	public ReplPair(String f, String r, int p, String n) {
+		find    = f;
+		replace = r;
 
-		name = n;
+		name = n;
 
-		priority = p;
-	}
+		priority = p;
+	}
 
 	/**
 	 * Read a list of replacement pairs from an input source.
@@ -123,9 +128,9 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The list of replacements.
 	 */
 	public static List<ReplPair> readList(Scanner scn) {
-		List<ReplPair> lst = new ArrayList<>();
+		List<ReplPair> lst = new ArrayList<>();
 
-		return readList(lst, scn);
+		return readList(lst, scn);
 	}
 
 	/**
@@ -140,15 +145,15 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The list of replacements.
 	 */
 	public static List<ReplPair> readList(List<ReplPair> detals, Scanner scn) {
-		List<ReplError> errList = new ArrayList<>();
+		List<ReplError> errList = new ArrayList<>();
 
-		List<ReplPair> rplPar = readList(detals, scn, errList);
+		List<ReplPair> rplPar = readList(detals, scn, errList);
 
-		if (errList.size() != 0) {
-			throw new ReplParseException("", errList);
+		if (errList.size() != 0) {
+			throw new BadReplParse("", errList);
 		}
 
-		return rplPar;
+		return rplPar;
 	}
 
 	/**
@@ -165,7 +170,7 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 	 * 	The list of replacements.
 	 */
 	public static List<ReplPair> readList(List<ReplPair> detals, Scanner scn, List<ReplError> errs) {
-		return readList(detals, scn, errs, new ReplOpts());
+		return readList(detals, scn, errs, new ReplOpts());
 	}
 
 	/**
@@ -187,627 +192,652 @@ public class ReplPair implements Comparable<ReplPair>, UnaryOperator<St
 			List<ReplPair> detals, Scanner scn,
 			List<ReplError> errs, ReplOpts ropts) 
 	{
-		IntHolder lno = new IntHolder();
-		IntHolder pno = new IntHolder();
+		IntHolder lno = new IntHolder();
+		IntHolder pno = new IntHolder();
 
-		List<List<ReplPair>> stages = new ArrayList<>();
-		stages.add(new ArrayList<ReplPair>());
+		List<List<ReplPair>> stages = new ArrayList<>();
+		stages.add(new ArrayList<ReplPair>());
 
 		// For every line in the source...
-		while (scn.hasNextLine()) {
-			String name = scn.nextLine().trim();
-			lno.incr();
+		while (scn.hasNextLine()) {
+			String name = scn.nextLine().trim();
+			lno.incr();
 
 			// If its commented or blank, skip it
-			if (name.equals(""))      continue;
-			if (name.startsWith("#")) continue;
+			if (name.equals(""))      continue;
+			if (name.startsWith("#")) continue;
 
 			// Global control. Process it.
-			if (name.startsWith("|//")) {
-				readGlobal(name, scn, errs, ropts, lno, pno);
+			if (name.startsWith("|//")) {
+				readGlobal(name, scn, errs, ropts, lno, pno);
 
-				continue;
+				continue;
 			}
 
-			ReplPair rp = new ReplPair();
+			ReplPair rp = new ReplPair();
 
-			rp.priority = ropts.defPrior;
-			rp.stat     = ropts.defStatus;
-			rp.lno      = lno.get();
-			rp.stage    = ropts.defStage;
+			rp.priority = ropts.defPrior;
+			rp.stat     = ropts.defStatus;
+			rp.lno      = lno.get();
+			rp.stage    = ropts.defStage;
 
-			boolean isMulti = ropts.defMulti;
+			boolean isMulti = ropts.defMulti;
 
 			{
-				String tmpName = readName(name, scn, errs, rp, ropts, lno, pno);
-				if (tmpName == null) continue;
-				name = tmpName;
+				String tmpName = readName(name, scn, errs, rp, ropts, lno, pno);
+				if (tmpName == null) continue;
+				name = tmpName;
 			}
 
-			rp.find = name;
-			if (rp.name == null) rp.name = name;
+			rp.find = name;
+			if (rp.name == null) rp.name = name;
 
 			// We started to process the pair, mark it as being
 			// started
-			pno.incr();
-			String body = null;
+			pno.incr();
+			String body = null;
 
 			// Read in the next uncommented line
 			do {
-				if (!scn.hasNextLine()) break; 
+				if (!scn.hasNextLine()) break; 
 
-				body = scn.nextLine().trim();
-				lno.incr();
-			} while (body.startsWith("#"));
+				body = scn.nextLine().trim();
+				lno.incr();
+			} while (body.startsWith("#"));
 
-			if (body == null) {
-				String msg = String.format(
+			if (body == null) {
+				String msg = String.format(
 						"Ran out of input looking for replacement body for raw name '%s'", name);
 
-				errs.add(new ReplError(lno, pno, msg, null));
-				break;
+				errs.add(new ReplError(lno, pno, msg, null));
+				break;
 			}
 
-			isMulti = ropts.defMulti;
+			isMulti = ropts.defMulti;
 			
-			ControlledString cs = getControls(body, errs, ropts, lno, pno, "body");
+			ControlledString cs = getControls(body, errs, ropts, lno, pno, "body");
 			// Body has attached controls, process them.
-			if (cs.hasControls()) {
-				for (Control cont : cs.controls) {
-					switch (cont.name) {
+			if (cs.hasControls()) {
+				for (Control cont : cs.controls) {
+					switch (cont.name) {
 					case "MULTITRUE":
 					case "MULTIT":
 					case "MT":
-						isMulti = true;
-						break;
+						isMulti = true;
+						break;
 					case "MULTIFALSE":
 					case "MULTIF":
 					case "MF":
-						isMulti = false;
-						break;
+						isMulti = false;
+						break;
 					case "MULTI":
 					case "M":
-						if (cont.count() != 1) {
-							String errMsg = String.format("Expected one multi flag (got %d)", cont.count());
-							errs.add(new ReplError(lno, pno, errMsg, body));
-						} else {
-							isMulti = Boolean.parseBoolean(cont.get(0));
+						if (cont.count() != 1) {
+							String errMsg = String.format("Expected one multi flag (got %d)", cont.count());
+							errs.add(new ReplError(lno, pno, errMsg, body));
+						} else {
+							isMulti = Boolean.parseBoolean(cont.get(0));
 						}
-						break;
+						break;
 					default: 
 						{
-							String errMsg = String.format("Invalid control name '%s'", cont.name);
-							errs.add(new ReplError(lno, pno, errMsg, body));
+							String errMsg = String.format("Invalid control name '%s'", cont.name);
+							errs.add(new ReplError(lno, pno, errMsg, body));
 						}
 						break;
 					}
 				}
 
-				body = cs.strang;
+				body = cs.strang;
 			}
 
-			if (isMulti) {
-				String tmp = readMultiLine(body, scn, ropts, errs, "body", lno);
-				if (tmp == null) continue;
-				body = tmp;
+			if (isMulti) {
+				String tmp = readMultiLine(body, scn, ropts, errs, "body", lno);
+				if (tmp == null) continue;
+				body = tmp;
 			}
 
-			rp.replace = body;
+			rp.replace = body;
 
-			List<ReplPair> stageList = null;
-			if (rp.stage == 0 || stages.size() < (rp.stage - 1)) {
-				stageList = stages.get(rp.stage);
+			List<ReplPair> stageList = null;
+			if (rp.stage == 0 || stages.size() < (rp.stage - 1)) {
+				stageList = stages.get(rp.stage);
 
-				if (stageList == null) {
-					stageList = new ArrayList<>();
+				if (stageList == null) {
+					stageList = new ArrayList<>();
 
-					stages.add(rp.stage, stageList);
+					stages.add(rp.stage, stageList);
 				}
 			} else {
-				for (int i = stages.size(); i <= rp.stage; i++) {
-					stages.add(new ArrayList<>());
+				for (int i = stages.size(); i <= rp.stage; i++) {
+					stages.add(new ArrayList<>());
 				}
 
-				stageList = stages.get(rp.stage);
+				stageList = stages.get(rp.stage);
 			}
 
-			if (ropts.isTrace) {
-				ropts.errStream.printf("\t[DEBUG] Stage %d: Added %s\n\t\tContents: %s\n",
-						rp.stage, rp, stageList);
+			if (ropts.isTrace) {
+				ropts.errStream.printf("\t[DEBUG] Stage %d: Added %s\n\t\tContents: %s\n",
+						rp.stage, rp, stageList);
 			}
 
-			stageList.add(rp);
-		}
+			stageList.add(rp);
+		}
 
 		// Special-case one-stage processing.
-		if (stages.size() == 1) {
-			if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Executing single-stage bypass\n");
+		if (stages.size() == 1) {
+			if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Executing single-stage bypass\n");
 
-			for (ReplPair rp : stages.iterator().next()) {
-				if (rp.stat == StageStatus.INTERNAL) {
-					if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluding internal RP %s\n", rp);
+			for (ReplPair rp : stages.iterator().next()) {
+				if (rp.stat == StageStatus.INTERNAL) {
+					if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluding internal RP %s\n", rp);
 
 					continue;
 				}
 
-				detals.add(rp);
-			}
+				detals.add(rp);
+			}
 
-			detals.sort(null);
+			detals.sort(null);
 
-			return detals;
+			return detals;
 		}
 
 		// Handle stages
-		List<ReplPair> tmpList = new ArrayList<>();
-		tmpList.addAll(detals);
+		List<ReplPair> tmpList = new ArrayList<>();
+		tmpList.addAll(detals);
 
-		if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Stages: %s\n", stages);
+		if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Stages: %s\n", stages);
 
-		int procStg = 0;
-		for (List<ReplPair> stageList : stages) {
-			procStg += 1;
-			List<ReplPair> curStage = new ArrayList<>();
+		int procStg = 0;
+		for (List<ReplPair> stageList : stages) {
+			procStg += 1;
+			List<ReplPair> curStage = new ArrayList<>();
 
-			if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Staging stage %d of %d: %s\n",
-					procStg, stageList.size(), stageList);
+			if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Staging stage %d of %d: %s\n",
+					procStg, stageList.size(), stageList);
 
-			for (ReplPair rp : stageList) {
+			for (ReplPair rp : stageList) {
 				// Process through every pair in the previous
 				// stages
-				for (ReplPair curPar : tmpList) {
-					String tmp = rp.replace.replaceAll(curPar.find, curPar.replace);
+				for (ReplPair curPar : tmpList) {
+					String tmp = rp.replace.replaceAll(curPar.find, curPar.replace);
 
-					if (ropts.isTrace && !rp.replace.equals(tmp)) {
-						ropts.errStream.printf("\t[DEBUG] Staged '%s' -> '%s'\t%s\n",
+					if (ropts.isTrace && !rp.replace.equals(tmp)) {
+						ropts.errStream.printf("\t[DEBUG] Staged '%s' -> '%s'\t%s\n",
 							rp.replace, tmp, curPar);
 					}
 
-					rp.replace = tmp;
-				}
+					rp.replace = tmp;
+				}
 
 				// If we're external; add straight to the output
-				if (rp.stat == StageStatus.EXTERNAL) {
-					if (ropts.isTrace) {
-						ropts.errStream.printf("\t[DEBUG] Skipped external for staging: %s\n",
+				if (rp.stat == StageStatus.EXTERNAL) {
+					if (ropts.isTrace) {
+						ropts.errStream.printf("\t[DEBUG] Skipped external for staging: %s\n",
 								rp);
 					}
 
-					detals.add(rp);
+					detals.add(rp);
 				} else {
-					if (ropts.isTrace) {
-						ropts.errStream.printf("\t[DEBUG] Added to stage %d: %s\n\t\tContents: %s\n",
-								procStg, rp, curStage);
+					if (ropts.isTrace) {
+						ropts.errStream.printf("\t[DEBUG] Added to stage %d: %s\n\t\tContents: %s\n",
+								procStg, rp, curStage);
 					}
 
-					curStage.add(rp);
+					curStage.add(rp);
 				}
-			}
+			}
 			
-			tmpList.addAll(curStage);
-			tmpList.sort(null);
-		}
+			tmpList.addAll(curStage);
+			tmpList.sort(null);
+		}
 
 		// Copy over to output, excluding internals
-		for (ReplPair rp : tmpList) {
-			if (rp.stat == StageStatus.INTERNAL) {
-				if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluded internal: %s\n", rp);
+		for (ReplPair rp : tmpList) {
+			if (rp.stat == StageStatus.INTERNAL) {
+				if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluded internal: %s\n", rp);
 
 				continue;
 			}
 
-			detals.add(rp);
-		}
+			detals.add(rp);
+		}
 
-		detals.sort(null);
+		detals.sort(null);
 
-		if (ropts.isTrace) {
-			ropts.errStream.printf("\t[DEBUG] Final output: %s\n", detals);
+		if (ropts.isTrace) {
+			ropts.errStream.printf("\t[DEBUG] Final output: %s\n", detals);
 		}
 
-		return detals;
+		return detals;
 	}
 
 	private static String readMultiLine(String lead, Scanner src, ReplOpts ropts,
 			List<ReplError> errs, String typ, IntHolder lno) {
-		String tmp = lead;
+		String tmp = lead;
 
-		if (ropts.isTrace && tmp.endsWith("\\")) 
-			ropts.errStream.printf("\t[TRACE] Starting multi-line parse for %s '%s'\n", typ, tmp);
+		if (ropts.isTrace && tmp.endsWith("\\")) 
+			ropts.errStream.printf("\t[TRACE] Starting multi-line parse for %s '%s'\n", typ, tmp);
 
-		boolean didMulti = tmp.endsWith("\\");
-		while (tmp.endsWith("\\")) {
-			boolean incNL = tmp.endsWith("|\\");
+		boolean didMulti = tmp.endsWith("\\");
+		while (tmp.endsWith("\\")) {
+			boolean incNL = tmp.endsWith("|\\");
 
-			if (!src.hasNextLine()) break;
+			if (!src.hasNextLine()) break;
 
-			String nxt = src.nextLine().trim();
-			lno.incr();
+			String nxt = src.nextLine().trim();
+			lno.incr();
 
-			if (nxt.startsWith("#")) continue;
+			if (nxt.startsWith("#")) continue;
 
-			String nlStr = incNL ? "\n" : "";
+			String nlStr = incNL ? "\n" : "";
 
-			if (tmp.endsWith("\\")) {
-				if (incNL) {
-					tmp = tmp.substring(0, tmp.length() - 2);
+			if (tmp.endsWith("\\")) {
+				if (incNL) {
+					tmp = tmp.substring(0, tmp.length() - 2);
 				} else {
-					tmp = tmp.substring(0, tmp.length() - 1);
+					tmp = tmp.substring(0, tmp.length() - 1);
 				}
 			}
 
-			tmp = String.format("%s%s%s", tmp, nlStr, nxt);
-		}
+			tmp = String.format("%s%s%s", tmp, nlStr, nxt);
+		}
 
-		if (ropts.isTrace && didMulti)
-			ropts.errStream.printf("\t[TRACE] Finished multi-line parse for %s:\n%s\n.\n",
+		if (ropts.isTrace && didMulti)
+			ropts.errStream.printf("\t[TRACE] Finished multi-line parse for %s:\n%s\n.\n",
 					typ, tmp);
 
-		return tmp;
+		return tmp;
 	}
 
 	@Override
 	public String apply(String inp) {
-		return inp.replaceAll(find, replace);
+		if (guard != null) {
+			if (!inp.matches(guard)) return inp;
+		}
+
+		return inp.replaceAll(find, replace);
 	}
 
 	@Override
 	public String toString() {
-		String nameStr = "";
+		String nameStr = "";
 
-		if (!find.equals(name)) nameStr = String.format("(%s)", name);
+		if (!find.equals(name)) nameStr = String.format("(%s)", name);
 
-		return String.format("%ss/(%s)/(%s)/p(%d)", nameStr, find, replace, priority);
+		return String.format("%ss/(%s)/(%s)/p(%d)", nameStr, find, replace, priority);
 	}
 
 	@Override
 	public int compareTo(ReplPair rp) {
-		if (this.priority == rp.priority) return this.lno - rp.lno;
+		if (this.priority == rp.priority) return this.lno - rp.lno;
 
-		return rp.priority - this.priority;
+		return rp.priority - this.priority;
 	}
 	
 	@Override
 	public int hashCode() {
-		final int prime = 31;
-		int result = 1;
-		result = prime * result + ((find == null) ? 0 : find.hashCode());
-		result = prime * result + ((name == null) ? 0 : name.hashCode());
-		result = prime * result + priority;
-		result = prime * result + ((replace == null) ? 0 : replace.hashCode());
-		result = prime * result + stage;
-		return result;
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((find == null) ? 0 : find.hashCode());
+		result = prime * result + ((name == null) ? 0 : name.hashCode());
+		result = prime * result + priority;
+		result = prime * result + ((replace == null) ? 0 : replace.hashCode());
+		result = prime * result + stage;
+		return result;
 	}
 
 	@Override
 	public boolean equals(Object obj) {
-		if (this == obj) return true;
-		if (obj == null) return false;
-		if (getClass() != obj.getClass()) return false;
-		ReplPair other = (ReplPair) obj;
-		if (find == null) {
-			if (other.find != null) return false;
-		} else if (!find.equals(other.find)) return false;
-		if (name == null) {
-			if (other.name != null) return false;
-		} else if (!name.equals(other.name)) return false;
-		if (priority != other.priority) return false;
-		if (replace == null) {
-			if (other.replace != null) return false;
-		} else if (!replace.equals(other.replace)) return false;
-		if (stage != other.stage) return false;
-		return true;
+		if (this == obj) return true;
+		if (obj == null) return false;
+		if (getClass() != obj.getClass()) return false;
+		ReplPair other = (ReplPair) obj;
+		if (find == null) {
+			if (other.find != null) return false;
+		} else if (!find.equals(other.find)) return false;
+		if (name == null) {
+			if (other.name != null) return false;
+		} else if (!name.equals(other.name)) return false;
+		if (priority != other.priority) return false;
+		if (replace == null) {
+			if (other.replace != null) return false;
+		} else if (!replace.equals(other.replace)) return false;
+		if (stage != other.stage) return false;
+		return true;
 	}
 
 	private static String readName(String nam, Scanner scn, List<ReplError> errs,
 			ReplPair rp, ReplOpts ropts, IntHolder lno, IntHolder pno) {
-		ControlledString cs = getControls(nam, errs, ropts, lno, pno, "name");
+		ControlledString cs = getControls(nam, errs, ropts, lno, pno, "name");
 
-		boolean isMulti = ropts.defMulti;
+		boolean isMulti = ropts.defMulti;
 
-		String name = cs.strang;
+		String name = cs.strang;
 
-		if (cs.hasControls()) {
-			for (Control cont : cs.controls) {
-				switch (cont.name) {
+		if (cs.hasControls()) {
+			for (Control cont : cs.controls) {
+				switch (cont.name) {
 					case "NAME":
 					case "N":
-						if (cont.count() != 1) {
-							String errMsg = String.format("One name argument was expected (got %d)",
-									cont.count());
+						if (cont.count() != 1) {
+							String errMsg = String.format("One name argument was expected (got %d)",
+									cont.count());
 
-							errs.add(new ReplError(lno, pno, errMsg, nam));
-						} else {
-							rp.name = cont.get(0);
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+						} else {
+							rp.name = cont.get(0);
 						}
-						break;
+						break;
+					case "GUARD":
+					case "G":
+						if (cont.count() != 1) {
+							String errMsg = String.format("One guard argument was expected (got %d)",
+									cont.count());
+
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+						} else {
+							String pat = cont.get(0);
+
+							try {
+								Pattern.compile(pat);
+							} catch (PatternSyntaxException psex) {
+								String errMsg = String.format("Guard argument '%s' is not a valid regex (%s)",
+										pat, psex.getMessage());
+
+								errs.add(new ReplError(lno, pno, errMsg, nam));
+							}
+
+							rp.guard = cont.get(0);
+						}
+						break;
 					case "PRIORITY":
 					case "PRIOR":
 					case "P":
 						try {
-							if (cont.count() != 1) {
-								String errMsg = String.format("One priority argument was expected (got %d",
-										cont.count());
+							if (cont.count() != 1) {
+								String errMsg = String.format("One priority argument was expected (got %d",
+										cont.count());
 
-								errs.add(new ReplError(lno, pno, errMsg, nam));
-							} else {
-								rp.priority = Integer.parseInt(cont.get(0));
+								errs.add(new ReplError(lno, pno, errMsg, nam));
+							} else {
+								rp.priority = Integer.parseInt(cont.get(0));
 							}
-						} catch (NumberFormatException nfex) {
-							String errMsg = String.format("'%s' is not a valid priority (must be an integer)",
-									cont.get(0));
+						} catch (NumberFormatException nfex) {
+							String errMsg = String.format("'%s' is not a valid priority (must be an integer)",
+									cont.get(0));
 
-							errs.add(new ReplError(lno, pno, errMsg, nam));
-						}
-						break;
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+						}
+						break;
 					case "STAGE":
 					case "S":
 						try {
-							if (cont.count() != 1) {
-								String errMsg = String.format("One stage argument was expected (got %d",
-										cont.count());
-
-								errs.add(new ReplError(lno, pno, errMsg, nam));
-							} else {
-								int tmpStage = Integer.parseInt(cont.get(0));
-								if (tmpStage < 0) {
-									String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
-											cont.get(0));
-									errs.add(new ReplError(lno, pno, errMsg, nam));
-
-									break;
+							if (cont.count() != 1) {
+								String errMsg = String.format("One stage argument was expected (got %d",
+										cont.count());
+
+								errs.add(new ReplError(lno, pno, errMsg, nam));
+							} else {
+								int tmpStage = Integer.parseInt(cont.get(0));
+								if (tmpStage < 0) {
+									String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
+											cont.get(0));
+									errs.add(new ReplError(lno, pno, errMsg, nam));
+
+									break;
 								}
-								rp.stage = tmpStage;
+								rp.stage = tmpStage;
 							}
-						} catch (NumberFormatException nfex) {
-							String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
-									cont.get(0));
+						} catch (NumberFormatException nfex) {
+							String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
+									cont.get(0));
 
-							errs.add(new ReplError(lno, pno, errMsg, nam));
-						}
-						break;
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+						}
+						break;
 					case "MULTITRUE":
 					case "MULTIT":
 					case "MT":
-						isMulti = true;
-						break;
+						isMulti = true;
+						break;
 					case "MULTIFALSE":
 					case "MULTIF":
 					case "MF":
-						isMulti = false;
-						break;
+						isMulti = false;
+						break;
 					case "MULTI":
 					case "M":
-						if (cont.count() != 1) {
-							String errMsg = String.format("One multi-flag argument was expected (got %d",
-									cont.count());
+						if (cont.count() != 1) {
+							String errMsg = String.format("One multi-flag argument was expected (got %d",
+									cont.count());
 
-							errs.add(new ReplError(lno, pno, errMsg, nam));
-						} else {
-							isMulti = Boolean.parseBoolean(cont.get(0));
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+						} else {
+							isMulti = Boolean.parseBoolean(cont.get(0));
 						}
-						break;
+						break;
 					case "INTERNAL":
 					case "INT":
 					case "I":
-						rp.stat = StageStatus.INTERNAL;
-						break;
+						rp.stat = StageStatus.INTERNAL;
+						break;
 					case "EXTERNAL":
 					case "EXT":
 					case "E":
-						rp.stat = StageStatus.EXTERNAL;
-						break;
+						rp.stat = StageStatus.EXTERNAL;
+						break;
 					case "BOTH":
 					case "B":
-						rp.stat = StageStatus.BOTH;
-						break;
+						rp.stat = StageStatus.BOTH;
+						break;
 					default: 
 						{
-							String errMsg = String.format("Unknown control name '%s' for name '%s'",
+							String errMsg = String.format("Unknown control name '%s' for name '%s'",
 									cont.name, nam);
 
-							ReplError erd = new ReplError(lno, pno, errMsg, nam);
+							ReplError erd = new ReplError(lno, pno, errMsg, nam);
 
-							errs.add(erd);
+							errs.add(erd);
 						}
 						break;
 				}
 			}
 
-			name = cs.strang;
+			name = cs.strang;
 		}
 
 		// Multi-line name with a trailer
-		if (isMulti) {
-			String tmp = readMultiLine(name, scn, ropts, errs, "name", lno);
-			if (tmp == null) return null;
-			name = tmp;
+		if (isMulti) {
+			String tmp = readMultiLine(name, scn, ropts, errs, "name", lno);
+			if (tmp == null) return null;
+			name = tmp;
 		}
 
-		return name;
+		return name;
 	}
 
 	private static void readGlobal(String nam, Scanner scn, List<ReplError> errs,
 			ReplOpts ropts, IntHolder lno, IntHolder pno) {
-		ControlledString cs = getControls(nam.substring(1), errs, ropts, lno, pno, "global");
+		ControlledString cs = getControls(nam.substring(1), errs, ropts, lno, pno, "global");
 
-		for (Control cont : cs.controls) {
-			switch (cont.name) {
+		for (Control cont : cs.controls) {
+			switch (cont.name) {
 			case "PRIORITY":
 			case "PRIOR":
 			case "P":
 				try {
-					if (cont.count() != 1) {
-						String errMsg = String.format("Must specify 1 priority (%d specified)",
-								cont.count());
-
-						errs.add(new ReplError(lno, pno, errMsg, nam));
-					} else {
-						int tmp = Integer.parseInt(cont.get(0));
-						ropts.defPrior = tmp;
+					if (cont.count() != 1) {
+						String errMsg = String.format("Must specify 1 priority (%d specified)",
+								cont.count());
+
+						errs.add(new ReplError(lno, pno, errMsg, nam));
+					} else {
+						int tmp = Integer.parseInt(cont.get(0));
+						ropts.defPrior = tmp;
 					}
-				} catch (NumberFormatException nfex) {
-					String errMsg = String.format("'%s' is not a valid priority (must be an integer)",
-							cont.get(0));
+				} catch (NumberFormatException nfex) {
+					String errMsg = String.format("'%s' is not a valid priority (must be an integer)",
+							cont.get(0));
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				}
-				break;
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				}
+				break;
 			case "STAGE":
 			case "S":
 				try {
-					if (cont.count() != 1) {
-						String errMsg = String.format("Must specify 1 stage (%d specified)",
-								cont.count());
+					if (cont.count() != 1) {
+						String errMsg = String.format("Must specify 1 stage (%d specified)",
+								cont.count());
 
-						errs.add(new ReplError(lno, pno, errMsg, nam));
-					} else {
-						int tmpStage = Integer.parseInt(cont.get(0));
+						errs.add(new ReplError(lno, pno, errMsg, nam));
+					} else {
+						int tmpStage = Integer.parseInt(cont.get(0));
 
-						if (tmpStage < 0) {
-							String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
-									cont.get(0));
+						if (tmpStage < 0) {
+							String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
+									cont.get(0));
 
-							errs.add(new ReplError(lno, pno, errMsg, nam));
-							break;
+							errs.add(new ReplError(lno, pno, errMsg, nam));
+							break;
 						}
 
-						ropts.defStage = tmpStage;
+						ropts.defStage = tmpStage;
 					}
-				} catch (NumberFormatException nfex) {
-					String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
-							cont.get(0));
+				} catch (NumberFormatException nfex) {
+					String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",
+							cont.get(0));
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				}
-				break;
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				}
+				break;
 			case "MULTITRUE":
 			case "MULTIT":
 			case "MT":
-				ropts.defMulti = true;
-				break;
+				ropts.defMulti = true;
+				break;
 			case "MULTIFALSE":
 			case "MULTIF":
 			case "MF":
-				ropts.defMulti = false;
-				break;
+				ropts.defMulti = false;
+				break;
 			case "MULTI":
 			case "M":
-				if (cont.count() != 1) {
-					String errMsg = String.format("Must specify 1 multi-flag (%d specified)",
-							cont.count());
+				if (cont.count() != 1) {
+					String errMsg = String.format("Must specify 1 multi-flag (%d specified)",
+							cont.count());
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				} else {
-					ropts.defMulti = Boolean.parseBoolean(cont.get(0));
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				} else {
+					ropts.defMulti = Boolean.parseBoolean(cont.get(0));
 				}
-				break;
+				break;
 			case "INTERNAL":
 			case "INT":
 			case "I":
-				ropts.defStatus = StageStatus.INTERNAL;
-				break;
+				ropts.defStatus = StageStatus.INTERNAL;
+				break;
 			case "EXTERNAL":
 			case "EXT":
 			case "E":
-				ropts.defStatus = StageStatus.EXTERNAL;
-				break;
+				ropts.defStatus = StageStatus.EXTERNAL;
+				break;
 			case "BOTH":
 			case "B":
-				ropts.defStatus = StageStatus.BOTH;
-				break;
+				ropts.defStatus = StageStatus.BOTH;
+				break;
 			case "DEBUGTRUE":
 			case "DEBUGT":
 			case "DT":
-				ropts.isDebug = true;
-				break;
+				ropts.isDebug = true;
+				break;
 			case "DEBUGFALSE":
 			case "DEBUGF":
 			case "DF":
-				ropts.isDebug = false;
-				break;
+				ropts.isDebug = false;
+				break;
 			case "DEBUG":
 			case "D":
-				if (cont.count() != 1) {
-					String errMsg = String.format("Must specify 1 debug flag (%d specified)",
-							cont.count());
+				if (cont.count() != 1) {
+					String errMsg = String.format("Must specify 1 debug flag (%d specified)",
+							cont.count());
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				} else {
-					ropts.isDebug = Boolean.parseBoolean(cont.get(0));
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				} else {
+					ropts.isDebug = Boolean.parseBoolean(cont.get(0));
 				}
-				break;
+				break;
 			case "TRACETRUE":
 			case "TRACET":
 			case "TT":
-				ropts.isTrace = true;
-				break;
+				ropts.isTrace = true;
+				break;
 			case "TRACEFALSE":
 			case "TRACEF":
 			case "TF":
-				ropts.isTrace = false;
-				break;
+				ropts.isTrace = false;
+				break;
 			case "TRACE":
 			case "T":
-				if (cont.count() != 1) {
-					String errMsg = String.format("Must specify 1 trace flag (%d specified)",
-							cont.count());
+				if (cont.count() != 1) {
+					String errMsg = String.format("Must specify 1 trace flag (%d specified)",
+							cont.count());
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				} else {
-					ropts.isTrace = Boolean.parseBoolean(cont.get(0));
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				} else {
+					ropts.isTrace = Boolean.parseBoolean(cont.get(0));
 				}
-				break;
+				break;
 			case "PERFTRUE":
 			case "PERFT":
 			case "PRFT":
-				ropts.isPerf = true;
-				break;
+				ropts.isPerf = true;
+				break;
 			case "PERFFALSE":
 			case "PERFF":
 			case "PRFF":
-				ropts.isPerf = false;
-				break;
+				ropts.isPerf = false;
+				break;
 			case "PERF":
 			case "PRF":
-				if (cont.count() != 1) {
-					String errMsg = String.format("Must specify 1 perf. flag (%d specified)",
-							cont.count());
+				if (cont.count() != 1) {
+					String errMsg = String.format("Must specify 1 perf. flag (%d specified)",
+							cont.count());
 
-					errs.add(new ReplError(lno, pno, errMsg, nam));
-				} else {
-					ropts.isPerf = Boolean.parseBoolean(cont.get(0));
+					errs.add(new ReplError(lno, pno, errMsg, nam));
+				} else {
+					ropts.isPerf = Boolean.parseBoolean(cont.get(0));
 				}
-				break;
+				break;
 			default: 
 				{
-					String msg = String.format("Invalid global control name '%s'", cont.name);
-					ReplError err = new ReplError(lno, pno, msg, nam);
-					errs.add(err);
+					String msg = String.format("Invalid global control name '%s'", cont.name);
+					ReplError err = new ReplError(lno, pno, msg, nam);
+					errs.add(err);
 				}
 				break;
 			}
 
-			if (ropts.isTrace) 
-				ropts.errStream.printf("\t[TRACE] Processed global control '%s'\n", cont);
+			if (ropts.isTrace) 
+				ropts.errStream.printf("\t[TRACE] Processed global control '%s'\n", cont);
 		}
 
-		return;
+		return;
 	}
 	
 	private static ControlledString getControls(String lne, List<ReplError> errs,
-			ReplOpts ropts, IntHolder lno, IntHolder pno, String type) 
-	{
+			ReplOpts ropts, IntHolder lno, IntHolder pno, String type) {
 		try {
-			return ControlledString.parse(lne, new ParseStrings("//", ";", "/", "|"));
-		} catch (IllegalArgumentException iaex) {
-			String msg = "Did not find control terminator (//) in %s where it should be";
-			msg = String.format(msg, type);
+			return ControlledString.parse(lne, new ParseStrings("//", ";", "/", "|"));
+		} catch (IllegalArgumentException iaex) {
+			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);
+			ReplError re = new ReplError(lno, pno, msg, lne);
+			errs.add(re);
 
-			return null;
+			return null;
 		}
 	}
 }
diff --git a/docs/jacoco-ut/bjc.everge/ReplParseException.html b/docs/jacoco-ut/bjc.everge/ReplParseException.html
deleted file mode 100644
index f80f7cb..0000000
--- a/docs/jacoco-ut/bjc.everge/ReplParseException.html
+++ /dev/null
@@ -1 +0,0 @@
-ReplParseException

ReplParseException

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total59 of 12853%6 of 1250%710112724
toString()280%20%224411
toPrintString()246272%4660%4651801
ReplParseException(String)70%n/a112211
ReplParseException(String, List)7100%n/a010301
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplParseException.java.html b/docs/jacoco-ut/bjc.everge/ReplParseException.java.html deleted file mode 100644 index 717bf7f..0000000 --- a/docs/jacoco-ut/bjc.everge/ReplParseException.java.html +++ /dev/null @@ -1,63 +0,0 @@ -ReplParseException.java

ReplParseException.java

package bjc.everge;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ReplParseException extends RuntimeException {
-	/**
-	 * Serialization ID.
-	 */
-	private static final long serialVersionUID = 4752304282380556849L;
-	public List<ReplError> errs;
-
-	public ReplParseException(String msg) {
-		this(msg, new ArrayList<>());
-	}
-
-	public ReplParseException(String msg, List<ReplError> errs) {
-		super(msg);
-
-		this.errs = errs;
-	}
-
-	@Override
-	public String toString() {
-		String errString;
-		if (errs.size() == 0) errString = "An error";
-		else                  errString = "Errors";
-
-		return String.format("%s occured parsing replacement pairs: %s\n%s",
-				errString, getMessage(), errs);
-	}
-
-	public String toPrintString() {
-		StringBuilder errString = new StringBuilder("[ERROR] ");
-
-		if (errs.size() == 0) {
-			errString.append("No specific errors");
-		} else if (errs.size() == 1) {
-			errString.append("An error");
-		} else {
-			errString.append(errs.size());
-			errString.append(" errors");
-		}
-
-		errString.append(" occured parsing replacement pairs:");
-		if (!getMessage().equals("")) {
-			errString.append(" ");
-			errString.append(getMessage());
-		}
-
-		if (errs.size() > 0) {
-			errString.append("\n\t");
-
-			for (ReplError err : errs) {
-				errString.append(err.toPrintString("\t"));
-				errString.append("\n\t");
-			}
-		}
-
-		return errString.toString().trim();
-	}
-}
-
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplSet.html b/docs/jacoco-ut/bjc.everge/ReplSet.html index 1edd220..125ee6b 100644 --- a/docs/jacoco-ut/bjc.everge/ReplSet.html +++ b/docs/jacoco-ut/bjc.everge/ReplSet.html @@ -1 +1 @@ -ReplSet

ReplSet

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total105 of 1050%6 of 60%99242466
addPairs(ReplPair[])260%20%224411
fromFile(String)240%n/a114411
addPairs(List)210%20%225511
apply(String)200%20%225511
ReplSet()80%n/a113311
ReplSet(List)60%n/a113311
\ No newline at end of file +ReplSet

ReplSet

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total105 of 1050%6 of 60%99242466
addPairs(ReplPair[])260%20%224411
fromFile(String)240%n/a114411
addPairs(List)210%20%225511
apply(String)200%20%225511
ReplSet()80%n/a113311
ReplSet(List)60%n/a113311
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/ReplSet.java.html b/docs/jacoco-ut/bjc.everge/ReplSet.java.html index f2f59a6..42da031 100644 --- a/docs/jacoco-ut/bjc.everge/ReplSet.java.html +++ b/docs/jacoco-ut/bjc.everge/ReplSet.java.html @@ -1,12 +1,8 @@ ReplSet.java

ReplSet.java

package bjc.everge;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Scanner;
+import java.util.*;
 
 /**
  * A set of ReplPairs, kept together for easy use
@@ -20,9 +16,9 @@ public class ReplSet {
 	/**
 	 * Create a new blank set of pairs.
 	 */
-	public ReplSet() {
-		parList = new ArrayList<>();
-	}
+	public ReplSet() {
+		parList = new ArrayList<>();
+	}
 
 	/**
 	 * Create a new set of pairs using an existing list of pairs.
@@ -32,18 +28,25 @@ public class ReplSet {
 	 * @param lst
 	 * 		The list of pairs to use.
 	 */
-	public ReplSet(List<ReplPair> lst) {
-		parList = lst;
-	}
+	public ReplSet(List<ReplPair> lst) {
+		parList = lst;
+	}
 
+	/**
+	 * Load a ReplSet from a file.
+	 * @param fName
+	 * 	The file to load the ReplSet from.
+	 * @return A ReplSet, loaded from the file.
+	 * @throws IOException if something goes badly reading it.
+	 */
 	public static ReplSet fromFile(String fName) throws IOException {
-		ReplSet rs = new ReplSet();
+		ReplSet rs = new ReplSet();
 
-		try (FileInputStream fis = new FileInputStream(fName); Scanner scn = new Scanner(fis)) {
-			rs.parList = ReplPair.readList(scn);
+		try (FileInputStream fis = new FileInputStream(fName); Scanner scn = new Scanner(fis)) {
+			rs.parList = ReplPair.readList(scn);
 		}
 
-		return rs;
+		return rs;
 	}
 
 	/**
@@ -53,13 +56,13 @@ public class ReplSet {
 	 * 	The pairs to add to the ReplSet.
 	 */
 	public void addPairs(List<ReplPair> pars) {
-		for (ReplPair par : pars) {
-			parList.add(par);
-		}
+		for (ReplPair par : pars) {
+			parList.add(par);
+		}
 
 		// Resort the pairs into priority order
-		parList.sort(null);
-	}
+		parList.sort(null);
+	}
 
 	/**
 	 * Adds more pairs to the ReplSet.
@@ -68,13 +71,13 @@ public class ReplSet {
 	 * 	The pairs to add to the ReplSet.
 	 */
 	public void addPairs(ReplPair... pars) {
-		for (ReplPair par : pars) {
-			parList.add(par);
+		for (ReplPair par : pars) {
+			parList.add(par);
 		}
 
 		// Resort the pairs into priority order
-		parList.sort(null);
-	}
+		parList.sort(null);
+	}
 
 	/**
 	 * Apply the ReplSet to a string.
@@ -85,13 +88,13 @@ public class ReplSet {
 	 * @return The result of applying the ReplSet.
 	 */
 	public String apply(String val) {
-		String ret = val;
+		String ret = val;
 
-		for (ReplPair par : parList) {
-			ret = par.apply(ret);
-		}
+		for (ReplPair par : parList) {
+			ret = par.apply(ret);
+		}
 
-		return ret;
+		return ret;
 	}
 }
 
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/StringUtils.html b/docs/jacoco-ut/bjc.everge/StringUtils.html index e21d36f..70dd0da 100644 --- a/docs/jacoco-ut/bjc.everge/StringUtils.html +++ b/docs/jacoco-ut/bjc.everge/StringUtils.html @@ -1 +1 @@ -StringUtils

StringUtils

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total190 of 46058%17 of 5468%1630248013
escapeSplit(String, String, String)18726758%173768%1528237801
StringUtils()0%n/a111111
static {...}100%n/a010101
\ No newline at end of file +StringUtils

StringUtils

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total114 of 36768%13 of 4872%1329167215
escapeSplit(String, String, String)11121265%133572%1225156401
StringUtils()30%n/a111111
sliceStringL(String, int, int)20100%n/a010301
sliceString(String, int, int)18100%n/a010301
static {...}3100%n/a010101
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/StringUtils.java.html b/docs/jacoco-ut/bjc.everge/StringUtils.java.html index f1f94d2..f701116 100644 --- a/docs/jacoco-ut/bjc.everge/StringUtils.java.html +++ b/docs/jacoco-ut/bjc.everge/StringUtils.java.html @@ -1,8 +1,6 @@ StringUtils.java

StringUtils.java

package bjc.everge;
 
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 import java.util.regex.Pattern;
 
@@ -11,11 +9,14 @@ import java.util.regex.Pattern;
  *
  * @author Ben Culkin.
  */
-public class StringUtils {
-	public static boolean isDebug = false;
+public class StringUtils {
+	/**
+	 * Is the class in debug mode or not?
+	 */
+	public static boolean isDebug = false;
 
 	/**
-	 * Split a string on every occurance of a string not preceeded by an escape.
+	 * Split a string on every occurrence of a string not preceded by an escape.
 	 *
 	 * @param escape
 	 * 		The escape that stops splitting.
@@ -27,168 +28,191 @@ import java.util.regex.Pattern;
 	 * @return The string split as specified above.
 	 */
 	public static String[] escapeSplit(String escape, String splat, String inp) {
-
 		/*
 		 * Special case some stuffs.
 		 */
-		if (inp == null || inp.equals("")) {
-			// No input
-			return new String[] {inp};
+
+		// No input
+		if (inp == null || inp.equals("")) {
+			return new String[] {inp};
 		}
 
-		if (!inp.contains(splat)) {
-			// Input does not contain any delimiters
-			return new String[] {inp};
+		// Input does not contain any delimiters
+		if (!inp.contains(splat)) {
+			return new String[] {inp};
 		}
 
-		if (escape == null || escape.equals("")) {
-			// No escape, so we can just split normally
-			return inp.split(Pattern.quote(splat));
+		// No escape, so we can just split normally
+		if (escape == null || escape.equals("")) {
+			return inp.split(Pattern.quote(splat));
 		}
 
-		List<String> ret = new ArrayList<>();
+		List<String> ret = new ArrayList<>();
 
-		String wrk = inp;
-		int sidx = wrk.indexOf(splat);
-		int eidx = wrk.indexOf(escape);
+		/*
+		 * Set up working variables
+		 */
+
+		// Copy of parameters
+		String wrk = inp;
 
-		boolean hadEscape = false;
+		// Index of first occurrence of split string
+		int sidx = wrk.indexOf(splat);
+		// Index of first occurrence of escaped string
+		int eidx = wrk.indexOf(escape);
 
-		while (sidx != -1 || eidx != -1) {
-			if (eidx > 0 && eidx < sidx) {
-				if (isDebug) System.err.printf("[TRACE] Considering escape\n");
+		// Was the last thing we saw an escape?
+		// 	This is used to enable the handling of escaping escapes
+		boolean hadEscape = false;
+
+		// As long as there an occurrence of either the split/escape
+		while (sidx != -1 || eidx != -1) {
+			// If there is an escape before a split
+			if (eidx > 0 && eidx < sidx) {
+				if (isDebug) System.err.printf("[TRACE] Considering escape\n");
 
 				/*
 				 * We potentially have an escaped sequence:
 				 * 	- either an escaped split
 				 * 	- or an escaped escape
 				 */
+
 				// Check for an escaped split
-				if (wrk.regionMatches(eidx + escape.length(), splat, 0, splat.length())) {
+				boolean hasEscapedSplit = wrk.startsWith(splat, eidx + escape.length());
+				if (hasEscapedSplit) {
 					// Skip over it
-					int ofst = eidx + splat.length();
+					int ofst = eidx + splat.length();
 
-					// Slice out the escape
-					{
-						String s1 = wrk.substring(0, eidx);
-						String s2 = wrk.substring(eidx + escape.length());
+					wrk = sliceStringL(wrk, eidx, escape.length());
 
-						String s3 = wrk.substring(eidx, eidx + escape.length());
+					// Recalculate indexes
+					sidx = wrk.indexOf(splat,  ofst);
+					eidx = wrk.indexOf(escape, ofst);
 
-						if (isDebug) {
-							System.err.printf("[TRACE] Skip esc. split (%s)/(%s); (%s)\n",
-									s1, s2, s3);
-						}
-
-						wrk = s1 + s2;
+					if (isDebug) {
+						System.err.printf("[TRACE] After esc. split (%s) %d/%d\n",
+								wrk, sidx, eidx);
 					}
 
-					sidx = wrk.indexOf(splat,  ofst);
-					eidx = wrk.indexOf(escape, ofst);
-
-					if (isDebug) {
-						System.err.printf("[TRACE] After esc. split (%s) %d/%d\n",
-								wrk, sidx, eidx);
-					}
-
-					hadEscape = false;
-					continue;
+					// No pending escape
+					hadEscape = false;
+					continue;
 				}
 
 				// Check for an escaped escape
-				if (wrk.regionMatches(eidx + escape.length(), escape, 0, escape.length())) {
+				boolean hasEscapedEscape = wrk.startsWith(escape, eidx + escape.length());
+				if (hasEscapedEscape) {
 					// Skip over it
-					int ofst = eidx + escape.length();
+					int ofst = eidx + escape.length();
 
-					// Slice out the escape
-					{
-						String s1 = wrk.substring(0, eidx);
-						String s2 = wrk.substring(eidx + escape.length());
+					wrk = sliceStringL(wrk, eidx, escape.length());
 
-						String s3 = wrk.substring(eidx, eidx + escape.length());
-						if (isDebug) {
-							System.err.printf("[TRACE] Skip esc. escape (%s)/(%s); (%s)\n",
-								s1, s2, s3);
-						}
+					// Recalculate indexes
+					sidx = wrk.indexOf(splat,  ofst);
+					eidx = wrk.indexOf(escape, ofst);
 
-						wrk = s1 + s2;
+					if (isDebug) {
+						System.err.printf("[TRACE] After esc. escape (%s)/(%s) %d/%d\n",
+								wrk, wrk.substring(ofst), sidx, eidx);
 					}
 
-					sidx = wrk.indexOf(splat,  ofst);
-					eidx = wrk.indexOf(escape, ofst);
-
-					if (isDebug) {
-						System.err.printf("[TRACE] After esc. escape (%s)/(%s) %d/%d\n",
-								wrk, wrk.substring(ofst), sidx, eidx);
-					}
-
-					hadEscape = true;
-					continue;
+					// There's a pending escape
+					hadEscape = true;
+					continue;
 				}
 			}
 
-			boolean hasEscape = false;
-
+			// Calculate whether there is currently an escape
+			boolean hasEscape = false;
 			{
-				boolean tmp = wrk.regionMatches(sidx - escape.length(), escape, 0, escape.length());
+				boolean tmp = wrk.startsWith(escape, sidx - escape.length());
+				// boolean tmp = wrk.regionMatches(lo, escape, 0, escape.length());
 
-				hasEscape = hadEscape ? false : tmp;
+				hasEscape = hadEscape ? false : tmp;
 			}
 
-			while (sidx != -1 && hasEscape) {
-				int oidx = wrk.indexOf(splat, sidx + escape.length());
+			// Handle anything that the pending escape may be applied to
+			while (sidx != -1 && hasEscape) {
+				int oidx = wrk.indexOf(splat, sidx + escape.length());
 
-				if (isDebug) {
-					String s1 = wrk.substring(0, sidx);
-					String s2 = wrk.substring(sidx, sidx + escape.length());
-					String s3 = wrk.substring(sidx + escape.length());
-				}
+				if (oidx == -1) break;
 
-				if (oidx == -1) break;
+				wrk = sliceStringL(wrk, oidx, escape.length());
 
-				{
-					String s1 = wrk.substring(0, oidx);
-					String s2 = wrk.substring(oidx + escape.length());
+				sidx = oidx;
 
-					wrk = s1 + s2;
-				}
-
-				sidx = oidx;
-
-				hasEscape = wrk.regionMatches(sidx - escape.length(), escape, 0, escape.length());
-			}
+				hasEscape = wrk.startsWith(escape, sidx - escape.length());
+			}
 
-			if (sidx == -1) {
-				break;
+			if (sidx == -1) {
+				break;
 			}
 
-			String tmp = wrk.substring(0, sidx);
+			String tmp = wrk.substring(0, sidx);
 
-			if (isDebug) {
-				System.err.printf("[TRACE] Adding (%s) to returned splits; (%s)\n",
-					tmp, wrk.substring(sidx));
+			if (isDebug) {
+				System.err.printf("[TRACE] Adding (%s) to returned splits; (%s)\n",
+					tmp, wrk.substring(sidx));
 			}
 
-			ret.add(tmp);
-			if (!tmp.equals("") && wrk.endsWith(tmp)) {
-				wrk = "";
+			ret.add(tmp);
+			if (!tmp.equals("") && wrk.endsWith(tmp)) {
+				wrk = "";
 			} else {
-				if (wrk.indexOf(splat, sidx) != -1) {
-					wrk = wrk.substring(sidx + splat.length());
+				if (wrk.indexOf(splat, sidx) != -1) {
+					wrk = wrk.substring(sidx + splat.length());
 				} else {
-					wrk = wrk.substring(sidx);
+					wrk = wrk.substring(sidx);
 				}
 			}
 
-			sidx = wrk.indexOf(splat);
-			eidx = wrk.indexOf(escape);
+			sidx = wrk.indexOf(splat);
+			eidx = wrk.indexOf(escape);
 
-			hadEscape = false;
-		}
+			hadEscape = false;
+		}
 
-		if (!wrk.equals("")) ret.add(wrk);
+		if (!wrk.equals("")) ret.add(wrk);
+
+		return ret.toArray(new String[0]);
+	}
+
+	/**
+	 * Slice a substring out of another string.
+	 *
+	 * @param strang
+	 * 	The string to remove a substring from.
+	 * @param lft
+	 * 	The left-side of the substring to remove.
+	 * @param rft
+	 * 	The right-side of the substring to remove.
+	 *
+	 * @return The string, with the substring removed.
+	 */
+	public static String sliceString(String strang, int lft, int rft) {
+		String leftSide  = strang.substring(0, lft);
+		String rightSide = strang.substring(rft);
+
+		return leftSide + rightSide;
+	}
+
+	/**
+	 * Slice a substring out of another string.
+	 *
+	 * @param strang
+	 * 	The string to remove a substring from.
+	 * @param lft
+	 * 	The left-side of the substring to remove.
+	 * @param len
+	 * 	The length of the substring to remove.
+	 *
+	 * @return The string, with the substring removed.
+	 */
+	public static String sliceStringL(String strang, int lft, int len) {
+		String leftSide  = strang.substring(0, lft);
+		String rightSide = strang.substring(lft + len);
 
-		return ret.toArray(new String[0]);
+		return leftSide + rightSide;
 	}
 }
 
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/index.html b/docs/jacoco-ut/bjc.everge/index.html index dbd7838..8de90e0 100644 --- a/docs/jacoco-ut/bjc.everge/index.html +++ b/docs/jacoco-ut/bjc.everge/index.html @@ -1 +1 @@ -bjc.everge

bjc.everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total2,256 of 4,20846%242 of 45947%2063214158522673113
ReplPair94083547%9910551%8313316135521801
Everge53431937%542934%41551241992801
StringUtils19027058%173768%163024801301
ReplOpts1473016%300%171822322301
ControlledString.Control13210143%222250%203121463901
ReplSet1050%60%9924246611
ControlledString7414866%31583%51617443701
ReplParseException596953%6650%71011272401
ReplError577556%5337%595182501
IntHolder2268%n/a265122601
ControlledString.ParseStrings1565%n/a12171201
Everge.InputStatus34100%n/a01040101
StageStatus34100%n/a01040101
\ No newline at end of file +bjc.everge

bjc.everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total2,246 of 4,19046%241 of 46047%2053244178592675113
ReplPair98786346%10011152%8413716937121801
Everge53831937%542934%41551241992801
ReplOpts1473016%300%171822322301
ControlledString.Control13210143%222250%203121463901
StringUtils11425368%133572%132916721501
ReplSet1050%60%9924246611
ControlledString7414466%31583%51617433701
ReplError726045%712%697182501
BadReplParse596953%6650%71011272401
IntHolder2268%n/a265122601
ControlledString.ParseStrings65%n/a12171201
Everge.InputStatus34100%n/a01040101
StageStatus34100%n/a01040101
\ No newline at end of file diff --git a/docs/jacoco-ut/bjc.everge/index.source.html b/docs/jacoco-ut/bjc.everge/index.source.html index 97db308..099940c 100644 --- a/docs/jacoco-ut/bjc.everge/index.source.html +++ b/docs/jacoco-ut/bjc.everge/index.source.html @@ -1 +1 @@ -bjc.everge

bjc.everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total2,256 of 4,20846%242 of 45947%2063214158522673113
ReplPair.java94083547%9910551%8313316135521801
Everge.java53435339%542934%41561242032902
ControlledString.java21426455%253759%2649399771803
StringUtils.java19027058%173768%163024801301
ReplOpts.java1473016%300%171822322301
ReplSet.java1050%60%9924246611
ReplParseException.java596953%6650%71011272401
ReplError.java577556%5337%595182501
IntHolder.java2268%n/a265122601
StageStatus.java34100%n/a01040101
\ No newline at end of file +bjc.everge

bjc.everge

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total2,246 of 4,19046%241 of 46047%2053244178592675113
ReplPair.java98786346%10011152%8413716937121801
Everge.java53835339%542934%41561242032902
ControlledString.java21426054%253759%2649399671803
ReplOpts.java1473016%300%171822322301
StringUtils.java11425368%133572%132916721501
ReplSet.java1050%60%9924246611
ReplError.java726045%712%697182501
BadReplParse.java596953%6650%71011272401
IntHolder.java2268%n/a265122601
StageStatus.java34100%n/a01040101
\ No newline at end of file -- cgit v1.2.3