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