diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils/TokenUtils.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/parserutils/TokenUtils.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java index 860bbdf..20c8ed2 100644 --- a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java +++ b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java @@ -5,6 +5,7 @@ import static bjc.utils.misc.PropertyDB.getCompiledRegex; import static bjc.utils.misc.PropertyDB.getRegex; import java.util.*; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,6 +59,8 @@ public class TokenUtils { private static Pattern doubleQuotePatt = Pattern.compile(rDoubleQuoteString); private static Pattern quotePatt = getCompiledRegex("unescapedQuote"); + + private static Map<String, Pattern> SUFFIX_MAP = new HashMap<>(); /* This may do something. */ // private static Pattern intLitPattern = getCompiledRegex("intLiteral"); @@ -296,7 +299,24 @@ public class TokenUtils { public static boolean isDouble(final String inp) { return DoubleMatcher.doubleLiteral.matcher(inp).matches(); } - + + /** + * Check if a given string would be successfully converted to a double by + * {@link Double#parseDouble(String)} if a given suffix was removed. + * + * @param inp + * The string to check. + * @param suffix + * The suffix to remove + * @return Whether the string is a valid double or not. + */ + public static boolean isSuffixedDouble(final String inp, final String suffix) { + Function<String, Pattern> patInit; + patInit = (String sfx) -> Pattern.compile("\\A" + DoubleMatcher.rawDouble + suffix + "\\Z"); + + return SUFFIX_MAP.computeIfAbsent(suffix, patInit).matcher(inp).matches(); + } + /** * Check if a given string would be successfully converted to a integer by * {@link Integer#parseInt(String)}. |
