diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java | 87 | ||||
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java | 25 |
2 files changed, 61 insertions, 51 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java index 8d0715d..03227ed 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java @@ -17,56 +17,55 @@ class DoubleMatcher { */ private static final String Exp = "[eE][+-]?" + Digits; - private static final String fpRegex = "[\\x00-\\x20]*" + // Optional - // leading - // "whitespace" - "[+-]?(" + // Optional sign character - "NaN|" + // "NaN" string - "Infinity|" + // "Infinity" string + private static final String fpRegex = + "[\\x00-\\x20]*" // Optional leading "whitespace" + + "[+-]?(" + // Optional sign character + "NaN|" + // "NaN" string + "Infinity|" + // "Infinity" string - /* - * A decimal floating-point string representing a finite - * positive number without a leading sign has at most - * five basic pieces: Digits . Digits ExponentPart - * FloatTypeSuffix - * - * Since this method allows integer-only strings as - * input in addition to strings of floating-point - * literals, the two sub-patterns below are - * simplifications of the grammar productions from - * section 3.10.2 of The Java™ Language Specification. - */ + /* + * A decimal floating-point string representing a finite + * positive number without a leading sign has at most + * five basic pieces: Digits . Digits ExponentPart + * FloatTypeSuffix + * + * Since this method allows integer-only strings as + * input in addition to strings of floating-point + * literals, the two sub-patterns below are + * simplifications of the grammar productions from + * section 3.10.2 of The Java™ Language Specification. + */ - /* - * Digits ._opt Digits_opt ExponentPart_opt - * FloatTypeSuffix_opt - */ - "(((" + Digits + "(\\.)?(" + Digits + "?)(" + Exp + ")?)|" + + /* + * Digits ._opt Digits_opt ExponentPart_opt + * FloatTypeSuffix_opt + */ + "(((" + Digits + "(\\.)?(" + Digits + "?)(" + Exp + ")?)|" + - /* - * . Digits ExponentPart_opt FloatTypeSuffix_opt - */ - "(\\.(" + Digits + ")(" + Exp + ")?)|" + + /* + * . Digits ExponentPart_opt FloatTypeSuffix_opt + */ + "(\\.(" + Digits + ")(" + Exp + ")?)|" + - /* - * Hexadecimal strings - */ - "((" + - /* - * 0[xX] HexDigits ._opt BinaryExponent - * FloatTypeSuffix_opt - */ - "(0[xX]" + HexDigits + "(\\.)?)|" + + /* + * Hexadecimal strings + */ + "((" + + /* + * 0[xX] HexDigits ._opt BinaryExponent + * FloatTypeSuffix_opt + */ + "(0[xX]" + HexDigits + "(\\.)?)|" + - /* - * 0[xX] HexDigits_opt . HexDigits BinaryExponent - * FloatTypeSuffix_opt - */ - "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + + /* + * 0[xX] HexDigits_opt . HexDigits BinaryExponent + * FloatTypeSuffix_opt + */ + "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + - ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"; // Optional - // trailing - // "whitespace" + ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"; // Optional + // trailing + // "whitespace" public static final Pattern floatingLiteral = Pattern.compile("\\A" + fpRegex + "\\Z"); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java index 25b1e03..9da457e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java @@ -11,8 +11,12 @@ public class NeoTokenSplitter { /* * This string is a format template for the delimiter matching regex * - * It does two things 1. Match the provided delimiter by positive - * lookahead 2. Match the provided delimiter by positive lookbehind + * It does two things: + * + * <ol> + * <li> Match to the left of the provided delimiter by positive lookahead </li> + * <li> Match to the right of the provided delimiter by positive lookbehind </li> + * </ol> * * Thus, it will only match in places where the delimiter is, but won't * actually match the delimiter, leaving split to put it into the stream @@ -29,9 +33,17 @@ public class NeoTokenSplitter { */ private static String WITH_MULTI_DELIM = "((?<=%1$s+)(?!%1$s)|(?<!%1$s)(?=%1$s+))"; + /* + * These represent the internal state of the splitter. + */ private StringBuilder currPatt; private StringBuilder currExclusionPatt; + /* + * These represent the external state of the splitter. + * + * Compilation causes internal to become external. + */ private Pattern compPatt; private Pattern exclusionPatt; @@ -78,10 +90,10 @@ public class NeoTokenSplitter { */ public void addDelimiter(String delim) { String quoteDelim = Pattern.quote(delim); - String delimPat = String.format(WITH_DELIM, quoteDelim); + String delimPat = String.format(WITH_DELIM, quoteDelim); if(currPatt == null) { - currPatt = new StringBuilder(); + currPatt = new StringBuilder(); currExclusionPatt = new StringBuilder(); currPatt.append("(?:" + delimPat + ")"); @@ -105,7 +117,7 @@ public class NeoTokenSplitter { String delimPat = String.format(WITH_MULTI_DELIM, "(?:" + delim + ")"); if(currPatt == null) { - currPatt = new StringBuilder(); + currPatt = new StringBuilder(); currExclusionPatt = new StringBuilder(); currPatt.append("(?:" + delimPat + ")"); @@ -133,14 +145,13 @@ public class NeoTokenSplitter { currExclusionPatt.append("|(?:" + delim + ")"); } } - /** * Compiles the current set of delimiters to a pattern. * * Makes this splitter ready to use. */ public void compile() { - compPatt = Pattern.compile(currPatt.toString()); + compPatt = Pattern.compile(currPatt.toString()); exclusionPatt = Pattern.compile(currExclusionPatt.toString()); } } |
