public static bool IsValid(string percentEncodedBytes) { if (percentEncodedBytes.Length != 3) { return(false); } if (percentEncodedBytes[0] != '\u0025') { return(false); } return(CodePoints.IsAsciiHexDigit(percentEncodedBytes[1]) && CodePoints.IsAsciiHexDigit(percentEncodedBytes[2])); }
public static byte[] DecodePercent(byte[] input) { List <byte> output = new List <byte>(); for (int i = 0; i < input.Length; i++) { if (input[i] != '\x25') { output.Add(input[i]); } else if (!(input.Length > i + 2 && CodePoints.IsAsciiHexDigit(input[i + 1]) && CodePoints.IsAsciiHexDigit(input[i + 2]))) { output.Add(input[i]); } else { char bytePoint = HexCharsToValue(input[i + 1], input[i + 2]); output.Add(Encoding.UTF8.GetBytes(new char[] { bytePoint })[0]); i += 2; } } return(output.ToArray()); }
public static bool InC0EncodeSet(char input) { return(CodePoints.IsC0Control(input) || input > '\u007e'); }