MCPcopy Create free account
hub / github.com/antlr/codebuff / fromString

Method fromString

output/java_guava/1.4.19/HashCode.java:360–370  ·  view source on GitHub ↗

Creates a HashCode from a hexadecimal (base 16) encoded string. The string must be at least 2 characters long, and contain only valid, lower-cased hexadecimal characters. This method accepts the exact format generated by #toString. If you require more lenient {@code base

(String string)

Source from the content-addressed store, hash-verified

358
359
360 public static HashCode fromString(String string) {
361 checkArgument(string.length() >= 2, "input string (%s) must have at least 2 characters", string);
362 checkArgument(string.length() % 2 == 0, "input string (%s) must have an even number of characters", string);
363 byte[] bytes = new byte[string.length() / 2];
364 for (int i = 0; i < string.length(); i += 2) {
365 int ch1 = decode(string.charAt(i)) << 4;
366 int ch2 = decode(string.charAt(i + 1));
367 bytes[i / 2] = (byte) (ch1 + ch2);
368 }
369 return fromBytesNoCopy(bytes);
370 }
371
372 private static int decode(char ch) {
373 if (ch >= '0' && ch <= '9') {

Callers

nothing calls this directly

Calls 4

decodeMethod · 0.95
fromBytesNoCopyMethod · 0.95
checkArgumentMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected