arturobernalg commented on a change in pull request #727:
URL: https://github.com/apache/commons-lang/pull/727#discussion_r586668513
##########
File path: src/main/java/org/apache/commons/lang3/math/NumberUtils.java
##########
@@ -1715,6 +1715,50 @@ public static boolean isCreatable(final String str) {
return !allowSigns && foundDigit;
}
+ /**
+ * Checks whether the given String is a hex number.
+ *
+ * <p>Valid parameter include hexadecimal marked with the {@code 0x} or
+ * {@code 0X} qualifier.</p>
+ *
+ * <p>{@code Null} and empty String will return {@code false}.</p>
+ *
+ * <pre>
+ * NumberUtils.isHexNumber(null)) = false
+ * NumberUtils.isHexNumber("")) = false
+ * NumberUtils.isHexNumber("0x12345678")) = true
+ * NumberUtils.isHexNumber("0x7fffffffffffffff")) = true
+ * NumberUtils.isHexNumber("0x7FFFFFFFFFFFFFFF")) = true
+ * NumberUtils.isHexNumber("5D0")) = true
+ * NumberUtils.isHexNumber("0x")) = false
+ * </pre>
+ *
+ * @param str the String to check.
+ * @return {@code true} if the string is a hex number.
+ * @since 3.12.1
+ */
+ public static boolean isHexNumber(final String str) {
+ if (StringUtils.isEmpty(str)) {
+ return false;
+ }
+ final char[] chars = str.toCharArray();
+ final int length = chars.length;
+ int i = 1;
+ if (chars[i] == 'x' || chars[i] == 'X') {
+ i = 2;
+ if (i == length) {
+ return false;
+ }
+ }
+ for (; i < chars.length; i++) {
Review comment:
Hi @garydgregory
don't you think this may be complicated the code? are you thinking in a
global solution, implement in isCreatable perhaps?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]