summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-04-06 16:18:22 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-04-06 16:18:22 -0400
commitb912d84b1afe05e5f079bd6edef2f0d74020f9aa (patch)
treea090a3aa65b2f3f93f4b6659a96bfc541d4463b9
parent0be891100df83544c89651c815105832e3e11eb9 (diff)
More properties
-rw-r--r--BJC-Utils2/data/formats.sprop9
-rw-r--r--BJC-Utils2/data/regexes.sprop9
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java40
3 files changed, 27 insertions, 31 deletions
diff --git a/BJC-Utils2/data/formats.sprop b/BJC-Utils2/data/formats.sprop
index bdd9286..ba54208 100644
--- a/BJC-Utils2/data/formats.sprop
+++ b/BJC-Utils2/data/formats.sprop
@@ -5,7 +5,14 @@
####################################################
## Format the three types of string escapes into a valid pattern.
+## The three types are:
+## 1) Short escapes.
+## 2) Octal escapes.
+## 3) Unicode escapes.
stringEscape \\(%1$s|%2$s|%3$s)
-## Format the parts of a regex into one that matches java-style double-quoted strings
+## Format the parts of a regex into one that matches java-style double-quoted strings.
+## The parts are:
+## 1) Anything that's not a possible escape sequence or quote.
+## 2) A possible escape sequence.
doubleQuotes ("(%1$s|%2$s)*") \ No newline at end of file
diff --git a/BJC-Utils2/data/regexes.sprop b/BJC-Utils2/data/regexes.sprop
index bece4d3..6c40e67 100644
--- a/BJC-Utils2/data/regexes.sprop
+++ b/BJC-Utils2/data/regexes.sprop
@@ -15,5 +15,10 @@ unicodeStringEscape u[0-9a-fA-F]{4}
## Match an unescaped quote in a string.
unescapedQuote (?<!\\)\"
-## Match characters that aren't escapes.
-nonStringEscape [^\\\"]+ \ No newline at end of file
+## Match one or more characters that aren't part of an escape or a quote.
+nonStringEscape [^\\\"]+
+
+##################################
+# Miscellaneous validation regexes
+##################################
+intLiteral \A[+\-]\d+\Z \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java
index 065aa2b..0ec00ee 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java
@@ -16,39 +16,23 @@ import static bjc.utils.PropertyDB.applyFormat;
*
*/
public class TokenUtils {
- /*
- * This regex matches potential single character escape sequences.
- */
- private static Pattern possibleEscape = getCompiledRegex("possibleStringEscape");
+ private static String possibleEscapeString = getRegex("possibleStringEscape");
+
+ private static Pattern possibleEscapePatt = Pattern.compile(possibleEscapeString);
private static String shortEscape = getRegex("shortFormStringEscape");
private static String octalEscape = getRegex("octalStringEscape");
private static String unicodeEscape = getRegex("unicodeStringEscape");
- /*
- * This regex matches java-style string escapes
- */
private static String escapeString = applyFormat("stringEscape", shortEscape, octalEscape, unicodeEscape);
private static Pattern escapePatt = Pattern.compile(escapeString);
- /*
- * The regular expression does the following, making sure to capture the
- * string contents.
- *
- * Match one or more characters that aren't quotes or slashes.
- *
- * Match escape sequences.
- *
- * Match all of those things zero or more times, followed by a closing
- * quote
- */
- private static Pattern doubleQuotePatt = Pattern
- .compile("(\"(" + getRegex("nonEscape") + "|" + escapeString + ")*\")");
+ private static String doubleQuoteString = applyFormat("doubleQuotes", getRegex("nonEscape"),
+ possibleEscapeString);
+
+ private static Pattern doubleQuotePatt = Pattern.compile(doubleQuoteString);
- /*
- * This regular expression matches non-escaped quotes.
- */
private static Pattern quotePatt = getCompiledRegex("unescapedQuote");
/**
@@ -95,8 +79,8 @@ public class TokenUtils {
mt.appendReplacement(work, "");
/*
- * Add the string preceeeding the double-quoted string
- * and the double-quoted string to the list.
+ * Add the string preceding the double-quoted string and
+ * the double-quoted string to the list.
*/
res.add(work.toString());
res.add(mt.group(1));
@@ -149,7 +133,7 @@ public class TokenUtils {
StringBuffer work = new StringBuffer();
- Matcher possibleEscapeFinder = possibleEscape.matcher(inp);
+ Matcher possibleEscapeFinder = possibleEscapePatt.matcher(inp);
Matcher escapeFinder = escapePatt.matcher(inp);
while(possibleEscapeFinder.find()) {
@@ -254,7 +238,7 @@ public class TokenUtils {
return DoubleMatcher.floatingLiteral.matcher(inp).matches();
}
- private static Pattern intLitPattern = Pattern.compile("\\A[+\\-]?\\d+\\Z");
+ private static Pattern intLitPattern = getCompiledRegex("intLiteral");
/**
* Check if a given string would be successfully converted to a integer
@@ -270,4 +254,4 @@ public class TokenUtils {
public static boolean isInt(String inp) {
return intLitPattern.matcher(inp).matches();
}
-}
+} \ No newline at end of file