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/StringUtils.java.html | 242 +++++++++++++----------- 1 file changed, 133 insertions(+), 109 deletions(-) (limited to 'docs/jacoco-ut/bjc.everge/StringUtils.java.html') 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 -- cgit v1.2.3