mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Consolidate hex string utils
Change-Id: Id4f4a287e3a2790b22bff7ad4a4617bf2ee82884
This commit is contained in:
parent
8aaae56cf6
commit
3894a5599b
@ -370,12 +370,19 @@ public final class StringUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hex string to byte array. The string length must be an even number.
|
||||
*/
|
||||
@UsedForTesting
|
||||
public static byte[] hexStringToByteArray(String hexString) {
|
||||
if (TextUtils.isEmpty(hexString)) {
|
||||
return null;
|
||||
}
|
||||
final int N = hexString.length();
|
||||
if (N % 2 != 0) {
|
||||
throw new NumberFormatException("Input hex string length must be an even number."
|
||||
+ " Length = " + N);
|
||||
}
|
||||
final byte[] bytes = new byte[N / 2];
|
||||
for (int i = 0; i < N; i += 2) {
|
||||
bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
|
||||
|
Loading…
Reference in New Issue
Block a user