Skip to content

Commit

Permalink
slightly smarter int matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 18, 2021
1 parent 9b03bd8 commit f88b86d
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,20 @@ else if (i + 1 < arg.length() && DOUBLE_SPECIAL_MATCHER.isMatch(arg.charAt(i))
return true;
}

private static final int MIN_LONG_LENGTH = Long.toString(Long.MIN_VALUE).length();
private static final int MAX_LONG_LENGTH = Long.toString(Long.MAX_VALUE).length();

public static boolean matchesInteger(String arg) {
return matchesDouble(arg) && INTEGER_MATCHER.isOnlyMatches(arg);
if (!INTEGER_MATCHER.isOnlyMatches(arg)) {
return false;
}
if (!matchesDouble(arg)) {
return false;
}
char firstChar = arg.charAt(0);
if (arg.length() > ((firstChar == '-' || firstChar == '+') ? MIN_LONG_LENGTH : MAX_LONG_LENGTH)) {
return false;
}
return true;
}
}

0 comments on commit f88b86d

Please sign in to comment.