8251989: Hex formatting and parsing utility

Reviewed-by: tvaleev, chegar, naoto, darcy
This commit is contained in:
Roger Riggs 2020-12-16 20:29:49 +00:00
parent efd61c6f53
commit aa9c136d67
14 changed files with 1921 additions and 167 deletions

View file

@ -37,6 +37,7 @@ import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import java.util.HexFormat;
import sun.nio.cs.UTF_8;
@ -47,6 +48,8 @@ import sun.nio.cs.UTF_8;
public final class ParseUtil {
private static final HexFormat HEX_UPPERCASE = HexFormat.of().withUpperCase();
private ParseUtil() {}
/**
@ -515,15 +518,9 @@ public final class ParseUtil {
}
}
private static final char[] hexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
private static void appendEscape(StringBuilder sb, byte b) {
sb.append('%');
sb.append(hexDigits[(b >> 4) & 0x0f]);
sb.append(hexDigits[(b >> 0) & 0x0f]);
HEX_UPPERCASE.toHexDigits(sb, b);
}
// Tell whether the given character is permitted by the given mask pair