mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
98307df486
commit
e85bd4ada4
@ -31,20 +31,20 @@ public class HexUtil {
|
||||
* @return 是否为16进制
|
||||
*/
|
||||
public static boolean isHexNumber(final String value) {
|
||||
final int index = (value.startsWith("-") ? 1 : 0);
|
||||
if (value.startsWith("0x", index) || value.startsWith("0X", index) || value.startsWith("#", index)) {
|
||||
int index = (value.startsWith("-") ? 1 : 0);
|
||||
if (value.startsWith("0x", index) || value.startsWith("0X", index)) {
|
||||
index += 2;
|
||||
} else if (value.startsWith("#", index)) {
|
||||
index ++;
|
||||
}
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
Long.decode(value);
|
||||
new BigInteger(value.substring(index), 16);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- encode
|
||||
|
||||
/**
|
||||
|
@ -40,9 +40,16 @@ public class HexUtilTest {
|
||||
|
||||
@Test
|
||||
public void isHexNumberTest() {
|
||||
final String a = "0x3544534F444";
|
||||
final boolean isHex = HexUtil.isHexNumber(a);
|
||||
Assert.assertTrue(isHex);
|
||||
String a = "0x3544534F444";
|
||||
Assert.assertTrue(HexUtil.isHexNumber(a));
|
||||
|
||||
// https://gitee.com/dromara/hutool/issues/I62H7K
|
||||
a = "0x0000000000000001158e460913d00000";
|
||||
Assert.assertTrue(HexUtil.isHexNumber(a));
|
||||
|
||||
// 错误的
|
||||
a = "0x0000001000T00001158e460913d00000";
|
||||
Assert.assertFalse(HexUtil.isHexNumber(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user